better display labels and less columns in tables (deliberately not yet in SepaMandate*)

This commit is contained in:
Michael Hoennig 2019-04-26 22:11:49 +02:00
parent a86e4d7afb
commit d81b71cd3a
31 changed files with 320 additions and 118 deletions

View File

@ -4,6 +4,7 @@ import org.hostsharing.hsadminng.domain.Asset;
import org.hostsharing.hsadminng.repository.AssetRepository;
import org.hostsharing.hsadminng.service.dto.AssetDTO;
import org.hostsharing.hsadminng.service.mapper.AssetMapper;
import org.hostsharing.hsadminng.web.rest.errors.BadRequestAlertException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
@ -23,11 +24,12 @@ public class AssetService {
private final Logger log = LoggerFactory.getLogger(AssetService.class);
private final EntityManager em;
private final AssetRepository assetRepository;
private final AssetMapper assetMapper;
private final AssetValidator assetValidator;
private final EntityManager em;
public AssetService(final EntityManager em, final AssetRepository assetRepository, final AssetMapper assetMapper, final AssetValidator assetValidator) {
this.em = em;
@ -86,6 +88,7 @@ public class AssetService {
*/
public void delete(Long id) {
log.debug("Request to delete Asset : {}", id);
assetRepository.deleteById(id);
throw new BadRequestAlertException("Asset transactions are immutable", Asset.ENTITY_NAME, "assetTransactionImmutable");
}
}

View File

@ -12,6 +12,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;
/**
@ -23,15 +24,19 @@ public class MembershipService implements IdToDtoResolver<MembershipDTO> {
private final Logger log = LoggerFactory.getLogger(MembershipService.class);
private final EntityManager em;
private final MembershipValidator membershipValidator;
private final MembershipRepository membershipRepository;
private final MembershipMapper membershipMapper;
public MembershipService(final MembershipValidator membershipValidator,
public MembershipService(final EntityManager em,
final MembershipValidator membershipValidator,
final MembershipRepository membershipRepository,
final MembershipMapper membershipMapper) {
this.em = em;
this.membershipValidator = membershipValidator;
this.membershipRepository = membershipRepository;
this.membershipMapper = membershipMapper;
@ -50,6 +55,8 @@ public class MembershipService implements IdToDtoResolver<MembershipDTO> {
Membership membership = membershipMapper.toEntity(membershipDTO);
membership = membershipRepository.save(membership);
em.flush();
em.refresh(membership);
return membershipMapper.toDto(membership);
}

View File

@ -12,6 +12,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;
/**
@ -23,13 +24,16 @@ public class ShareService implements IdToDtoResolver<ShareDTO> {
private final Logger log = LoggerFactory.getLogger(ShareService.class);
private final EntityManager em;
private final ShareRepository shareRepository;
private final ShareMapper shareMapper;
private final ShareValidator shareValidator;
public ShareService(ShareRepository shareRepository, ShareMapper shareMapper, ShareValidator shareValidator) {
public ShareService(final EntityManager em, final ShareRepository shareRepository, final ShareMapper shareMapper, final ShareValidator shareValidator) {
this.em = em;
this.shareRepository = shareRepository;
this.shareMapper = shareMapper;
this.shareValidator = shareValidator;
@ -48,6 +52,8 @@ public class ShareService implements IdToDtoResolver<ShareDTO> {
Share share = shareMapper.toEntity(shareDTO);
share = shareRepository.save(share);
em.flush();
em.refresh(share);
return shareMapper.toDto(share);
}

View File

@ -47,7 +47,7 @@ public class AssetDTO implements Serializable, AccessMappings {
private Long membershipId;
@AccessFor(init=Role.ANYBODY, update=Role.ANYBODY, read = {Role.CONTRACTUAL_CONTACT, Role.FINANCIAL_CONTACT})
private String membershipDisplayReference;
private String membershipDisplayLabel;
public Long getId() {
return id;
@ -105,12 +105,12 @@ public class AssetDTO implements Serializable, AccessMappings {
this.membershipId = membershipId;
}
public String getMembershipDisplayReference() {
return membershipDisplayReference;
public String getMembershipDisplayLabel() {
return membershipDisplayLabel;
}
public void setMembershipDisplayReference(String membershipDisplayReference) {
this.membershipDisplayReference = membershipDisplayReference;
public void setMembershipDisplayLabel(String membershipDisplayLabel) {
this.membershipDisplayLabel = membershipDisplayLabel;
}
@Override
@ -144,7 +144,7 @@ public class AssetDTO implements Serializable, AccessMappings {
", amount=" + getAmount() +
", remark='" + getRemark() + "'" +
", membership=" + getMembershipId() +
", membership='" + getMembershipDisplayReference() + "'" +
", membership='" + getMembershipDisplayLabel() + "'" +
"}";
}

View File

@ -85,6 +85,9 @@ public class CustomerDTO extends FluentBuilder<CustomerDTO> implements AccessMap
@AccessFor(init = Role.ADMIN, update = Role.SUPPORTER, read = Role.SUPPORTER)
private String remark;
@AccessFor(init=Role.ANYBODY, update=Role.ANYBODY, read = Role.ANY_CUSTOMER_USER)
private String displayLabel;
public Long getId() {
return id;
}
@ -213,6 +216,14 @@ public class CustomerDTO extends FluentBuilder<CustomerDTO> implements AccessMap
this.remark = remark;
}
public String getDisplayLabel() {
return displayLabel;
}
public void setDisplayLabel(final String displayLabel) {
this.displayLabel = displayLabel;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@ -25,18 +25,18 @@ public class MembershipDTO extends FluentBuilder<MembershipDTO> implements Seria
@AccessFor(init = Role.ADMIN, read = {Role.CONTRACTUAL_CONTACT, Role.FINANCIAL_CONTACT})
private LocalDate admissionDocumentDate;
@AccessFor(init = Role.ADMIN, read = {Role.CONTRACTUAL_CONTACT, Role.FINANCIAL_CONTACT})
@AccessFor(init = Role.ADMIN, update = Role.ADMIN, read = {Role.CONTRACTUAL_CONTACT, Role.FINANCIAL_CONTACT})
private LocalDate cancellationDocumentDate;
@NotNull
@AccessFor(init = Role.ADMIN, read = {Role.CONTRACTUAL_CONTACT, Role.FINANCIAL_CONTACT})
private LocalDate memberFromDate;
@AccessFor(init = Role.ADMIN, read = {Role.CONTRACTUAL_CONTACT, Role.FINANCIAL_CONTACT})
@AccessFor(init = Role.ADMIN, update = Role.ADMIN, read = {Role.CONTRACTUAL_CONTACT, Role.FINANCIAL_CONTACT})
private LocalDate memberUntilDate;
@Size(max = 160)
@AccessFor(init = Role.ADMIN, read = Role.SUPPORTER)
@AccessFor(init = Role.ADMIN,update = Role.ADMIN, read = Role.SUPPORTER)
private String remark;
@ParentId(resolver = CustomerService.class)
@ -46,8 +46,11 @@ public class MembershipDTO extends FluentBuilder<MembershipDTO> implements Seria
@AccessFor(init = Role.ADMIN, read = {Role.CONTRACTUAL_CONTACT, Role.FINANCIAL_CONTACT})
private String customerPrefix;
@AccessFor(read = {Role.CONTRACTUAL_CONTACT, Role.FINANCIAL_CONTACT})
private String membershipDisplayReference;
@AccessFor(init = Role.ANYBODY, update = Role.ANYBODY, read = Role.FINANCIAL_CONTACT)
private String displayLabel;
@AccessFor(init = Role.ANYBODY, update = Role.ANYBODY, read = Role.FINANCIAL_CONTACT)
private String customerDisplayLabel;
public Long getId() {
return id;
@ -113,12 +116,20 @@ public class MembershipDTO extends FluentBuilder<MembershipDTO> implements Seria
this.customerPrefix = customerPrefix;
}
private String getMembershipDisplayReference() {
return membershipDisplayReference;
public String getDisplayLabel() {
return displayLabel;
}
public void setMembershipDisplayReference(final String membershipDisplayReference) {
this.membershipDisplayReference = membershipDisplayReference;
public void setDisplayLabel(final String displayLabel) {
this.displayLabel = displayLabel;
}
public String getCustomerDisplayLabel() {
return customerDisplayLabel;
}
public void setCustomerDisplayLabel(final String customerDisplayLabel) {
this.customerDisplayLabel = customerDisplayLabel;
}
@Override

View File

@ -48,7 +48,7 @@ public class ShareDTO implements Serializable {
private Long membershipId;
@AccessFor(read = {Role.CONTRACTUAL_CONTACT, Role.FINANCIAL_CONTACT})
private String membershipDisplayReference;
private String membershipDisplayLabel;
public Long getId() {
return id;
@ -106,12 +106,12 @@ public class ShareDTO implements Serializable {
this.membershipId = membershipId;
}
public String getMembershipDisplayReference() {
return membershipDisplayReference;
public String getMembershipDisplayLabel() {
return membershipDisplayLabel;
}
public void setMembershipDisplayReference(String membershipDisplayReference) {
this.membershipDisplayReference = membershipDisplayReference;
public void setMembershipDisplayLabel(String membershipDisplayLabel) {
this.membershipDisplayLabel = membershipDisplayLabel;
}
@Override
@ -145,7 +145,7 @@ public class ShareDTO implements Serializable {
", quantity=" + getQuantity() +
", remark='" + getRemark() + "'" +
", membership=" + getMembershipId() +
", membership='" + getMembershipDisplayReference() + "'" +
", membership='" + getMembershipDisplayLabel() + "'" +
"}";
}
}

View File

@ -1,16 +1,12 @@
package org.hostsharing.hsadminng.service.mapper;
import org.hostsharing.hsadminng.domain.Asset;
import org.hostsharing.hsadminng.domain.Customer;
import org.hostsharing.hsadminng.domain.Membership;
import org.hostsharing.hsadminng.service.dto.AssetDTO;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import java.util.Objects;
/**
* Mapper for the entity Asset and its DTO AssetDTO.
*/
@ -18,19 +14,12 @@ import java.util.Objects;
public interface AssetMapper extends EntityMapper<AssetDTO, Asset> {
@Mapping(source = "membership.id", target = "membershipId")
@Mapping(target = "membershipDisplayReference", ignore = true)
@Mapping(target = "membershipDisplayLabel", ignore = true)
AssetDTO toDto(Asset asset);
@AfterMapping
default void setMembershipDisplayReference(final @MappingTarget AssetDTO dto, final Asset entity) {
// TODO: rather use method extracted from MembershipMaper.setMembershipDisplayReference() to avoid duplicate code
final Membership membership = entity.getMembership();
final Customer customer = membership.getCustomer();
dto.setMembershipDisplayReference(customer.getReference()
+ ":" + customer.getPrefix()
+ " [" + customer.getName() + "] "
+ membership.getAdmissionDocumentDate().toString() + " - "
+ Objects.toString(membership.getCancellationDocumentDate(), ""));
default void setMembershipDisplayLabel(final @MappingTarget AssetDTO dto, final Asset entity) {
dto.setMembershipDisplayLabel(MembershipMapper.displayLabel(entity.getMembership()));
}
@Mapping(source = "membershipId", target = "membership")

View File

@ -1,9 +1,11 @@
package org.hostsharing.hsadminng.service.mapper;
import org.hostsharing.hsadminng.domain.*;
import org.hostsharing.hsadminng.domain.Customer;
import org.hostsharing.hsadminng.service.dto.CustomerDTO;
import org.mapstruct.*;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
/**
* Mapper for the entity Customer and its DTO CustomerDTO.
@ -11,6 +13,18 @@ import org.mapstruct.*;
@Mapper(componentModel = "spring", uses = {})
public interface CustomerMapper extends EntityMapper<CustomerDTO, Customer> {
static String displayLabel(Customer customer) {
return customer.getName()
+ " [" + customer.getReference() + ":" + customer.getPrefix() +"]";
}
@Mapping(target = "displayLabel", ignore = true)
CustomerDTO toDto(Customer customer);
@AfterMapping
default void setDisplayLabel(final @MappingTarget CustomerDTO dto, final Customer entity) {
dto.setDisplayLabel(displayLabel(entity));
}
@Mapping(target = "memberships", ignore = true)
@Mapping(target = "sepamandates", ignore = true)

View File

@ -16,21 +16,25 @@ import java.util.Objects;
@Mapper(componentModel = "spring", uses = {CustomerMapper.class})
public interface MembershipMapper extends EntityMapper<MembershipDTO, Membership> {
static String displayLabel(final Membership entity) {
final Customer customer = entity.getCustomer();
return CustomerMapper.displayLabel(customer) + " "
+ Objects.toString(entity.getAdmissionDocumentDate(), "") + " - "
+ Objects.toString(entity.getCancellationDocumentDate(), "...");
}
@Mapping(source = "customer.id", target = "customerId")
@Mapping(source = "customer.prefix", target = "customerPrefix")
@Mapping(target = "membershipDisplayReference", ignore = true)
@Mapping(target = "displayLabel", ignore = true)
@Mapping(target = "customerDisplayLabel", ignore = true)
MembershipDTO toDto(Membership membership);
// TODO BLOG HOWTO: multi-field display reference for selection lists
// also change the filed in the option list in *-update.html
@AfterMapping
default void setMembershipDisplayReference(final @MappingTarget MembershipDTO dto, final Membership entity) {
final Customer customer = entity.getCustomer();
dto.setMembershipDisplayReference(customer.getReference()
+ ":" + customer.getPrefix()
+ " [" + customer.getName() + "] "
+ entity.getAdmissionDocumentDate().toString() + " - "
+ Objects.toString(entity.getCancellationDocumentDate(), ""));
default void setMembershipDisplayLabel(final @MappingTarget MembershipDTO dto, final Membership entity) {
dto.setDisplayLabel(displayLabel(entity));
dto.setCustomerDisplayLabel(CustomerMapper.displayLabel(entity.getCustomer()));
}
@Mapping(target = "shares", ignore = true)

View File

@ -2,8 +2,10 @@ package org.hostsharing.hsadminng.service.mapper;
import org.hostsharing.hsadminng.domain.Share;
import org.hostsharing.hsadminng.service.dto.ShareDTO;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
/**
* Mapper for the entity Share and its DTO ShareDTO.
@ -12,9 +14,14 @@ import org.mapstruct.Mapping;
public interface ShareMapper extends EntityMapper<ShareDTO, Share> {
@Mapping(source = "membership.id", target = "membershipId")
@Mapping(source = "membership.admissionDocumentDate", target = "membershipDisplayReference")
@Mapping(target = "membershipDisplayLabel", ignore = true)
ShareDTO toDto(Share share);
@AfterMapping
default void setMembershipDisplayLabel(final @MappingTarget ShareDTO dto, final Share entity) {
dto.setMembershipDisplayLabel(MembershipMapper.displayLabel(entity.getMembership()));
}
@Mapping(source = "membershipId", target = "membership")
Share toEntity(ShareDTO shareDTO);

View File

@ -1,7 +1,7 @@
<div class="row justify-content-center">
<div class="col-8">
<div *ngIf="asset">
<h2><span jhiTranslate="hsadminNgApp.asset.detail.title">Asset</span> {{asset.id}}</h2>
<h2><span jhiTranslate="hsadminNgApp.asset.detail.title">Asset</span>: #{{asset.id}} - {{asset.membershipDisplayLabel}}</h2>
<hr>
<jhi-alert-error></jhi-alert-error>
<dl class="row-md jh-entity-details">
@ -28,7 +28,7 @@
<dt><span jhiTranslate="hsadminNgApp.asset.membership">Membership</span></dt>
<dd>
<div *ngIf="asset.membershipId">
<a [routerLink]="['/membership', asset.membershipId, 'view']">{{asset.membershipDisplayReference}}</a>
<a [routerLink]="['/membership', asset.membershipId, 'view']">{{asset.membershipDisplayLabel}}</a>
</div>
</dd>
</dl>

View File

@ -89,7 +89,7 @@
<label class="form-control-label" jhiTranslate="hsadminNgApp.asset.membership" for="field_membership">Membership</label>
<select class="form-control" id="field_membership" name="membership" [(ngModel)]="asset.membershipId" required>
<option *ngIf="!editForm.value.membership" [ngValue]="null" selected></option>
<option [ngValue]="membershipOption.id" *ngFor="let membershipOption of memberships; trackBy: trackMembershipById">{{membershipOption.membershipDisplayReference}}</option>
<option [ngValue]="membershipOption.id" *ngFor="let membershipOption of memberships; trackBy: trackMembershipById">{{membershipOption.displayLabel}}</option>
</select>
</div>
<div [hidden]="!(editForm.controls.membership?.dirty && editForm.controls.membership?.invalid)">

View File

@ -19,8 +19,7 @@
<th jhiSortBy="valueDate"><span jhiTranslate="hsadminNgApp.asset.valueDate">Value Date</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="action"><span jhiTranslate="hsadminNgApp.asset.action">Action</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="amount"><span jhiTranslate="hsadminNgApp.asset.amount">Amount</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="remark"><span jhiTranslate="hsadminNgApp.asset.remark">Remark</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="membershipDisplayReference"><span jhiTranslate="hsadminNgApp.asset.membership">Membership</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="membershipDisplayLabel"><span jhiTranslate="hsadminNgApp.asset.membership">Membership</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th></th>
</tr>
</thead>
@ -31,10 +30,9 @@
<td>{{asset.valueDate | date:'mediumDate'}}</td>
<td jhiTranslate="{{'hsadminNgApp.AssetAction.' + asset.action}}">{{asset.action}}</td>
<td>{{asset.amount}}</td>
<td>{{asset.remark}}</td>
<td>
<div *ngIf="asset.membershipId">
<a [routerLink]="['../membership', asset.membershipId , 'view' ]" >{{asset.membershipDisplayReference}}</a>
<a [routerLink]="['../membership', asset.membershipId , 'view' ]" >{{asset.membershipDisplayLabel}}</a>
</div>
</td>
<td class="text-right">

View File

@ -1,7 +1,7 @@
<div class="row justify-content-center">
<div class="col-8">
<div *ngIf="customer">
<h2><span jhiTranslate="hsadminNgApp.customer.detail.title">Customer</span> {{customer.id}}</h2>
<h2><span jhiTranslate="hsadminNgApp.customer.detail.title">Customer</span>: {{customer.displayLabel}}</h2>
<hr>
<jhi-alert-error></jhi-alert-error>
<dl class="row-md jh-entity-details">

View File

@ -18,18 +18,7 @@
<th jhiSortBy="reference"><span jhiTranslate="hsadminNgApp.customer.reference">Reference</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="prefix"><span jhiTranslate="hsadminNgApp.customer.prefix">Prefix</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="name"><span jhiTranslate="hsadminNgApp.customer.name">Name</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="kind"><span jhiTranslate="hsadminNgApp.customer.kind">Kind</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="birthDate"><span jhiTranslate="hsadminNgApp.customer.birthDate">Birth Date</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="birthPlace"><span jhiTranslate="hsadminNgApp.customer.birthPlace">Birth Place</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="registrationCourt"><span jhiTranslate="hsadminNgApp.customer.registrationCourt">Registration Court</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="registrationNumber"><span jhiTranslate="hsadminNgApp.customer.registrationNumber">Registration Number</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="vatRegion"><span jhiTranslate="hsadminNgApp.customer.vatRegion">Vat Region</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="vatNumber"><span jhiTranslate="hsadminNgApp.customer.vatNumber">Vat Number</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="contractualSalutation"><span jhiTranslate="hsadminNgApp.customer.contractualSalutation">Contractual Salutation</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="contractualAddress"><span jhiTranslate="hsadminNgApp.customer.contractualAddress">Contractual Address</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="billingSalutation"><span jhiTranslate="hsadminNgApp.customer.billingSalutation">Billing Salutation</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="billingAddress"><span jhiTranslate="hsadminNgApp.customer.billingAddress">Billing Address</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="remark"><span jhiTranslate="hsadminNgApp.customer.remark">Remark</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="kind"><span jhiTranslate="hsadminNgApp.customer.kind">Kind</span> <fa-icon [icon]="'sort'"></fa-icon></thn></th>
<th></th>
</tr>
</thead>
@ -40,17 +29,6 @@
<td>{{customer.prefix}}</td>
<td>{{customer.name}}</td>
<td jhiTranslate="{{'hsadminNgApp.CustomerKind.' + customer.kind}}">{{customer.kind}}</td>
<td>{{customer.birthDate | date:'mediumDate'}}</td>
<td>{{customer.birthPlace}}</td>
<td>{{customer.registrationCourt}}</td>
<td>{{customer.registrationNumber}}</td>
<td jhiTranslate="{{'hsadminNgApp.VatRegion.' + customer.vatRegion}}">{{customer.vatRegion}}</td>
<td>{{customer.vatNumber}}</td>
<td>{{customer.contractualSalutation}}</td>
<td>{{customer.contractualAddress}}</td>
<td>{{customer.billingSalutation}}</td>
<td>{{customer.billingAddress}}</td>
<td>{{customer.remark}}</td>
<td class="text-right">
<div class="btn-group flex-btn-group-container">
<button type="submit"

View File

@ -1,7 +1,7 @@
<div class="row justify-content-center">
<div class="col-8">
<div *ngIf="membership">
<h2><span jhiTranslate="hsadminNgApp.membership.detail.title">Membership</span> {{membership.id}}</h2>
<h2><span jhiTranslate="hsadminNgApp.membership.detail.title">Membership</span>: {{membership.displayLabel}}</h2>
<hr>
<jhi-alert-error></jhi-alert-error>
<dl class="row-md jh-entity-details">
@ -28,7 +28,7 @@
<dt><span jhiTranslate="hsadminNgApp.membership.customer">Customer</span></dt>
<dd>
<div *ngIf="membership.customerId">
<a [routerLink]="['/customer', membership.customerId, 'view']">{{membership.customerPrefix}}</a>
<a [routerLink]="['/customer', membership.customerId, 'view']">{{membership.customerDisplayLabel}}</a>
</div>
</dd>
</dl>

View File

@ -77,7 +77,7 @@
<label class="form-control-label" jhiTranslate="hsadminNgApp.membership.customer" for="field_customer">Customer</label>
<select class="form-control" id="field_customer" name="customer" [(ngModel)]="membership.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

@ -19,7 +19,6 @@
<th jhiSortBy="cancellationDocumentDate"><span jhiTranslate="hsadminNgApp.membership.cancellationDocumentDate">Cancellation Document Date</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="memberFromDate"><span jhiTranslate="hsadminNgApp.membership.memberFromDate">Member From Date</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="memberUntilDate"><span jhiTranslate="hsadminNgApp.membership.memberUntilDate">Member Until Date</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="remark"><span jhiTranslate="hsadminNgApp.membership.remark">Remark</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="customerPrefix"><span jhiTranslate="hsadminNgApp.membership.customer">Customer</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th></th>
</tr>
@ -28,13 +27,12 @@
<tr *ngFor="let membership of memberships ;trackBy: trackId">
<td><a [routerLink]="['/membership', membership.id, 'view' ]">{{membership.id}}</a></td>
<td>{{membership.admissionDocumentDate | date:'mediumDate'}}</td>
<td>{{membership.cancellationDocumentDate | date:'mediumDate'}}</td>
<td>{{membership.cancellationDocumentDate | date:'mediumDsate'}}</td>
<td>{{membership.memberFromDate | date:'mediumDate'}}</td>
<td>{{membership.memberUntilDate | date:'mediumDate'}}</td>
<td>{{membership.remark}}</td>
<td>
<div *ngIf="membership.customerId">
<a [routerLink]="['../customer', membership.customerId , 'view' ]" >{{membership.customerPrefix}}</a>
<a [routerLink]="['../customer', membership.customerId , 'view' ]" >{{membership.customerDisplayLabel}}</a>
</div>
</td>
<td class="text-right">

View File

@ -1,7 +1,7 @@
<div class="row justify-content-center">
<div class="col-8">
<div *ngIf="share">
<h2><span jhiTranslate="hsadminNgApp.share.detail.title">Share</span> {{share.id}}</h2>
<h2><span jhiTranslate="hsadminNgApp.share.detail.title">Share</span>: #{{share.id}} - {{share.membershipDisplayLabel}}</h2>
<hr>
<jhi-alert-error></jhi-alert-error>
<dl class="row-md jh-entity-details">
@ -28,7 +28,7 @@
<dt><span jhiTranslate="hsadminNgApp.share.membership">Membership</span></dt>
<dd>
<div *ngIf="share.membershipId">
<a [routerLink]="['/membership', share.membershipId, 'view']">{{share.membershipDisplayReference}}</a>
<a [routerLink]="['/membership', share.membershipId, 'view']">{{share.membershipDisplayLabel}}</a>
</div>
</dd>
</dl>

View File

@ -85,7 +85,7 @@
<label class="form-control-label" jhiTranslate="hsadminNgApp.share.membership" for="field_membership">Membership</label>
<select class="form-control" id="field_membership" name="membership" [(ngModel)]="share.membershipId" required>
<option *ngIf="!editForm.value.membership" [ngValue]="null" selected></option>
<option [ngValue]="membershipOption.id" *ngFor="let membershipOption of memberships; trackBy: trackMembershipById">{{membershipOption.admissionDocumentDate}}</option>
<option [ngValue]="membershipOption.id" *ngFor="let membershipOption of memberships; trackBy: trackMembershipById">{{membershipOption.displayLabel}}</option>
</select>
</div>
<div [hidden]="!(editForm.controls.membership?.dirty && editForm.controls.membership?.invalid)">

View File

@ -19,8 +19,7 @@
<th jhiSortBy="valueDate"><span jhiTranslate="hsadminNgApp.share.valueDate">Value Date</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="action"><span jhiTranslate="hsadminNgApp.share.action">Action</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="quantity"><span jhiTranslate="hsadminNgApp.share.quantity">Quantity</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="remark"><span jhiTranslate="hsadminNgApp.share.remark">Remark</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="membershipDisplayReference"><span jhiTranslate="hsadminNgApp.share.membership">Membership</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="membershipDisplayLabel"><span jhiTranslate="hsadminNgApp.share.membership">Membership</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th></th>
</tr>
</thead>
@ -31,10 +30,9 @@
<td>{{share.valueDate | date:'mediumDate'}}</td>
<td jhiTranslate="{{'hsadminNgApp.ShareAction.' + share.action}}">{{share.action}}</td>
<td>{{share.quantity}}</td>
<td>{{share.remark}}</td>
<td>
<div *ngIf="share.membershipId">
<a [routerLink]="['../membership', share.membershipId , 'view' ]" >{{share.membershipDisplayReference}}</a>
<a [routerLink]="['../membership', share.membershipId , 'view' ]" >{{share.membershipDisplayLabel}}</a>
</div>
</td>
<td class="text-right">

View File

@ -16,8 +16,8 @@ export interface IAsset {
action?: AssetAction;
amount?: number;
remark?: string;
membershipDisplayReference?: string;
membershipId?: number;
membershipDisplayLabel?: string;
}
export class Asset implements IAsset {
@ -28,7 +28,7 @@ export class Asset implements IAsset {
public action?: AssetAction,
public amount?: number,
public remark?: string,
public membershipDisplayReference?: string,
public membershipId?: number
public membershipId?: number,
public membershipDisplayLabel?: string
) {}
}

View File

@ -32,6 +32,7 @@ export interface ICustomer {
remark?: string;
memberships?: IMembership[];
sepamandates?: ISepaMandate[];
displayLabel?: string;
}
export class Customer implements ICustomer {
@ -53,6 +54,7 @@ export class Customer implements ICustomer {
public billingAddress?: string,
public remark?: string,
public memberships?: IMembership[],
public sepamandates?: ISepaMandate[]
public sepamandates?: ISepaMandate[],
public displayLabel?: string
) {}
}

View File

@ -13,7 +13,8 @@ export interface IMembership {
assets?: IAsset[];
customerPrefix?: string;
customerId?: number;
membershipDisplayReference?: string;
membershipDisplayLabel?: string;
displayLabel?: string;
}
export class Membership implements IMembership {
@ -28,6 +29,7 @@ export class Membership implements IMembership {
public assets?: IAsset[],
public customerPrefix?: string,
public customerId?: number,
public membershipDisplayReference?: string
public displayLabel?: string,
public membershipDisplayLabel?: string
) {}
}

View File

@ -12,7 +12,7 @@ export interface IShare {
action?: ShareAction;
quantity?: number;
remark?: string;
membershipDisplayReference?: string;
membershipDisplayLabel?: string;
membershipId?: number;
}
@ -24,7 +24,7 @@ export class Share implements IShare {
public action?: ShareAction,
public quantity?: number,
public remark?: string,
public membershipDisplayReference?: string,
public membershipDisplayLabel?: string,
public membershipId?: number
) {}
}

View File

@ -0,0 +1,167 @@
package org.hostsharing.hsadminng.service;
import org.apache.commons.lang3.RandomUtils;
import org.hostsharing.hsadminng.domain.Asset;
import org.hostsharing.hsadminng.domain.enumeration.AssetAction;
import org.hostsharing.hsadminng.repository.AssetRepository;
import org.hostsharing.hsadminng.service.dto.AssetDTO;
import org.hostsharing.hsadminng.service.mapper.AssetMapper;
import org.hostsharing.hsadminng.web.rest.errors.BadRequestAlertException;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import javax.persistence.EntityManager;
import java.math.BigDecimal;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowableOfType;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.*;
// HINT: In IntelliJ IDEA such unit test classes can be created with Shift-Ctrl-T.
// Do not forget to amend the class name (.e.g. ...UnitTest / ...IntTest)!
public class AssetServiceUnitTest {
@Rule
public MockitoRule mockitoRule = MockitoJUnit.rule();
@Mock
private EntityManager em;
@Mock
private AssetRepository assetRepository;
@Mock
private AssetValidator assetValidator; // needed for @InjectMocks assetService
@Mock
private AssetMapper assetMapper;
@InjectMocks
private AssetService assetService;
// HINT: Click outside of any test method (e.g. here) and use Ctrl-Shift-F10
// to run all tests from this test class. Use Ctrl-F5 to run the last execution again;
// 'execution' here can also apply to running the application, whatever ran last.
// HINT: In IntelliJ IDEA such test methods can be created with Alt-Insert.
@Test
public void deleteIsRejectedForAssetTransactions() {
// when
final Throwable throwException = catchThrowableOfType(() -> assetService.delete(RandomUtils.nextLong()), BadRequestAlertException.class);
// then
// HINT: When using auto-import for assertions (e.g. via Alt-Enter in IntelliJ IDEA),
// beware to use the correct candidate from org.assertj.core.api.Assertions.
assertThat(throwException).isEqualToComparingFieldByField(
new BadRequestAlertException("Asset transactions are immutable", "asset", "assetTransactionImmutable"));
}
@Test
public void saveShouldPersistValidTransactions() {
// given
final AssetDTO givenAssetDTO = givenAssetDTO(null, AssetAction.PAYMENT, anyPositiveAmout());
// HINT: given(...)...will...() can't be used for void methods, in that case use Mockito's do...() methods
doNothing().when(assetValidator).validate(givenAssetDTO);
// when
final AssetDTO returnedAssetDto = assetService.save(givenAssetDTO);
// then
verify(em).flush();
verify(em).refresh(any(Asset.class));
assertThat(returnedAssetDto).isEqualToIgnoringGivenFields(givenAssetDTO, "id");
}
@Test
public void saveShouldNotPersistInvalidTransactions() {
// given
final AssetDTO givenAssetDTO = givenAssetDTO(null, AssetAction.PAYMENT, anyNegativeAmount());
doThrow(new BadRequestAlertException("Some Dummy Test Violation", "asset", "assetInvalidTestDummy")).when(assetValidator).validate(givenAssetDTO);
// when
final Throwable throwException = catchThrowableOfType(() -> assetService.save(givenAssetDTO), BadRequestAlertException.class);
// then
assertThat(throwException).isEqualToComparingFieldByField(
new BadRequestAlertException("Some Dummy Test Violation", "asset", "assetInvalidTestDummy"));
}
@Test
public void saveShouldUpdateValidTransactions() {
// given
final AssetDTO givenAssetDTO = givenAssetDTO(anyNonNullId(), AssetAction.PAYMENT, anyPositiveAmout());
doNothing().when(assetValidator).validate(givenAssetDTO);
// when
final AssetDTO returnedAssetDto = assetService.save(givenAssetDTO);
// then
verify(em).flush();
verify(em).refresh(any(Asset.class));
assertThat(returnedAssetDto).isEqualToIgnoringGivenFields(givenAssetDTO, "id");
}
@Test
public void saveShouldNotUpdateInvalidTransactions() {
// given
final AssetDTO givenAssetDTO = givenAssetDTO(anyNonNullId(), AssetAction.PAYMENT, anyNegativeAmount());
// HINT: given(...) can't be used for void methods, in that case use Mockito's do...() methods
doThrow(new BadRequestAlertException("Some Dummy Test Violation", "asset", "assetInvalidTestDummy")).when(assetValidator).validate(givenAssetDTO);
// when
final Throwable throwException = catchThrowableOfType(() -> assetService.save(givenAssetDTO), BadRequestAlertException.class);
// then
assertThat(throwException).isEqualToComparingFieldByField(
new BadRequestAlertException("Some Dummy Test Violation", "asset", "assetInvalidTestDummy"));
}
// --- only test fixture code below ---
private long anyNonNullId() {
return RandomUtils.nextInt();
}
// HINT: This rather complicated setup indicates that the method AssetService::save breaks the single responsibility principle.
private AssetDTO givenAssetDTO(final Long id, final AssetAction givenAction, final BigDecimal givenQuantity) {
final AssetDTO givenAssetDTO = createAssetDTO(id, givenAction, givenQuantity);
// dto -> entity
final Asset givenAssetEntity = Mockito.mock(Asset.class);
given(assetMapper.toEntity(same(givenAssetDTO))).willReturn(givenAssetEntity);
// assetRepository.save(entity);
final Asset persistedAssetEntity = Mockito.mock(Asset.class);
given(assetRepository.save(same(givenAssetEntity))).willReturn(persistedAssetEntity);
// entity -> dto
AssetDTO persistedAssetDTO = createAssetDTO(id == null ? RandomUtils.nextLong() : id, givenAction, givenQuantity);
given(assetMapper.toDto(same(persistedAssetEntity))).willReturn(persistedAssetDTO);
return givenAssetDTO;
}
private AssetDTO createAssetDTO(Long id, AssetAction givenAction, BigDecimal givenAmount) {
final AssetDTO givenAssetDTO = new AssetDTO();
givenAssetDTO.setId(id);
givenAssetDTO.setAction(givenAction);
givenAssetDTO.setAmount(givenAmount);
return givenAssetDTO;
}
private BigDecimal anyPositiveAmout() {
return BigDecimal.valueOf(RandomUtils.nextInt()).add(new BigDecimal("0.1"));
}
private BigDecimal anyNegativeAmount() {
return anyPositiveAmout().negate();
}
}

View File

@ -15,12 +15,13 @@ import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import javax.persistence.EntityManager;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowableOfType;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.*;
// HINT: In IntelliJ IDEA such unit test classes can be created with Shift-Ctrl-T.
@ -30,6 +31,9 @@ public class ShareServiceUnitTest {
@Rule
public MockitoRule mockitoRule = MockitoJUnit.rule();
@Mock
private EntityManager em;
@Mock
private ShareRepository shareRepository;
@ -70,6 +74,8 @@ public class ShareServiceUnitTest {
final ShareDTO returnedShareDto = shareService.save(givenShareDTO);
// then
verify(em).flush();
verify(em).refresh(any(Share.class));
assertThat(returnedShareDto).isEqualToIgnoringGivenFields(givenShareDTO, "id");
}
@ -97,6 +103,8 @@ public class ShareServiceUnitTest {
final ShareDTO returnedShareDto = shareService.save(givenShareDTO);
// then
verify(em).flush();
verify(em).refresh(any(Share.class));
assertThat(returnedShareDto).isEqualToIgnoringGivenFields(givenShareDTO, "id");
}

View File

@ -82,7 +82,8 @@ public class CustomerDTOUnitTest {
toJSonFieldDefinition("id", given.getId()) + "," +
toJSonFieldDefinition("reference", given.getReference()) + "," +
toJSonFieldDefinition("prefix", given.getPrefix()) + "," +
toJSonFieldDefinition("name", given.getName()) +
toJSonFieldDefinition("name", given.getName()) + "," +
toJSonFieldDefinition("displayLabel", given.getDisplayLabel()) +
"}";
assertEquals(expectedJSon, actual);
}
@ -118,7 +119,7 @@ public class CustomerDTOUnitTest {
expected.setId(1234L);
expected.setContractualSalutation("Hallo Updated");
expected.setBillingSalutation("Moin Updated");
assertThat(actual).isEqualToComparingFieldByField(expected);
assertThat(actual).isEqualToIgnoringGivenFields(expected, "displayLabel");
}
// --- only test fixture below ---
@ -140,12 +141,11 @@ public class CustomerDTOUnitTest {
toJSonFieldDefinitionIfPresent("contractualAddress", dto.getContractualAddress()) +
toJSonFieldDefinitionIfPresent("billingSalutation", dto.getBillingSalutation()) +
toJSonFieldDefinitionIfPresent("billingAddress", dto.getBillingAddress()) +
toJSonFieldDefinitionIfPresent("remark", dto.getRemark());
toJSonFieldDefinitionIfPresent("remark", dto.getRemark()) +
toJSonFieldDefinitionIfPresent("displayLabel", dto.getDisplayLabel());
return "{" + json.substring(0, json.length() - 1) + "}";
}
private String toJSonFieldDefinition(String name, String value) {
return inQuotes(name) + ":" + (value != null ? inQuotes(value) : "null");
}
@ -186,6 +186,7 @@ public class CustomerDTOUnitTest {
given.setBillingAddress("Noch eine Adresse");
given.setBillingSalutation("Moin");
given.setRemark("Eine Bemerkung");
given.setDisplayLabel("Display Label");
return given;
}
}

View File

@ -154,7 +154,7 @@ public class ShareDTOUnitTest {
givenDTO.setAction(ShareAction.SUBSCRIPTION);
givenDTO.setQuantity(3);
givenDTO.setDocumentDate(LocalDate.parse("2019-04-22"));
givenDTO.setMembershipDisplayReference("2019-04-21"); // TODO: why is this not a LocalDate?
givenDTO.setMembershipDisplayLabel("2019-04-21"); // TODO: why is this not a LocalDate?
givenDTO.setValueDate(LocalDate.parse("2019-04-30"));
givenDTO.setRemark("Some Remark");
return givenDTO;

View File

@ -248,7 +248,7 @@ public class MembershipResourceIntTest {
.andExpect(jsonPath("$.[*].cancellationDocumentDate").value(hasItem(DEFAULT_CANCELLATION_DOCUMENT_DATE.toString())))
.andExpect(jsonPath("$.[*].memberFromDate").value(hasItem(DEFAULT_MEMBER_FROM_DATE.toString())))
.andExpect(jsonPath("$.[*].memberUntilDate").value(hasItem(DEFAULT_MEMBER_UNTIL_DATE.toString())))
.andExpect(jsonPath("$.[*].remark").value(hasItem(DEFAULT_REMARK.toString())));
.andExpect(jsonPath("$.[*].remark").value(hasItem(DEFAULT_REMARK)));
}
@Test
@ -266,7 +266,7 @@ public class MembershipResourceIntTest {
.andExpect(jsonPath("$.cancellationDocumentDate").value(DEFAULT_CANCELLATION_DOCUMENT_DATE.toString()))
.andExpect(jsonPath("$.memberFromDate").value(DEFAULT_MEMBER_FROM_DATE.toString()))
.andExpect(jsonPath("$.memberUntilDate").value(DEFAULT_MEMBER_UNTIL_DATE.toString()))
.andExpect(jsonPath("$.remark").value(DEFAULT_REMARK.toString()));
.andExpect(jsonPath("$.remark").value(DEFAULT_REMARK));
}
@Test
@ -682,9 +682,7 @@ public class MembershipResourceIntTest {
// Disconnect from session so that the updates on updatedMembership are not directly saved in db
em.detach(updatedMembership);
updatedMembership
.admissionDocumentDate(UPDATED_ADMISSION_DOCUMENT_DATE)
.cancellationDocumentDate(UPDATED_CANCELLATION_DOCUMENT_DATE)
.memberFromDate(UPDATED_MEMBER_FROM_DATE)
.memberUntilDate(UPDATED_MEMBER_UNTIL_DATE)
.remark(UPDATED_REMARK);
MembershipDTO membershipDTO = membershipMapper.toDto(updatedMembership);
@ -698,9 +696,9 @@ public class MembershipResourceIntTest {
List<Membership> membershipList = membershipRepository.findAll();
assertThat(membershipList).hasSize(databaseSizeBeforeUpdate);
Membership testMembership = membershipList.get(membershipList.size() - 1);
assertThat(testMembership.getAdmissionDocumentDate()).isEqualTo(UPDATED_ADMISSION_DOCUMENT_DATE);
assertThat(testMembership.getAdmissionDocumentDate()).isEqualTo(DEFAULT_ADMISSION_DOCUMENT_DATE);
assertThat(testMembership.getCancellationDocumentDate()).isEqualTo(UPDATED_CANCELLATION_DOCUMENT_DATE);
assertThat(testMembership.getMemberFromDate()).isEqualTo(UPDATED_MEMBER_FROM_DATE);
assertThat(testMembership.getMemberFromDate()).isEqualTo(DEFAULT_MEMBER_FROM_DATE);
assertThat(testMembership.getMemberUntilDate()).isEqualTo(UPDATED_MEMBER_UNTIL_DATE);
assertThat(testMembership.getRemark()).isEqualTo(UPDATED_REMARK);
}