use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class NodeDefinitionProxy method fromList.
static List<NodeDefinitionProxy> fromList(EntityDefinitionProxy parent, List<? extends NodeDefinition> list) {
List<NodeDefinitionProxy> proxies = new ArrayList<NodeDefinitionProxy>();
if (list != null) {
for (NodeDefinition n : list) {
NodeDefinitionProxy p = null;
CollectSurvey survey = (CollectSurvey) n.getSurvey();
UIOptions uiOptions = survey.getUIOptions();
boolean hidden = uiOptions.isHidden(n);
if (!hidden) {
if (n instanceof AttributeDefinition) {
if (n instanceof BooleanAttributeDefinition) {
p = new BooleanAttributeDefinitionProxy(parent, (BooleanAttributeDefinition) n);
} else if (n instanceof CodeAttributeDefinition) {
p = new CodeAttributeDefinitionProxy(parent, (CodeAttributeDefinition) n);
} else if (n instanceof CoordinateAttributeDefinition) {
p = new CoordinateAttributeDefinitionProxy(parent, (CoordinateAttributeDefinition) n);
} else if (n instanceof DateAttributeDefinition) {
p = new DateAttributeDefinitionProxy(parent, (DateAttributeDefinition) n);
} else if (n instanceof FileAttributeDefinition) {
p = new FileAttributeDefinitionProxy(parent, (FileAttributeDefinition) n);
} else if (n instanceof NumberAttributeDefinition) {
p = new NumberAttributeDefinitionProxy(parent, (NumberAttributeDefinition) n);
} else if (n instanceof RangeAttributeDefinition) {
p = new RangeAttributeDefinitionProxy(parent, (RangeAttributeDefinition) n);
} else if (n instanceof TaxonAttributeDefinition) {
p = new TaxonAttributeDefinitionProxy(parent, (TaxonAttributeDefinition) n);
} else if (n instanceof TextAttributeDefinition) {
p = new TextAttributeDefinitionProxy(parent, (TextAttributeDefinition) n);
} else if (n instanceof TimeAttributeDefinition) {
p = new TimeAttributeDefinitionProxy(parent, (TimeAttributeDefinition) n);
} else {
throw new RuntimeException("AttributeDefinition not supported: " + n.getClass().getSimpleName());
}
} else if (n instanceof EntityDefinition) {
p = new EntityDefinitionProxy(parent, (EntityDefinition) n);
}
if (p != null) {
proxies.add(p);
}
}
}
}
return proxies;
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class UIFieldView method getAttributeType.
public String getAttributeType() {
AttributeDefinition attrDef = uiObject.getAttributeDefinition();
AttributeType attrType = AttributeType.valueOf(attrDef);
return attrType.name();
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class SchemaProxy method getKeyAttributeDefinitionIdsByRootEntityId.
@ExternalizedProperty
public Map<Integer, List<Integer>> getKeyAttributeDefinitionIdsByRootEntityId() {
Map<Integer, List<Integer>> result = new HashMap<Integer, List<Integer>>();
List<EntityDefinition> rootEntityDefinitions = schema.getRootEntityDefinitions();
for (EntityDefinition rootEntity : rootEntityDefinitions) {
List<Integer> keyDefnIds = new ArrayList<Integer>();
List<AttributeDefinition> keyDefns = rootEntity.getKeyAttributeDefinitions();
for (AttributeDefinition keyDefn : keyDefns) {
keyDefnIds.add(keyDefn.getId());
}
result.put(rootEntity.getId(), keyDefnIds);
}
return result;
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class CSVDataImportProcess method setValuesInAttributes.
private void setValuesInAttributes(Entity ancestorEntity, Map<FieldValueKey, String> fieldValues, Map<FieldValueKey, String> colNameByField, long row) {
Set<Entry<FieldValueKey, String>> entrySet = fieldValues.entrySet();
// delete all multiple attributes
for (Entry<FieldValueKey, String> entry : entrySet) {
FieldValueKey fieldValueKey = entry.getKey();
EntityDefinition ancestorDefn = ancestorEntity.getDefinition();
Schema schema = ancestorDefn.getSchema();
AttributeDefinition attrDefn = (AttributeDefinition) schema.getDefinitionById(fieldValueKey.getAttributeDefinitionId());
Entity parentEntity = getOrCreateParentEntity(ancestorEntity, attrDefn);
if (attrDefn.isMultiple()) {
List<Node<?>> attributes = parentEntity.getChildren(attrDefn);
int tot = attributes.size();
for (int i = 0; i < tot; i++) {
Node<?> node = attributes.get(0);
NodeChangeSet changes = recordUpdater.deleteNode(node);
if (nodeChangeBatchProcessor != null) {
nodeChangeBatchProcessor.add(changes, adminUser.getUsername());
}
}
}
}
// set values
for (Entry<FieldValueKey, String> entry : entrySet) {
FieldValueKey fieldValueKey = entry.getKey();
String strValue = entry.getValue();
EntityDefinition ancestorDefn = ancestorEntity.getDefinition();
Schema schema = ancestorDefn.getSchema();
AttributeDefinition attrDefn = (AttributeDefinition) schema.getDefinitionById(fieldValueKey.getAttributeDefinitionId());
String fieldName = fieldValueKey.getFieldName();
Entity parentEntity = getOrCreateParentEntity(ancestorEntity, attrDefn);
String colName = colNameByField.get(fieldValueKey);
int attrPos = fieldValueKey.getAttributePosition();
setValueInField(parentEntity, attrDefn, attrPos - 1, fieldName, strValue, colName, row);
}
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class DataCSVReader method getKeyAttributeColumnNames.
protected static String[] getKeyAttributeColumnNames(EntityDefinition parentEntityDefinition, List<AttributeDefinition> ancestorKeyAttrDefns) {
List<String> result = new ArrayList<String>(ancestorKeyAttrDefns.size());
for (int i = 0; i < ancestorKeyAttrDefns.size(); i++) {
AttributeDefinition attrDefn = ancestorKeyAttrDefns.get(i);
result.addAll(getKeyAttributeColumnNames(parentEntityDefinition, attrDefn));
}
return result.toArray(new String[result.size()]);
}
Aggregations