Search in sources :

Example 41 with NodeDefinition

use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.

the class RecordIndexManagerIntegrationTest method roundTripTest.

@Test
public void roundTripTest() throws Exception {
    CollectSurvey survey = loadSurvey();
    String[] gpsModels = new String[] { "GPS MAP 62 S", "GPS MAP 60CSX", "SXBLUEII-L", "GPS MAP 62S" };
    createIndex(survey, gpsModels);
    NodeDefinition autoCompleteNodeDefn = survey.getSchema().getDefinitionByPath("/cluster/gps_model");
    testSingleResultMatching(survey, autoCompleteNodeDefn);
    testMultipleResultsFoundWithNonCompleteTerm(survey, autoCompleteNodeDefn);
    testMultipleResultsFound(survey, autoCompleteNodeDefn);
    // testSingleResultMatchingPhrase(survey, autoCompleteNodeDefn);
    testLimitedMultipleResultsFound(survey, autoCompleteNodeDefn);
    testNoResultsFound(survey, autoCompleteNodeDefn);
}
Also used : NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) CollectSurvey(org.openforis.collect.model.CollectSurvey) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 42 with NodeDefinition

use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.

the class Validator method getChildDefinition.

private NodeDefinition getChildDefinition(Entity entity, String childName) {
    EntityDefinition entityDefn = entity.getDefinition();
    NodeDefinition childDefn = entityDefn.getChildDefinition(childName);
    return childDefn;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Example 43 with NodeDefinition

use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.

the class MaxCountValidatorTest method updateMaxCount.

// protected boolean containsMaxCountError(List<ValidationResult> errors, String name) {
// for (ValidationResult result : errors) {
// ValidationRule validator = result.getValidator();
// if (validator instanceof MaxCountValidator) {
// MaxCountValidator v = (MaxCountValidator) validator;
// NodeDefinition nodeDefinition = v.getNodeDefinition();
// if (nodeDefinition.getName().equals(name)) {
// return true;
// }
// }
// }
// return false;
// }
private void updateMaxCount(Entity entity, String childName) {
    NodeDefinition childDef = entity.getDefinition().getChildDefinition(childName);
    try {
        String expr = childDef.getMaxCountExpression();
        Integer count = null;
        if (StringUtils.isNotBlank(expr)) {
            Number val = expressionEvaluator.evaluateNumericValue(entity, null, expr);
            count = val.intValue();
        } else if (!childDef.isMultiple()) {
            count = 1;
        }
        entity.setMaxCount(childDef, count);
    } catch (InvalidExpressionException e) {
        throw new RuntimeException(e);
    }
}
Also used : InvalidExpressionException(org.openforis.idm.model.expression.InvalidExpressionException) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Example 44 with NodeDefinition

use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.

the class MinCountValidatorTest method updateMinCount.

// private boolean containsMinCountError(List<ValidationResult> errors, String name) {
// for (ValidationResult result : errors) {
// ValidationRule<?> validator = result.getValidator();
// if (validator instanceof MinCountValidator) {
// MinCountValidator v = (MinCountValidator) validator;
// NodeDefinition nodeDefinition = v.getNodeDefinition();
// if (nodeDefinition.getName().equals(name)) {
// return true;
// }
// }
// }
// return false;
// }
private void updateMinCount(Entity entity, String childName) {
    NodeDefinition childDef = entity.getDefinition().getChildDefinition(childName);
    try {
        String expr = childDef.getMinCountExpression();
        int count;
        if (StringUtils.isNotBlank(expr)) {
            Number val = expressionEvaluator.evaluateNumericValue(entity, null, expr);
            count = val.intValue();
        } else {
            count = 0;
        }
        entity.setMinCount(childDef, count);
    } catch (InvalidExpressionException e) {
        throw new RuntimeException(e);
    }
}
Also used : InvalidExpressionException(org.openforis.idm.model.expression.InvalidExpressionException) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Example 45 with NodeDefinition

use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.

the class DefaultValueTest method addItem.

protected Entity addItem(Entity rootEntity, Integer qtyValue, Double priceValue) {
    EntityDefinition rootEntityDefn = rootEntity.getDefinition();
    EntityDefinition itemDefn = (EntityDefinition) rootEntityDefn.getChildDefinition("item");
    Entity item = (Entity) itemDefn.createNode();
    if (qtyValue != null) {
        NodeDefinition qtyDefn = itemDefn.getChildDefinition("qty");
        IntegerAttribute qty = (IntegerAttribute) qtyDefn.createNode();
        qty.setValue(new IntegerValue(qtyValue, null));
        qty.updateSummaryInfo();
        item.add(qty);
    }
    if (priceValue != null) {
        NumericAttributeDefinition priceDefn = (NumericAttributeDefinition) itemDefn.getChildDefinition("price");
        RealAttribute price = (RealAttribute) priceDefn.createNode();
        price.setValue(new RealValue(priceValue, null));
        price.updateSummaryInfo();
        item.add(price);
    }
    NumericAttributeDefinition totalDefn = (NumericAttributeDefinition) itemDefn.getChildDefinition("total");
    RealAttribute total = (RealAttribute) totalDefn.createNode();
    item.add(total);
    rootEntity.add(item);
    return item;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition)

Aggregations

NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)173 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)70 ArrayList (java.util.ArrayList)42 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)27 Schema (org.openforis.idm.metamodel.Schema)24 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)22 CollectSurvey (org.openforis.collect.model.CollectSurvey)20 Entity (org.openforis.idm.model.Entity)19 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)16 NodeDefinitionVisitor (org.openforis.idm.metamodel.NodeDefinitionVisitor)14 UITab (org.openforis.collect.metamodel.ui.UITab)12 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)11 Survey (org.openforis.idm.metamodel.Survey)11 Test (org.junit.Test)10 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)9 ModelVersion (org.openforis.idm.metamodel.ModelVersion)9 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)8 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)8 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)8 Node (org.openforis.idm.model.Node)8