Search in sources :

Example 6 with SurveyContext

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));
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Survey(org.openforis.idm.metamodel.Survey) TestSurveyContext(org.openforis.idm.model.TestSurveyContext) ArrayList(java.util.ArrayList) Record(org.openforis.idm.model.Record) SurveyContext(org.openforis.idm.metamodel.SurveyContext) TestSurveyContext(org.openforis.idm.model.TestSurveyContext)

Example 7 with SurveyContext

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;
    }
}
Also used : CoordinateOperations(org.openforis.idm.geospatial.CoordinateOperations) CollectSurvey(org.openforis.collect.model.CollectSurvey) SurveyContext(org.openforis.idm.metamodel.SurveyContext)

Example 8 with SurveyContext

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();
}
Also used : Survey(org.openforis.idm.metamodel.Survey) SurveyContext(org.openforis.idm.metamodel.SurveyContext)

Example 9 with SurveyContext

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();
}
Also used : CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CodeListService(org.openforis.idm.metamodel.CodeListService) CodeListItem(org.openforis.idm.metamodel.CodeListItem) SurveyContext(org.openforis.idm.metamodel.SurveyContext)

Example 10 with SurveyContext

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);
    }
}
Also used : IdmInterpretationError(org.openforis.idm.metamodel.IdmInterpretationError) Attribute(org.openforis.idm.model.Attribute) InvalidExpressionException(org.openforis.idm.model.expression.InvalidExpressionException) Node(org.openforis.idm.model.Node) Value(org.openforis.idm.model.Value) ExpressionEvaluator(org.openforis.idm.model.expression.ExpressionEvaluator) SurveyContext(org.openforis.idm.metamodel.SurveyContext)

Aggregations

SurveyContext (org.openforis.idm.metamodel.SurveyContext)26 ExpressionEvaluator (org.openforis.idm.model.expression.ExpressionEvaluator)9 Survey (org.openforis.idm.metamodel.Survey)8 CodeListService (org.openforis.idm.metamodel.CodeListService)6 InvalidExpressionException (org.openforis.idm.model.expression.InvalidExpressionException)6 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)5 CollectSurvey (org.openforis.collect.model.CollectSurvey)4 IdmInterpretationError (org.openforis.idm.metamodel.IdmInterpretationError)4 Schema (org.openforis.idm.metamodel.Schema)4 Record (org.openforis.idm.model.Record)4 ArrayList (java.util.ArrayList)3 SurveyIdmlBinder (org.openforis.idm.metamodel.xml.SurveyIdmlBinder)3 Node (org.openforis.idm.model.Node)3 InputStream (java.io.InputStream)2 AttributeDefault (org.openforis.idm.metamodel.AttributeDefault)2 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)2 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)2 CodeListItem (org.openforis.idm.metamodel.CodeListItem)2 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)2 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)2