cdm.event.common.functions.Qualify_OnDemandPayment Maven / Gradle / Ivy
package cdm.event.common.functions;
import cdm.event.common.BusinessEvent;
import cdm.event.common.Instruction;
import cdm.event.common.PrimitiveInstruction;
import cdm.event.common.TermsChangeInstruction;
import cdm.event.common.Trade;
import cdm.event.common.TradeState;
import cdm.event.common.metafields.ReferenceWithMetaTradeState;
import cdm.product.common.settlement.Cashflow;
import cdm.product.common.settlement.CashflowType;
import cdm.product.common.settlement.ScheduledTransferEnum;
import cdm.product.template.ContractualProduct;
import cdm.product.template.EconomicTerms;
import cdm.product.template.Payout;
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.functions.IQualifyFunctionExtension;
import com.rosetta.model.lib.functions.RosettaFunction;
import com.rosetta.model.lib.mapper.Mapper;
import com.rosetta.model.lib.mapper.MapperC;
import com.rosetta.model.lib.mapper.MapperS;
import java.util.Arrays;
import javax.inject.Inject;
import static com.rosetta.model.lib.expression.ExpressionOperators.*;
@ImplementedBy(Qualify_OnDemandPayment.Qualify_OnDemandPaymentDefault.class)
public abstract class Qualify_OnDemandPayment 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 Mapper extends TradeState> afterTradeStates(BusinessEvent businessEvent);
protected abstract Mapper extends Cashflow> beforeCashFlow(BusinessEvent businessEvent);
protected abstract Mapper extends Cashflow> afterCashFlow(BusinessEvent businessEvent);
public static class Qualify_OnDemandPaymentDefault extends Qualify_OnDemandPayment {
@Override
protected Boolean doEvaluate(BusinessEvent businessEvent) {
Boolean is_event = null;
return assignOutput(is_event, businessEvent);
}
protected Boolean assignOutput(Boolean is_event, BusinessEvent businessEvent) {
is_event = areEqual(MapperS.of(MapperS.of(businessEvent).mapC("getInstruction", eventInstruction -> eventInstruction.getInstruction()).map("getBefore", instruction -> instruction.getBefore()).map("getValue", _f->_f.getValue()).resultCount()), MapperS.of(Integer.valueOf(1)), CardinalityOperator.All).and(areEqual(MapperS.of(MapperS.of(businessEvent).mapC("getAfter", _businessEvent -> _businessEvent.getAfter()).resultCount()), MapperS.of(Integer.valueOf(1)), CardinalityOperator.All)).and(areEqual(MapperS.of(MapperC.of(afterTradeStates(businessEvent).getMulti()).resultCount()), MapperS.of(Integer.valueOf(1)), CardinalityOperator.All)).and(onlyExists(Arrays.asList(MapperS.of(businessEvent).mapC("getInstruction", eventInstruction -> eventInstruction.getInstruction()).map("getPrimitiveInstruction", instruction -> instruction.getPrimitiveInstruction()).map("getTermsChange", primitiveInstruction -> primitiveInstruction.getTermsChange())))).and(greaterThan(MapperS.of(MapperC.of(afterCashFlow(businessEvent).getMulti()).resultCount()), MapperS.of(MapperC.of(beforeCashFlow(businessEvent).getMulti()).resultCount()), CardinalityOperator.All)).and(areEqual(MapperC.of(afterCashFlow(businessEvent).getMulti()).map("getCashflowType", cashflow -> cashflow.getCashflowType()).map("getCashflowType", cashflowType -> cashflowType.getCashflowType()), MapperS.of(ScheduledTransferEnum.NET_INTEREST), CardinalityOperator.All)).get();
return is_event;
}
@Override
protected Mapper extends TradeState> afterTradeStates(BusinessEvent businessEvent) {
return MapperC.of(filterOpenTradeStates.evaluate(MapperS.of(businessEvent).mapC("getAfter", _businessEvent -> _businessEvent.getAfter()).getMulti()));
}
@Override
protected Mapper extends Cashflow> beforeCashFlow(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()).map("getPayout", economicTerms -> economicTerms.getPayout()).mapC("getCashflow", payout -> payout.getCashflow());
}
@Override
protected Mapper extends Cashflow> afterCashFlow(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()).map("getPayout", economicTerms -> economicTerms.getPayout()).mapC("getCashflow", payout -> payout.getCashflow());
}
}
@Override
public String getNamePrefix() {
return "Qualify";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy