cdm.event.common.validation.datarule.BillingSummaryGrandTotal Maven / Gradle / Ivy
package cdm.event.common.validation.datarule;
import cdm.base.staticdata.party.PartyReferencePayerReceiver;
import cdm.event.common.BillingSummary;
import cdm.event.common.RecordAmountTypeEnum;
import cdm.event.common.Transfer;
import com.google.inject.ImplementedBy;
import com.rosetta.model.lib.annotations.RosettaDataRule;
import com.rosetta.model.lib.expression.CardinalityOperator;
import com.rosetta.model.lib.expression.ComparisonResult;
import com.rosetta.model.lib.mapper.MapperS;
import com.rosetta.model.lib.path.RosettaPath;
import com.rosetta.model.lib.validation.ValidationResult;
import com.rosetta.model.lib.validation.ValidationResult.ValidationType;
import com.rosetta.model.lib.validation.Validator;
import static com.rosetta.model.lib.expression.ExpressionOperators.*;
/**
* @version 6.0.0-dev.82
*/
@RosettaDataRule("BillingSummaryGrandTotal")
@ImplementedBy(BillingSummaryGrandTotal.Default.class)
public interface BillingSummaryGrandTotal extends Validator {
String NAME = "BillingSummaryGrandTotal";
String DEFINITION = "if summaryAmountType = RecordAmountTypeEnum -> GrandTotal then summaryTransfer exists and summaryTransfer -> payerReceiver is absent";
ValidationResult validate(RosettaPath path, BillingSummary billingSummary);
class Default implements BillingSummaryGrandTotal {
@Override
public ValidationResult validate(RosettaPath path, BillingSummary billingSummary) {
ComparisonResult result = executeDataRule(billingSummary);
if (result.get()) {
return ValidationResult.success(NAME, ValidationResult.ValidationType.DATA_RULE, "BillingSummary", path, DEFINITION);
}
String failureMessage = result.getError();
if (failureMessage == null || failureMessage.contains("Null") || failureMessage == "") {
failureMessage = "Condition has failed.";
}
return ValidationResult.failure(NAME, ValidationType.DATA_RULE, "BillingSummary", path, DEFINITION, failureMessage);
}
private ComparisonResult executeDataRule(BillingSummary billingSummary) {
try {
if (areEqual(MapperS.of(billingSummary).map("getSummaryAmountType", _billingSummary -> _billingSummary.getSummaryAmountType()), MapperS.of(RecordAmountTypeEnum.GRAND_TOTAL), CardinalityOperator.All).getOrDefault(false)) {
return exists(MapperS.of(billingSummary).map("getSummaryTransfer", _billingSummary -> _billingSummary.getSummaryTransfer())).and(notExists(MapperS.of(billingSummary).map("getSummaryTransfer", _billingSummary -> _billingSummary.getSummaryTransfer()).map("getPayerReceiver", transfer -> transfer.getPayerReceiver())));
}
return ComparisonResult.successEmptyOperand("");
}
catch (Exception ex) {
return ComparisonResult.failure(ex.getMessage());
}
}
}
@SuppressWarnings("unused")
class NoOp implements BillingSummaryGrandTotal {
@Override
public ValidationResult validate(RosettaPath path, BillingSummary billingSummary) {
return ValidationResult.success(NAME, ValidationResult.ValidationType.DATA_RULE, "BillingSummary", path, DEFINITION);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy