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

cdm.product.template.validation.datarule.SettlementPayoutIndex Maven / Gradle / Ivy

There is a newer version: 6.0.0-dev.89
Show newest version
package cdm.product.template.validation.datarule;

import cdm.observable.asset.Index;
import cdm.observable.asset.Observable;
import cdm.observable.asset.metafields.ReferenceWithMetaObservable;
import cdm.product.common.settlement.CashSettlementTerms;
import cdm.product.common.settlement.SettlementTerms;
import cdm.product.template.SettlementPayout;
import cdm.product.template.Underlier;
import com.google.inject.ImplementedBy;
import com.rosetta.model.lib.annotations.RosettaDataRule;
import com.rosetta.model.lib.expression.ComparisonResult;
import com.rosetta.model.lib.mapper.MapperS;
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 static com.rosetta.model.lib.expression.ExpressionOperators.*;

/**
 * @version 6.0.0-dev.82
 */
@RosettaDataRule("SettlementPayoutIndex")
@ImplementedBy(SettlementPayoutIndex.Default.class)
public interface SettlementPayoutIndex extends Validator {
	
	String NAME = "SettlementPayoutIndex";
	String DEFINITION = "if underlier -> Observable -> Index exists then settlementTerms -> cashSettlementTerms exists";
	
	ValidationResult validate(RosettaPath path, SettlementPayout settlementPayout);
	
	class Default implements SettlementPayoutIndex {
	
		@Override
		public ValidationResult validate(RosettaPath path, SettlementPayout settlementPayout) {
			ComparisonResult result = executeDataRule(settlementPayout);
			if (result.get()) {
				return ValidationResult.success(NAME, ValidationResult.ValidationType.DATA_RULE, "SettlementPayout", path, DEFINITION);
			}
			
			String failureMessage = result.getError();
			if (failureMessage == null || failureMessage.contains("Null") || failureMessage == "") {
				failureMessage = "Condition has failed.";
			}
			return ValidationResult.failure(NAME, ValidationType.DATA_RULE, "SettlementPayout", path, DEFINITION, failureMessage);
		}
		
		private ComparisonResult executeDataRule(SettlementPayout settlementPayout) {
			try {
				if (exists(MapperS.of(settlementPayout).map("getUnderlier", _settlementPayout -> _settlementPayout.getUnderlier()).map("getObservable", underlier -> underlier.getObservable()).map("Type coercion", referenceWithMetaObservable -> referenceWithMetaObservable == null ? null : referenceWithMetaObservable.getValue()).map("getIndex", observable -> observable.getIndex())).getOrDefault(false)) {
					return exists(MapperS.of(settlementPayout).map("getSettlementTerms", _settlementPayout -> _settlementPayout.getSettlementTerms()).mapC("getCashSettlementTerms", settlementTerms -> settlementTerms.getCashSettlementTerms()));
				}
				return ComparisonResult.successEmptyOperand("");
			}
			catch (Exception ex) {
				return ComparisonResult.failure(ex.getMessage());
			}
		}
	}
	
	@SuppressWarnings("unused")
	class NoOp implements SettlementPayoutIndex {
	
		@Override
		public ValidationResult validate(RosettaPath path, SettlementPayout settlementPayout) {
			return ValidationResult.success(NAME, ValidationResult.ValidationType.DATA_RULE, "SettlementPayout", path, DEFINITION);
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy