com.rosetta.metatest.model.validation.datarule.Observable12Choice Maven / Gradle / Ivy
package com.rosetta.metatest.model.validation.datarule;
import com.google.inject.ImplementedBy;
import com.rosetta.metatest.model.Observable12;
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.ChoiceRuleValidationMethod;
import com.rosetta.model.lib.validation.ValidationResult;
import com.rosetta.model.lib.validation.ValidationResult.ValidationType;
import com.rosetta.model.lib.validation.Validator;
import java.util.Arrays;
import static com.rosetta.model.lib.expression.ExpressionOperators.*;
/**
* @version test
*/
@RosettaDataRule("Observable12Choice")
@ImplementedBy(Observable12Choice.Default.class)
public interface Observable12Choice extends Validator {
String NAME = "Observable12Choice";
String DEFINITION = "";
ValidationResult validate(RosettaPath path, Observable12 observable12);
class Default implements Observable12Choice {
@Override
public ValidationResult validate(RosettaPath path, Observable12 observable12) {
ComparisonResult result = executeDataRule(observable12);
if (result.get()) {
return ValidationResult.success(NAME, ValidationResult.ValidationType.DATA_RULE, "Observable12", path, DEFINITION);
}
String failureMessage = result.getError();
if (failureMessage == null || failureMessage.contains("Null") || failureMessage == "") {
failureMessage = "Condition has failed.";
}
return ValidationResult.failure(NAME, ValidationType.DATA_RULE, "Observable12", path, DEFINITION, failureMessage);
}
private ComparisonResult executeDataRule(Observable12 observable12) {
try {
return choice(MapperS.of(observable12), Arrays.asList("Asset12"), ChoiceRuleValidationMethod.REQUIRED);
}
catch (Exception ex) {
return ComparisonResult.failure(ex.getMessage());
}
}
}
@SuppressWarnings("unused")
class NoOp implements Observable12Choice {
@Override
public ValidationResult validate(RosettaPath path, Observable12 observable12) {
return ValidationResult.success(NAME, ValidationResult.ValidationType.DATA_RULE, "Observable12", path, DEFINITION);
}
}
}