cdm.event.common.validation.datarule.TradeBarrierDerterminationAgent Maven / Gradle / Ivy
package cdm.event.common.validation.datarule;
import cdm.base.staticdata.party.PartyRole;
import cdm.base.staticdata.party.PartyRoleEnum;
import cdm.base.staticdata.party.functions.FilterPartyRole;
import cdm.event.common.Trade;
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.MapperC;
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 javax.inject.Inject;
import static com.rosetta.model.lib.expression.ExpressionOperators.*;
/**
* @version 6.0.0-dev.72
*/
@RosettaDataRule("TradeBarrierDerterminationAgent")
@ImplementedBy(TradeBarrierDerterminationAgent.Default.class)
public interface TradeBarrierDerterminationAgent extends Validator {
String NAME = "TradeBarrierDerterminationAgent";
String DEFINITION = "if partyRole -> role contains PartyRoleEnum -> BarrierDeterminationAgent then FilterPartyRole(partyRole, PartyRoleEnum -> BarrierDeterminationAgent) count <= 1";
ValidationResult validate(RosettaPath path, Trade trade);
class Default implements TradeBarrierDerterminationAgent {
@Inject protected FilterPartyRole filterPartyRole;
@Override
public ValidationResult validate(RosettaPath path, Trade trade) {
ComparisonResult result = executeDataRule(trade);
if (result.get()) {
return ValidationResult.success(NAME, ValidationResult.ValidationType.DATA_RULE, "Trade", path, DEFINITION);
}
String failureMessage = result.getError();
if (failureMessage == null || failureMessage.contains("Null") || failureMessage == "") {
failureMessage = "Condition has failed.";
}
return ValidationResult.failure(NAME, ValidationType.DATA_RULE, "Trade", path, DEFINITION, failureMessage);
}
private ComparisonResult executeDataRule(Trade trade) {
try {
if (contains(MapperS.of(trade).mapC("getPartyRole", _trade -> _trade.getPartyRole()).map("getRole", partyRole -> partyRole.getRole()), MapperS.of(PartyRoleEnum.BARRIER_DETERMINATION_AGENT)).getOrDefault(false)) {
return lessThanEquals(MapperS.of(MapperC.of(filterPartyRole.evaluate(MapperS.of(trade).mapC("getPartyRole", _trade -> _trade.getPartyRole()).getMulti(), PartyRoleEnum.BARRIER_DETERMINATION_AGENT)).resultCount()), MapperS.of(1), CardinalityOperator.All);
}
return ComparisonResult.successEmptyOperand("");
}
catch (Exception ex) {
return ComparisonResult.failure(ex.getMessage());
}
}
}
@SuppressWarnings("unused")
class NoOp implements TradeBarrierDerterminationAgent {
@Override
public ValidationResult validate(RosettaPath path, Trade trade) {
return ValidationResult.success(NAME, ValidationResult.ValidationType.DATA_RULE, "Trade", path, DEFINITION);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy