Search in sources :

Example 16 with AttributeDefinition

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;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) ArrayList(java.util.ArrayList) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition)

Example 17 with AttributeDefinition

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;
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition)

Example 18 with AttributeDefinition

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) Date(java.sql.Date) RecordSummary(org.openforis.collect.model.RecordSummary) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Record(org.jooq.Record)

Example 19 with AttributeDefinition

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);
        }
    }
}
Also used : NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition)

Example 20 with AttributeDefinition

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);
}
Also used : Entity(org.openforis.idm.model.Entity) Attribute(org.openforis.idm.model.Attribute) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) DataInconsistencyException(org.openforis.collect.persistence.DataInconsistencyException)

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