Search in sources :

Example 6 with NodeVisitor

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

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

the class CollectRecord method getFileAttributes.

public List<FileAttribute> getFileAttributes() {
    final List<FileAttribute> result = new ArrayList<FileAttribute>();
    Entity rootEntity = getRootEntity();
    rootEntity.traverse(new NodeVisitor() {

        @Override
        public void visit(Node<? extends NodeDefinition> node, int pos) {
            if (node instanceof FileAttribute) {
                result.add((FileAttribute) node);
            }
        }
    });
    return result;
}
Also used : Entity(org.openforis.idm.model.Entity) ArrayList(java.util.ArrayList) FileAttribute(org.openforis.idm.model.FileAttribute) NodeVisitor(org.openforis.idm.model.NodeVisitor)

Example 8 with NodeVisitor

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

the class RecordValidationReportGenerator method extractCardinalityValidationResultItems.

protected List<RecordValidationReportItem> extractCardinalityValidationResultItems(final Locale locale, final ValidationResultFlag level, final boolean includeConfirmedErrors) {
    final List<RecordValidationReportItem> result = new ArrayList<RecordValidationReportItem>();
    Entity rootEntity = record.getRootEntity();
    rootEntity.traverse(new NodeVisitor() {

        @Override
        public void visit(Node<? extends NodeDefinition> node, int idx) {
            if (node instanceof Entity) {
                Entity entity = (Entity) node;
                List<RecordValidationReportItem> items = extractCardinalityValidationItems(locale, entity, level, includeConfirmedErrors);
                result.addAll(items);
            }
        }
    });
    return result;
}
Also used : Entity(org.openforis.idm.model.Entity) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) NodeVisitor(org.openforis.idm.model.NodeVisitor)

Aggregations

NodeVisitor (org.openforis.idm.model.NodeVisitor)8 Entity (org.openforis.idm.model.Entity)6 ArrayList (java.util.ArrayList)5 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)3 Attribute (org.openforis.idm.model.Attribute)3 List (java.util.List)2 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)2 BooleanAttribute (org.openforis.idm.model.BooleanAttribute)2 CodeAttribute (org.openforis.idm.model.CodeAttribute)2 NumberAttribute (org.openforis.idm.model.NumberAttribute)2 NumericRangeAttribute (org.openforis.idm.model.NumericRangeAttribute)2 IOException (java.io.IOException)1 Arrays.asList (java.util.Arrays.asList)1 Collections.emptyList (java.util.Collections.emptyList)1 ParseException (org.apache.lucene.queryParser.ParseException)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)1 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)1 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1 ModelVersion (org.openforis.idm.metamodel.ModelVersion)1