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);
}
}
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);
}
}
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);
}
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;
}
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;
}
Aggregations