Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.rosetta.jptlegalagreement.model.validation.CsaInitialMargin2016JapaneseLawValidator Maven / Gradle / Ivy
package com.rosetta.jptlegalagreement.model.validation;
import com.google.common.collect.Lists;
import com.rosetta.jptlegalagreement.model.AdditionalRepresentation;
import com.rosetta.jptlegalagreement.model.CalculationDateLocation;
import com.rosetta.jptlegalagreement.model.ConditionsPrecedent;
import com.rosetta.jptlegalagreement.model.ContactElection;
import com.rosetta.jptlegalagreement.model.CreditSupportObligationsInitialMargin;
import com.rosetta.jptlegalagreement.model.CsaInitialMargin2016JapaneseLaw;
import com.rosetta.jptlegalagreement.model.DisputeResolution;
import com.rosetta.jptlegalagreement.model.FxHaircutCurrency;
import com.rosetta.jptlegalagreement.model.Method;
import com.rosetta.jptlegalagreement.model.NotificationTime;
import com.rosetta.jptlegalagreement.model.OneWayProvisions;
import com.rosetta.jptlegalagreement.model.Regime;
import com.rosetta.jptlegalagreement.model.SensitivityMethodology;
import com.rosetta.jptlegalagreement.model.Substitution;
import com.rosetta.jptlegalagreement.model.TerminationCurrencyAmendment;
import com.rosetta.model.lib.expression.ComparisonResult;
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 com.rosetta.model.metafields.FieldWithMetaString;
import java.util.List;
import static com.google.common.base.Strings.isNullOrEmpty;
import static com.rosetta.model.lib.expression.ExpressionOperators.checkCardinality;
import static com.rosetta.model.lib.validation.ValidationResult.failure;
import static com.rosetta.model.lib.validation.ValidationResult.success;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
public class CsaInitialMargin2016JapaneseLawValidator implements Validator {
private List getComparisonResults(CsaInitialMargin2016JapaneseLaw o) {
return Lists.newArrayList(
checkCardinality("baseCurrency", (FieldWithMetaString) o.getBaseCurrency() != null ? 1 : 0, 1, 1),
checkCardinality("additionalObligations", (String) o.getAdditionalObligations() != null ? 1 : 0, 0, 1),
checkCardinality("conditionsPrecedent", (ConditionsPrecedent) o.getConditionsPrecedent() != null ? 1 : 0, 1, 1),
checkCardinality("substitution", (Substitution) o.getSubstitution() != null ? 1 : 0, 1, 1),
checkCardinality("disputeResolution", (DisputeResolution) o.getDisputeResolution() != null ? 1 : 0, 1, 1),
checkCardinality("additionalRepresentation", (AdditionalRepresentation) o.getAdditionalRepresentation() != null ? 1 : 0, 1, 1),
checkCardinality("demandsAndNotices", (ContactElection) o.getDemandsAndNotices() != null ? 1 : 0, 1, 1),
checkCardinality("addressesForTransfer", (ContactElection) o.getAddressesForTransfer() != null ? 1 : 0, 1, 1),
checkCardinality("bespokeProvision", (String) o.getBespokeProvision() != null ? 1 : 0, 0, 1),
checkCardinality("regime", (Regime) o.getRegime() != null ? 1 : 0, 1, 1),
checkCardinality("oneWayProvisions", (OneWayProvisions) o.getOneWayProvisions() != null ? 1 : 0, 1, 1),
checkCardinality("method", (Method) o.getMethod() != null ? 1 : 0, 1, 1),
checkCardinality("identifiedCrossCurrencySwap", (Boolean) o.getIdentifiedCrossCurrencySwap() != null ? 1 : 0, 1, 1),
checkCardinality("sensitivityToEquity", (SensitivityMethodology) o.getSensitivityToEquity() != null ? 1 : 0, 1, 1),
checkCardinality("sensitivityToCommodity", (SensitivityMethodology) o.getSensitivityToCommodity() != null ? 1 : 0, 1, 1),
checkCardinality("fxHaircutCurrency", (FxHaircutCurrency) o.getFxHaircutCurrency() != null ? 1 : 0, 1, 1),
checkCardinality("creditSupportObligations", (CreditSupportObligationsInitialMargin) o.getCreditSupportObligations() != null ? 1 : 0, 1, 1),
checkCardinality("calculationDateLocation", (CalculationDateLocation) o.getCalculationDateLocation() != null ? 1 : 0, 1, 1),
checkCardinality("notificationTime", (NotificationTime) o.getNotificationTime() != null ? 1 : 0, 1, 1),
checkCardinality("terminationCurrency", (TerminationCurrencyAmendment) o.getTerminationCurrency() != null ? 1 : 0, 1, 1),
checkCardinality("automaticSetOff", (Boolean) o.getAutomaticSetOff() != null ? 1 : 0, 1, 1)
);
}
@Override
public ValidationResult validate(RosettaPath path, CsaInitialMargin2016JapaneseLaw o) {
String error = getComparisonResults(o)
.stream()
.filter(res -> !res.get())
.map(res -> res.getError())
.collect(joining("; "));
if (!isNullOrEmpty(error)) {
return failure("CsaInitialMargin2016JapaneseLaw", ValidationType.CARDINALITY, "CsaInitialMargin2016JapaneseLaw", path, "", error);
}
return success("CsaInitialMargin2016JapaneseLaw", ValidationType.CARDINALITY, "CsaInitialMargin2016JapaneseLaw", path, "");
}
@Override
public List> getValidationResults(RosettaPath path, CsaInitialMargin2016JapaneseLaw o) {
return getComparisonResults(o)
.stream()
.map(res -> {
if (!isNullOrEmpty(res.getError())) {
return failure("CsaInitialMargin2016JapaneseLaw", ValidationType.CARDINALITY, "CsaInitialMargin2016JapaneseLaw", path, "", res.getError());
}
return success("CsaInitialMargin2016JapaneseLaw", ValidationType.CARDINALITY, "CsaInitialMargin2016JapaneseLaw", path, "");
})
.collect(toList());
}
}