use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.
the class ValidationMessageBuilder method getMaxCountValidationMessage.
public String getMaxCountValidationMessage(Entity parentEntity, String childName, Locale locale) {
EntityDefinition defn = parentEntity.getDefinition();
NodeDefinition childDefn = defn.getChildDefinition(childName);
Integer maxCount = parentEntity.getMaxCount(childDefn);
Object[] args = new Integer[] { maxCount > 0 ? maxCount : 1 };
String surveyDefaultLanguage = defn.getSurvey().getDefaultLanguage();
String message = getMessage(surveyDefaultLanguage, locale, "validation.maxCount", args);
return message;
}
use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.
the class Mondrian4SchemaGenerator method createCube.
private Cube createCube(DataTable dataTable) {
NodeDefinition nodeDef = dataTable.getNodeDefinition();
Cube cube = new Cube();
cube.name = nodeDef.getName();
MeasureGroups measureGroups = new MondrianDef.MeasureGroups();
MeasureGroup measureGroup = new MeasureGroup();
measureGroup.name = cube.name;
Measures measures = new Measures();
List<Measure> measureList = createMeasures(dataTable);
measures.list().addAll(measureList);
measureGroup.children.add(measures);
measureGroup.table = dataTable.getName();
DimensionLinks dimensionLinks = new DimensionLinks();
measureGroup.children.add(dimensionLinks);
measureGroups.list().add(measureGroup);
cube.children.add(measureGroups);
if (nodeDef instanceof EntityDefinition) {
Dimensions dimensions = new Dimensions();
Queue<NodeDefinition> queue = new LinkedList<NodeDefinition>();
queue.addAll(((EntityDefinition) nodeDef).getChildDefinitions());
while (!queue.isEmpty()) {
NodeDefinition def = queue.poll();
if (def instanceof AttributeDefinition) {
AttributeDefinition attrDef = (AttributeDefinition) def;
Dimension dimension = createDimension(dataTable, attrDef);
if (dimension != null) {
dimensions.list().add(dimension);
// add dimension link
DimensionLink dimensionLink = createDimensionLink(dimension, attrDef);
dimensionLinks.list().add(dimensionLink);
}
} else if (!def.isMultiple()) {
queue.addAll(((EntityDefinition) def).getChildDefinitions());
}
}
cube.children.add(dimensions);
}
return cube;
}
use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.
the class RelationalTransformer method initDataTableTransformations.
/**
* Recursively init table transformations
* @param defn
*/
private void initDataTableTransformations(EntityDefinition defn) {
List<NodeDefinition> children = defn.getChildDefinitions();
for (NodeDefinition child : children) {
if (child instanceof EntityDefinition) {
initDataTableTransformations((EntityDefinition) child);
}
}
if (defn.isMultiple()) {
Transformation xform = Transformation.createDefaultTransformation(defn);
Path path = (Path) xform.getRowAxis();
dataTransforms.put(path, xform);
System.out.println(path);
}
}
use of org.openforis.idm.metamodel.NodeDefinition 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.NodeDefinition 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;
}
Aggregations