use of org.openforis.idm.metamodel.expression.SchemaPathExpression 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);
}
}
}
}
}
use of org.openforis.idm.metamodel.expression.SchemaPathExpression in project collect by openforis.
the class StateDependencyMap method registerDependencies.
/**
* Registers the dependencies related to an expression using the parent definition of the specified
* node definition as context
*
* @param dependentDef context node definition
* @param expression expression to evaluate
*/
void registerDependencies(NodeDefinition dependentDef, String expression) {
if (StringUtils.isBlank(expression)) {
return;
}
try {
EntityDefinition dependentParentDef = dependentDef.getParentEntityDefinition();
Set<String> sourcePaths = getReferencedPaths(expression);
for (String sourcePath : sourcePaths) {
String sourceAbsolutePath = toNodeDefinitionAbsolutePath(sourcePath);
SchemaPathExpression sourceExpression = new SchemaPathExpression(sourceAbsolutePath);
NodeDefinition sourceDef = sourceExpression.evaluate(dependentParentDef, dependentDef);
EntityDefinition commonAncestor = getCommonAncestor(dependentParentDef, sourceAbsolutePath);
registerDependent(commonAncestor, sourceDef, dependentDef);
registerSource(commonAncestor, sourceDef, dependentDef);
}
} catch (Exception e) {
if (LOG.isErrorEnabled()) {
LOG.error("Unable to register dependencies for node " + dependentDef.getPath() + " with expression " + expression, e);
}
}
}
use of org.openforis.idm.metamodel.expression.SchemaPathExpression in project collect by openforis.
the class SchemaExpressionTest method testExpression.
@Test
public void testExpression() {
EntityDefinition cluster = survey.getSchema().getFirstRootEntityDefinition();
NodeDefinition plot = cluster.getChildDefinition("plot");
SchemaPathExpression expression = new SchemaPathExpression("plot/tree");
Object obj = expression.evaluate(cluster, plot);
assertEquals(EntityDefinition.class, obj.getClass());
EntityDefinition tree = (EntityDefinition) obj;
assertEquals("tree", tree.getName());
}
Aggregations