![JAR search and dependency download from the Maven repository](/logo.png)
com.rosetta.jptlegalagreement.model.validation.LegalAgreementValidator Maven / Gradle / Ivy
package com.rosetta.jptlegalagreement.model.validation;
import com.google.common.collect.Lists;
import com.rosetta.jptlegalagreement.model.CsaInitialMargin2016JapaneseLaw;
import com.rosetta.jptlegalagreement.model.CsaInitialMargin2016NewYorkLaw;
import com.rosetta.jptlegalagreement.model.CsdInitialMargin2016EnglishLaw;
import com.rosetta.jptlegalagreement.model.LegalAgreement;
import com.rosetta.jptlegalagreement.model.LegalAgreementType;
import com.rosetta.model.lib.expression.ComparisonResult;
import com.rosetta.model.lib.path.RosettaPath;
import com.rosetta.model.lib.records.Date;
import com.rosetta.model.lib.validation.ValidationResult;
import com.rosetta.model.lib.validation.ValidationResult.ValidationType;
import com.rosetta.model.lib.validation.Validator;
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 LegalAgreementValidator implements Validator {
private List getComparisonResults(LegalAgreement o) {
return Lists.newArrayList(
checkCardinality("agreementDate", (Date) o.getAgreementDate() != null ? 1 : 0, 1, 1),
checkCardinality("effectiveDate", (Date) o.getEffectiveDate() != null ? 1 : 0, 0, 1),
checkCardinality("agreementType", (LegalAgreementType) o.getAgreementType() != null ? 1 : 0, 1, 1),
checkCardinality("csdInitialMargin2016EnglishLaw", (CsdInitialMargin2016EnglishLaw) o.getCsdInitialMargin2016EnglishLaw() != null ? 1 : 0, 0, 1),
checkCardinality("csaInitialMargin2016JapaneseLaw", (CsaInitialMargin2016JapaneseLaw) o.getCsaInitialMargin2016JapaneseLaw() != null ? 1 : 0, 0, 1),
checkCardinality("csaInitialMargin2016NewYorkLaw", (CsaInitialMargin2016NewYorkLaw) o.getCsaInitialMargin2016NewYorkLaw() != null ? 1 : 0, 0, 1)
);
}
@Override
public ValidationResult validate(RosettaPath path, LegalAgreement o) {
String error = getComparisonResults(o)
.stream()
.filter(res -> !res.get())
.map(res -> res.getError())
.collect(joining("; "));
if (!isNullOrEmpty(error)) {
return failure("LegalAgreement", ValidationType.CARDINALITY, "LegalAgreement", path, "", error);
}
return success("LegalAgreement", ValidationType.CARDINALITY, "LegalAgreement", path, "");
}
@Override
public List> getValidationResults(RosettaPath path, LegalAgreement o) {
return getComparisonResults(o)
.stream()
.map(res -> {
if (!isNullOrEmpty(res.getError())) {
return failure("LegalAgreement", ValidationType.CARDINALITY, "LegalAgreement", path, "", res.getError());
}
return success("LegalAgreement", ValidationType.CARDINALITY, "LegalAgreement", path, "");
})
.collect(toList());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy