Search in sources :

Example 11 with NodeDefinitionVisitor

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;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) RelationalSchema(org.openforis.collect.relational.model.RelationalSchema) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) NodeDefinitionVisitor(org.openforis.idm.metamodel.NodeDefinitionVisitor)

Example 12 with NodeDefinitionVisitor

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;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) NodeDefinitionVisitor(org.openforis.idm.metamodel.NodeDefinitionVisitor)

Example 13 with NodeDefinitionVisitor

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;
}
Also used : Schema(org.openforis.idm.metamodel.Schema) ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TextAttributeDefinition(org.openforis.idm.metamodel.TextAttributeDefinition) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition) RangeAttributeDefinition(org.openforis.idm.metamodel.RangeAttributeDefinition) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition) KeyAttributeDefinition(org.openforis.idm.metamodel.KeyAttributeDefinition) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) CollectAnnotations(org.openforis.collect.metamodel.CollectAnnotations) NodeDefinitionVisitor(org.openforis.idm.metamodel.NodeDefinitionVisitor)

Example 14 with NodeDefinitionVisitor

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);
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Task(org.openforis.concurrency.Task) CsvWriter(org.openforis.commons.io.csv.CsvWriter) FileOutputStream(java.io.FileOutputStream) Schema(org.openforis.idm.metamodel.Schema) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) OutputStreamWriter(java.io.OutputStreamWriter) NodeDefinitionVisitor(org.openforis.idm.metamodel.NodeDefinitionVisitor) BufferedWriter(java.io.BufferedWriter)

Aggregations

NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)14 NodeDefinitionVisitor (org.openforis.idm.metamodel.NodeDefinitionVisitor)14 ArrayList (java.util.ArrayList)8 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)8 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)7 Schema (org.openforis.idm.metamodel.Schema)5 CollectAnnotations (org.openforis.collect.metamodel.CollectAnnotations)3 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)3 BufferedWriter (java.io.BufferedWriter)1 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 HashMap (java.util.HashMap)1 UIConfiguration (org.openforis.collect.metamodel.ui.UIConfiguration)1 UIModelObject (org.openforis.collect.metamodel.ui.UIModelObject)1 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)1 UITable (org.openforis.collect.metamodel.ui.UITable)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 RelationalSchema (org.openforis.collect.relational.model.RelationalSchema)1 CsvWriter (org.openforis.commons.io.csv.CsvWriter)1 Task (org.openforis.concurrency.Task)1