Search in sources :

Example 21 with EntityDefinition

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

the class CSVDataImportProcess method setRecordKeys.

private void setRecordKeys(DataLine line, CollectRecord record) {
    EntityDefinition rootEntityDefn = record.getRootEntity().getDefinition();
    Value[] recordKeyValues = line.getRecordKeyValues(rootEntityDefn);
    List<AttributeDefinition> keyAttributeDefinitions = rootEntityDefn.getKeyAttributeDefinitions();
    for (int i = 0; i < keyAttributeDefinitions.size(); i++) {
        AttributeDefinition keyDefn = keyAttributeDefinitions.get(i);
        // for record key attributes, absolute path must be equal to relative path
        Attribute<?, ?> keyAttr = record.findNodeByPath(keyDefn.getPath());
        Value keyVal = recordKeyValues[i];
        setValueInField(keyAttr, keyDefn.getMainFieldName(), ((AbstractValue) keyVal).toInternalString(), line.getLineNumber(), null);
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) AbstractValue(org.openforis.idm.model.AbstractValue) Value(org.openforis.idm.model.Value) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition) CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition)

Example 22 with EntityDefinition

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

the class CSVDataImportProcess method createParentEntitySearchError.

private ParsingError createParentEntitySearchError(CollectRecord record, DataLine line, EntityIdentifier<?> identifier, String messageKey) {
    EntityIdentifierDefinition identifierDefn = identifier.getDefinition();
    Survey survey = record.getSurvey();
    Schema schema = survey.getSchema();
    EntityDefinition parentEntityDefn = (EntityDefinition) schema.getDefinitionById(identifierDefn.getEntityDefinitionId());
    String[] colNames = DataCSVReader.getKeyAttributeColumnNames(parentEntityDefn, parentEntityDefn.getKeyAttributeDefinitions());
    ParsingError error = new ParsingError(ErrorType.INVALID_VALUE, line.getLineNumber(), colNames, messageKey);
    List<String> recordKeys = record.getRootEntityKeyValues();
    CollectionUtils.filter(recordKeys, new Predicate() {

        @Override
        public boolean evaluate(Object object) {
            return StringUtils.isNotBlank((String) object);
        }
    });
    String jointRecordKeys = StringUtils.join(recordKeys, ", ");
    String jointParentEntityKeys = identifier instanceof EntityPositionIdentifier ? "[" + ((EntityPositionIdentifier) identifier).getPosition() + "]" : StringUtils.join(((EntityKeysIdentifier) identifier).getKeyValues(), ", ");
    error.setMessageArgs(new String[] { parentEntityDefn.getName(), jointParentEntityKeys, jointRecordKeys });
    return error;
}
Also used : EntityPositionIdentifier(org.openforis.collect.io.data.DataLine.EntityPositionIdentifier) EntityKeysIdentifier(org.openforis.collect.io.data.DataLine.EntityKeysIdentifier) Schema(org.openforis.idm.metamodel.Schema) Predicate(org.apache.commons.collections.Predicate) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CollectSurvey(org.openforis.collect.model.CollectSurvey) Survey(org.openforis.idm.metamodel.Survey) ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) EntityIdentifierDefinition(org.openforis.collect.io.data.DataLine.EntityIdentifierDefinition)

Example 23 with EntityDefinition

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

the class CSVDataImportProcess method setKeyValues.

private void setKeyValues(Entity entity, Value[] values, Map<FieldValueKey, String> colNamesByField, long row) {
    // create key attribute values by name
    Map<FieldValueKey, String> keyValuesByField = new HashMap<FieldValueKey, String>();
    EntityDefinition entityDefn = entity.getDefinition();
    List<AttributeDefinition> keyDefns = entityDefn.getKeyAttributeDefinitions();
    for (int i = 0; i < keyDefns.size(); i++) {
        AttributeDefinition keyDefn = keyDefns.get(i);
        Value keyValue = values[i];
        Map<String, Object> keyValueMap = keyValue.toMap();
        List<String> keyFieldNames = keyDefn.getKeyFieldNames();
        for (String keyFieldName : keyFieldNames) {
            Object keyValueFieldVal = keyValueMap.get(keyFieldName);
            keyValuesByField.put(new FieldValueKey(keyDefn, keyFieldName), keyValueFieldVal.toString());
        }
    }
    setValuesInAttributes(entity, keyValuesByField, colNamesByField, row);
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) HashMap(java.util.HashMap) FieldValueKey(org.openforis.collect.io.data.DataLine.FieldValueKey) AbstractValue(org.openforis.idm.model.AbstractValue) Value(org.openforis.idm.model.Value) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition) CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition)

