Search in sources :

Example 1 with EntityPositionIdentifier

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

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

the class CSVDataImportProcess method createChildEntity.

private Entity createChildEntity(Entity currentParent, String childName, EntityIdentifier<?> identifier, Map<FieldValueKey, String> colNamesByField, long row) {
    if (identifier instanceof EntityPositionIdentifier) {
        int position = ((EntityPositionIdentifier) identifier).getPosition();
        if (position == currentParent.getCount(childName) + 1) {
            Entity entity = (Entity) performNodeAdd(currentParent, childName);
            return entity;
        } else {
            throw new IllegalArgumentException(String.format("Trying to create child in a invalid position: row=%d path=%s[%d]", row, currentParent.getPath() + "/" + childName, position));
        }
    } else {
        Entity entity = (Entity) performNodeAdd(currentParent, childName);
        Value[] keyValues = ((EntityKeysIdentifier) identifier).getKeyValues();
        setKeyValues(entity, keyValues, colNamesByField, row);
        return entity;
    }
}
Also used : EntityPositionIdentifier(org.openforis.collect.io.data.DataLine.EntityPositionIdentifier) Entity(org.openforis.idm.model.Entity) EntityKeysIdentifier(org.openforis.collect.io.data.DataLine.EntityKeysIdentifier) AbstractValue(org.openforis.idm.model.AbstractValue) Value(org.openforis.idm.model.Value)

Example 3 with EntityPositionIdentifier

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

the class CSVDataImportProcess method findChildEntities.

private List<Entity> findChildEntities(Entity currentParent, String childName, EntityIdentifier<?> identifier) {
    if (identifier instanceof EntityPositionIdentifier) {
        int position = ((EntityPositionIdentifier) identifier).getPosition();
        if (currentParent.getCount(childName) >= position) {
            ArrayList<Entity> result = new ArrayList<Entity>();
            Entity child = (Entity) currentParent.getChild(childName, position - 1);
            result.add(child);
            return result;
        } else {
            return Collections.emptyList();
        }
    } else {
        EntityDefinition parentDefn = currentParent.getDefinition();
        EntityDefinition childDefn = parentDefn.getChildDefinition(childName, EntityDefinition.class);
        Value[] keyValues = ((EntityKeysIdentifier) identifier).getKeyValues();
        return currentParent.findChildEntitiesByKeys(childDefn, keyValues);
    }
}
Also used : EntityPositionIdentifier(org.openforis.collect.io.data.DataLine.EntityPositionIdentifier) Entity(org.openforis.idm.model.Entity) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) EntityKeysIdentifier(org.openforis.collect.io.data.DataLine.EntityKeysIdentifier) ArrayList(java.util.ArrayList) AbstractValue(org.openforis.idm.model.AbstractValue) Value(org.openforis.idm.model.Value)

Aggregations

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