Search in sources :

Example 46 with AttributeDefinition

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;
}
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 47 with AttributeDefinition

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

Example 48 with AttributeDefinition

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

Example 49 with AttributeDefinition

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);
}
Also used : AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) DataQuery(org.openforis.collect.datacleansing.DataQuery) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 50 with AttributeDefinition

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;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) AttributeType(org.openforis.collect.designer.metamodel.AttributeType) ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) TextAttributeDefinition(org.openforis.idm.metamodel.TextAttributeDefinition) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition)

Aggregations

AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)107 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)47 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)37 ArrayList (java.util.ArrayList)33 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)27 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)21 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)20 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)18 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)18 CollectSurvey (org.openforis.collect.model.CollectSurvey)17 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)16 KeyAttributeDefinition (org.openforis.idm.metamodel.KeyAttributeDefinition)16 TextAttributeDefinition (org.openforis.idm.metamodel.TextAttributeDefinition)12 TimeAttributeDefinition (org.openforis.idm.metamodel.TimeAttributeDefinition)12 CollectAnnotations (org.openforis.collect.metamodel.CollectAnnotations)11 Schema (org.openforis.idm.metamodel.Schema)10 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)9 Entity (org.openforis.idm.model.Entity)9 Value (org.openforis.idm.model.Value)9 RangeAttributeDefinition (org.openforis.idm.metamodel.RangeAttributeDefinition)8