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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations