Search in sources :

Example 11 with NodeDefinition

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

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

the class Entity method move.

public void move(String name, int oldIndex, int newIndex) {
    NodeDefinition childDef = definition.getChildDefinition(name);
    move(childDef, oldIndex, newIndex);
}
Also used : NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Example 13 with NodeDefinition

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

the class Entity method write.

@Override
protected void write(StringWriter sw, int indent) {
    for (int i = 0; i < indent; i++) {
        sw.append('\t');
    }
    if (indent == 0) {
        sw.append(getPath());
    } else {
        sw.append(getName());
        if (this.getDefinition().isMultiple()) {
            sw.append("[");
            sw.append(String.valueOf(getIndex() + 1));
            sw.append("]");
        }
    }
    sw.append(":\n");
    List<NodeDefinition> definitions = getDefinition().getChildDefinitions();
    for (NodeDefinition defn : definitions) {
        List<Node<?>> children = childrenByDefinition.get(defn);
        if (children != null) {
            for (Node<?> child : children) {
                child.write(sw, indent + 1);
                sw.append("\n");
            }
        }
    }
}
Also used : NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Example 14 with NodeDefinition

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

the class Entity method getSortedChildren.

/**
 * Returns a list of children with the same sorting as the children node definitions
 * @return List of children
 */
public List<Node<? extends NodeDefinition>> getSortedChildren() {
    List<Node<?>> result = new ArrayList<Node<?>>();
    List<NodeDefinition> childDefinitions = getDefinition().getChildDefinitions();
    for (NodeDefinition childDefn : childDefinitions) {
        List<Node<?>> tempChildren = childrenByDefinition.get(childDefn);
        if (tempChildren != null) {
            result.addAll(tempChildren);
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Example 15 with NodeDefinition

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

the class EntityBuilder method createNode.

private static <T extends Node<D>, D extends NodeDefinition> T createNode(Entity entity, String name, Class<T> type, Class<D> definitionType) {
    try {
        EntityDefinition entityDefn = entity.getDefinition();
        NodeDefinition definition = entityDefn.getChildDefinition(name, definitionType);
        Constructor<T> constructor = type.getConstructor(definitionType);
        return constructor.newInstance(definition);
    } catch (SecurityException e) {
        throw new RuntimeException(e);
    } catch (InstantiationException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        } else {
            throw new RuntimeException(e);
        }
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) InvocationTargetException(java.lang.reflect.InvocationTargetException)

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