Search in sources :

Example 1 with EntityIdentifierDefinition

use of org.openforis.collect.io.data.DataLine.EntityIdentifierDefinition 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 2 with EntityIdentifierDefinition

use of org.openforis.collect.io.data.DataLine.EntityIdentifierDefinition 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)

Example 3 with EntityIdentifierDefinition

use of org.openforis.collect.io.data.DataLine.EntityIdentifierDefinition in project collect by openforis.

the class DataCSVReader method getAncestorIdentifiers.

private List<EntityIdentifierDefinition> getAncestorIdentifiers() {
    List<EntityDefinition> ancestorEntityDefns = parentEntityDefinition.getAncestorEntityDefinitionsInReverseOrder();
    ancestorEntityDefns.add(parentEntityDefinition);
    List<EntityIdentifierDefinition> entityIdentifierDefns = new ArrayList<DataLine.EntityIdentifierDefinition>();
    for (EntityDefinition ancestorEntityDefn : ancestorEntityDefns) {
        EntityIdentifierDefinition identifier;
        if (ancestorEntityDefn.isMultiple()) {
            List<AttributeDefinition> keyDefns = ancestorEntityDefn.getKeyAttributeDefinitions();
            if (keyDefns.isEmpty()) {
                identifier = new DataLine.EntityPositionIdentifierDefinition(ancestorEntityDefn.getId());
            } else {
                identifier = new DataLine.EntityKeysIdentifierDefintion(ancestorEntityDefn);
            }
        } else {
            identifier = new DataLine.SingleEntityIdentifierDefinition(ancestorEntityDefn.getId());
        }
        entityIdentifierDefns.add(identifier);
    }
    return entityIdentifierDefns;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) EntityKeysIdentifierDefintion(org.openforis.collect.io.data.DataLine.EntityKeysIdentifierDefintion) SingleEntityIdentifierDefinition(org.openforis.collect.io.data.DataLine.SingleEntityIdentifierDefinition) ArrayList(java.util.ArrayList) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) EntityPositionIdentifierDefinition(org.openforis.collect.io.data.DataLine.EntityPositionIdentifierDefinition) SingleEntityIdentifierDefinition(org.openforis.collect.io.data.DataLine.SingleEntityIdentifierDefinition) EntityIdentifierDefinition(org.openforis.collect.io.data.DataLine.EntityIdentifierDefinition)

Aggregations

EntityIdentifierDefinition (org.openforis.collect.io.data.DataLine.EntityIdentifierDefinition)3 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)3 ArrayList (java.util.ArrayList)2 EntityPositionIdentifierDefinition (org.openforis.collect.io.data.DataLine.EntityPositionIdentifierDefinition)2 SingleEntityIdentifierDefinition (org.openforis.collect.io.data.DataLine.SingleEntityIdentifierDefinition)2 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)2 Schema (org.openforis.idm.metamodel.Schema)2 List (java.util.List)1 Predicate (org.apache.commons.collections.Predicate)1 EntityKeysIdentifier (org.openforis.collect.io.data.DataLine.EntityKeysIdentifier)1 EntityKeysIdentifierDefintion (org.openforis.collect.io.data.DataLine.EntityKeysIdentifierDefintion)1 EntityPositionIdentifier (org.openforis.collect.io.data.DataLine.EntityPositionIdentifier)1 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 Survey (org.openforis.idm.metamodel.Survey)1