Search in sources :

Example 1 with Attribute

use of org.openforis.idm.model.Attribute in project collect by openforis.

the class ValidationMessageBuilder method getKeyText.

public String getKeyText(Entity entity, Locale locale) {
    EntityDefinition defn = entity.getDefinition();
    List<AttributeDefinition> keyDefns = defn.getKeyAttributeDefinitions();
    if (!keyDefns.isEmpty()) {
        List<String> shortKeyParts = new ArrayList<String>();
        List<String> fullKeyParts = new ArrayList<String>();
        for (AttributeDefinition keyDefn : keyDefns) {
            Attribute<?, ?> keyAttr = (Attribute<?, ?>) entity.getChild(keyDefn, 0);
            if (keyAttr != null) {
                Object keyValue = getKeyLabelPart(keyAttr);
                if (keyValue != null && StringUtils.isNotBlank(keyValue.toString())) {
                    shortKeyParts.add(keyValue.toString());
                    String label = getPrettyLabelText(keyDefn, locale);
                    String fullKeyPart = label + " " + keyValue;
                    fullKeyParts.add(fullKeyPart);
                }
            }
        }
        return StringUtils.join(shortKeyParts, RECORD_KEYS_LABEL_SEPARATOR);
    } else if (entity.getParent() != null) {
        return "" + (entity.getIndex() + 1);
    } else {
        return null;
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Attribute(org.openforis.idm.model.Attribute) TaxonAttribute(org.openforis.idm.model.TaxonAttribute) ArrayList(java.util.ArrayList) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition)

Example 2 with Attribute

use of org.openforis.idm.model.Attribute in project collect by openforis.

the class QueryExecutorIntegrationTest method testSimpleQuery.

@Test
public void testSimpleQuery() {
    // select region from tree where dbh > 20
    DataQuery query = new DataQuery(survey);
    EntityDefinition treeDef = (EntityDefinition) survey.getSchema().getDefinitionByPath("/cluster/plot/tree");
    AttributeDefinition dbhDef = (AttributeDefinition) survey.getSchema().getDefinitionByPath("/cluster/plot/tree/dbh");
    query.setEntityDefinition(treeDef);
    query.setAttributeDefinition(dbhDef);
    query.setConditions("dbh > 20");
    final List<Node<?>> nodes = new ArrayList<Node<?>>();
    DataQueryExecutorJob job = jobManager.createJob(DataQueryExecutorJob.class);
    DataQueryExecutorJobInput input = new DataQueryExecutorJobInput(query, Step.ENTRY, new NodeProcessor() {

        public void process(Node<?> node) {
            nodes.add(node);
        }
    });
    job.setInput(input);
    jobManager.start(job, false);
    assertFalse(nodes.isEmpty());
    // first result
    Node<?> node = nodes.get(0);
    assertTrue(node instanceof Attribute);
    CollectRecord record = (CollectRecord) node.getRecord();
    assertEquals(Arrays.asList("10_117"), record.getRootEntityKeyValues());
}
Also used : DataQueryExecutorJobInput(org.openforis.collect.datacleansing.DataQueryExecutorJob.DataQueryExecutorJobInput) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CollectRecord(org.openforis.collect.model.CollectRecord) NodeProcessor(org.openforis.collect.model.NodeProcessor) Attribute(org.openforis.idm.model.Attribute) Node(org.openforis.idm.model.Node) ArrayList(java.util.ArrayList) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 3 with Attribute

use of org.openforis.idm.model.Attribute in project collect by openforis.

the class EventProducer method produceFor.

public List<RecordEvent> produceFor(CollectRecord record, final String userName) {
    final List<RecordEvent> events = new ArrayList<RecordEvent>();
    final Integer recordId = record.getId();
    final RecordStep recordStep = record.getStep().toRecordStep();
    record.getRootEntity().traverse(new NodeVisitor() {

        public void visit(Node<? extends NodeDefinition> node, int idx) {
            NodeDefinition nodeDef = node.getDefinition();
            List<String> ancestorIds = getAncestorIds(nodeDef, node.getAncestorIds());
            EventFactory factory = new EventFactory(recordId, recordStep, ancestorIds, node, userName);
            if (node instanceof Entity) {
                events.addAll(factory.entityCreated());
            } else if (node instanceof Attribute) {
                if (nodeDef.isMultiple()) {
                    events.addAll(factory.attributeCreated());
                } else {
                    events.addAll(factory.attributeUpdated());
                }
            }
        }
    });
    return events;
}
Also used : Entity(org.openforis.idm.model.Entity) CoordinateAttribute(org.openforis.idm.model.CoordinateAttribute) CodeAttribute(org.openforis.idm.model.CodeAttribute) Attribute(org.openforis.idm.model.Attribute) DateAttribute(org.openforis.idm.model.DateAttribute) TimeAttribute(org.openforis.idm.model.TimeAttribute) NumberAttribute(org.openforis.idm.model.NumberAttribute) BooleanAttribute(org.openforis.idm.model.BooleanAttribute) TextAttribute(org.openforis.idm.model.TextAttribute) NumericRangeAttribute(org.openforis.idm.model.NumericRangeAttribute) TaxonAttribute(org.openforis.idm.model.TaxonAttribute) ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) NodeVisitor(org.openforis.idm.model.NodeVisitor) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List)

Example 4 with Attribute

use of org.openforis.idm.model.Attribute in project collect by openforis.

the class DataHandler method endAttributeElement.

@SuppressWarnings({ "rawtypes" })
protected void endAttributeElement() {
    Attribute attr = (Attribute) node;
    try {
        if (field != null) {
            Field<?> fld = getField();
            if (fld != null) {
                setField(fld);
            } else {
                warn(field, "Can't parse field with type " + attr.getClass().getSimpleName());
            // this.node = node.getParent();
            }
        }
    } catch (NumberFormatException e) {
        warn(field, e.toString());
    }
    if (field == null) {
        Node<?> oldNode = node;
        this.node = node.getParent();
        removeIfEmpty(oldNode);
    } else {
        this.field = null;
    }
}
Also used : Attribute(org.openforis.idm.model.Attribute) FileAttribute(org.openforis.idm.model.FileAttribute)

Example 5 with Attribute

use of org.openforis.idm.model.Attribute 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

Attribute (org.openforis.idm.model.Attribute)23 ArrayList (java.util.ArrayList)8 Entity (org.openforis.idm.model.Entity)8 BooleanAttribute (org.openforis.idm.model.BooleanAttribute)7 CodeAttribute (org.openforis.idm.model.CodeAttribute)7 Value (org.openforis.idm.model.Value)6 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)5 Node (org.openforis.idm.model.Node)5 Test (org.junit.Test)4 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)4 Record (org.openforis.idm.model.Record)4 TextAttribute (org.openforis.idm.model.TextAttribute)4 HashSet (java.util.HashSet)3 LinkedHashSet (java.util.LinkedHashSet)3 BooleanValue (org.openforis.idm.model.BooleanValue)3 NodePointer (org.openforis.idm.model.NodePointer)3 NodeVisitor (org.openforis.idm.model.NodeVisitor)3 TextValue (org.openforis.idm.model.TextValue)3 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)2 FileAttribute (org.openforis.idm.model.FileAttribute)2