Search in sources :

Example 11 with AttributeDefinition

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

the class RecordIndexService method search.

public List<String> search(SearchType searchType, Survey survey, int attributeDefnId, int fieldIndex, String queryText, int maxResults) throws RecordIndexException {
    Schema schema = survey.getSchema();
    AttributeDefinition defn = (AttributeDefinition) schema.getDefinitionById(attributeDefnId);
    String indexName = defn.getAnnotation(Annotation.AUTOCOMPLETE.getQName());
    if (StringUtils.isNotBlank(indexName)) {
        try {
            // search in ram directory
            List<String> tempResult = volatileIndexManager.search(searchType, survey, attributeDefnId, fieldIndex, queryText, maxResults);
            // search in file system index
            List<String> committedResult = persistedIndexManager.search(searchType, survey, attributeDefnId, fieldIndex, queryText, maxResults);
            List<String> result = mergeSearchResults(maxResults, tempResult, committedResult);
            return result;
        } catch (Exception e) {
            throw new RecordIndexException(e);
        }
    } else {
        throw new RecordIndexException("Index name is not defined for attribute with id: " + attributeDefnId);
    }
}
Also used : Schema(org.openforis.idm.metamodel.Schema) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) RecordIndexException(org.openforis.collect.manager.RecordIndexException) RecordIndexException(org.openforis.collect.manager.RecordIndexException)

Example 12 with AttributeDefinition

use of org.openforis.idm.metamodel.AttributeDefinition 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 13 with AttributeDefinition

use of org.openforis.idm.metamodel.AttributeDefinition 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 14 with AttributeDefinition

use of org.openforis.idm.metamodel.AttributeDefinition 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 15 with AttributeDefinition

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

the class DataCSVReader method extractFieldDefinition.

private FieldDefinition<?> extractFieldDefinition(EntityDefinition parentEntityDefn, String colName) {
    String absoluteColName = getAbsoluteColName(colName);
    List<NodeDefinition> childDefns = parentEntityDefn.getChildDefinitions();
    for (NodeDefinition childDefn : childDefns) {
        String childName = childDefn.getName();
        if (absoluteColName.equals(childName)) {
            if (childDefn instanceof AttributeDefinition) {
                AttributeDefinition attrDefn = (AttributeDefinition) childDefn;
                if (attrDefn.hasMainField()) {
                    String mainFieldName = attrDefn.getMainFieldName();
                    return attrDefn.getFieldDefinition(mainFieldName);
                } else {
                    // it is a composite attribute without a "main" field (date, time, coordinate, taxon)
                    return null;
                }
            } else {
                // column name matches an entity name: error
                return null;
            }
        } else if (absoluteColName.startsWith(childName + ATTRIBUTE_FIELD_SEPARATOR)) {
            if (childDefn instanceof EntityDefinition) {
                if (childDefn.isMultiple()) {
                // ignore it
                } else {
                    String colNamePart = absoluteColName.substring(childName.length() + ATTRIBUTE_FIELD_SEPARATOR.length());
                    FieldDefinition<?> nestedFieldDefn = extractFieldDefinition((EntityDefinition) childDefn, colNamePart);
                    if (nestedFieldDefn != null) {
                        return nestedFieldDefn;
                    }
                }
            } else {
                for (FieldDefinition<?> fieldDefn : ((AttributeDefinition) childDefn).getFieldDefinitions()) {
                    if (absoluteColName.equals(childName + ATTRIBUTE_FIELD_SEPARATOR + fieldDefn.getName())) {
                        return fieldDefn;
                    }
                }
            }
        }
    }
    return null;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) FieldDefinition(org.openforis.idm.metamodel.FieldDefinition) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition)

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