use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.
the class MinCountDependencyGraph method determineDependents.
@Override
protected Set<NodePathPointer> determineDependents(NodePointer source) throws InvalidExpressionException {
NodeDefinition def = source.getChildDefinition();
Survey survey = def.getSurvey();
Set<NodePathPointer> minCountDependencies = survey.getMinCountDependencies(def);
return filterByVersion(minCountDependencies, source.getModelVersion());
}
use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.
the class NodePointerDependencyGraph method toItems.
@Override
protected Collection<NodePointer> toItems(Node<?> node) {
if (node instanceof Entity) {
EntityDefinition def = (EntityDefinition) node.getDefinition();
List<NodeDefinition> defs = def.getChildDefinitionsInVersion(node.getModelVersion());
List<NodePointer> result = new ArrayList<NodePointer>(defs.size());
for (NodeDefinition childDef : defs) {
result.add(new NodePointer((Entity) node, childDef));
}
return result;
} else if (node.getParent() != null) {
return Collections.singleton(new NodePointer(node));
} else {
return Collections.emptySet();
}
}
use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.
the class EntitySchema method writeTo.
@Override
public void writeTo(Output out, Entity entity) throws IOException {
List<Node<? extends NodeDefinition>> children = entity.getChildren();
for (Node<?> node : children) {
if (isNodeToBeSaved(node)) {
out.writeUInt32(DEFINITION_ID_FIELD_NUMBER, node.getDefinition().getId(), false);
out.writeObject(NODE_FIELD_NUMBER, node, getSchema(node.getClass()), false);
}
}
EntityDefinition definition = entity.getDefinition();
List<NodeDefinition> childDefinitions = definition.getChildDefinitions();
for (NodeDefinition childDefinition : childDefinitions) {
State childState = entity.getChildState(childDefinition);
out.writeInt32(CHILD_NODE_STATE_FIELD_NUMBER, childState.intValue(), false);
out.writeInt32(CHILD_DEFINITION_ID_FIELD_NUMBER, childDefinition.getId(), false);
}
}
use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.
the class MaxCountDependencyGraph method determineDependents.
@Override
protected Set<NodePathPointer> determineDependents(NodePointer source) throws InvalidExpressionException {
NodeDefinition def = source.getChildDefinition();
Survey survey = def.getSurvey();
Set<NodePathPointer> dependentPointers = survey.getMaxCountDependencies(def);
return filterByVersion(dependentPointers, source.getModelVersion());
}
use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.
the class StateDependencyMap method registerDependencies.
private void registerDependencies(NodeDefinition nodeDefinition, String expression, Map<Integer, Map<String, String>> dependencies) {
if (StringUtils.isNotBlank(expression)) {
List<String> referencedPaths = getReferencedPaths(expression);
for (String path : referencedPaths) {
try {
String normalizedPath = getNormalizedPath(path);
SchemaPathExpression schemaExpression = new SchemaPathExpression(normalizedPath);
EntityDefinition parentDefinition = nodeDefinition.getParentDefinition();
NodeDefinition dependantNode = schemaExpression.evaluate(parentDefinition);
String sourcePath = dependantNode.getPath();
String destinationPath = nodeDefinition.getPath();
String relativePath = getRelativePath(sourcePath, destinationPath);
Integer surveyId = nodeDefinition.getSurvey().getId();
Map<String, String> dependenciesMap = getDependenciesMap(dependencies, surveyId);
dependenciesMap.put(sourcePath, relativePath);
} catch (Exception e) {
if (LOG.isErrorEnabled()) {
LOG.error("Unable to register dependency for node " + nodeDefinition.getPath() + " with expression " + path, e);
}
}
}
}
}
Aggregations