Shares and Assets.
This commit is contained in:
parent
e3792d9570
commit
bc1c94a364
@ -21,6 +21,8 @@ import org.hostsharing.hsadminng.domain.enumeration.AssetAction;
|
|||||||
public class Asset implements Serializable {
|
public class Asset implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public static final String ENTITY_NAME = "asset";
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
|
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
|
||||||
|
@ -26,10 +26,12 @@ public class AssetService {
|
|||||||
private final AssetRepository assetRepository;
|
private final AssetRepository assetRepository;
|
||||||
|
|
||||||
private final AssetMapper assetMapper;
|
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.assetRepository = assetRepository;
|
||||||
this.assetMapper = assetMapper;
|
this.assetMapper = assetMapper;
|
||||||
|
this.assetValidator = assetValidator;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,6 +42,9 @@ public class AssetService {
|
|||||||
*/
|
*/
|
||||||
public AssetDTO save(AssetDTO assetDTO) {
|
public AssetDTO save(AssetDTO assetDTO) {
|
||||||
log.debug("Request to save Asset : {}", assetDTO);
|
log.debug("Request to save Asset : {}", assetDTO);
|
||||||
|
|
||||||
|
assetValidator.validate(assetDTO);
|
||||||
|
|
||||||
Asset asset = assetMapper.toEntity(assetDTO);
|
Asset asset = assetMapper.toEntity(assetDTO);
|
||||||
asset = assetRepository.save(asset);
|
asset = assetRepository.save(asset);
|
||||||
return assetMapper.toDto(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;
|
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.shareRepository = shareRepository;
|
||||||
this.shareMapper = shareMapper;
|
this.shareMapper = shareMapper;
|
||||||
|
this.shareValidator = shareValidator;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,16 +45,8 @@ public class ShareService {
|
|||||||
public ShareDTO save(ShareDTO shareDTO) {
|
public ShareDTO save(ShareDTO shareDTO) {
|
||||||
log.debug("Request to save Share : {}", shareDTO);
|
log.debug("Request to save Share : {}", shareDTO);
|
||||||
|
|
||||||
if (shareDTO.getId() != null) {
|
shareValidator.validate(shareDTO);
|
||||||
throw new BadRequestAlertException("Share transactions are immutable", Share.ENTITY_NAME, "shareTransactionImmutable");
|
|
||||||
}
|
|
||||||
|
|
||||||
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 share = shareMapper.toEntity(shareDTO);
|
||||||
share = shareRepository.save(share);
|
share = shareRepository.save(share);
|
||||||
return shareMapper.toDto(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");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -2,25 +2,25 @@
|
|||||||
"hsadminNgApp": {
|
"hsadminNgApp": {
|
||||||
"asset": {
|
"asset": {
|
||||||
"home": {
|
"home": {
|
||||||
"title": "Assets",
|
"title": "Geschäftsguthaben-Transaktionen",
|
||||||
"createLabel": "Asset erstellen",
|
"createLabel": "Geschäftsguthaben-Transaktion erfassen",
|
||||||
"createOrEditLabel": "Asset erstellen oder bearbeiten"
|
"createOrEditLabel": "Geschäftsguthaben-Transaktion erfassen oder bearbeiten"
|
||||||
},
|
},
|
||||||
"created": "Asset erstellt mit ID {{ param }}",
|
"created": "Geschäftsguthaben-Transaktion erfasst mit ID {{ param }}",
|
||||||
"updated": "Asset aktualisiert mit ID {{ param }}",
|
"updated": "Geschäftsguthaben-Transaktion aktualisiert mit ID {{ param }}",
|
||||||
"deleted": "Asset gelöscht mit ID {{ param }}",
|
"deleted": "Geschäftsguthaben-Transaktion gelöscht mit ID {{ param }}",
|
||||||
"delete": {
|
"delete": {
|
||||||
"question": "Soll Asset {{ id }} wirklich dauerhaft gelöscht werden?"
|
"question": "Soll die Geschäftsguthaben-Transaktion {{ id }} wirklich dauerhaft gelöscht werden?"
|
||||||
},
|
},
|
||||||
"detail": {
|
"detail": {
|
||||||
"title": "Asset"
|
"title": "Geschäftsguthaben-Transaktion"
|
||||||
},
|
},
|
||||||
"documentDate": "Document Date",
|
"documentDate": "Belegdatum",
|
||||||
"valueDate": "Value Date",
|
"valueDate": "Buchungsdatum",
|
||||||
"action": "Action",
|
"action": "Transaktion",
|
||||||
"amount": "Amount",
|
"amount": "Betrag",
|
||||||
"remark": "Remark",
|
"remark": "Bemerkung",
|
||||||
"membership": "Membership"
|
"membership": "zugehörige Mitgliedschaft"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
"hsadminNgApp": {
|
"hsadminNgApp": {
|
||||||
"AssetAction": {
|
"AssetAction": {
|
||||||
"null": "",
|
"null": "",
|
||||||
"PAYMENT": "PAYMENT",
|
"PAYMENT": "Einzahlung",
|
||||||
"HANDOVER": "HANDOVER",
|
"HANDOVER": "Übertragung",
|
||||||
"ADOPTION": "ADOPTION",
|
"ADOPTION": "Übernahme",
|
||||||
"LOSS": "LOSS",
|
"LOSS": "Verlust",
|
||||||
"CLEARING": "CLEARING",
|
"CLEARING": "Verrechnung",
|
||||||
"PAYBACK": "PAYBACK"
|
"PAYBACK": "Auszahlung"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,17 @@
|
|||||||
{
|
{
|
||||||
"error": {
|
"error": {
|
||||||
"shareSubscriptionPositivQuantity": "Zeichnungen von Geschäftsanteilen erfordern eine positive Stückzahl",
|
"shareSubscriptionPositiveQuantity": "Zeichnungen von Geschäftsanteilen erfordern eine positive Stückzahl",
|
||||||
"shareCancellationNegativeQuantity": "Kündigungen von Geschäftsanteilen erfordern eine negative Stückzahl",
|
"shareCancellationNegativeQuantity": "Kündigungen von Geschäftsanteilen erfordern eine negative Stückzahl",
|
||||||
"shareTransactionImmutable": "Transaktionen mit Geschäftsanteilen sind unveränderlich",
|
"shareTransactionImmutable": "Transaktionen mit Geschäftsanteilen sind unveränderlich",
|
||||||
"membershipNotDeletable": "Mitgliedschaft kann nicht gelöscht werden, setze stattdessen das 'untilDate'",
|
"membershipNotDeletable": "Mitgliedschaft kann nicht gelöscht werden, setze stattdessen das 'untilDate'",
|
||||||
"untilDateMustBeAfterSinceDate": "Mitgliedshafts-Austrittsdatum muss nach dem Beitrittsdatum liegen",
|
"untilDateMustBeAfterSinceDate": "Mitgliedshaftsaustrittsdatum muss nach dem Beitrittsdatum liegen",
|
||||||
"anotherUncancelledMembershipExists": "Nur eine einzige ungekündigte Mitgliedschaft pro Kunde ist zulässig"
|
"documentDateMayNotBeAfterValueDate": "Belegdatum darf nicht vor dem Buchungsdatum liegen",
|
||||||
|
"anotherUncancelledMembershipExists": "Nur eine einzige ungekündigte Mitgliedschaft pro Kunde ist zulässig",
|
||||||
|
"assetPaymentsPositiveAmount": "Einzahlungen von Geschäftsguthaben erfordern einen positiven Betrag",
|
||||||
|
"assetAdoptionsPositiveAmount": "Übernahmen von Geschäftsguthaben erfordern einen positiven Betrag",
|
||||||
|
"assetPaybacksNegativeAmount": "Auszahlungen von Geschäftsguthaben erfordern einen negativen Betrag",
|
||||||
|
"assetHandoversNegativeAmount": "Übertragungen von Geschäftsguthaben erfordern einen negativen Betrag",
|
||||||
|
"assetLossesNegativeAmount": "Verluste von Geschäftsguthaben erfordern einen negativen Betrag",
|
||||||
|
"assetClearingsNegativeAmount": "Verrechnungen von Geschäftsguthaben erfordern einen negativen Betrag"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,25 +2,25 @@
|
|||||||
"hsadminNgApp": {
|
"hsadminNgApp": {
|
||||||
"share": {
|
"share": {
|
||||||
"home": {
|
"home": {
|
||||||
"title": "Shares",
|
"title": "Geschäftsanteil-Transaktionen",
|
||||||
"createLabel": "Share erstellen",
|
"createLabel": "Geschäftsanteil-Transaktion erfassen",
|
||||||
"createOrEditLabel": "Share erstellen oder bearbeiten"
|
"createOrEditLabel": "Geschäftsanteil-Transaktion erfassen oder bearbeiten"
|
||||||
},
|
},
|
||||||
"created": "Share erstellt mit ID {{ param }}",
|
"created": "Geschäftsanteil-Transaktion erfasst mit ID {{ param }}",
|
||||||
"updated": "Share aktualisiert mit ID {{ param }}",
|
"updated": "Geschäftsanteil-Transaktion aktualisiert mit ID {{ param }}",
|
||||||
"deleted": "Share gelöscht mit ID {{ param }}",
|
"deleted": "Geschäftsanteil-Transaktion gelöscht mit ID {{ param }}",
|
||||||
"delete": {
|
"delete": {
|
||||||
"question": "Soll Share {{ id }} wirklich dauerhaft gelöscht werden?"
|
"question": "Soll die Geschäftsanteil-Transaktion {{ id }} wirklich dauerhaft gelöscht werden?"
|
||||||
},
|
},
|
||||||
"detail": {
|
"detail": {
|
||||||
"title": "Share"
|
"title": "Geschäftsanteil-Transaktion"
|
||||||
},
|
},
|
||||||
"documentDate": "Document Date",
|
"documentDate": "Belegdatum",
|
||||||
"valueDate": "Value Date",
|
"valueDate": "Buchungsdatum",
|
||||||
"action": "Action",
|
"action": "Aktion",
|
||||||
"quantity": "Quantity",
|
"quantity": "Anzahl",
|
||||||
"remark": "Remark",
|
"remark": "Bemerkung",
|
||||||
"membership": "Membership"
|
"membership": "zugehörige Mitgliedschaft"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
"hsadminNgApp": {
|
"hsadminNgApp": {
|
||||||
"ShareAction": {
|
"ShareAction": {
|
||||||
"null": "",
|
"null": "",
|
||||||
"SUBSCRIPTION": "SUBSCRIPTION",
|
"SUBSCRIPTION": "Zeichnung",
|
||||||
"CANCELLATION": "CANCELLATION"
|
"CANCELLATION": "Kündigung"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,25 +2,25 @@
|
|||||||
"hsadminNgApp": {
|
"hsadminNgApp": {
|
||||||
"asset": {
|
"asset": {
|
||||||
"home": {
|
"home": {
|
||||||
"title": "Assets",
|
"title": "Asset Transactions",
|
||||||
"createLabel": "Create a new Asset",
|
"createLabel": "Register a new asset transaction",
|
||||||
"createOrEditLabel": "Create or edit a Asset"
|
"createOrEditLabel": "Register or edit an asset transaction"
|
||||||
},
|
},
|
||||||
"created": "A new Asset is created with identifier {{ param }}",
|
"created": "A new asset transaction is registered with identifier {{ param }}",
|
||||||
"updated": "A Asset is updated with identifier {{ param }}",
|
"updated": "An asset transaction is updated with identifier {{ param }}",
|
||||||
"deleted": "A Asset is deleted with identifier {{ param }}",
|
"deleted": "An asset transaction is deleted with identifier {{ param }}",
|
||||||
"delete": {
|
"delete": {
|
||||||
"question": "Are you sure you want to delete Asset {{ id }}?"
|
"question": "Are you sure you want to delete asset transaction {{ id }}?"
|
||||||
},
|
},
|
||||||
"detail": {
|
"detail": {
|
||||||
"title": "Asset"
|
"title": "Asset transaction"
|
||||||
},
|
},
|
||||||
"documentDate": "Document Date",
|
"documentDate": "Document date",
|
||||||
"valueDate": "Value Date",
|
"valueDate": "Value date",
|
||||||
"action": "Action",
|
"action": "Action",
|
||||||
"amount": "Amount",
|
"amount": "Amount",
|
||||||
"remark": "Remark",
|
"remark": "Remark",
|
||||||
"membership": "Membership"
|
"membership": "Related membership"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
"hsadminNgApp": {
|
"hsadminNgApp": {
|
||||||
"AssetAction": {
|
"AssetAction": {
|
||||||
"null": "",
|
"null": "",
|
||||||
"PAYMENT": "PAYMENT",
|
"PAYMENT": "Payment",
|
||||||
"HANDOVER": "HANDOVER",
|
"HANDOVER": "Handover",
|
||||||
"ADOPTION": "ADOPTION",
|
"ADOPTION": "Adoption",
|
||||||
"LOSS": "LOSS",
|
"LOSS": "Loss",
|
||||||
"CLEARING": "CLEARING",
|
"CLEARING": "Clearing",
|
||||||
"PAYBACK": "PAYBACK"
|
"PAYBACK": "Payback"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,17 @@
|
|||||||
{
|
{
|
||||||
"error": {
|
"error": {
|
||||||
"shareSubscriptionPositivQuantity": "Share subscriptions require a positive quantity",
|
"shareSubscriptionPositiveQuantity": "Share subscriptions require a positive quantity",
|
||||||
"shareCancellationNegativeQuantity": "Share cancellations require a negative quantity",
|
"shareCancellationNegativeQuantity": "Share cancellations require a negative quantity",
|
||||||
"shareTransactionImmutable": "Share transactions are immutable",
|
"shareTransactionImmutable": "Share transactions are immutable",
|
||||||
"membershipNotDeletable": "Membership cannot be deleted, instead set 'untilDate'",
|
"membershipNotDeletable": "Membership cannot be deleted, instead set 'untilDate'",
|
||||||
"untilDateMustBeAfterSinceDate": "Membership until date must be after since date",
|
"untilDateMustBeAfterSinceDate": "Membership until date must be after since date",
|
||||||
"anotherUncancelledMembershipExists": "Only a single uncancelled membership allowed per customer"
|
"documentDateMayNotBeAfterValueDate": "Document date may not be after value date",
|
||||||
|
"anotherUncancelledMembershipExists": "Only a single uncancelled membership allowed per customer",
|
||||||
|
"assetPaymentsPositiveAmount": "Asset payments require a positive amount",
|
||||||
|
"assetAdoptionsPositiveAmount": "Asset adoptions require a positive amount",
|
||||||
|
"assetPaybacksNegativeAmount": "Asset paybacks require a negative amount",
|
||||||
|
"assetHandoversNegativeAmount": "Asset handovers require a negative amount",
|
||||||
|
"assetLossesNegativeAmount": "Asset losses require a negative amount",
|
||||||
|
"assetClearingsNegativeAmount": "Asset clearings require a negative amount"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,25 +2,25 @@
|
|||||||
"hsadminNgApp": {
|
"hsadminNgApp": {
|
||||||
"share": {
|
"share": {
|
||||||
"home": {
|
"home": {
|
||||||
"title": "Shares",
|
"title": "Share Transactions",
|
||||||
"createLabel": "Create a new Share",
|
"createLabel": "Register a new share transaction",
|
||||||
"createOrEditLabel": "Create or edit a Share"
|
"createOrEditLabel": "Register or edit a share transaction"
|
||||||
},
|
},
|
||||||
"created": "A new Share is created with identifier {{ param }}",
|
"created": "A new share transactions is registered with identifier {{ param }}",
|
||||||
"updated": "A Share is updated with identifier {{ param }}",
|
"updated": "A share transaction is updated with identifier {{ param }}",
|
||||||
"deleted": "A Share is deleted with identifier {{ param }}",
|
"deleted": "A share transcation is deleted with identifier {{ param }}",
|
||||||
"delete": {
|
"delete": {
|
||||||
"question": "Are you sure you want to delete Share {{ id }}?"
|
"question": "Are you sure you want to delete share transaction {{ id }}?"
|
||||||
},
|
},
|
||||||
"detail": {
|
"detail": {
|
||||||
"title": "Share"
|
"title": "Share transaction"
|
||||||
},
|
},
|
||||||
"documentDate": "Document Date",
|
"documentDate": "Document date",
|
||||||
"valueDate": "Value Date",
|
"valueDate": "Value date",
|
||||||
"action": "Action",
|
"action": "Action",
|
||||||
"quantity": "Quantity",
|
"quantity": "Quantity",
|
||||||
"remark": "Remark",
|
"remark": "Remark",
|
||||||
"membership": "Membership"
|
"membership": "Related membership"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
"hsadminNgApp": {
|
"hsadminNgApp": {
|
||||||
"ShareAction": {
|
"ShareAction": {
|
||||||
"null": "",
|
"null": "",
|
||||||
"SUBSCRIPTION": "SUBSCRIPTION",
|
"SUBSCRIPTION": "Subscription",
|
||||||
"CANCELLATION": "CANCELLATION"
|
"CANCELLATION": "Cancellation"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,205 @@
|
|||||||
|
package org.hostsharing.hsadminng.service;
|
||||||
|
|
||||||
|
import org.assertj.core.api.AbstractThrowableAssert;
|
||||||
|
import org.hostsharing.hsadminng.domain.enumeration.AssetAction;
|
||||||
|
import org.hostsharing.hsadminng.service.dto.AssetDTO;
|
||||||
|
import org.hostsharing.hsadminng.web.rest.errors.BadRequestAlertException;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.catchThrowableOfType;
|
||||||
|
|
||||||
|
public class AssetValidatorUnitTest {
|
||||||
|
|
||||||
|
private AssetValidator assetValidator = new AssetValidator();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldAcceptValidAssetDTO() {
|
||||||
|
new GivenAssetValidationTestCase()
|
||||||
|
.withDocumentDate("2019-04-11").withValueDate("2019-04-12")
|
||||||
|
.withAction(AssetAction.PAYMENT).withAmount("64.00")
|
||||||
|
.when((AssetDTO assetDto) -> assetValidator.validate(assetDto))
|
||||||
|
.thenActualException().isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldAcceptIfDocumentDateEqualsValueDate() {
|
||||||
|
new GivenAssetValidationTestCase()
|
||||||
|
.withDocumentDate("2019-04-11").withValueDate("2019-04-11")
|
||||||
|
.withAction(AssetAction.PAYMENT).withAmount("64.00")
|
||||||
|
.when((AssetDTO assetDto) -> assetValidator.validate(assetDto))
|
||||||
|
.thenActualException().isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRejectIfDocumentDateAfterValueDate() {
|
||||||
|
new GivenAssetValidationTestCase()
|
||||||
|
.withDocumentDate("2019-04-13").withValueDate("2019-04-12")
|
||||||
|
.withAction(AssetAction.PAYMENT).withAmount("64.00")
|
||||||
|
.when((AssetDTO assetDto) -> assetValidator.validate(assetDto))
|
||||||
|
.thenActualException().isEqualToComparingFieldByField(new BadRequestAlertException(
|
||||||
|
"Document date may not be after value date", "asset", "documentDateMayNotBeAfterValueDate"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRejectIfPaymentWithNegativeAmount() {
|
||||||
|
new GivenAssetValidationTestCase()
|
||||||
|
.withDocumentDate("2019-04-11").withValueDate("2019-04-12")
|
||||||
|
.withAction(AssetAction.PAYMENT).withAmount("-64.00")
|
||||||
|
.when((AssetDTO assetDto) -> assetValidator.validate(assetDto))
|
||||||
|
.thenActualException().isEqualToComparingFieldByField(new BadRequestAlertException(
|
||||||
|
"Asset payments require a positive amount", "asset", "assetPaymentsPositiveAmount"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRejectIfPaymentWithZeroAmount() {
|
||||||
|
new GivenAssetValidationTestCase()
|
||||||
|
.withDocumentDate("2019-04-11").withValueDate("2019-04-12")
|
||||||
|
.withAction(AssetAction.PAYMENT).withAmount("0.00")
|
||||||
|
.when((AssetDTO assetDto) -> assetValidator.validate(assetDto))
|
||||||
|
.thenActualException().isEqualToComparingFieldByField(new BadRequestAlertException(
|
||||||
|
"Asset payments require a positive amount", "asset", "assetPaymentsPositiveAmount"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRejectIfAdoptionWithNegativeAmount() {
|
||||||
|
new GivenAssetValidationTestCase()
|
||||||
|
.withDocumentDate("2019-04-11").withValueDate("2019-04-12")
|
||||||
|
.withAction(AssetAction.ADOPTION).withAmount("-64.00")
|
||||||
|
.when((AssetDTO assetDto) -> assetValidator.validate(assetDto))
|
||||||
|
.thenActualException().isEqualToComparingFieldByField(new BadRequestAlertException(
|
||||||
|
"Asset adoptions require a positive amount", "asset", "assetAdoptionsPositiveAmount"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRejectIfAdoptionWithZeroAmount() {
|
||||||
|
new GivenAssetValidationTestCase()
|
||||||
|
.withDocumentDate("2019-04-11").withValueDate("2019-04-12")
|
||||||
|
.withAction(AssetAction.ADOPTION).withAmount("0.00")
|
||||||
|
.when((AssetDTO assetDto) -> assetValidator.validate(assetDto))
|
||||||
|
.thenActualException().isEqualToComparingFieldByField(new BadRequestAlertException(
|
||||||
|
"Asset adoptions require a positive amount", "asset", "assetAdoptionsPositiveAmount"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRejectIfPaybackWithPositiveAmount() {
|
||||||
|
new GivenAssetValidationTestCase()
|
||||||
|
.withDocumentDate("2019-04-11").withValueDate("2019-04-12")
|
||||||
|
.withAction(AssetAction.PAYBACK).withAmount("64.00")
|
||||||
|
.when((AssetDTO assetDto) -> assetValidator.validate(assetDto))
|
||||||
|
.thenActualException().isEqualToComparingFieldByField(new BadRequestAlertException(
|
||||||
|
"Asset paybacks require a negative amount", "asset", "assetPaybacksNegativeAmount"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRejectIfPaybackWithZeroAmount() {
|
||||||
|
new GivenAssetValidationTestCase()
|
||||||
|
.withDocumentDate("2019-04-11").withValueDate("2019-04-12")
|
||||||
|
.withAction(AssetAction.PAYBACK).withAmount("0.00")
|
||||||
|
.when((AssetDTO assetDto) -> assetValidator.validate(assetDto))
|
||||||
|
.thenActualException().isEqualToComparingFieldByField(new BadRequestAlertException(
|
||||||
|
"Asset paybacks require a negative amount", "asset", "assetPaybacksNegativeAmount"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRejectIfHandoverWithPositiveAmount() {
|
||||||
|
new GivenAssetValidationTestCase()
|
||||||
|
.withDocumentDate("2019-04-11").withValueDate("2019-04-12")
|
||||||
|
.withAction(AssetAction.HANDOVER).withAmount("64.00")
|
||||||
|
.when((AssetDTO assetDto) -> assetValidator.validate(assetDto))
|
||||||
|
.thenActualException().isEqualToComparingFieldByField(new BadRequestAlertException(
|
||||||
|
"Asset handovers require a negative amount", "asset", "assetHandoversNegativeAmount"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRejectIfHandoverWithZeroAmount() {
|
||||||
|
new GivenAssetValidationTestCase()
|
||||||
|
.withDocumentDate("2019-04-11").withValueDate("2019-04-12")
|
||||||
|
.withAction(AssetAction.HANDOVER).withAmount("0.00")
|
||||||
|
.when((AssetDTO assetDto) -> assetValidator.validate(assetDto))
|
||||||
|
.thenActualException().isEqualToComparingFieldByField(new BadRequestAlertException(
|
||||||
|
"Asset handovers require a negative amount", "asset", "assetHandoversNegativeAmount"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRejectIfLossWithPositiveAmount() {
|
||||||
|
new GivenAssetValidationTestCase()
|
||||||
|
.withDocumentDate("2019-04-11").withValueDate("2019-04-12")
|
||||||
|
.withAction(AssetAction.LOSS).withAmount("64.00")
|
||||||
|
.when((AssetDTO assetDto) -> assetValidator.validate(assetDto))
|
||||||
|
.thenActualException().isEqualToComparingFieldByField(new BadRequestAlertException(
|
||||||
|
"Asset losses require a negative amount", "asset", "assetLossesNegativeAmount"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRejectIfLossWithZeroAmount() {
|
||||||
|
new GivenAssetValidationTestCase()
|
||||||
|
.withDocumentDate("2019-04-11").withValueDate("2019-04-12")
|
||||||
|
.withAction(AssetAction.LOSS).withAmount("0.00")
|
||||||
|
.when((AssetDTO assetDto) -> assetValidator.validate(assetDto))
|
||||||
|
.thenActualException().isEqualToComparingFieldByField(new BadRequestAlertException(
|
||||||
|
"Asset losses require a negative amount", "asset", "assetLossesNegativeAmount"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRejectIfClearingWithPositiveAmount() {
|
||||||
|
new GivenAssetValidationTestCase()
|
||||||
|
.withDocumentDate("2019-04-11").withValueDate("2019-04-12")
|
||||||
|
.withAction(AssetAction.CLEARING).withAmount("64.00")
|
||||||
|
.when((AssetDTO assetDto) -> assetValidator.validate(assetDto))
|
||||||
|
.thenActualException().isEqualToComparingFieldByField(new BadRequestAlertException(
|
||||||
|
"Asset clearings require a negative amount", "asset", "assetClearingsNegativeAmount"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRejectIfClearingWithZeroAmount() {
|
||||||
|
new GivenAssetValidationTestCase()
|
||||||
|
.withDocumentDate("2019-04-11").withValueDate("2019-04-12")
|
||||||
|
.withAction(AssetAction.CLEARING).withAmount("0.00")
|
||||||
|
.when((AssetDTO assetDto) -> assetValidator.validate(assetDto))
|
||||||
|
.thenActualException().isEqualToComparingFieldByField(new BadRequestAlertException(
|
||||||
|
"Asset clearings require a negative amount", "asset", "assetClearingsNegativeAmount"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// -- only test fixture below ---
|
||||||
|
|
||||||
|
private class GivenAssetValidationTestCase {
|
||||||
|
|
||||||
|
private final AssetDTO assetDto = new AssetDTO();
|
||||||
|
private BadRequestAlertException actualException;
|
||||||
|
|
||||||
|
GivenAssetValidationTestCase withDocumentDate(String documentDate) {
|
||||||
|
assetDto.setDocumentDate(LocalDate.parse(documentDate));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
GivenAssetValidationTestCase withValueDate(String valueDate) {
|
||||||
|
assetDto.setValueDate(LocalDate.parse(valueDate));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
GivenAssetValidationTestCase withAction(AssetAction assetAction) {
|
||||||
|
assetDto.setAction(assetAction);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
GivenAssetValidationTestCase withAmount(String amount) {
|
||||||
|
assetDto.setAmount(new BigDecimal(amount));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
GivenAssetValidationTestCase when(final Consumer<AssetDTO> statement) {
|
||||||
|
actualException = catchThrowableOfType(() -> assetValidator.validate(assetDto), BadRequestAlertException.class);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbstractThrowableAssert<?, ? extends Throwable> thenActualException() {
|
||||||
|
return assertThat(actualException);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,126 @@
|
|||||||
|
package org.hostsharing.hsadminng.service;
|
||||||
|
|
||||||
|
import org.assertj.core.api.AbstractThrowableAssert;
|
||||||
|
import org.hostsharing.hsadminng.domain.enumeration.ShareAction;
|
||||||
|
import org.hostsharing.hsadminng.service.dto.ShareDTO;
|
||||||
|
import org.hostsharing.hsadminng.web.rest.errors.BadRequestAlertException;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.catchThrowableOfType;
|
||||||
|
|
||||||
|
public class ShareValidatorUnitTest {
|
||||||
|
|
||||||
|
private ShareValidator shareValidator = new ShareValidator();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldAcceptValidShareDTO() {
|
||||||
|
new GivenShareValidationTestCase()
|
||||||
|
.withDocumentDate("2019-04-11").withValueDate("2019-04-12")
|
||||||
|
.withAction(ShareAction.SUBSCRIPTION).withQuantity(1)
|
||||||
|
.when((ShareDTO shareDto) -> shareValidator.validate(shareDto))
|
||||||
|
.thenActualException().isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldAcceptIfDocumentDateEqualsValueDate() {
|
||||||
|
new GivenShareValidationTestCase()
|
||||||
|
.withDocumentDate("2019-04-11").withValueDate("2019-04-11")
|
||||||
|
.withAction(ShareAction.SUBSCRIPTION).withQuantity(1)
|
||||||
|
.when((ShareDTO shareDto) -> shareValidator.validate(shareDto))
|
||||||
|
.thenActualException().isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRejectIfDocumentDateAfterValueDate() {
|
||||||
|
new GivenShareValidationTestCase()
|
||||||
|
.withDocumentDate("2019-04-13").withValueDate("2019-04-12")
|
||||||
|
.withAction(ShareAction.SUBSCRIPTION).withQuantity(1)
|
||||||
|
.when((ShareDTO shareDto) -> shareValidator.validate(shareDto))
|
||||||
|
.thenActualException().isEqualToComparingFieldByField(new BadRequestAlertException(
|
||||||
|
"Document date may not be after value date", "share", "documentDateMayNotBeAfterValueDate"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRejectIfSubscriptionWithNegativeQuantity() {
|
||||||
|
new GivenShareValidationTestCase()
|
||||||
|
.withDocumentDate("2019-04-11").withValueDate("2019-04-12")
|
||||||
|
.withAction(ShareAction.SUBSCRIPTION).withQuantity(-1)
|
||||||
|
.when((ShareDTO shareDto) -> shareValidator.validate(shareDto))
|
||||||
|
.thenActualException().isEqualToComparingFieldByField(new BadRequestAlertException(
|
||||||
|
"Share subscriptions require a positive quantity", "share", "shareSubscriptionPositiveQuantity"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRejectIfSubscriptionWithZeroQuantity() {
|
||||||
|
new GivenShareValidationTestCase()
|
||||||
|
.withDocumentDate("2019-04-11").withValueDate("2019-04-12")
|
||||||
|
.withAction(ShareAction.SUBSCRIPTION).withQuantity(0)
|
||||||
|
.when((ShareDTO shareDto) -> shareValidator.validate(shareDto))
|
||||||
|
.thenActualException().isEqualToComparingFieldByField(new BadRequestAlertException(
|
||||||
|
"Share subscriptions require a positive quantity", "share", "shareSubscriptionPositiveQuantity"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRejectIfCancellationWithPositiveQuantity() {
|
||||||
|
new GivenShareValidationTestCase()
|
||||||
|
.withDocumentDate("2019-04-11").withValueDate("2019-04-12")
|
||||||
|
.withAction(ShareAction.CANCELLATION).withQuantity(1)
|
||||||
|
.when((ShareDTO shareDto) -> shareValidator.validate(shareDto))
|
||||||
|
.thenActualException().isEqualToComparingFieldByField(new BadRequestAlertException(
|
||||||
|
"Share cancellations require a negative quantity", "share", "shareCancellationNegativeQuantity"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRejectIfCancellationWithZeroQuantity() {
|
||||||
|
new GivenShareValidationTestCase()
|
||||||
|
.withDocumentDate("2019-04-11").withValueDate("2019-04-12")
|
||||||
|
.withAction(ShareAction.CANCELLATION).withQuantity(0)
|
||||||
|
.when((ShareDTO shareDto) -> shareValidator.validate(shareDto))
|
||||||
|
.thenActualException().isEqualToComparingFieldByField(new BadRequestAlertException(
|
||||||
|
"Share cancellations require a negative quantity", "share", "shareCancellationNegativeQuantity"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// -- only test fixture below ---
|
||||||
|
|
||||||
|
private class GivenShareValidationTestCase {
|
||||||
|
|
||||||
|
private final ShareDTO shareDto = new ShareDTO();
|
||||||
|
private BadRequestAlertException actualException;
|
||||||
|
|
||||||
|
GivenShareValidationTestCase withDocumentDate(String documentDate) {
|
||||||
|
shareDto.setDocumentDate(LocalDate.parse(documentDate));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
GivenShareValidationTestCase withValueDate(String valueDate) {
|
||||||
|
shareDto.setValueDate(LocalDate.parse(valueDate));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
GivenShareValidationTestCase withAction(ShareAction shareAction) {
|
||||||
|
shareDto.setAction(shareAction);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
GivenShareValidationTestCase withQuantity(Integer quantity) {
|
||||||
|
shareDto.setQuantity(quantity);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
GivenShareValidationTestCase when(final Consumer<ShareDTO> statement) {
|
||||||
|
actualException = catchThrowableOfType(() -> shareValidator.validate(shareDto), BadRequestAlertException.class);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbstractThrowableAssert<?, ? extends Throwable> thenActualException() {
|
||||||
|
return assertThat(actualException);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user