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.Csa2016Validator 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.ConditionsPrecedent;
import com.rosetta.jptlegalagreement.model.ContactElection;
import com.rosetta.jptlegalagreement.model.Csa2016;
import com.rosetta.jptlegalagreement.model.DisputeResolution;
import com.rosetta.jptlegalagreement.model.Substitution;
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 Csa2016Validator implements Validator {
private List getComparisonResults(Csa2016 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)
);
}
@Override
public ValidationResult validate(RosettaPath path, Csa2016 o) {
String error = getComparisonResults(o)
.stream()
.filter(res -> !res.get())
.map(res -> res.getError())
.collect(joining("; "));
if (!isNullOrEmpty(error)) {
return failure("Csa2016", ValidationType.CARDINALITY, "Csa2016", path, "", error);
}
return success("Csa2016", ValidationType.CARDINALITY, "Csa2016", path, "");
}
@Override
public List> getValidationResults(RosettaPath path, Csa2016 o) {
return getComparisonResults(o)
.stream()
.map(res -> {
if (!isNullOrEmpty(res.getError())) {
return failure("Csa2016", ValidationType.CARDINALITY, "Csa2016", path, "", res.getError());
}
return success("Csa2016", ValidationType.CARDINALITY, "Csa2016", path, "");
})
.collect(toList());
}
}