use of org.openforis.idm.metamodel.NodeDefinitionVisitor in project collect by openforis.
the class NewMondrianSchemaGenerator method generateSchema.
private Schema generateSchema() {
final Schema schema = new Schema(survey.getName());
EntityDefinition rootEntityDef = survey.getSchema().getFirstRootEntityDefinition();
rootEntityDef.traverse(new NodeDefinitionVisitor() {
public void visit(NodeDefinition def) {
if (def instanceof EntityDefinition && def.isMultiple()) {
Cube cube = generateCube((EntityDefinition) def);
schema.cubes.add(cube);
}
}
});
/*
VirtualCube virtualCube = new VirtualCube("Survey Data");
List<Cube> cubes = schema.cubes;
List<CubeUsage> cubeUsages = new ArrayList<CubeUsage>(cubes.size());
List<VirtualCubeDimension> cubeDimensions = new ArrayList<VirtualCubeDimension>();
List<VirtualCubeMeasure> cubeMeasures = new ArrayList<VirtualCubeMeasure>();
for (Cube cube : cubes) {
CubeUsage cubeUsage = new CubeUsage(cube.name);
cubeUsage.cubeName = cube.name;
cubeUsages.add(cubeUsage);
for (Dimension dimension : cube.dimensions) {
VirtualCubeDimension virtualCubeDimension = new VirtualCubeDimension(dimension.name);
virtualCubeDimension.cubeName = cube.name;
cubeDimensions.add(virtualCubeDimension);
}
for (Measure measure : cube.measures) {
VirtualCubeMeasure virtualCubeMeasure = new VirtualCubeMeasure("[Measures].[" + measure.name + "]");
virtualCubeMeasure.cubeName = cube.name;
cubeMeasures.add(virtualCubeMeasure);
}
}
virtualCube.cubeUsages = new CubeUsages("");
virtualCube.cubeUsages.cubeUsages = cubeUsages;
virtualCube.virtualCubeDimensions = cubeDimensions;
virtualCube.virtualCubeMeasures = cubeMeasures;
schema.virtualCubes.add(virtualCube);
*/
return schema;
}
use of org.openforis.idm.metamodel.NodeDefinitionVisitor in project collect by openforis.
the class RecordGenerator method findSamplingPointCodeAttributes.
private List<CodeAttributeDefinition> findSamplingPointCodeAttributes(final CollectSurvey survey) {
EntityDefinition rootEntityDef = survey.getSchema().getFirstRootEntityDefinition();
final List<CodeAttributeDefinition> samplingPointDataCodeAttributeDefs = new ArrayList<CodeAttributeDefinition>();
rootEntityDef.traverse(new NodeDefinitionVisitor() {
public void visit(NodeDefinition def) {
if (def instanceof CodeAttributeDefinition && ((CodeAttributeDefinition) def).getList().equals(survey.getSamplingDesignCodeList())) {
samplingPointDataCodeAttributeDefs.add((CodeAttributeDefinition) def);
}
}
}, TraversalType.BFS);
return samplingPointDataCodeAttributeDefs;
}
use of org.openforis.idm.metamodel.NodeDefinitionVisitor in project collect by openforis.
the class CollectEarthBalloonGenerator method getHiddenNodeDefinitions.
private List<AttributeDefinition> getHiddenNodeDefinitions() {
final List<AttributeDefinition> nodesFromCSV = new ArrayList<AttributeDefinition>();
final CollectAnnotations annotations = survey.getAnnotations();
Schema schema = survey.getSchema();
schema.traverse(new NodeDefinitionVisitor() {
public void visit(NodeDefinition definition) {
if (definition instanceof AttributeDefinition) {
AttributeDefinition attrDef = (AttributeDefinition) definition;
if (annotations.isFromCollectEarthCSV(attrDef) && !annotations.isShowReadOnlyFieldInCollectEarth(attrDef) || attrDef.isKey() && definition.getParentEntityDefinition().isRoot()) {
nodesFromCSV.add(attrDef);
}
}
}
});
return nodesFromCSV;
}
use of org.openforis.idm.metamodel.NodeDefinitionVisitor in project collect by openforis.
the class SchemaSummaryCSVExportJob method buildTasks.
@Override
protected void buildTasks() throws Throwable {
Task task = new Task() {
@Override
protected void execute() throws Throwable {
FileOutputStream out = new FileOutputStream(outputFile);
final CsvWriter csvWriter = new CsvWriter(new BufferedWriter(new OutputStreamWriter(out, "UTF-8")), ',', '"');
try {
csvWriter.writeHeaders(HEADERS);
Schema schema = survey.getSchema();
schema.traverse(new NodeDefinitionVisitor() {
@Override
public void visit(NodeDefinition nodeDefn) {
csvWriter.writeNext(new String[] { Integer.toString(nodeDefn.getId()), nodeDefn.getPath(), nodeDefn instanceof EntityDefinition ? "entity" : "attribute", nodeDefn instanceof AttributeDefinition ? AttributeType.valueOf((AttributeDefinition) nodeDefn).getLabel() : "", nodeDefn.getLabel(Type.INSTANCE, labelLanguage), String.valueOf(nodeDefn.isAlwaysRelevant()), nodeDefn.isAlwaysRelevant() ? "" : nodeDefn.getRelevantExpression(), String.valueOf(nodeDefn.isAlwaysRequired()), nodeDefn.isAlwaysRequired() ? "" : nodeDefn.getMinCountExpression(), extractValidationRules(nodeDefn) });
}
});
} finally {
IOUtils.closeQuietly(csvWriter);
}
}
};
addTask(task);
}
Aggregations