Revert "@AccessFrom in AssetDTO and AssetMapper with improved membershipDisplayReference"

This reverts commit 4ad0d5d954.
This commit is contained in:
Michael Hoennig 2019-04-27 06:37:56 +02:00
parent 51ff0c4990
commit 6570981dc2
5 changed files with 8 additions and 63 deletions

View File

@ -11,7 +11,6 @@ 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;
/**
@ -27,10 +26,8 @@ public class AssetService {
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;
public AssetService(AssetRepository assetRepository, AssetMapper assetMapper, AssetValidator assetValidator ) {
this.assetRepository = assetRepository;
this.assetMapper = assetMapper;
this.assetValidator = assetValidator;
@ -47,8 +44,6 @@ public class AssetService {
assetValidator.validate(assetDTO);
Asset asset = assetMapper.toEntity(assetDTO);
asset = assetRepository.save(asset);
em.flush();
em.refresh(asset);
return assetMapper.toDto(asset);
}

View File

@ -1,10 +1,6 @@
package org.hostsharing.hsadminng.service.dto;
import org.hostsharing.hsadminng.domain.enumeration.AssetAction;
import org.hostsharing.hsadminng.service.CustomerService;
import org.hostsharing.hsadminng.service.accessfilter.*;
import org.springframework.boot.jackson.JsonComponent;
import org.springframework.context.ApplicationContext;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
@ -16,37 +12,28 @@ import java.util.Objects;
/**
* A DTO for the Asset entity.
*/
public class AssetDTO implements Serializable, AccessMappings {
public class AssetDTO implements Serializable {
@SelfId(resolver = CustomerService.class)
@AccessFor(read = Role.ANY_CUSTOMER_USER)
private Long id;
@NotNull
@AccessFor(init = Role.ADMIN, update = Role.ADMIN, read = {Role.CONTRACTUAL_CONTACT, Role.FINANCIAL_CONTACT})
private LocalDate documentDate;
@NotNull
@AccessFor(init = Role.ADMIN, update = Role.ADMIN, read = {Role.CONTRACTUAL_CONTACT, Role.FINANCIAL_CONTACT})
private LocalDate valueDate;
@NotNull
@AccessFor(init = Role.ADMIN, update = Role.ADMIN, read = {Role.CONTRACTUAL_CONTACT, Role.FINANCIAL_CONTACT})
private AssetAction action;
@NotNull
@AccessFor(init = Role.ADMIN, update = Role.ADMIN, read = {Role.CONTRACTUAL_CONTACT, Role.FINANCIAL_CONTACT})
private BigDecimal amount;
@Size(max = 160)
@AccessFor(init = Role.ADMIN, update = Role.ADMIN, read = Role.ADMIN)
private String remark;
@ParentId(resolver = CustomerService.class)
@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;
public Long getId() {
@ -147,20 +134,4 @@ public class AssetDTO implements Serializable, AccessMappings {
", membership='" + getMembershipDisplayReference() + "'" +
"}";
}
@JsonComponent
public static class AssetJsonSerializer extends JsonSerializerWithAccessFilter<AssetDTO> {
public AssetJsonSerializer(final ApplicationContext ctx) {
super(ctx);
}
}
@JsonComponent
public static class AssetJsonDeserializer extends JsonDeserializerWithAccessFilter<AssetDTO> {
public AssetJsonDeserializer(final ApplicationContext ctx) {
super(ctx);
}
}
}

View File

@ -1,15 +1,9 @@
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,21 +12,9 @@ import java.util.Objects;
public interface AssetMapper extends EntityMapper<AssetDTO, Asset> {
@Mapping(source = "membership.id", target = "membershipId")
@Mapping(target = "membershipDisplayReference", ignore = true)
@Mapping(source = "membership.admissionDocumentDate", target = "membershipDisplayReference")
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(), ""));
}
@Mapping(source = "membershipId", target = "membership")
Asset toEntity(AssetDTO assetDTO);

View File

@ -37,10 +37,7 @@ spring:
indent-output: true
datasource:
type: com.zaxxer.hikari.HikariDataSource
# H2 in memory:
url: jdbc:h2:mem:hsadminng;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
# H2 in file:
# url: jdbc:h2:~/.hsadminng.h2db;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
username: hsadminNg
password:
hikari:

View File

@ -54,8 +54,8 @@ public class AssetResourceIntTest {
private static final AssetAction DEFAULT_ACTION = AssetAction.PAYMENT;
private static final AssetAction UPDATED_ACTION = AssetAction.HANDOVER;
private static final BigDecimal DEFAULT_AMOUNT = new BigDecimal("1.00");
private static final BigDecimal UPDATED_AMOUNT = new BigDecimal("2.00");
private static final BigDecimal DEFAULT_AMOUNT = new BigDecimal(1);
private static final BigDecimal UPDATED_AMOUNT = new BigDecimal(2);
private static final String DEFAULT_REMARK = "AAAAAAAAAA";
private static final String UPDATED_REMARK = "BBBBBBBBBB";
@ -283,7 +283,7 @@ public class AssetResourceIntTest {
.andExpect(jsonPath("$.[*].valueDate").value(hasItem(DEFAULT_VALUE_DATE.toString())))
.andExpect(jsonPath("$.[*].action").value(hasItem(DEFAULT_ACTION.toString())))
.andExpect(jsonPath("$.[*].amount").value(hasItem(DEFAULT_AMOUNT.intValue())))
.andExpect(jsonPath("$.[*].remark").value(hasItem(DEFAULT_REMARK)));
.andExpect(jsonPath("$.[*].remark").value(hasItem(DEFAULT_REMARK.toString())));
}
@Test
@ -301,7 +301,7 @@ public class AssetResourceIntTest {
.andExpect(jsonPath("$.valueDate").value(DEFAULT_VALUE_DATE.toString()))
.andExpect(jsonPath("$.action").value(DEFAULT_ACTION.toString()))
.andExpect(jsonPath("$.amount").value(DEFAULT_AMOUNT.intValue()))
.andExpect(jsonPath("$.remark").value(DEFAULT_REMARK));
.andExpect(jsonPath("$.remark").value(DEFAULT_REMARK.toString()));
}
@Test