All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.rosetta.jptlegalagreement.model.validation.CsaInitialMargin2016Validator Maven / Gradle / Ivy

There is a newer version: 11.25.1
Show newest version
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.CsaInitialMargin2016;
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 CsaInitialMargin2016Validator implements Validator {

	private List getComparisonResults(CsaInitialMargin2016 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)
			);
	}

	@Override
	public ValidationResult validate(RosettaPath path, CsaInitialMargin2016 o) {
		String error = getComparisonResults(o)
			.stream()
			.filter(res -> !res.get())
			.map(res -> res.getError())
			.collect(joining("; "));

		if (!isNullOrEmpty(error)) {
			return failure("CsaInitialMargin2016", ValidationType.CARDINALITY, "CsaInitialMargin2016", path, "", error);
		}
		return success("CsaInitialMargin2016", ValidationType.CARDINALITY, "CsaInitialMargin2016", path, "");
	}

	@Override
	public List> getValidationResults(RosettaPath path, CsaInitialMargin2016 o) {
		return getComparisonResults(o)
			.stream()
			.map(res -> {
				if (!isNullOrEmpty(res.getError())) {
					return failure("CsaInitialMargin2016", ValidationType.CARDINALITY, "CsaInitialMargin2016", path, "", res.getError());
				}
				return success("CsaInitialMargin2016", ValidationType.CARDINALITY, "CsaInitialMargin2016", path, "");
			})
			.collect(toList());
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy