cdm.event.qualification.functions.Qualify_PartialNovation Maven / Gradle / Ivy
package cdm.event.qualification.functions;
import cdm.base.staticdata.party.Counterparty;
import cdm.base.staticdata.party.Party;
import cdm.base.staticdata.party.metafields.ReferenceWithMetaParty;
import cdm.event.common.BusinessEvent;
import cdm.event.common.EventIntentEnum;
import cdm.event.common.Instruction;
import cdm.event.common.PrimitiveInstruction;
import cdm.event.common.SplitInstruction;
import cdm.event.common.Trade;
import cdm.event.common.TradeIdentifier;
import cdm.event.common.TradeState;
import cdm.event.common.functions.FilterClosedTradeStates;
import cdm.event.common.functions.FilterOpenTradeStates;
import cdm.event.common.functions.QuantityDecreased;
import cdm.event.common.metafields.ReferenceWithMetaTradeState;
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 javax.inject.Inject;
import static com.rosetta.model.lib.expression.ExpressionOperators.*;
@ImplementedBy(Qualify_PartialNovation.Qualify_PartialNovationDefault.class)
public abstract class Qualify_PartialNovation implements RosettaFunction,IQualifyFunctionExtension {
// RosettaFunction dependencies
//
@Inject protected FilterClosedTradeStates filterClosedTradeStates;
@Inject protected FilterOpenTradeStates filterOpenTradeStates;
@Inject protected QuantityDecreased quantityDecreased;
/**
* @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 beforeTradeState(BusinessEvent businessEvent);
protected abstract MapperC extends TradeState> closedTradeStates(BusinessEvent businessEvent);
protected abstract MapperC extends TradeState> openTradeStates(BusinessEvent businessEvent);
public static class Qualify_PartialNovationDefault extends Qualify_PartialNovation {
@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(businessEvent).map("getIntent", _businessEvent -> _businessEvent.getIntent()), MapperS.of(EventIntentEnum.NOVATION), CardinalityOperator.All).and(areEqual(MapperS.of(closedTradeStates(businessEvent).resultCount()), MapperS.of(0), CardinalityOperator.All)).and(areEqual(MapperS.of(openTradeStates(businessEvent).resultCount()), MapperS.of(2), CardinalityOperator.All)).and(exists(MapperS.of(businessEvent).mapC("getInstruction", _businessEvent -> _businessEvent.getInstruction()).map("getPrimitiveInstruction", instruction -> instruction.getPrimitiveInstruction()).map("getSplit", primitiveInstruction -> primitiveInstruction.getSplit()))).and(areEqual(openTradeStates(businessEvent)
.mapItem(item -> {
final ReferenceWithMetaTradeState referenceWithMetaTradeState4 = beforeTradeState(businessEvent).get();
return notEqual(item.map("getTrade", tradeState -> tradeState.getTrade()).mapC("getCounterparty", trade -> trade.getCounterparty()).map("getPartyReference", counterparty -> counterparty.getPartyReference()).map("Type coercion", referenceWithMetaParty -> referenceWithMetaParty.getValue()), beforeTradeState(businessEvent).map("Type coercion", referenceWithMetaTradeState0 -> referenceWithMetaTradeState0 == null ? null : referenceWithMetaTradeState0.getValue()).map("getTrade", tradeState -> tradeState.getTrade()).mapC("getCounterparty", trade -> trade.getCounterparty()).map("getPartyReference", counterparty -> counterparty.getPartyReference()).map("Type coercion", referenceWithMetaParty -> referenceWithMetaParty.getValue()), CardinalityOperator.Any).and(notEqual(item.map("getTrade", tradeState -> tradeState.getTrade()).mapC("getTradeIdentifier", trade -> trade.getTradeIdentifier()), beforeTradeState(businessEvent).map("Type coercion", referenceWithMetaTradeState1 -> referenceWithMetaTradeState1 == null ? null : referenceWithMetaTradeState1.getValue()).map("getTrade", tradeState -> tradeState.getTrade()).mapC("getTradeIdentifier", trade -> trade.getTradeIdentifier()), CardinalityOperator.Any)).or(areEqual(item.map("getTrade", tradeState -> tradeState.getTrade()).mapC("getCounterparty", trade -> trade.getCounterparty()).map("getPartyReference", counterparty -> counterparty.getPartyReference()).map("Type coercion", referenceWithMetaParty -> referenceWithMetaParty.getValue()), beforeTradeState(businessEvent).map("Type coercion", referenceWithMetaTradeState2 -> referenceWithMetaTradeState2 == null ? null : referenceWithMetaTradeState2.getValue()).map("getTrade", tradeState -> tradeState.getTrade()).mapC("getCounterparty", trade -> trade.getCounterparty()).map("getPartyReference", counterparty -> counterparty.getPartyReference()).map("Type coercion", referenceWithMetaParty -> referenceWithMetaParty.getValue()), CardinalityOperator.All).and(areEqual(item.map("getTrade", tradeState -> tradeState.getTrade()).mapC("getTradeIdentifier", trade -> trade.getTradeIdentifier()), beforeTradeState(businessEvent).map("Type coercion", referenceWithMetaTradeState3 -> referenceWithMetaTradeState3 == null ? null : referenceWithMetaTradeState3.getValue()).map("getTrade", tradeState -> tradeState.getTrade()).mapC("getTradeIdentifier", trade -> trade.getTradeIdentifier()), CardinalityOperator.All)).and(ComparisonResult.of(MapperS.of(quantityDecreased.evaluate((referenceWithMetaTradeState4 == null ? null : referenceWithMetaTradeState4.getValue()), MapperC.of(item).getMulti()))))).asMapper();
}), MapperS.of(true), CardinalityOperator.All)).get();
return is_event;
}
@Override
protected MapperS beforeTradeState(BusinessEvent businessEvent) {
return MapperS.of(MapperS.of(businessEvent).mapC("getInstruction", _businessEvent -> _businessEvent.getInstruction()).map("getBefore", instruction -> instruction.getBefore()).get());
}
@Override
protected MapperC extends TradeState> closedTradeStates(BusinessEvent businessEvent) {
return MapperC.of(filterClosedTradeStates.evaluate(MapperS.of(businessEvent).mapC("getAfter", _businessEvent -> _businessEvent.getAfter()).getMulti()));
}
@Override
protected MapperC extends TradeState> openTradeStates(BusinessEvent businessEvent) {
return MapperC.of(filterOpenTradeStates.evaluate(MapperS.of(businessEvent).mapC("getAfter", _businessEvent -> _businessEvent.getAfter()).getMulti()));
}
}
@Override
public String getNamePrefix() {
return "Qualify";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy