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);
}
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;
}
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);
}
}
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);
}
}
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;
}
Aggregations