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;
}
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);
}
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");
}
}
}
}
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;
}
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);
}
}
Aggregations