Search in sources :

Example 1 with SchemaPathExpression

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);
                }
            }
        }
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) SchemaPathExpression(org.openforis.idm.metamodel.expression.SchemaPathExpression) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) InvalidExpressionException(org.openforis.idm.model.expression.InvalidExpressionException)

Example 2 with SchemaPathExpression

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);
        }
    }
}
Also used : SchemaPathExpression(org.openforis.idm.metamodel.expression.SchemaPathExpression) InvalidExpressionException(org.openforis.idm.model.expression.InvalidExpressionException)

Example 3 with SchemaPathExpression

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());
}
Also used : SchemaPathExpression(org.openforis.idm.metamodel.expression.SchemaPathExpression) AbstractTest(org.openforis.idm.AbstractTest) Test(org.junit.Test)

Aggregations

SchemaPathExpression (org.openforis.idm.metamodel.expression.SchemaPathExpression)3 InvalidExpressionException (org.openforis.idm.model.expression.InvalidExpressionException)2 Test (org.junit.Test)1 AbstractTest (org.openforis.idm.AbstractTest)1 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)1