diff --git a/src/main/java/org/hostsharing/hsadminng/service/AssetService.java b/src/main/java/org/hostsharing/hsadminng/service/AssetService.java index 7ad083de..dd60f120 100644 --- a/src/main/java/org/hostsharing/hsadminng/service/AssetService.java +++ b/src/main/java/org/hostsharing/hsadminng/service/AssetService.java @@ -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 implements IdToDtoResolver { 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 implements IdToDtoResolver { */ 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"); } } diff --git a/src/main/java/org/hostsharing/hsadminng/service/MembershipService.java b/src/main/java/org/hostsharing/hsadminng/service/MembershipService.java index 473f5d7e..82e365d2 100644 --- a/src/main/java/org/hostsharing/hsadminng/service/MembershipService.java +++ b/src/main/java/org/hostsharing/hsadminng/service/MembershipService.java @@ -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 { 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 { Membership membership = membershipMapper.toEntity(membershipDTO); membership = membershipRepository.save(membership); + em.flush(); + em.refresh(membership); return membershipMapper.toDto(membership); } diff --git a/src/main/java/org/hostsharing/hsadminng/service/ShareService.java b/src/main/java/org/hostsharing/hsadminng/service/ShareService.java index c9ff868b..4fbc8bec 100644 --- a/src/main/java/org/hostsharing/hsadminng/service/ShareService.java +++ b/src/main/java/org/hostsharing/hsadminng/service/ShareService.java @@ -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 { 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 { Share share = shareMapper.toEntity(shareDTO); share = shareRepository.save(share); + em.flush(); + em.refresh(share); return shareMapper.toDto(share); } diff --git a/src/main/java/org/hostsharing/hsadminng/service/dto/AssetDTO.java b/src/main/java/org/hostsharing/hsadminng/service/dto/AssetDTO.java index 173c7c1f..87dca80e 100644 --- a/src/main/java/org/hostsharing/hsadminng/service/dto/AssetDTO.java +++ b/src/main/java/org/hostsharing/hsadminng/service/dto/AssetDTO.java @@ -47,8 +47,8 @@ public class AssetDTO implements Serializable, AccessMappings { @AccessFor(init = Role.ADMIN, update = Role.ADMIN, read = {Role.CONTRACTUAL_CONTACT, Role.FINANCIAL_CONTACT}) private Long membershipId; - @AccessFor(init = Role.ANYBODY, update = Role.ANYBODY, read = {Role.CONTRACTUAL_CONTACT, Role.FINANCIAL_CONTACT}) - private String membershipDisplayReference; + @AccessFor(init=Role.ANYBODY, update = Role.ANYBODY, read = {Role.CONTRACTUAL_CONTACT, Role.FINANCIAL_CONTACT}) + private String membershipDisplayLabel; public Long getId() { return id; @@ -106,12 +106,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 @@ -145,7 +145,7 @@ public class AssetDTO implements Serializable, AccessMappings { ", amount=" + getAmount() + ", remark='" + getRemark() + "'" + ", membership=" + getMembershipId() + - ", membership='" + getMembershipDisplayReference() + "'" + + ", membership='" + getMembershipDisplayLabel() + "'" + "}"; } diff --git a/src/main/java/org/hostsharing/hsadminng/service/dto/CustomerDTO.java b/src/main/java/org/hostsharing/hsadminng/service/dto/CustomerDTO.java index c1b42b75..85908ac9 100644 --- a/src/main/java/org/hostsharing/hsadminng/service/dto/CustomerDTO.java +++ b/src/main/java/org/hostsharing/hsadminng/service/dto/CustomerDTO.java @@ -85,6 +85,9 @@ public class CustomerDTO extends FluentBuilder 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 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) { diff --git a/src/main/java/org/hostsharing/hsadminng/service/dto/MembershipDTO.java b/src/main/java/org/hostsharing/hsadminng/service/dto/MembershipDTO.java index d8bc972f..7efeaaba 100644 --- a/src/main/java/org/hostsharing/hsadminng/service/dto/MembershipDTO.java +++ b/src/main/java/org/hostsharing/hsadminng/service/dto/MembershipDTO.java @@ -46,8 +46,11 @@ public class MembershipDTO extends FluentBuilder 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 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 diff --git a/src/main/java/org/hostsharing/hsadminng/service/dto/ShareDTO.java b/src/main/java/org/hostsharing/hsadminng/service/dto/ShareDTO.java index cb61e088..8bd1daa4 100644 --- a/src/main/java/org/hostsharing/hsadminng/service/dto/ShareDTO.java +++ b/src/main/java/org/hostsharing/hsadminng/service/dto/ShareDTO.java @@ -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() + "'" + "}"; } } diff --git a/src/main/java/org/hostsharing/hsadminng/service/mapper/AssetMapper.java b/src/main/java/org/hostsharing/hsadminng/service/mapper/AssetMapper.java index e4e4a530..293d87e8 100644 --- a/src/main/java/org/hostsharing/hsadminng/service/mapper/AssetMapper.java +++ b/src/main/java/org/hostsharing/hsadminng/service/mapper/AssetMapper.java @@ -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 { @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") diff --git a/src/main/java/org/hostsharing/hsadminng/service/mapper/CustomerMapper.java b/src/main/java/org/hostsharing/hsadminng/service/mapper/CustomerMapper.java index 6c9c204a..ced8f394 100644 --- a/src/main/java/org/hostsharing/hsadminng/service/mapper/CustomerMapper.java +++ b/src/main/java/org/hostsharing/hsadminng/service/mapper/CustomerMapper.java @@ -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 { + 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) diff --git a/src/main/java/org/hostsharing/hsadminng/service/mapper/MembershipMapper.java b/src/main/java/org/hostsharing/hsadminng/service/mapper/MembershipMapper.java index 3ef2c51b..ef2e5a47 100644 --- a/src/main/java/org/hostsharing/hsadminng/service/mapper/MembershipMapper.java +++ b/src/main/java/org/hostsharing/hsadminng/service/mapper/MembershipMapper.java @@ -16,21 +16,25 @@ import java.util.Objects; @Mapper(componentModel = "spring", uses = {CustomerMapper.class}) public interface MembershipMapper extends EntityMapper { + 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() + "] " - + Objects.toString(entity.getAdmissionDocumentDate()) + " - " - + 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) diff --git a/src/main/java/org/hostsharing/hsadminng/service/mapper/ShareMapper.java b/src/main/java/org/hostsharing/hsadminng/service/mapper/ShareMapper.java index 775ca7be..80ddc52b 100644 --- a/src/main/java/org/hostsharing/hsadminng/service/mapper/ShareMapper.java +++ b/src/main/java/org/hostsharing/hsadminng/service/mapper/ShareMapper.java @@ -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 { @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); diff --git a/src/main/webapp/app/entities/asset/asset-detail.component.html b/src/main/webapp/app/entities/asset/asset-detail.component.html index d31955d3..d092b737 100644 --- a/src/main/webapp/app/entities/asset/asset-detail.component.html +++ b/src/main/webapp/app/entities/asset/asset-detail.component.html @@ -1,7 +1,7 @@
-

Asset {{asset.id}}

+

Asset: #{{asset.id}} - {{asset.membershipDisplayLabel}}


@@ -28,7 +28,7 @@
Membership
diff --git a/src/main/webapp/app/entities/asset/asset-update.component.html b/src/main/webapp/app/entities/asset/asset-update.component.html index c11e140a..951db0b4 100644 --- a/src/main/webapp/app/entities/asset/asset-update.component.html +++ b/src/main/webapp/app/entities/asset/asset-update.component.html @@ -89,7 +89,7 @@
diff --git a/src/main/webapp/app/entities/asset/asset.component.html b/src/main/webapp/app/entities/asset/asset.component.html index 29ac04a6..8472107d 100644 --- a/src/main/webapp/app/entities/asset/asset.component.html +++ b/src/main/webapp/app/entities/asset/asset.component.html @@ -19,8 +19,7 @@ Value Date Action Amount - Remark - Membership + Membership @@ -31,10 +30,9 @@ {{asset.valueDate | date:'mediumDate'}} {{asset.action}} {{asset.amount}} - {{asset.remark}} diff --git a/src/main/webapp/app/entities/customer/customer-detail.component.html b/src/main/webapp/app/entities/customer/customer-detail.component.html index 93c22ade..3a74ce9e 100644 --- a/src/main/webapp/app/entities/customer/customer-detail.component.html +++ b/src/main/webapp/app/entities/customer/customer-detail.component.html @@ -1,7 +1,7 @@
-

Customer {{customer.id}}

+

Customer: {{customer.displayLabel}}


diff --git a/src/main/webapp/app/entities/customer/customer.component.html b/src/main/webapp/app/entities/customer/customer.component.html index afb4fb12..c655cc04 100644 --- a/src/main/webapp/app/entities/customer/customer.component.html +++ b/src/main/webapp/app/entities/customer/customer.component.html @@ -18,18 +18,7 @@ Reference Prefix Name - Kind - Birth Date - Birth Place - Registration Court - Registration Number - Vat Region - Vat Number - Contractual Salutation - Contractual Address - Billing Salutation - Billing Address - Remark + Kind @@ -40,17 +29,6 @@ {{customer.prefix}} {{customer.name}} {{customer.kind}} - {{customer.birthDate | date:'mediumDate'}} - {{customer.birthPlace}} - {{customer.registrationCourt}} - {{customer.registrationNumber}} - {{customer.vatRegion}} - {{customer.vatNumber}} - {{customer.contractualSalutation}} - {{customer.contractualAddress}} - {{customer.billingSalutation}} - {{customer.billingAddress}} - {{customer.remark}}