use of org.openforis.idm.metamodel.AttributeDefinition 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.AttributeDefinition in project collect by openforis.
the class RecordFilter method setQualifiersByName.
public void setQualifiersByName(Map<String, String> qualifiers) {
List<String> qualifierValues = new ArrayList<String>();
EntityDefinition rootEntityDefinition = survey.getSchema().getRootEntityDefinition(rootEntityId);
List<AttributeDefinition> qualifierAttrDefs = survey.getSchema().getQualifierAttributeDefinitions(rootEntityDefinition);
for (AttributeDefinition qualifierDef : qualifierAttrDefs) {
String qualifierVal = qualifiers.get(qualifierDef.getName());
qualifierValues.add(qualifierVal);
}
setQualifiers(qualifierValues);
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class CSVWriterDataQueryResultItemProcessor method process.
@Override
public void process(DataQueryResultItem item) {
List<String> lineValues = new ArrayList<String>();
lineValues.addAll(item.getRecordKeyValues());
lineValues.add(item.extractNodePath());
AttributeDefinition attrDef = item.getAttributeDefinition();
Value value = item.extractAttributeValue();
Map<String, Object> valueMap = value == null ? null : value.toMap();
List<String> fieldNames = attrDef.getFieldNames();
for (String fieldName : fieldNames) {
Object fieldValue = valueMap == null ? null : valueMap.get(fieldName);
lineValues.add(fieldValue == null ? "" : fieldValue.toString());
}
csvWriter.writeNext(lineValues);
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class DataCleansingStepValidator method validateCondition.
private void validateCondition(DataCleansingStepForm target, Errors errors, DataCleansingStepValue updateValue, boolean lastRow) {
String condition = updateValue.getCondition();
if (StringUtils.isBlank(condition)) {
return;
}
CollectSurvey survey = getActiveSurvey();
DataQuery query = dataQueryManager.loadById(survey, target.getQueryId());
AttributeDefinition attrDef = query.getAttributeDefinition();
validateBooleanExpression(errors, attrDef.getParentEntityDefinition(), attrDef, UPDATE_VALUES_FIELD, condition);
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class CollectEarthSurveyValidator method validateAllRequiredFieldsDefined.
private List<SurveyValidationResult> validateAllRequiredFieldsDefined(CollectSurvey survey) {
final List<SurveyValidationResult> results = new ArrayList<SurveyValidationResult>();
final EntityDefinition rootEntityDef = getMainRootEntityDefinition(survey);
for (CollectEarthField field : REQUIRED_FIELDS) {
String fieldName = field.getName();
try {
NodeDefinition foundFieldDef = rootEntityDef.getChildDefinition(fieldName);
if (!field.getType().isAssignableFrom(foundFieldDef.getClass())) {
Class<? extends AttributeDefinition> type = field.getType();
AttributeType expectedAttributeType = AttributeType.valueOf(type);
String expectedType = expectedAttributeType.getLabel();
String foundType;
if (foundFieldDef instanceof AttributeDefinition) {
AttributeType foundTypeEnum = AttributeType.valueOf((AttributeDefinition) foundFieldDef);
foundType = foundTypeEnum.getLabel();
} else {
foundType = NodeType.ENTITY.getLabel();
}
results.add(new SurveyValidationResult(rootEntityDef.getPath() + "/" + fieldName, "survey.validation.collect_earth.unexpected_field_type", expectedType, foundType));
}
} catch (Exception e) {
results.add(new SurveyValidationResult(rootEntityDef.getPath() + "/" + fieldName, "survey.validation.collect_earth.missing_required_field"));
}
}
return results;
}
Aggregations