Search in sources :

Example 46 with NodeDefinition

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

the class MetaModelExpressionTest method testParentExpression.

@Test
public void testParentExpression() {
    Schema schema = survey.getSchema();
    EntityDefinition clusterDefn = schema.getRootEntityDefinition("cluster");
    EntityDefinition plotDefn = (EntityDefinition) clusterDefn.getChildDefinition("plot");
    NodeDefinition plotNoDefn = plotDefn.getChildDefinition("no");
    SchemaPathExpression expression = new SchemaPathExpression("parent()");
    NodeDefinition resultDefn = expression.evaluate(plotDefn, plotNoDefn);
    Assert.assertEquals(clusterDefn, resultDefn);
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Schema(org.openforis.idm.metamodel.Schema) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) AbstractTest(org.openforis.idm.AbstractTest) Test(org.junit.Test)

Example 47 with NodeDefinition

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

the class AbstractExpression method getReferencedNodeDefinition.

private NodeDefinition getReferencedNodeDefinition(NodeDefinition context, NodeDefinition thisNodeDef, String path) throws InvalidExpressionException {
    StringTokenizer tokenizer = new StringTokenizer(path, String.valueOf(Path.SEPARATOR));
    NodeDefinition currentContext = context;
    while (tokenizer.hasMoreTokens()) {
        String pathSection = tokenizer.nextToken();
        if (currentContext instanceof AttributeDefinition && pathSection.startsWith("@")) {
            if (tokenizer.hasMoreTokens()) {
                String message = String.format("cannot have nested levels inside %s", currentContext.getPath());
                throw new InvalidExpressionException(message, compiledExpression.toString());
            }
            checkPropertyExists((AttributeDefinition) currentContext, pathSection);
            return currentContext;
        } else {
            currentContext = getChildDefinition(currentContext, thisNodeDef, pathSection);
        }
    }
    return currentContext;
}
Also used : StringTokenizer(java.util.StringTokenizer) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition)

Example 48 with NodeDefinition

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

the class Path method pathOf.

public static Path pathOf(NodeDefinition defn) {
    NodeDefinition parent = defn.getParentDefinition();
    String name = defn.getName();
    PathElement elem = new PathElement(name);
    if (parent == null) {
        return new Path(elem, true);
    } else {
        Path parentPath = Path.pathOf(parent);
        return parentPath.append(elem);
    }
}
Also used : NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Example 49 with NodeDefinition

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

the class UIOptionsTest method testTabSetAssociation.

@Test
public void testTabSetAssociation() throws InvalidPathException {
    UITabSet clusterTabSet = uiOptions.getTabSet("cluster");
    assertNotNull(clusterTabSet);
    assertEquals("cluster", clusterTabSet.getName());
    EntityDefinition cluster = schema.getRootEntityDefinition("cluster");
    clusterTabSet = uiOptions.getAssignedRootTabSet(cluster);
    assertEquals("cluster", clusterTabSet.getName());
    EntityDefinition plot = (EntityDefinition) cluster.getChildDefinition("plot");
    UITab assignedTab = uiOptions.getAssignedTab(plot);
    assertEquals("plot", assignedTab.getName());
    NodeDefinition tree = plot.getChildDefinition("tree");
    assignedTab = uiOptions.getAssignedTab(tree);
    assertEquals("tree", assignedTab.getName());
    UITabSet assignedToParentTabSet = uiOptions.getAssignedTabSet(plot);
    assertEquals("plot", assignedToParentTabSet.getName());
    assignedToParentTabSet = uiOptions.getAssignedTabSet(cluster);
    assertEquals("cluster", assignedToParentTabSet.getName());
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) Test(org.junit.Test)

Example 50 with NodeDefinition

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

the class SchemaVM method getSelectedNodeParentTab.

private UITab getSelectedNodeParentTab() {
    UITab parentTab;
    SurveyObject selectedSurveyObject = selectedTreeNode.getSurveyObject();
    if (selectedSurveyObject instanceof UITab) {
        parentTab = (UITab) selectedSurveyObject;
    } else {
        UIOptions uiOptions = survey.getUIOptions();
        parentTab = uiOptions.getAssignedTab((NodeDefinition) selectedSurveyObject);
    }
    return parentTab;
}
Also used : UITab(org.openforis.collect.metamodel.ui.UITab) SurveyObject(org.openforis.idm.metamodel.SurveyObject) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

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