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;
}
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;
}
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));
}
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()));
}
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()));
}
Aggregations