Example 24 with EntityDefinition

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

the class DataCSVReader method getKeyAttributeColumnNames.

protected static List<String> getKeyAttributeColumnNames(EntityDefinition parentEntityDefinition, AttributeDefinition keyAttrDefn) {
    EntityDefinition parentDefn = keyAttrDefn.getParentEntityDefinition();
    String prefix = parentDefn == parentEntityDefinition ? "" : parentDefn.getName() + "_";
    List<String> keyFieldNames = keyAttrDefn.getKeyFieldNames();
    if (keyFieldNames.size() == 1) {
        return Arrays.asList(prefix + keyAttrDefn.getName());
    } else {
        List<String> result = new ArrayList<String>(keyFieldNames.size());
        for (String fieldName : keyFieldNames) {
            result.add(prefix + keyAttrDefn.getName() + "_" + fieldName);
        }
        return result;
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) ArrayList(java.util.ArrayList)

Example 25 with EntityDefinition

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

the class DataCSVReader method getExpectedAncestorKeyColumnNames.

private List<String> getExpectedAncestorKeyColumnNames() {
    List<EntityIdentifierDefinition> entityIdentifierDefns = getAncestorIdentifiers();
    // validate ancestor key columns
    Schema schema = parentEntityDefinition.getSchema();
    List<String> expectedEntityKeyColumns = new ArrayList<String>();
    for (EntityIdentifierDefinition identifier : entityIdentifierDefns) {
        int defnId = identifier.getEntityDefinitionId();
        EntityDefinition defn = (EntityDefinition) schema.getDefinitionById(defnId);
        if (identifier instanceof EntityPositionIdentifierDefinition) {
            String expectedColName = getPositionColumnName(defn);
            expectedEntityKeyColumns.add(expectedColName);
        } else if (identifier instanceof SingleEntityIdentifierDefinition) {
        // skip
        } else {
            List<AttributeDefinition> keyDefns = defn.getKeyAttributeDefinitions();
            for (AttributeDefinition keyDefn : keyDefns) {
                List<String> expectedColNames = getKeyAttributeColumnNames(parentEntityDefinition, keyDefn);
                expectedEntityKeyColumns.addAll(expectedColNames);
            }
        }
    }
    return expectedEntityKeyColumns;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) SingleEntityIdentifierDefinition(org.openforis.collect.io.data.DataLine.SingleEntityIdentifierDefinition) Schema(org.openforis.idm.metamodel.Schema) ArrayList(java.util.ArrayList) EntityPositionIdentifierDefinition(org.openforis.collect.io.data.DataLine.EntityPositionIdentifierDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) ArrayList(java.util.ArrayList) List(java.util.List) SingleEntityIdentifierDefinition(org.openforis.collect.io.data.DataLine.SingleEntityIdentifierDefinition) EntityIdentifierDefinition(org.openforis.collect.io.data.DataLine.EntityIdentifierDefinition)

Aggregations

EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)235 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)70 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)47 Schema (org.openforis.idm.metamodel.Schema)46 ArrayList (java.util.ArrayList)44 Test (org.junit.Test)38 Entity (org.openforis.idm.model.Entity)36 CollectRecord (org.openforis.collect.model.CollectRecord)30 CollectSurvey (org.openforis.collect.model.CollectSurvey)28 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)24 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)24 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)19 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)18 UITab (org.openforis.collect.metamodel.ui.UITab)16 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)14 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)13 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)12 RecordFilter (org.openforis.collect.model.RecordFilter)11 SurveyObject (org.openforis.idm.metamodel.SurveyObject)10 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)9