Search in sources :

Example 1 with NodeDefinitionVisitor

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

Example 2 with NodeDefinitionVisitor

use of org.openforis.idm.metamodel.NodeDefinitionVisitor 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;
}
Also used : ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) Check(org.openforis.idm.metamodel.validation.Check) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) NodeDefinitionVisitor(org.openforis.idm.metamodel.NodeDefinitionVisitor)

Example 3 with NodeDefinitionVisitor

use of org.openforis.idm.metamodel.NodeDefinitionVisitor in project collect by openforis.

the class SurveyValidator method validateSchemaNodes.

/**
 * Checks for the existence of empty entities
 *
 * @param survey
 * @return
 */
protected List<SurveyValidationResult> validateSchemaNodes(CollectSurvey survey) {
    final List<SurveyValidationResult> results = new ArrayList<SurveyValidationResult>();
    Schema schema = survey.getSchema();
    schema.traverse(new NodeDefinitionVisitor() {

        @Override
        public void visit(NodeDefinition def) {
            results.addAll(validateSchemaNode(def));
        }
    });
    return results;
}
Also used : Schema(org.openforis.idm.metamodel.Schema) ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) NodeDefinitionVisitor(org.openforis.idm.metamodel.NodeDefinitionVisitor)

Example 4 with NodeDefinitionVisitor

use of org.openforis.idm.metamodel.NodeDefinitionVisitor in project collect by openforis.

the class CollectSurvey method getExtendedDataFields.

/**
 * Goes though the attributes on the survey finding those that are marked as coming "From CSV" meaning that the popup-up will not show the attributes and they will be kept as hidden inputs
 * @param survey
 * @return The list of attributes that are marked as coming "From CSV" or that are key attributes
 */
public List<AttributeDefinition> getExtendedDataFields() {
    final CollectAnnotations annotations = getAnnotations();
    final List<AttributeDefinition> fromCsvAttributes = new ArrayList<AttributeDefinition>();
    getSchema().traverse(new NodeDefinitionVisitor() {

        public void visit(NodeDefinition def) {
            if (def instanceof AttributeDefinition) {
                AttributeDefinition attrDef = (AttributeDefinition) def;
                if (annotations.isFromCollectEarthCSV(attrDef) && !attrDef.isKey()) {
                    fromCsvAttributes.add(attrDef);
                }
            }
        }
    });
    return fromCsvAttributes;
}
Also used : ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CollectAnnotations(org.openforis.collect.metamodel.CollectAnnotations) NodeDefinitionVisitor(org.openforis.idm.metamodel.NodeDefinitionVisitor)

Example 5 with NodeDefinitionVisitor

use of org.openforis.idm.metamodel.NodeDefinitionVisitor in project collect by openforis.

the class CSVDataExportProcess method getEntitiesToExport.

private Collection<EntityDefinition> getEntitiesToExport() {
    final Collection<EntityDefinition> result = new ArrayList<EntityDefinition>();
    Schema schema = recordFilter.getSurvey().getSchema();
    if (entityId == null) {
        EntityDefinition rootEntity = schema.getRootEntityDefinition(recordFilter.getRootEntityId());
        rootEntity.traverse(new NodeDefinitionVisitor() {

            @Override
            public void visit(NodeDefinition node) {
                if (node instanceof EntityDefinition && node.isMultiple()) {
                    result.add((EntityDefinition) node);
                }
            }
        });
    } else {
        EntityDefinition entity = (EntityDefinition) schema.getDefinitionById(entityId);
        result.add(entity);
    }
    return result;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Schema(org.openforis.idm.metamodel.Schema) ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) NodeDefinitionVisitor(org.openforis.idm.metamodel.NodeDefinitionVisitor)

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