Search in sources :

Example 71 with Entity

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

the class RecordIndexManager method index.

protected void index(final IndexWriter indexWriter, CollectRecord record) throws RecordIndexException {
    try {
        Entity rootEntity = record.getRootEntity();
        rootEntity.traverse(new NodeVisitor() {

            @Override
            public void visit(Node<? extends NodeDefinition> node, int idx) {
                NodeDefinition defn = node.getDefinition();
                if (defn instanceof AttributeDefinition) {
                    index(indexWriter, (Attribute<?, ?>) node);
                }
            }
        });
    } catch (Exception e) {
        throw new RecordIndexException(e);
    }
}
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) ParseException(org.apache.lucene.queryParser.ParseException) IOException(java.io.IOException) NodeVisitor(org.openforis.idm.model.NodeVisitor)

Example 72 with Entity

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

the class RecordUpdater method validateCardinality.

private Set<NodePointer> validateCardinality(Record record, Collection<NodePointer> pointers, NodeChangeMap changeMap) {
    Set<NodePointer> updatedPointers = new HashSet<NodePointer>();
    Validator validator = record.getSurveyContext().getValidator();
    for (NodePointer nodePointer : pointers) {
        Entity entity = nodePointer.getEntity();
        NodeDefinition childDef = nodePointer.getChildDefinition();
        ValidationResultFlag minCountResult, maxCountResult;
        if (entity.isRelevant(childDef)) {
            minCountResult = validator.validateMinCount(entity, childDef);
            maxCountResult = validator.validateMaxCount(entity, childDef);
        } else {
            minCountResult = maxCountResult = ValidationResultFlag.OK;
        }
        if (entity.getMinCountValidationResult(childDef) != minCountResult) {
            entity.setMinCountValidationResult(childDef, minCountResult);
            changeMap.addMinCountValidationResultChange(nodePointer, minCountResult);
            updatedPointers.add(nodePointer);
        }
        if (entity.getMaxCountValidationResult(childDef) != maxCountResult) {
            entity.setMaxCountValidationResult(childDef, maxCountResult);
            changeMap.addMaxCountValidationResultChange(nodePointer, maxCountResult);
            updatedPointers.add(nodePointer);
        }
    }
    return updatedPointers;
}
Also used : Entity(org.openforis.idm.model.Entity) ValidationResultFlag(org.openforis.idm.metamodel.validation.ValidationResultFlag) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) NodePointer(org.openforis.idm.model.NodePointer) Validator(org.openforis.idm.metamodel.validation.Validator) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 73 with Entity

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

the class RecordUpdater method getDescendantNodePointers.

private List<NodePointer> getDescendantNodePointers(Entity entity) {
    ModelVersion version = entity.getRecord().getVersion();
    List<NodePointer> pointers = new ArrayList<NodePointer>();
    EntityDefinition definition = entity.getDefinition();
    for (NodeDefinition childDef : definition.getChildDefinitionsInVersion(version)) {
        pointers.add(new NodePointer(entity, childDef));
        if (childDef instanceof EntityDefinition) {
            for (Node<?> childEntity : entity.getChildren(childDef)) {
                pointers.addAll(getDescendantNodePointers((Entity) childEntity));
            }
        }
    }
    return pointers;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Entity(org.openforis.idm.model.Entity) ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) ModelVersion(org.openforis.idm.metamodel.ModelVersion) NodePointer(org.openforis.idm.model.NodePointer)

Example 74 with Entity

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

the class RecordUpdater method addEmptyNodes.

private void addEmptyNodes(Entity entity) {
    Record record = entity.getRecord();
    ModelVersion version = record.getVersion();
    addEmptyEnumeratedEntities(entity);
    EntityDefinition entityDefn = entity.getDefinition();
    List<NodeDefinition> childDefinitions = entityDefn.getChildDefinitionsInVersion(version);
    for (NodeDefinition childDefn : childDefinitions) {
        if (entity.getCount(childDefn) == 0) {
            if (addEmptyMultipleEntitiesWhenAddingNewEntities || !(childDefn instanceof EntityDefinition && childDefn.isMultiple())) {
                int toBeInserted = entity.getMinCount(childDefn);
                if (toBeInserted <= 0 && childDefn instanceof AttributeDefinition || !childDefn.isMultiple()) {
                    // insert at least one node
                    toBeInserted = 1;
                }
                addEmptyChildren(entity, childDefn, toBeInserted);
            }
        } else {
            entity.visitChildren(childDefn, new NodeVisitor() {

                public void visit(Node<? extends NodeDefinition> child, int idx) {
                    if (child instanceof Entity) {
                        addEmptyNodes((Entity) child);
                    }
                }
            });
        }
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Entity(org.openforis.idm.model.Entity) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) Record(org.openforis.idm.model.Record) ModelVersion(org.openforis.idm.metamodel.ModelVersion) NodeVisitor(org.openforis.idm.model.NodeVisitor)

Example 75 with Entity

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

the class RecordUpdater method updateMinCount.

private Collection<NodePointer> updateMinCount(Collection<NodePointer> nodePointers) {
    List<NodePointer> updatedPointers = new ArrayList<NodePointer>();
    for (NodePointer nodePointer : nodePointers) {
        Entity entity = nodePointer.getEntity();
        NodeDefinition childDef = nodePointer.getChildDefinition();
        Integer oldCount = entity.getMinCount(childDef);
        int newCount = calculateMinCount(nodePointer);
        entity.setMinCount(childDef, newCount);
        if (oldCount == null || oldCount.intValue() != newCount) {
            updatedPointers.add(nodePointer);
        }
    }
    return updatedPointers;
}
Also used : Entity(org.openforis.idm.model.Entity) ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) NodePointer(org.openforis.idm.model.NodePointer)

Aggregations

Entity (org.openforis.idm.model.Entity)164 Test (org.junit.Test)88 CollectRecord (org.openforis.collect.model.CollectRecord)37 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)36 Code (org.openforis.idm.model.Code)35 RealAttribute (org.openforis.idm.model.RealAttribute)25 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)23 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)19 Node (org.openforis.idm.model.Node)19 AbstractTest (org.openforis.idm.AbstractTest)18 Date (org.openforis.idm.model.Date)16 ArrayList (java.util.ArrayList)14 CodeAttribute (org.openforis.idm.model.CodeAttribute)14 Time (org.openforis.idm.model.Time)12 GregorianCalendar (java.util.GregorianCalendar)9 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)9 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)9 TextAttribute (org.openforis.idm.model.TextAttribute)9 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)8 Attribute (org.openforis.idm.model.Attribute)8