From 087e6617d369ed8f66518502802dde875c89dc8a Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Mon, 29 Apr 2019 18:43:23 +0200 Subject: [PATCH] using a proper displayLabel for the parent SepaMandate->Customer (HOWTO) Unfortunately without a test for the HTML template changes of the Angular components because these seem to come only with Protractor, which we had not configured in JHipster. --- .../hsadminng/service/SepaMandateService.java | 8 +++++++- .../hsadminng/service/dto/SepaMandateDTO.java | 12 ++++++------ .../service/mapper/SepaMandateMapper.java | 15 +++++++++++---- .../sepa-mandate-detail.component.html | 3 ++- .../sepa-mandate-update.component.html | 2 +- .../sepa-mandate/sepa-mandate.component.html | 4 ++-- .../webapp/app/shared/model/sepa-mandate.model.ts | 4 ++-- .../service/dto/SepaMandateDTOIntTest.java | 5 +++-- .../service/dto/SepaMandateDTOUnitTest.java | 6 +++--- .../web/rest/SepaMandateResourceIntTest.java | 2 +- 10 files changed, 38 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/hostsharing/hsadminng/service/SepaMandateService.java b/src/main/java/org/hostsharing/hsadminng/service/SepaMandateService.java index dc954647..0f0f33ae 100644 --- a/src/main/java/org/hostsharing/hsadminng/service/SepaMandateService.java +++ b/src/main/java/org/hostsharing/hsadminng/service/SepaMandateService.java @@ -11,6 +11,7 @@ import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import javax.persistence.EntityManager; import java.util.Optional; /** @@ -22,11 +23,14 @@ public class SepaMandateService implements IdToDtoResolver { private final Logger log = LoggerFactory.getLogger(SepaMandateService.class); + private final EntityManager em; + private final SepaMandateRepository sepaMandateRepository; private final SepaMandateMapper sepaMandateMapper; - public SepaMandateService(SepaMandateRepository sepaMandateRepository, SepaMandateMapper sepaMandateMapper) { + public SepaMandateService(final EntityManager em, final SepaMandateRepository sepaMandateRepository, final SepaMandateMapper sepaMandateMapper) { + this.em = em; this.sepaMandateRepository = sepaMandateRepository; this.sepaMandateMapper = sepaMandateMapper; } @@ -41,6 +45,8 @@ public class SepaMandateService implements IdToDtoResolver { log.debug("Request to save SepaMandate : {}", sepaMandateDTO); SepaMandate sepaMandate = sepaMandateMapper.toEntity(sepaMandateDTO); sepaMandate = sepaMandateRepository.save(sepaMandate); + em.flush(); + em.refresh(sepaMandate); return sepaMandateMapper.toDto(sepaMandate); } diff --git a/src/main/java/org/hostsharing/hsadminng/service/dto/SepaMandateDTO.java b/src/main/java/org/hostsharing/hsadminng/service/dto/SepaMandateDTO.java index 7bf86a89..81f51a8e 100644 --- a/src/main/java/org/hostsharing/hsadminng/service/dto/SepaMandateDTO.java +++ b/src/main/java/org/hostsharing/hsadminng/service/dto/SepaMandateDTO.java @@ -59,7 +59,7 @@ public class SepaMandateDTO implements AccessMappings, FluentBuilder { @Mapping(source = "customer.id", target = "customerId") - @Mapping(source = "customer.prefix", target = "customerPrefix") + @Mapping(target = "customerDisplayLabel", ignore = true) SepaMandateDTO toDto(SepaMandate sepaMandate); + @AfterMapping + default void setDisplayLabels(final @MappingTarget SepaMandateDTO dto, final SepaMandate entity) { + dto.setCustomerDisplayLabel(CustomerMapper.displayLabel(entity.getCustomer())); + } + @Mapping(source = "customerId", target = "customer") SepaMandate toEntity(SepaMandateDTO sepaMandateDTO); diff --git a/src/main/webapp/app/entities/sepa-mandate/sepa-mandate-detail.component.html b/src/main/webapp/app/entities/sepa-mandate/sepa-mandate-detail.component.html index af5b3bf5..31330485 100644 --- a/src/main/webapp/app/entities/sepa-mandate/sepa-mandate-detail.component.html +++ b/src/main/webapp/app/entities/sepa-mandate/sepa-mandate-detail.component.html @@ -37,6 +37,7 @@
{{sepaMandate.lastUsedDate}}
+
Remark
{{sepaMandate.remark}} @@ -44,7 +45,7 @@
Customer
diff --git a/src/main/webapp/app/entities/sepa-mandate/sepa-mandate-update.component.html b/src/main/webapp/app/entities/sepa-mandate/sepa-mandate-update.component.html index 507750c8..10a4d11e 100644 --- a/src/main/webapp/app/entities/sepa-mandate/sepa-mandate-update.component.html +++ b/src/main/webapp/app/entities/sepa-mandate/sepa-mandate-update.component.html @@ -124,7 +124,7 @@
diff --git a/src/main/webapp/app/entities/sepa-mandate/sepa-mandate.component.html b/src/main/webapp/app/entities/sepa-mandate/sepa-mandate.component.html index 2fca9893..a6c693d3 100644 --- a/src/main/webapp/app/entities/sepa-mandate/sepa-mandate.component.html +++ b/src/main/webapp/app/entities/sepa-mandate/sepa-mandate.component.html @@ -24,7 +24,7 @@ Valid Until Date Last Used Date Remark - Customer + Customer @@ -42,7 +42,7 @@ {{sepaMandate.remark}} diff --git a/src/main/webapp/app/shared/model/sepa-mandate.model.ts b/src/main/webapp/app/shared/model/sepa-mandate.model.ts index 5edb606f..57aa32b4 100644 --- a/src/main/webapp/app/shared/model/sepa-mandate.model.ts +++ b/src/main/webapp/app/shared/model/sepa-mandate.model.ts @@ -11,7 +11,7 @@ export interface ISepaMandate { validUntilDate?: Moment; lastUsedDate?: Moment; remark?: string; - customerPrefix?: string; + customerDisplayLabel?: string; customerId?: number; } @@ -27,7 +27,7 @@ export class SepaMandate implements ISepaMandate { public validUntilDate?: Moment, public lastUsedDate?: Moment, public remark?: string, - public customerPrefix?: string, + public customerDisplayLabel?: string, public customerId?: number ) {} } diff --git a/src/test/java/org/hostsharing/hsadminng/service/dto/SepaMandateDTOIntTest.java b/src/test/java/org/hostsharing/hsadminng/service/dto/SepaMandateDTOIntTest.java index 28f706e8..648ff43b 100644 --- a/src/test/java/org/hostsharing/hsadminng/service/dto/SepaMandateDTOIntTest.java +++ b/src/test/java/org/hostsharing/hsadminng/service/dto/SepaMandateDTOIntTest.java @@ -57,6 +57,7 @@ public class SepaMandateDTOIntTest { private static final Integer SOME_CUSTOMER_REFERENCE = 10001; private static final String SOME_CUSTOMER_PREFIX = "abc"; private static final String SOME_CUSTOMER_NAME = "Some Customer Name"; + private static final String SOME_CUSTOMER_DISPLAY_LABEL = "Some Customer Name [10001:abc]"; private static final Customer SOME_CUSTOMER = new Customer().id(SOME_CUSTOMER_ID) .reference(SOME_CUSTOMER_REFERENCE).prefix(SOME_CUSTOMER_PREFIX).name(SOME_CUSTOMER_NAME); @@ -164,7 +165,7 @@ public class SepaMandateDTOIntTest { expected.setId(SOME_SEPA_MANDATE_ID); expected.setCustomerId(SOME_CUSTOMER_ID); expected.setRemark("Updated Remark"); - expected.setCustomerPrefix(SOME_CUSTOMER_PREFIX); + expected.setCustomerDisplayLabel(SOME_CUSTOMER_DISPLAY_LABEL); assertThat(actual).isEqualToIgnoringGivenFields(expected, "displayLabel"); } @@ -183,7 +184,7 @@ public class SepaMandateDTOIntTest { .withFieldValueIfPresent("lastUsedDate", Objects.toString(dto.getLastUsedDate())) .withFieldValueIfPresent("remark", dto.getRemark()) .withFieldValueIfPresent("customerId", dto.getCustomerId()) - .withFieldValue("customerPrefix", dto.getCustomerPrefix()) + .withFieldValue("customerDisplayLabel", dto.getCustomerDisplayLabel()) .toString(); } } diff --git a/src/test/java/org/hostsharing/hsadminng/service/dto/SepaMandateDTOUnitTest.java b/src/test/java/org/hostsharing/hsadminng/service/dto/SepaMandateDTOUnitTest.java index aa3a06da..d0db7861 100644 --- a/src/test/java/org/hostsharing/hsadminng/service/dto/SepaMandateDTOUnitTest.java +++ b/src/test/java/org/hostsharing/hsadminng/service/dto/SepaMandateDTOUnitTest.java @@ -40,7 +40,7 @@ public class SepaMandateDTOUnitTest extends AccessMappingsUnitTestBase