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.
This commit is contained in:
Michael Hoennig 2019-04-29 18:43:23 +02:00
parent 2980103764
commit 087e6617d3
10 changed files with 38 additions and 23 deletions

View File

@ -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<SepaMandateDTO> {
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<SepaMandateDTO> {
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);
}

View File

@ -59,7 +59,7 @@ public class SepaMandateDTO implements AccessMappings, FluentBuilder<SepaMandate
private Long customerId;
@AccessFor(update = Role.IGNORED, read = {Role.CONTRACTUAL_CONTACT, Role.FINANCIAL_CONTACT})
private String customerPrefix;
private String customerDisplayLabel;
public Long getId() {
return id;
@ -149,12 +149,12 @@ public class SepaMandateDTO implements AccessMappings, FluentBuilder<SepaMandate
this.customerId = customerId;
}
public String getCustomerPrefix() {
return customerPrefix;
public String getCustomerDisplayLabel() {
return customerDisplayLabel;
}
public void setCustomerPrefix(String customerPrefix) {
this.customerPrefix = customerPrefix;
public void setCustomerDisplayLabel(String customerDisplayLabel) {
this.customerDisplayLabel = customerDisplayLabel;
}
@Override
@ -192,7 +192,7 @@ public class SepaMandateDTO implements AccessMappings, FluentBuilder<SepaMandate
", lastUsedDate='" + getLastUsedDate() + "'" +
", remark='" + getRemark() + "'" +
", customer=" + getCustomerId() +
", customerPrefix='" + getCustomerPrefix() + "'" +
", customerDisplayLabel='" + getCustomerDisplayLabel() + "'" +
"}";
}

View File

@ -1,9 +1,11 @@
package org.hostsharing.hsadminng.service.mapper;
import org.hostsharing.hsadminng.domain.*;
import org.hostsharing.hsadminng.domain.SepaMandate;
import org.hostsharing.hsadminng.service.dto.SepaMandateDTO;
import org.mapstruct.*;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
/**
* Mapper for the entity SepaMandate and its DTO SepaMandateDTO.
@ -12,9 +14,14 @@ import org.mapstruct.*;
public interface SepaMandateMapper extends EntityMapper<SepaMandateDTO, SepaMandate> {
@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);

View File

@ -37,6 +37,7 @@
<dd>
<span>{{sepaMandate.lastUsedDate}}</span>
</dd>
</dd>
<dt><span jhiTranslate="hsadminNgApp.sepaMandate.remark">Remark</span></dt>
<dd>
<span>{{sepaMandate.remark}}</span>
@ -44,7 +45,7 @@
<dt><span jhiTranslate="hsadminNgApp.sepaMandate.customer">Customer</span></dt>
<dd>
<div *ngIf="sepaMandate.customerId">
<a [routerLink]="['/customer', sepaMandate.customerId, 'view']">{{sepaMandate.customerPrefix}}</a>
<a [routerLink]="['/customer', sepaMandate.customerId, 'view']">{{sepaMandate.customerDisplayLabel}}</a>
</div>
</dd>
</dl>

View File

@ -124,7 +124,7 @@
<label class="form-control-label" jhiTranslate="hsadminNgApp.sepaMandate.customer" for="field_customer">Customer</label>
<select class="form-control" id="field_customer" name="customer" [(ngModel)]="sepaMandate.customerId" required>
<option *ngIf="!editForm.value.customer" [ngValue]="null" selected></option>
<option [ngValue]="customerOption.id" *ngFor="let customerOption of customers; trackBy: trackCustomerById">{{customerOption.prefix}}</option>
<option [ngValue]="customerOption.id" *ngFor="let customerOption of customers; trackBy: trackCustomerById">{{customerOption.displayLabel}}</option>
</select>
</div>
<div [hidden]="!(editForm.controls.customer?.dirty && editForm.controls.customer?.invalid)">

View File

@ -24,7 +24,7 @@
<th jhiSortBy="validUntilDate"><span jhiTranslate="hsadminNgApp.sepaMandate.validUntilDate">Valid Until Date</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="lastUsedDate"><span jhiTranslate="hsadminNgApp.sepaMandate.lastUsedDate">Last Used Date</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="remark"><span jhiTranslate="hsadminNgApp.sepaMandate.remark">Remark</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="customerPrefix"><span jhiTranslate="hsadminNgApp.sepaMandate.customer">Customer</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="customerDisplayLabel"><span jhiTranslate="hsadminNgApp.sepaMandate.customer">Customer</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th></th>
</tr>
</thead>
@ -42,7 +42,7 @@
<td>{{sepaMandate.remark}}</td>
<td>
<div *ngIf="sepaMandate.customerId">
<a [routerLink]="['../customer', sepaMandate.customerId , 'view' ]" >{{sepaMandate.customerPrefix}}</a>
<a [routerLink]="['../customer', sepaMandate.customerId , 'view' ]" >{{sepaMandate.customerDisplayLabel}}</a>
</div>
</td>
<td class="text-right">

View File

@ -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
) {}
}

View File

@ -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();
}
}

View File

@ -40,7 +40,7 @@ public class SepaMandateDTOUnitTest extends AccessMappingsUnitTestBase<SepaManda
"validUntilDate", "revokationDocumentDate");
readAccessFor(SepaMandateDTO.class, Role.CONTRACTUAL_CONTACT).shouldBeExactlyFor(
"grantingDocumentDate", "bic", "id", "validUntilDate", "customerId", "validFromDate", "iban",
"revokationDocumentDate", "customerPrefix", "lastUsedDate", "reference");
"revokationDocumentDate", "customerDisplayLabel", "lastUsedDate", "reference");
}
@Test
@ -72,7 +72,7 @@ public class SepaMandateDTOUnitTest extends AccessMappingsUnitTestBase<SepaManda
dto.setBic("BIC1234");
dto.setRemark("Some Remark");
dto.setCustomerId(parentId);
dto.setCustomerPrefix("abc");
dto.setCustomerDisplayLabel("abc");
return dto;
}
@ -90,7 +90,7 @@ public class SepaMandateDTOUnitTest extends AccessMappingsUnitTestBase<SepaManda
dto.setBic(RandomStringUtils.randomAlphanumeric(10).toUpperCase());
dto.setRemark(RandomStringUtils.randomAlphanumeric(20).toUpperCase());
dto.setCustomerId(parentId);
dto.setCustomerPrefix(RandomStringUtils.randomAlphabetic(3).toLowerCase());
dto.setCustomerDisplayLabel(RandomStringUtils.randomAlphabetic(3).toLowerCase());
return dto;
}
}

View File

@ -179,7 +179,7 @@ public class SepaMandateResourceIntTest {
// Create the SepaMandate
SepaMandateDTO sepaMandateDTO = sepaMandateMapper.toDto(sepaMandate);
sepaMandateDTO.setCustomerPrefix(null);
sepaMandateDTO.setCustomerDisplayLabel(null);
sepaMandateDTO.setRemark(null);
sepaMandateDTO.setRevokationDocumentDate(null);
sepaMandateDTO.setLastUsedDate(null);