use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class DataCSVReader method getAncestorKeyAttributeDefinitions.
protected List<AttributeDefinition> getAncestorKeyAttributeDefinitions() {
List<AttributeDefinition> result = new ArrayList<AttributeDefinition>();
List<EntityDefinition> ancestors = parentEntityDefinition.getAncestorEntityDefinitionsInReverseOrder();
for (EntityDefinition ancestor : ancestors) {
result.addAll(ancestor.getKeyAttributeDefinitions());
}
result.addAll(parentEntityDefinition.getKeyAttributeDefinitions());
return result;
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class Entity method getKeyAttributeValues.
public Value[] getKeyAttributeValues() {
EntityDefinition defn = getDefinition();
List<AttributeDefinition> keyDefns = defn.getKeyAttributeDefinitions();
if (keyDefns.isEmpty()) {
return null;
} else {
Value[] result = new Value[keyDefns.size()];
for (int i = 0; i < keyDefns.size(); i++) {
AttributeDefinition keyDefn = keyDefns.get(i);
Attribute<?, Value> keyAttr = getKeyAttribute(keyDefn);
Value keyValue = keyAttr == null ? null : keyAttr.getValue();
result[i] = keyValue;
}
return result;
}
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class RecordSummaryDao method mapRecordsToSummaries.
private List<RecordSummary> mapRecordsToSummaries(List<Record> records, List<AttributeDefinition> keyDefs, List<EntityDefinition> countable) {
List<RecordSummary> result = new ArrayList<RecordSummary>();
for (Record record : records) {
Integer id = record.getValueAsInteger(RECORD.ID);
// String createdBy = r.getValueAsString(USER_MODIFIED_BY_ALIAS);
String createdBy = null;
Date dateCreated = record.getValueAsDate(DATE_CREATED_ALIAS);
// String modifiedBy = r.getValueAsString(USER_CREATED_BY_ALIAS);
String modifiedBy = null;
Date modifiedDate = record.getValueAsDate(DATE_MODIFIED_ALIAS);
Integer step = record.getValueAsInteger(RECORD.STEP);
Integer warnings = record.getValueAsInteger(RECORD.WARNINGS);
Integer errors = record.getValueAsInteger(RECORD.ERRORS);
Integer skipped = record.getValueAsInteger(RECORD.SKIPPED);
Integer missing = record.getValueAsInteger(RECORD.MISSING);
// create count map
Map<String, Integer> entityCounts = new HashMap<String, Integer>();
for (EntityDefinition def : countable) {
String alias = COUNT_ALIAS_PREFIX + def.getName();
String key = def.getName();
Integer value = record.getValueAsInteger(alias);
entityCounts.put(key, value);
}
// create key attributes map
Map<String, String> keyAttributes = new HashMap<String, String>();
for (AttributeDefinition attributeDefinition : keyDefs) {
String projectionAlias = KEY_ALIAS_PREFIX + attributeDefinition.getName();
String key = attributeDefinition.getName();
Object value = record.getValue(projectionAlias);
String valueStr = value != null ? value.toString() : "";
keyAttributes.put(key, valueStr);
}
RecordSummary recordSummary = new RecordSummary(id, keyAttributes, entityCounts, createdBy, dateCreated, modifiedBy, modifiedDate, step, skipped, missing, errors, warnings);
result.add(recordSummary);
}
return result;
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class StateDependencyMap method registerDependencies.
private void registerDependencies(EntityDefinition entityDefinition) {
List<NodeDefinition> childDefinitions = entityDefinition.getChildDefinitions();
for (NodeDefinition nodeDefinition : childDefinitions) {
registerDependencies(nodeDefinition, nodeDefinition.getRelevantExpression(), relevantDependencies);
registerDependencies(nodeDefinition, nodeDefinition.getRequiredExpression(), requiredDependencies);
if (nodeDefinition instanceof AttributeDefinition) {
registerDependencies((AttributeDefinition) nodeDefinition);
} else {
registerDependencies((EntityDefinition) nodeDefinition);
}
}
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class DataLoader method processRow.
private void processRow(CollectRecord record, Record row) throws DataInconsistencyException {
Integer id = row.getValueAsInteger(DATA.ID);
Integer parentId = row.getValueAsInteger(DATA.PARENT_ID);
Integer defnId = row.getValueAsInteger(DATA.DEFINITION_ID);
Node<?> o;
if (parentId == null) {
// Process root entity
o = record.getRootEntity();
Integer rootEntityDefnId = o.getDefinition().getId();
if (!rootEntityDefnId.equals(defnId)) {
throw new DataInconsistencyException(DATA.DEFINITION_ID + " " + defnId + " does not match " + RECORD.ROOT_ENTITY_ID + " " + rootEntityDefnId);
}
} else {
// Process other objects
Node<? extends NodeDefinition> parent = objectsById.get(parentId);
if (parent == null) {
throw new DataInconsistencyException("Parent " + parentId + " not yet loaded");
}
if (!(parent instanceof Entity)) {
throw new DataInconsistencyException("Parent " + parentId + " not an entity");
}
NodeDefinition defn = record.getSurvey().getSchema().getById(defnId);
if (defn == null) {
throw new DataInconsistencyException("Unknown schema definition " + DATA.DEFINITION_ID);
}
NodeMapper mapper = NodeMapper.getInstance(defn.getClass());
Node<?> o1 = mapper.addNode(defn, row, (Entity) parent);
if (defn instanceof AttributeDefinition) {
String remarks = row.getValue(DATA.REMARKS);
String s = row.getValueAsString(DATA.SYMBOL);
Character symbol = null;
if (s != null && s.length() == 1) {
symbol = s.charAt(0);
}
Attribute<?, ?> attribute = (Attribute<?, ?>) o1;
attribute.setRemarks(remarks);
attribute.setSymbol(symbol);
}
o = o1;
}
objectsById.put(id, o);
}
Aggregations