cdm.product.template.validation.datarule.SettlementPayoutUnderlier Maven / Gradle / Ivy
package cdm.product.template.validation.datarule;
import cdm.product.template.NonTransferableProduct;
import cdm.product.template.Product;
import cdm.product.template.SettlementPayout;
import cdm.product.template.Underlier;
import com.google.inject.ImplementedBy;
import com.rosetta.model.lib.annotations.RosettaDataRule;
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.72
*/
@RosettaDataRule("SettlementPayoutUnderlier")
@ImplementedBy(SettlementPayoutUnderlier.Default.class)
public interface SettlementPayoutUnderlier extends Validator {
String NAME = "SettlementPayoutUnderlier";
String DEFINITION = "underlier -> Product -> NonTransferableProduct is absent";
ValidationResult validate(RosettaPath path, SettlementPayout settlementPayout);
class Default implements SettlementPayoutUnderlier {
@Override
public ValidationResult validate(RosettaPath path, SettlementPayout settlementPayout) {
ComparisonResult result = executeDataRule(settlementPayout);
if (result.get()) {
return ValidationResult.success(NAME, ValidationResult.ValidationType.DATA_RULE, "SettlementPayout", path, DEFINITION);
}
String failureMessage = result.getError();
if (failureMessage == null || failureMessage.contains("Null") || failureMessage == "") {
failureMessage = "Condition has failed.";
}
return ValidationResult.failure(NAME, ValidationType.DATA_RULE, "SettlementPayout", path, DEFINITION, failureMessage);
}
private ComparisonResult executeDataRule(SettlementPayout settlementPayout) {
try {
return notExists(MapperS.of(settlementPayout).map("getUnderlier", _settlementPayout -> _settlementPayout.getUnderlier()).map("getProduct", underlier -> underlier.getProduct()).map("getNonTransferableProduct", product -> product.getNonTransferableProduct()));
}
catch (Exception ex) {
return ComparisonResult.failure(ex.getMessage());
}
}
}
@SuppressWarnings("unused")
class NoOp implements SettlementPayoutUnderlier {
@Override
public ValidationResult validate(RosettaPath path, SettlementPayout settlementPayout) {
return ValidationResult.success(NAME, ValidationResult.ValidationType.DATA_RULE, "SettlementPayout", path, DEFINITION);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy