use of org.openforis.idm.metamodel.SurveyContext in project collect by openforis.
the class RecordUpdater method calculateMinCount.
private int calculateMinCount(Entity entity, NodeDefinition defn) {
String expression = defn.getMinCountExpression();
if (!entity.isRelevant(defn) || StringUtils.isBlank(expression)) {
return 0;
}
if (defn.getFixedMinCount() != null) {
return defn.getFixedMinCount();
}
try {
SurveyContext surveyContext = defn.getSurvey().getContext();
ExpressionEvaluator expressionEvaluator = surveyContext.getExpressionEvaluator();
Number value = expressionEvaluator.evaluateNumericValue(entity, null, expression);
return value == null ? 0 : value.intValue();
} catch (InvalidExpressionException e) {
throw new IdmInterpretationError("Error evaluating required expression", e);
}
}
use of org.openforis.idm.metamodel.SurveyContext in project collect by openforis.
the class DescendantNodeFilter method accept.
@Override
public boolean accept(Node<?> node) {
NodeDefinition nodeDef = node.getDefinition();
if (!(nodeDef instanceof EntityDefinition) || !descendantAttributeDefinition.isDescendantOf((EntityDefinition) nodeDef)) {
return false;
}
Record record = node.getRecord();
SurveyContext surveyContext = record.getSurveyContext();
ExpressionEvaluator expressionEvaluator = surveyContext.getExpressionEvaluator();
List<Node<?>> attributes = record.findNodesByPath(descendantAttributeDefinition.getPath());
for (Node<?> attribute : attributes) {
try {
Entity parentEntity = attribute.getParent();
if (parentEntity == node && expressionEvaluator.evaluateBoolean(parentEntity, attribute, descendantAttributeCondition)) {
return true;
}
} catch (InvalidExpressionException e) {
throw new RuntimeException(e);
}
}
return false;
}
use of org.openforis.idm.metamodel.SurveyContext in project collect by openforis.
the class CodeColumnProvider method getCodeListService.
private CodeListService getCodeListService() {
SurveyContext context = attributeDefinition.getSurvey().getContext();
CodeListService codeListService = context.getCodeListService();
return codeListService;
}
use of org.openforis.idm.metamodel.SurveyContext in project collect by openforis.
the class EnumerableEntityColumnProvider method createProviders.
private static List<ColumnProvider> createProviders(CSVDataExportParameters config, EntityDefinition defn) {
List<ColumnProvider> providers = new ArrayList<ColumnProvider>();
List<AttributeDefinition> keyDefs = defn.getKeyAttributeDefinitions();
CodeAttributeDefinition keyDef = (CodeAttributeDefinition) keyDefs.get(0);
CodeList codeList = keyDef.getList();
SurveyContext context = defn.getSurvey().getContext();
CodeListService codeListService = context.getCodeListService();
List<CodeListItem> items = codeListService.loadRootItems(codeList);
for (CodeListItem item : items) {
String code = item.getCode();
String keyName = keyDef.getName();
EnumeratedCodeItemColumnProvider p = new EnumeratedCodeItemColumnProvider(config, defn, keyName, code);
providers.add(p);
}
return providers;
}
use of org.openforis.idm.metamodel.SurveyContext in project collect by openforis.
the class ValidationMessageBuilder method getComparisonCheckMessageArg.
protected String getComparisonCheckMessageArg(Attribute<?, ?> attribute, String expression, Locale locale) {
if (StringUtils.isNotBlank(expression)) {
String result = expression;
Survey survey = attribute.getSurvey();
Schema schema = survey.getSchema();
SurveyContext surveyContext = survey.getContext();
ExpressionEvaluator expressionEvaluator = surveyContext.getExpressionEvaluator();
try {
Entity parentEntity = attribute.getParent();
EntityDefinition parentDefinition = parentEntity.getDefinition();
Set<String> referencedPaths = expressionEvaluator.determineReferencedPaths(expression);
for (String path : referencedPaths) {
String absolutePath = parentDefinition.getPath() + PATH_SEPARATOR + path;
NodeDefinition nodeDefinition = schema.getDefinitionByPath(absolutePath);
String label = getPrettyLabelText(nodeDefinition, locale);
result = result.replaceAll(nodeDefinition.getName(), label);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return result;
} else {
return expression;
}
}
Aggregations