cdm.event.common.functions.Qualify_Cancellation Maven / Gradle / Ivy
package cdm.event.common.functions;
import cdm.base.datetime.AdjustableDate;
import cdm.base.datetime.AdjustableOrRelativeDate;
import cdm.event.common.BusinessEvent;
import cdm.event.common.Instruction;
import cdm.event.common.Trade;
import cdm.event.common.TradeState;
import cdm.event.common.metafields.ReferenceWithMetaTradeState;
import cdm.product.template.ContractualProduct;
import cdm.product.template.EconomicTerms;
import cdm.product.template.Product;
import cdm.product.template.TradableProduct;
import com.google.inject.ImplementedBy;
import com.rosetta.model.lib.expression.CardinalityOperator;
import com.rosetta.model.lib.expression.ComparisonResult;
import com.rosetta.model.lib.functions.IQualifyFunctionExtension;
import com.rosetta.model.lib.functions.RosettaFunction;
import com.rosetta.model.lib.mapper.MapperC;
import com.rosetta.model.lib.mapper.MapperS;
import com.rosetta.model.lib.records.Date;
import javax.inject.Inject;
import static com.rosetta.model.lib.expression.ExpressionOperators.*;
@ImplementedBy(Qualify_Cancellation.Qualify_CancellationDefault.class)
public abstract class Qualify_Cancellation implements RosettaFunction,IQualifyFunctionExtension {
// RosettaFunction dependencies
//
@Inject protected FilterClosedTradeStates filterClosedTradeStates;
@Inject protected FilterOpenTradeStates filterOpenTradeStates;
/**
* @param businessEvent
* @return is_event
*/
@Override
public Boolean evaluate(BusinessEvent businessEvent) {
Boolean is_event = doEvaluate(businessEvent);
return is_event;
}
protected abstract Boolean doEvaluate(BusinessEvent businessEvent);
protected abstract MapperS extends EconomicTerms> closedEconomicTerms(BusinessEvent businessEvent);
protected abstract MapperS extends EconomicTerms> openEconomicTerms(BusinessEvent businessEvent);
public static class Qualify_CancellationDefault extends Qualify_Cancellation {
@Override
protected Boolean doEvaluate(BusinessEvent businessEvent) {
Boolean is_event = null;
return assignOutput(is_event, businessEvent);
}
protected Boolean assignOutput(Boolean is_event, BusinessEvent businessEvent) {
final ComparisonResult ifThenElseResult;
if (exists(openEconomicTerms(businessEvent).map("getTerminationDate", economicTerms -> economicTerms.getTerminationDate())).and(exists(closedEconomicTerms(businessEvent).map("getTerminationDate", economicTerms -> economicTerms.getTerminationDate()))).getOrDefault(false)) {
ifThenElseResult = lessThan(openEconomicTerms(businessEvent).map("getTerminationDate", economicTerms -> economicTerms.getTerminationDate()).map("getAdjustableDate", adjustableOrRelativeDate -> adjustableOrRelativeDate.getAdjustableDate()).map("getUnadjustedDate", adjustableDate -> adjustableDate.getUnadjustedDate()), closedEconomicTerms(businessEvent).map("getTerminationDate", economicTerms -> economicTerms.getTerminationDate()).map("getAdjustableDate", adjustableOrRelativeDate -> adjustableOrRelativeDate.getAdjustableDate()).map("getUnadjustedDate", adjustableDate -> adjustableDate.getUnadjustedDate()), CardinalityOperator.All);
} else {
ifThenElseResult = exists(openEconomicTerms(businessEvent).map("getTerminationDate", economicTerms -> economicTerms.getTerminationDate()));
}
is_event = areEqual(MapperS.of(MapperS.of(businessEvent).mapC("getInstruction", _businessEvent -> _businessEvent.getInstruction()).map("getBefore", instruction -> instruction.getBefore()).map("getValue", _f->_f.getValue()).resultCount()), MapperS.of(1), CardinalityOperator.All).and(exists(closedEconomicTerms(businessEvent))).and(exists(openEconomicTerms(businessEvent))).and(ifThenElseResult).get();
return is_event;
}
@Override
protected MapperS extends EconomicTerms> closedEconomicTerms(BusinessEvent businessEvent) {
return MapperS.of(MapperC.of(filterClosedTradeStates.evaluate(MapperS.of(businessEvent).mapC("getAfter", _businessEvent -> _businessEvent.getAfter()).getMulti())).get()).map("getTrade", tradeState -> tradeState.getTrade()).map("getTradableProduct", trade -> trade.getTradableProduct()).map("getProduct", tradableProduct -> tradableProduct.getProduct()).map("getContractualProduct", product -> product.getContractualProduct()).map("getEconomicTerms", contractualProduct -> contractualProduct.getEconomicTerms());
}
@Override
protected MapperS extends EconomicTerms> openEconomicTerms(BusinessEvent businessEvent) {
return MapperS.of(MapperC.of(filterOpenTradeStates.evaluate(MapperS.of(businessEvent).mapC("getAfter", _businessEvent -> _businessEvent.getAfter()).getMulti())).get()).map("getTrade", tradeState -> tradeState.getTrade()).map("getTradableProduct", trade -> trade.getTradableProduct()).map("getProduct", tradableProduct -> tradableProduct.getProduct()).map("getContractualProduct", product -> product.getContractualProduct()).map("getEconomicTerms", contractualProduct -> contractualProduct.getEconomicTerms());
}
}
@Override
public String getNamePrefix() {
return "Qualify";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy