use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class DataCSVReader method getAncestorIdentifiers.
private List<EntityIdentifierDefinition> getAncestorIdentifiers() {
List<EntityDefinition> ancestorEntityDefns = parentEntityDefinition.getAncestorEntityDefinitionsInReverseOrder();
ancestorEntityDefns.add(parentEntityDefinition);
List<EntityIdentifierDefinition> entityIdentifierDefns = new ArrayList<DataLine.EntityIdentifierDefinition>();
for (EntityDefinition ancestorEntityDefn : ancestorEntityDefns) {
EntityIdentifierDefinition identifier;
if (ancestorEntityDefn.isMultiple()) {
List<AttributeDefinition> keyDefns = ancestorEntityDefn.getKeyAttributeDefinitions();
if (keyDefns.isEmpty()) {
identifier = new DataLine.EntityPositionIdentifierDefinition(ancestorEntityDefn.getId());
} else {
identifier = new DataLine.EntityKeysIdentifierDefintion(ancestorEntityDefn);
}
} else {
identifier = new DataLine.SingleEntityIdentifierDefinition(ancestorEntityDefn.getId());
}
entityIdentifierDefns.add(identifier);
}
return entityIdentifierDefns;
}
use of org.openforis.idm.metamodel.AttributeDefinition 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.AttributeDefinition in project collect by openforis.
the class CSVDataExportColumnProviderGenerator method createAncestorColumnProvider.
private ColumnProvider createAncestorColumnProvider(EntityDefinition contextEntityDefn, EntityDefinition ancestorEntityDefn) {
List<ColumnProvider> providers = new ArrayList<ColumnProvider>();
if (configuration.isIncludeAllAncestorAttributes()) {
AutomaticColumnProvider ancestorEntityColumnProvider = new AutomaticColumnProvider(configuration, ColumnProviders.generateHeadingPrefix(ancestorEntityDefn, configuration) + configuration.getFieldHeadingSeparator(), ancestorEntityDefn);
providers.add(0, ancestorEntityColumnProvider);
} else {
// include only key attributes
List<AttributeDefinition> keyAttrDefns = ancestorEntityDefn.getKeyAttributeDefinitions();
for (AttributeDefinition keyDefn : keyAttrDefns) {
String relativePath = contextEntityDefn.getRelativePath(ancestorEntityDefn);
ColumnProvider keyColumnProvider = ColumnProviders.createAttributeProvider(configuration, keyDefn);
String headingPrefix = configuration.isIncludeGroupingLabels() ? ColumnProviders.generateHeadingPrefix(keyDefn.getParentEntityDefinition(), configuration) + configuration.getFieldHeadingSeparator() : "";
PivotExpressionColumnProvider columnProvider = new PivotExpressionColumnProvider(configuration, relativePath, headingPrefix, keyColumnProvider);
providers.add(columnProvider);
}
if (isPositionColumnRequired(ancestorEntityDefn)) {
String relativePath = contextEntityDefn.getRelativePath(ancestorEntityDefn);
ColumnProvider positionColumnProvider = createPositionColumnProvider(ancestorEntityDefn);
PivotExpressionColumnProvider columnProvider = new PivotExpressionColumnProvider(configuration, relativePath, "", positionColumnProvider);
providers.add(columnProvider);
}
}
return new ColumnProviderChain(configuration, providers);
}
use of org.openforis.idm.metamodel.AttributeDefinition 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.AttributeDefinition in project collect by openforis.
the class XPathDataQueryEvaluator method evaluate.
@Override
public List<Node<?>> evaluate(CollectRecord record) {
List<Node<?>> result = new ArrayList<Node<?>>();
String condition = query.getConditions();
AttributeDefinition attrDef = query.getAttributeDefinition();
SurveyContext surveyContext = record.getSurveyContext();
ExpressionEvaluator expressionEvaluator = surveyContext.getExpressionEvaluator();
List<Node<?>> nodes = record.findNodesByPath(attrDef.getPath());
for (Node<?> node : nodes) {
try {
if (expressionEvaluator.evaluateBoolean(node.getParent(), node, condition)) {
result.add(node);
}
} catch (InvalidExpressionException e) {
throw new RuntimeException(e);
}
}
return result;
}
Aggregations