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

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

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

import cdm.base.datetime.BusinessDayAdjustments;
import cdm.product.asset.InterestRatePayout;
import cdm.product.common.schedule.PaymentDates;
import cdm.product.template.Payout;
import com.google.inject.ImplementedBy;
import com.rosetta.model.lib.annotations.RosettaDataRule;
import com.rosetta.model.lib.expression.CardinalityOperator;
import com.rosetta.model.lib.expression.ComparisonResult;
import com.rosetta.model.lib.mapper.MapperS;
import com.rosetta.model.lib.mapper.MapperUtils;
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 5.0.1
 */
@RosettaDataRule("PayoutPaymentDatesAdjustments")
@ImplementedBy(PayoutPaymentDatesAdjustments.Default.class)
public interface PayoutPaymentDatesAdjustments extends Validator {
	
	String NAME = "PayoutPaymentDatesAdjustments";
	String DEFINITION = "if interestRatePayout count = 2 and interestRatePayout -> paymentDates exists then interestRatePayout -> paymentDates -> paymentDatesAdjustments exists";
	
	ValidationResult validate(RosettaPath path, Payout payout);
	
	class Default implements PayoutPaymentDatesAdjustments {
	
		@Override
		public ValidationResult validate(RosettaPath path, Payout payout) {
			ComparisonResult result = executeDataRule(payout);
			if (result.get()) {
				return ValidationResult.success(NAME, ValidationResult.ValidationType.DATA_RULE, "Payout", path, DEFINITION);
			}
			
			String failureMessage = result.getError();
			if (failureMessage == null || failureMessage.contains("Null") || failureMessage == "") {
				failureMessage = "Condition has failed.";
			}
			return ValidationResult.failure(NAME, ValidationType.DATA_RULE, "Payout", path, DEFINITION, failureMessage);
		}
		
		private ComparisonResult executeDataRule(Payout payout) {
			try {
				ComparisonResult result = MapperUtils.toComparisonResult(MapperUtils.runSingle(() -> {
					if (areEqual(MapperS.of(MapperS.of(payout).mapC("getInterestRatePayout", _payout -> _payout.getInterestRatePayout()).resultCount()), MapperS.of(Integer.valueOf(2)), CardinalityOperator.All).and(exists(MapperS.of(payout).mapC("getInterestRatePayout", _payout -> _payout.getInterestRatePayout()).map("getPaymentDates", interestRatePayout -> interestRatePayout.getPaymentDates()))).getOrDefault(false)) {
						return exists(MapperS.of(payout).mapC("getInterestRatePayout", _payout -> _payout.getInterestRatePayout()).map("getPaymentDates", interestRatePayout -> interestRatePayout.getPaymentDates()).map("getPaymentDatesAdjustments", paymentDates -> paymentDates.getPaymentDatesAdjustments()));
					}
					else {
						return null;
					}
				}));
				return result.get() == null ? ComparisonResult.success() : result;
			}
			catch (Exception ex) {
				return ComparisonResult.failure(ex.getMessage());
			}
		}
	}
	
	@SuppressWarnings("unused")
	class NoOp implements PayoutPaymentDatesAdjustments {
	
		@Override
		public ValidationResult validate(RosettaPath path, Payout payout) {
			return ValidationResult.success(NAME, ValidationResult.ValidationType.DATA_RULE, "Payout", path, DEFINITION);
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy