cdm.observable.asset.validation.exists.BasketConstituentOnlyExistsValidator Maven / Gradle / Ivy
package cdm.observable.asset.validation.exists;
import cdm.base.math.metafields.ReferenceWithMetaNonNegativeQuantitySchedule;
import cdm.base.staticdata.asset.common.Asset;
import cdm.base.staticdata.asset.common.Index;
import cdm.base.staticdata.asset.common.metafields.FieldWithMetaProductIdentifier;
import cdm.observable.asset.Basket;
import cdm.observable.asset.BasketConstituent;
import cdm.observable.asset.metafields.FieldWithMetaFloatingRateOption;
import cdm.observable.asset.metafields.ReferenceWithMetaPriceSchedule;
import com.google.common.collect.ImmutableMap;
import com.rosetta.model.lib.path.RosettaPath;
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 BasketConstituentOnlyExistsValidator 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("asset", ExistenceChecker.isSet((Asset) o.getAsset()))
.put("basket", ExistenceChecker.isSet((Basket) o.getBasket()))
.put("index", ExistenceChecker.isSet((Index) o.getIndex()))
.put("productIdentifier", ExistenceChecker.isSet((List extends FieldWithMetaProductIdentifier>) o.getProductIdentifier()))
.put("rateOption", ExistenceChecker.isSet((FieldWithMetaFloatingRateOption) o.getRateOption()))
.put("quantity", ExistenceChecker.isSet((List extends ReferenceWithMetaNonNegativeQuantitySchedule>) o.getQuantity()))
.put("initialValuationPrice", ExistenceChecker.isSet((List extends ReferenceWithMetaPriceSchedule>) o.getInitialValuationPrice()))
.put("interimValuationPrice", ExistenceChecker.isSet((List extends ReferenceWithMetaPriceSchedule>) o.getInterimValuationPrice()))
.put("finalValuationPrice", ExistenceChecker.isSet((List extends ReferenceWithMetaPriceSchedule>) o.getFinalValuationPrice()))
.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("BasketConstituent", ValidationType.ONLY_EXISTS, "BasketConstituent", path, "");
}
return failure("BasketConstituent", ValidationType.ONLY_EXISTS, "BasketConstituent", path, "",
String.format("[%s] should only be set. Set fields: %s", fields, setFields));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy