use of org.openforis.idm.metamodel.SurveyContext in project collect by openforis.
the class TestFixture method survey.
public static TestFixture survey(NodeDefinitionBuilder.EntityDefinitionBuilder entityDefinitionBuilder, RecordBuilder... recordBuilders) {
SurveyContext surveyContext = new TestSurveyContext();
Survey survey = surveyContext.createSurvey();
EntityDefinition rootEntityDef = (EntityDefinition) entityDefinitionBuilder.buildInternal(survey);
survey.getSchema().addRootEntityDefinition(rootEntityDef);
survey.refreshSurveyDependencies();
List<Record> records = new ArrayList<Record>();
for (RecordBuilder recordBuilder : recordBuilders) {
Record record = recordBuilder.build(survey);
records.add(record);
}
return new TestFixture(survey, Collections.unmodifiableList(records));
}
use of org.openforis.idm.metamodel.SurveyContext in project collect by openforis.
the class SRSFormValidator method validateWKT.
private boolean validateWKT(ValidationContext ctx) {
String wkt = (String) getValue(ctx, WKT_FIELD);
CollectSurvey survey = getSurvey(ctx);
SurveyContext context = survey.getContext();
CoordinateOperations coordinateOperations = context.getCoordinateOperations();
try {
coordinateOperations.validateWKT(wkt);
return true;
} catch (Exception e) {
String message = Labels.getLabel("survey.srs.validation.error.invalid_wkt", new String[] { e.getMessage() });
addInvalidMessage(ctx, WKT_FIELD, message);
return false;
}
}
use of org.openforis.idm.metamodel.SurveyContext in project collect by openforis.
the class ExternalCodeValidator method getExternalCodeListProvider.
private ExternalCodeListProvider getExternalCodeListProvider(CodeAttribute codeAttribute) {
Survey survey = codeAttribute.getSurvey();
SurveyContext surveyContext = survey.getContext();
return surveyContext.getExternalCodeListProvider();
}
use of org.openforis.idm.metamodel.SurveyContext in project collect by openforis.
the class MinCountValidator method isAvailableCodeListItems.
private boolean isAvailableCodeListItems(Entity parentEntity) {
CodeAttributeDefinition codeAttrDef = (CodeAttributeDefinition) nodeDefinition;
SurveyContext context = codeAttrDef.getSurvey().getContext();
CodeListService codeListService = context.getCodeListService();
if (codeListService == null) {
// test context does not have a CodeListService
return true;
}
List<CodeListItem> validItems = codeListService.loadValidItems(parentEntity, codeAttrDef);
return !validItems.isEmpty();
}
use of org.openforis.idm.metamodel.SurveyContext in project collect by openforis.
the class UniquenessCheck method evaluate.
@Override
public ValidationResultFlag evaluate(final Attribute<?, ?> attribute) {
try {
SurveyContext recordContext = attribute.getRecord().getSurveyContext();
ExpressionEvaluator expressionEvaluator = recordContext.getExpressionEvaluator();
Node<?> duplicateNode = expressionEvaluator.findNode(attribute.getParent(), attribute, expression, new Predicate<Node<?>>() {
public boolean evaluate(Node<?> node) {
if (node instanceof Attribute && node != attribute) {
Value value = ((Attribute<?, ?>) node).getValue();
if (value != null && value.equals(attribute.getValue())) {
return true;
}
}
return false;
}
});
boolean unique = duplicateNode == null;
return ValidationResultFlag.valueOf(unique, this.getFlag());
} catch (InvalidExpressionException e) {
throw new IdmInterpretationError("Error evaluating uniqueness check", e);
}
}
Aggregations