use of org.openforis.idm.metamodel.Survey in project collect by openforis.
the class MaxCountDependencyGraph method determineDependents.
@Override
protected Set<NodePathPointer> determineDependents(NodePointer source) throws InvalidExpressionException {
NodeDefinition def = source.getChildDefinition();
Survey survey = def.getSurvey();
Set<NodePathPointer> dependentPointers = survey.getMaxCountDependencies(def);
return filterByVersion(dependentPointers, source.getModelVersion());
}
use of org.openforis.idm.metamodel.Survey 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.Survey 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.Survey in project collect by openforis.
the class ProtostuffSerializationTest method testRoundTrip.
@Test
public void testRoundTrip() 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);
// Read
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.Survey 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()));
}
Aggregations