use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.
the class CSVDataExportProcess method getEntitiesToExport.
private Collection<EntityDefinition> getEntitiesToExport() {
final Collection<EntityDefinition> result = new ArrayList<EntityDefinition>();
Schema schema = recordFilter.getSurvey().getSchema();
if (entityId == null) {
EntityDefinition rootEntity = schema.getRootEntityDefinition(recordFilter.getRootEntityId());
rootEntity.traverse(new NodeDefinitionVisitor() {
@Override
public void visit(NodeDefinition node) {
if (node instanceof EntityDefinition && node.isMultiple()) {
result.add((EntityDefinition) node);
}
}
});
} else {
EntityDefinition entity = (EntityDefinition) schema.getDefinitionById(entityId);
result.add(entity);
}
return result;
}
use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.
the class AutomaticColumnProvider method createProviders.
private static List<ColumnProvider> createProviders(CSVDataExportParameters config, EntityDefinition rowDefn, List<String> exclusions) {
List<ColumnProvider> cols = new ArrayList<ColumnProvider>();
CollectSurvey survey = (CollectSurvey) rowDefn.getSurvey();
CollectAnnotations surveyAnnotations = survey.getAnnotations();
List<NodeDefinition> childDefinitions = rowDefn.getChildDefinitions();
for (NodeDefinition childDefn : childDefinitions) {
if (includeChild(exclusions, childDefn)) {
if (childDefn instanceof EntityDefinition) {
createEntityProviders(config, (EntityDefinition) childDefn, cols);
} else if (childDefn instanceof AttributeDefinition && surveyAnnotations.isIncludedInDataExport(childDefn)) {
cols.add(ColumnProviders.createAttributeProvider(config, (AttributeDefinition) childDefn));
}
}
}
return cols;
}
use of org.openforis.idm.metamodel.NodeDefinition 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.NodeDefinition in project collect by openforis.
the class ValidationMessageBuilder method getPrettyFormatPath.
public String getPrettyFormatPath(Entity parentEntity, String childName, Locale locale) {
EntityDefinition parentEntityDefn = parentEntity.getDefinition();
NodeDefinition childDefn = parentEntityDefn.getChildDefinition(childName);
String label = getPrettyLabelText(childDefn, locale);
if (parentEntity.getParent() != null && parentEntity.getParent() != null) {
String parentEntityPath = getPrettyFormatPath(parentEntity, locale);
return parentEntityPath + PRETTY_PATH_SEPARATOR + label;
} else {
return label;
}
}
use of org.openforis.idm.metamodel.NodeDefinition 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