Search in sources :

Example 66 with NodeDefinition

use of org.openforis.idm.metamodel.NodeDefinition 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 67 with NodeDefinition

use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.

the class SurveyValidator method validateSchemaNodes.

/**
 * Checks for the existence of empty entities
 *
 * @param survey
 * @return
 */
protected List<SurveyValidationResult> validateSchemaNodes(CollectSurvey survey) {
    final List<SurveyValidationResult> results = new ArrayList<SurveyValidationResult>();
    Schema schema = survey.getSchema();
    schema.traverse(new NodeDefinitionVisitor() {

        @Override
        public void visit(NodeDefinition def) {
            results.addAll(validateSchemaNode(def));
        }
    });
    return results;
}
Also used : Schema(org.openforis.idm.metamodel.Schema) ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) NodeDefinitionVisitor(org.openforis.idm.metamodel.NodeDefinitionVisitor)

Example 68 with NodeDefinition

use of org.openforis.idm.metamodel.NodeDefinition 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 69 with NodeDefinition

use of org.openforis.idm.metamodel.NodeDefinition 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 70 with NodeDefinition

use of org.openforis.idm.metamodel.NodeDefinition 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)

Aggregations

NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)173 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)70 ArrayList (java.util.ArrayList)42 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)27 Schema (org.openforis.idm.metamodel.Schema)24 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)22 CollectSurvey (org.openforis.collect.model.CollectSurvey)20 Entity (org.openforis.idm.model.Entity)19 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)16 NodeDefinitionVisitor (org.openforis.idm.metamodel.NodeDefinitionVisitor)14 UITab (org.openforis.collect.metamodel.ui.UITab)12 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)11 Survey (org.openforis.idm.metamodel.Survey)11 Test (org.junit.Test)10 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)9 ModelVersion (org.openforis.idm.metamodel.ModelVersion)9 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)8 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)8 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)8 Node (org.openforis.idm.model.Node)8