Search in sources :

Example 31 with EntityDefinition

use of org.openforis.idm.metamodel.EntityDefinition 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);
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 32 with EntityDefinition

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

the class EntityBuilder method createEntity.

public static Entity createEntity(Entity parentEntity, String name) {
    EntityDefinition parentDefn = parentEntity.getDefinition();
    EntityDefinition defn = parentDefn.getChildDefinition(name, EntityDefinition.class);
    Entity entity = (Entity) defn.createNode();
    return entity;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition)

Example 33 with EntityDefinition

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

the class EntityDefinitionPR method onStartDefinition.

@Override
protected void onStartDefinition() throws XmlParseException, XmlPullParserException, IOException {
    super.onStartDefinition();
    EntityDefinition def = (EntityDefinition) getDefinition();
    boolean virtual = getBooleanAttributeWithDefault(VIRTUAL, false);
    def.setVirtual(virtual);
    if (virtual) {
        String generatorExpression = getAttribute(GENERATOR_EXPRESSION, true);
        def.setGeneratorExpression(generatorExpression);
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition)

Example 34 with EntityDefinition

use of org.openforis.idm.metamodel.EntityDefinition 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();
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) ArrayList(java.util.ArrayList)

Example 35 with EntityDefinition

use of org.openforis.idm.metamodel.EntityDefinition 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);
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Aggregations

EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)235 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)70 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)47 Schema (org.openforis.idm.metamodel.Schema)46 ArrayList (java.util.ArrayList)44 Test (org.junit.Test)38 Entity (org.openforis.idm.model.Entity)36 CollectRecord (org.openforis.collect.model.CollectRecord)30 CollectSurvey (org.openforis.collect.model.CollectSurvey)28 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)24 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)24 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)19 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)18 UITab (org.openforis.collect.metamodel.ui.UITab)16 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)14 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)13 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)12 RecordFilter (org.openforis.collect.model.RecordFilter)11 SurveyObject (org.openforis.idm.metamodel.SurveyObject)10 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)9