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

cdm.base.math.validation.datarule.MeasureScheduleValueExists Maven / Gradle / Ivy

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

import cdm.base.math.DatedValue;
import cdm.base.math.MeasureSchedule;
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 java.math.BigDecimal;

import static com.rosetta.model.lib.expression.ExpressionOperators.*;

/**
 * @version 6.0.0-dev.72
 */
@RosettaDataRule("MeasureScheduleValueExists")
@ImplementedBy(MeasureScheduleValueExists.Default.class)
public interface MeasureScheduleValueExists extends Validator {
	
	String NAME = "MeasureScheduleValueExists";
	String DEFINITION = "value exists or datedValue exists";
	
	ValidationResult validate(RosettaPath path, MeasureSchedule measureSchedule);
	
	class Default implements MeasureScheduleValueExists {
	
		@Override
		public ValidationResult validate(RosettaPath path, MeasureSchedule measureSchedule) {
			ComparisonResult result = executeDataRule(measureSchedule);
			if (result.get()) {
				return ValidationResult.success(NAME, ValidationResult.ValidationType.DATA_RULE, "MeasureSchedule", path, DEFINITION);
			}
			
			String failureMessage = result.getError();
			if (failureMessage == null || failureMessage.contains("Null") || failureMessage == "") {
				failureMessage = "Condition has failed.";
			}
			return ValidationResult.failure(NAME, ValidationType.DATA_RULE, "MeasureSchedule", path, DEFINITION, failureMessage);
		}
		
		private ComparisonResult executeDataRule(MeasureSchedule measureSchedule) {
			try {
				return exists(MapperS.of(measureSchedule).map("getValue", _measureSchedule -> _measureSchedule.getValue())).or(exists(MapperS.of(measureSchedule).mapC("getDatedValue", _measureSchedule -> _measureSchedule.getDatedValue())));
			}
			catch (Exception ex) {
				return ComparisonResult.failure(ex.getMessage());
			}
		}
	}
	
	@SuppressWarnings("unused")
	class NoOp implements MeasureScheduleValueExists {
	
		@Override
		public ValidationResult validate(RosettaPath path, MeasureSchedule measureSchedule) {
			return ValidationResult.success(NAME, ValidationResult.ValidationType.DATA_RULE, "MeasureSchedule", path, DEFINITION);
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy