Shares and Assets.
This commit is contained in:
@ -21,6 +21,8 @@ import org.hostsharing.hsadminng.domain.enumeration.AssetAction;
|
||||
public class Asset implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final String ENTITY_NAME = "asset";
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
|
||||
|
@ -26,10 +26,12 @@ public class AssetService {
|
||||
private final AssetRepository assetRepository;
|
||||
|
||||
private final AssetMapper assetMapper;
|
||||
private final AssetValidator assetValidator;
|
||||
|
||||
public AssetService(AssetRepository assetRepository, AssetMapper assetMapper) {
|
||||
public AssetService(AssetRepository assetRepository, AssetMapper assetMapper, AssetValidator assetValidator ) {
|
||||
this.assetRepository = assetRepository;
|
||||
this.assetMapper = assetMapper;
|
||||
this.assetValidator = assetValidator;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,6 +42,9 @@ public class AssetService {
|
||||
*/
|
||||
public AssetDTO save(AssetDTO assetDTO) {
|
||||
log.debug("Request to save Asset : {}", assetDTO);
|
||||
|
||||
assetValidator.validate(assetDTO);
|
||||
|
||||
Asset asset = assetMapper.toEntity(assetDTO);
|
||||
asset = assetRepository.save(asset);
|
||||
return assetMapper.toDto(asset);
|
||||
|
@ -0,0 +1,43 @@
|
||||
package org.hostsharing.hsadminng.service;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.Asset;
|
||||
import org.hostsharing.hsadminng.domain.enumeration.AssetAction;
|
||||
import org.hostsharing.hsadminng.service.dto.AssetDTO;
|
||||
import org.hostsharing.hsadminng.web.rest.errors.BadRequestAlertException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Service
|
||||
public class AssetValidator {
|
||||
public void validate(final AssetDTO assetDTO) {
|
||||
if (assetDTO.getId() != null) {
|
||||
throw new BadRequestAlertException("Asset transactions are immutable", Asset.ENTITY_NAME, "assetTransactionImmutable");
|
||||
}
|
||||
|
||||
if (assetDTO.getDocumentDate().isAfter(assetDTO.getValueDate())) {
|
||||
throw new BadRequestAlertException("Document date may not be after value date", Asset.ENTITY_NAME, "documentDateMayNotBeAfterValueDate");
|
||||
}
|
||||
|
||||
if ((assetDTO.getAction() == AssetAction.PAYMENT) && (assetDTO.getAmount().compareTo(BigDecimal.valueOf(0)) <= 0)) {
|
||||
throw new BadRequestAlertException("Asset payments require a positive amount", Asset.ENTITY_NAME, "assetPaymentsPositiveAmount");
|
||||
}
|
||||
if ((assetDTO.getAction() == AssetAction.ADOPTION) && (assetDTO.getAmount().compareTo(BigDecimal.valueOf(0)) <= 0)) {
|
||||
throw new BadRequestAlertException("Asset adoptions require a positive amount", Asset.ENTITY_NAME, "assetAdoptionsPositiveAmount");
|
||||
}
|
||||
|
||||
if ((assetDTO.getAction() == AssetAction.PAYBACK) && (assetDTO.getAmount().compareTo(BigDecimal.valueOf(0)) >= 0)) {
|
||||
throw new BadRequestAlertException("Asset paybacks require a negative amount", Asset.ENTITY_NAME, "assetPaybacksNegativeAmount");
|
||||
}
|
||||
if ((assetDTO.getAction() == AssetAction.HANDOVER) && (assetDTO.getAmount().compareTo(BigDecimal.valueOf(0)) >= 0)) {
|
||||
throw new BadRequestAlertException("Asset handovers require a negative amount", Asset.ENTITY_NAME, "assetHandoversNegativeAmount");
|
||||
}
|
||||
if ((assetDTO.getAction() == AssetAction.LOSS) && (assetDTO.getAmount().compareTo(BigDecimal.valueOf(0)) >= 0)) {
|
||||
throw new BadRequestAlertException("Asset losses require a negative amount", Asset.ENTITY_NAME, "assetLossesNegativeAmount");
|
||||
}
|
||||
if ((assetDTO.getAction() == AssetAction.CLEARING) && (assetDTO.getAmount().compareTo(BigDecimal.valueOf(0)) >= 0)) {
|
||||
throw new BadRequestAlertException("Asset clearings require a negative amount", Asset.ENTITY_NAME, "assetClearingsNegativeAmount");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -28,9 +28,12 @@ public class ShareService {
|
||||
|
||||
private final ShareMapper shareMapper;
|
||||
|
||||
public ShareService(ShareRepository shareRepository, ShareMapper shareMapper) {
|
||||
private final ShareValidator shareValidator;
|
||||
|
||||
public ShareService(ShareRepository shareRepository, ShareMapper shareMapper, ShareValidator shareValidator) {
|
||||
this.shareRepository = shareRepository;
|
||||
this.shareMapper = shareMapper;
|
||||
this.shareValidator = shareValidator;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -42,16 +45,8 @@ public class ShareService {
|
||||
public ShareDTO save(ShareDTO shareDTO) {
|
||||
log.debug("Request to save Share : {}", shareDTO);
|
||||
|
||||
if (shareDTO.getId() != null) {
|
||||
throw new BadRequestAlertException("Share transactions are immutable", Share.ENTITY_NAME, "shareTransactionImmutable");
|
||||
}
|
||||
shareValidator.validate(shareDTO);
|
||||
|
||||
if((shareDTO.getAction() == ShareAction.SUBSCRIPTION) && (shareDTO.getQuantity() <= 0)) {
|
||||
throw new BadRequestAlertException("Share subscriptions require a positive quantity", Share.ENTITY_NAME, "shareSubscriptionPositivQuantity");
|
||||
}
|
||||
if((shareDTO.getAction() == ShareAction.CANCELLATION) && (shareDTO.getQuantity() >= 0)) {
|
||||
throw new BadRequestAlertException("Share cancellations require a negative quantity", Share.ENTITY_NAME, "shareCancellationNegativeQuantity");
|
||||
}
|
||||
Share share = shareMapper.toEntity(shareDTO);
|
||||
share = shareRepository.save(share);
|
||||
return shareMapper.toDto(share);
|
||||
|
@ -0,0 +1,30 @@
|
||||
package org.hostsharing.hsadminng.service;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.Share;
|
||||
import org.hostsharing.hsadminng.domain.enumeration.ShareAction;
|
||||
import org.hostsharing.hsadminng.service.dto.ShareDTO;
|
||||
import org.hostsharing.hsadminng.web.rest.errors.BadRequestAlertException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class ShareValidator {
|
||||
|
||||
public void validate(final ShareDTO shareDTO) {
|
||||
if (shareDTO.getId() != null) {
|
||||
throw new BadRequestAlertException("Share transactions are immutable", Share.ENTITY_NAME, "shareTransactionImmutable");
|
||||
}
|
||||
|
||||
if (shareDTO.getDocumentDate().isAfter(shareDTO.getValueDate())) {
|
||||
throw new BadRequestAlertException("Document date may not be after value date", Share.ENTITY_NAME, "documentDateMayNotBeAfterValueDate");
|
||||
}
|
||||
|
||||
if ((shareDTO.getAction() == ShareAction.SUBSCRIPTION) && (shareDTO.getQuantity() <= 0)) {
|
||||
throw new BadRequestAlertException("Share subscriptions require a positive quantity", Share.ENTITY_NAME, "shareSubscriptionPositiveQuantity");
|
||||
}
|
||||
|
||||
if ((shareDTO.getAction() == ShareAction.CANCELLATION) && (shareDTO.getQuantity() >= 0)) {
|
||||
throw new BadRequestAlertException("Share cancellations require a negative quantity", Share.ENTITY_NAME, "shareCancellationNegativeQuantity");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user