com.rosetta.jptlegalagreement.model.validation.exists.LegalAgreementOnlyExistsValidator Maven / Gradle / Ivy
package com.rosetta.jptlegalagreement.model.validation.exists;
import com.google.common.collect.ImmutableMap;
import com.rosetta.jptlegalagreement.model.CsaInitialMargin2016JapaneseLaw;
import com.rosetta.jptlegalagreement.model.CsaInitialMargin2016NewYorkLaw;
import com.rosetta.jptlegalagreement.model.CsdInitialMargin2016EnglishLaw;
import com.rosetta.jptlegalagreement.model.Identifier;
import com.rosetta.jptlegalagreement.model.LegalAgreement;
import com.rosetta.jptlegalagreement.model.LegalAgreementType;
import com.rosetta.model.lib.path.RosettaPath;
import com.rosetta.model.lib.records.Date;
import com.rosetta.model.lib.validation.ExistenceChecker;
import com.rosetta.model.lib.validation.ValidationResult;
import com.rosetta.model.lib.validation.ValidationResult.ValidationType;
import com.rosetta.model.lib.validation.ValidatorWithArg;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import static com.rosetta.model.lib.validation.ValidationResult.failure;
import static com.rosetta.model.lib.validation.ValidationResult.success;
public class LegalAgreementOnlyExistsValidator implements ValidatorWithArg> {
/* Casting is required to ensure types are output to ensure recompilation in Rosetta */
@Override
public ValidationResult validate(RosettaPath path, T2 o, Set fields) {
Map fieldExistenceMap = ImmutableMap.builder()
.put("agreementDate", ExistenceChecker.isSet((Date) o.getAgreementDate()))
.put("effectiveDate", ExistenceChecker.isSet((Date) o.getEffectiveDate()))
.put("identifier", ExistenceChecker.isSet((List extends Identifier>) o.getIdentifier()))
.put("agreementType", ExistenceChecker.isSet((LegalAgreementType) o.getAgreementType()))
.put("csdInitialMargin2016EnglishLaw", ExistenceChecker.isSet((CsdInitialMargin2016EnglishLaw) o.getCsdInitialMargin2016EnglishLaw()))
.put("csaInitialMargin2016JapaneseLaw", ExistenceChecker.isSet((CsaInitialMargin2016JapaneseLaw) o.getCsaInitialMargin2016JapaneseLaw()))
.put("csaInitialMargin2016NewYorkLaw", ExistenceChecker.isSet((CsaInitialMargin2016NewYorkLaw) o.getCsaInitialMargin2016NewYorkLaw()))
.build();
// Find the fields that are set
Set setFields = fieldExistenceMap.entrySet().stream()
.filter(Map.Entry::getValue)
.map(Map.Entry::getKey)
.collect(Collectors.toSet());
if (setFields.equals(fields)) {
return success("LegalAgreement", ValidationType.ONLY_EXISTS, "LegalAgreement", path, "");
}
return failure("LegalAgreement", ValidationType.ONLY_EXISTS, "LegalAgreement", path, "",
String.format("[%s] should only be set. Set fields: %s", fields, setFields));
}
}