use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class Mondrian4SchemaGenerator method getAttributeCaption.
private String getAttributeCaption(FieldDefinition<?> fieldDef) {
AttributeDefinition attrDef = fieldDef.getAttributeDefinition();
String caption = extractLabel(attrDef);
if (!(attrDef.hasMainField() && attrDef.getMainFieldDefinition() == fieldDef)) {
caption += " - " + fieldDef.getName();
}
return caption;
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class QueryExecutorIntegrationTest method testSimpleQuery.
@Test
public void testSimpleQuery() {
// select region from tree where dbh > 20
DataQuery query = new DataQuery(survey);
EntityDefinition treeDef = (EntityDefinition) survey.getSchema().getDefinitionByPath("/cluster/plot/tree");
AttributeDefinition dbhDef = (AttributeDefinition) survey.getSchema().getDefinitionByPath("/cluster/plot/tree/dbh");
query.setEntityDefinition(treeDef);
query.setAttributeDefinition(dbhDef);
query.setConditions("dbh > 20");
final List<Node<?>> nodes = new ArrayList<Node<?>>();
DataQueryExecutorJob job = jobManager.createJob(DataQueryExecutorJob.class);
DataQueryExecutorJobInput input = new DataQueryExecutorJobInput(query, Step.ENTRY, new NodeProcessor() {
public void process(Node<?> node) {
nodes.add(node);
}
});
job.setInput(input);
jobManager.start(job, false);
assertFalse(nodes.isEmpty());
// first result
Node<?> node = nodes.get(0);
assertTrue(node instanceof Attribute);
CollectRecord record = (CollectRecord) node.getRecord();
assertEquals(Arrays.asList("10_117"), record.getRootEntityKeyValues());
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class RelationalSchemaGenerator method addDataObjects.
/**
* Recursively creates and adds tables and columns
*
* @param rs
* @param parentTable
* @param defn
* @throws CollectRdbException
*/
private void addDataObjects(RelationalSchema rs, DataTable table, NodeDefinition defn, Path relativePath) throws CollectRdbException {
if (defn instanceof EntityDefinition) {
if (defn.isMultiple()) {
// Create table for multiple entity
table = createDataTable(rs, table, defn, relativePath);
rs.addTable(table);
} else {
// just keep a reference
rs.assignAncestorTable((EntityDefinition) defn);
}
// Add child tables and columns
EntityDefinition entityDefn = (EntityDefinition) defn;
for (NodeDefinition child : entityDefn.getChildDefinitions()) {
Path childPath;
if (defn.isMultiple()) {
childPath = Path.relative(child.getName());
} else {
childPath = relativePath.appendElement(child.getName());
}
addDataObjects(rs, table, child, childPath);
}
} else if (defn instanceof AttributeDefinition) {
AttributeDefinition attrDefn = (AttributeDefinition) defn;
CollectSurvey survey = (CollectSurvey) defn.getSurvey();
CollectAnnotations annotations = survey.getAnnotations();
// do not include if it's a calculated attribute and it has not to be included in data export
if (!attrDefn.isCalculated() || annotations.isIncludedInDataExport(defn)) {
if (defn.isMultiple()) {
// Create table for multiple attributes
table = createDataTable(rs, table, defn, relativePath);
rs.addTable(table);
relativePath = Path.relative(".");
}
// Add columns for attributes in entity tables or attribute tables
addDataColumns(rs, table, (AttributeDefinition) defn, relativePath);
}
}
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class DataQueryGenerator method generateMissingDataQueries.
public List<DataQuery> generateMissingDataQueries(final CollectSurvey survey, final DataQueryType type) {
final List<DataQuery> result = new ArrayList<DataQuery>();
survey.getSchema().traverse(new NodeDefinitionVisitor() {
public void visit(NodeDefinition def) {
if (def instanceof AttributeDefinition) {
if (StringUtils.isNotBlank(def.getMinCountExpression())) {
DataQuery query = new DataQuery(survey);
query.setTitle(String.format(MISSING_DATA_QUERY_TITLE_FORMAT, def.getName()));
query.setAttributeDefinition((AttributeDefinition) def);
query.setEntityDefinition(def.getParentEntityDefinition());
query.setConditions(String.format(MISSING_DATA_CONDITION_FORMAT, def.getName()));
query.setType(type);
result.add(query);
}
}
}
});
return result;
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class DataQueryGenerator method generateValidationCheckQueries.
public List<DataQuery> generateValidationCheckQueries(CollectSurvey survey) {
final List<DataQuery> result = new ArrayList<DataQuery>();
survey.getSchema().traverse(new NodeDefinitionVisitor() {
public void visit(NodeDefinition def) {
if (def instanceof AttributeDefinition) {
for (Check<?> check : ((AttributeDefinition) def).getChecks()) {
DataQuery query = createQuery(def, check);
result.add(query);
}
}
}
});
return result;
}
Aggregations