Search in sources :

Example 41 with EntityDefinition

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

the class NodeBuilder method createEntity.

private Entity createEntity(Entity parent) {
    EntityDefinition def = (EntityDefinition) parent.getDefinition().getChildDefinition(name);
    Entity entity = createDetachedEntity(def);
    return entity;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Entity(org.openforis.idm.model.Entity)

Example 42 with EntityDefinition

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

the class SurveyBuilder method survey.

public static Survey survey(NodeDefinitionBuilder... builders) {
    String rootEntityName = "root";
    Survey survey = new TestSurveyContext().createSurvey();
    EntityDefinitionBuilder entityBuilder = new EntityDefinitionBuilder(rootEntityName, builders);
    EntityDefinition rootEntityDef = (EntityDefinition) entityBuilder.buildInternal(survey);
    Schema schema = survey.getSchema();
    if (schema.getRootEntityDefinition(rootEntityName) != null) {
        schema.removeRootEntityDefinition(rootEntityName);
    }
    schema.addRootEntityDefinition(rootEntityDef);
    survey.refreshSurveyDependencies();
    return survey;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Survey(org.openforis.idm.metamodel.Survey) EntityDefinitionBuilder(org.openforis.idm.testfixture.NodeDefinitionBuilder.EntityDefinitionBuilder) TestSurveyContext(org.openforis.idm.model.TestSurveyContext) Schema(org.openforis.idm.metamodel.Schema)

Example 43 with EntityDefinition

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

the class TestFixture method survey.

public static TestFixture survey(NodeDefinitionBuilder.EntityDefinitionBuilder entityDefinitionBuilder, RecordBuilder... recordBuilders) {
    SurveyContext surveyContext = new TestSurveyContext();
    Survey survey = surveyContext.createSurvey();
    EntityDefinition rootEntityDef = (EntityDefinition) entityDefinitionBuilder.buildInternal(survey);
    survey.getSchema().addRootEntityDefinition(rootEntityDef);
    survey.refreshSurveyDependencies();
    List<Record> records = new ArrayList<Record>();
    for (RecordBuilder recordBuilder : recordBuilders) {
        Record record = recordBuilder.build(survey);
        records.add(record);
    }
    return new TestFixture(survey, Collections.unmodifiableList(records));
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Survey(org.openforis.idm.metamodel.Survey) TestSurveyContext(org.openforis.idm.model.TestSurveyContext) ArrayList(java.util.ArrayList) Record(org.openforis.idm.model.Record) SurveyContext(org.openforis.idm.metamodel.SurveyContext) TestSurveyContext(org.openforis.idm.model.TestSurveyContext)

Example 44 with EntityDefinition

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

the class ProtostuffSerializationTest method testSkipRemovedAttribute.

@Test
public void testSkipRemovedAttribute() throws Exception {
    // Set up
    Survey survey = getTestSurvey();
    // assignFakeNodeDefinitionIds(survey.getSchema());
    Record record1 = createTestRecord(survey);
    Entity cluster1 = record1.getRootEntity();
    // Write
    ModelSerializer ser = new ModelSerializer(10000);
    byte[] data = ser.toByteArray(cluster1);
    // remove attribute from record before comparing it with the new one
    cluster1.remove("crew_no", 0);
    // remove node definition from schema
    Schema schema = survey.getSchema();
    EntityDefinition clusterDefn = schema.getRootEntityDefinition("cluster");
    NodeDefinition crewNumDefn = clusterDefn.getChildDefinition("crew_no");
    clusterDefn.removeChildDefinition(crewNumDefn);
    Record record2 = new Record(survey, "2.0", "cluster");
    ser.mergeFrom(data, record2.getRootEntity());
    // Compare
    Assert.assertTrue(record1.getRootEntity().deepEquals(record2.getRootEntity()));
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Survey(org.openforis.idm.metamodel.Survey) Schema(org.openforis.idm.metamodel.Schema) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) Test(org.junit.Test)

Example 45 with EntityDefinition

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

the class ProtostuffSerializationTest method testSkipRemovedEntity.

@Test
public void testSkipRemovedEntity() throws Exception {
    // Set up
    Survey survey = getTestSurvey();
    // assignFakeNodeDefinitionIds(survey.getSchema());
    Record record1 = createTestRecord(survey);
    Entity cluster1 = record1.getRootEntity();
    // Write
    ModelSerializer ser = new ModelSerializer(10000);
    byte[] data = ser.toByteArray(cluster1);
    // remove data
    cluster1.remove("map_sheet", 1);
    cluster1.remove("map_sheet", 0);
    Schema schema = survey.getSchema();
    EntityDefinition clusterDefn = schema.getRootEntityDefinition("cluster");
    NodeDefinition mapSheetDefn = clusterDefn.getChildDefinition("map_sheet");
    clusterDefn.removeChildDefinition(mapSheetDefn);
    Record record2 = new Record(survey, "2.0", "cluster");
    ser.mergeFrom(data, record2.getRootEntity());
    // Compare
    Assert.assertTrue(record1.getRootEntity().deepEquals(record2.getRootEntity()));
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Survey(org.openforis.idm.metamodel.Survey) Schema(org.openforis.idm.metamodel.Schema) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) Test(org.junit.Test)

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