use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.
the class UIOptionsMigratorTest method testMigration.
@Test
public void testMigration() {
UIOptionsMigrator migrator = new UIOptionsMigrator();
UIConfiguration uiModel = migrator.migrateToUIConfiguration(uiOptions);
assertNotNull(uiModel);
Schema schema = survey.getSchema();
{
EntityDefinition cluster = schema.getRootEntityDefinition("cluster");
UIFormSet formSet = uiModel.getFormSetByRootEntityId(cluster.getId());
List<UIForm> forms = formSet.getForms();
assertEquals(3, forms.size());
// cluster form
{
UIForm form = forms.get(0);
List<UIFormComponent> children = form.getChildren();
assertEquals(16, children.size());
{
// task
UIFormComponent component = children.get(0);
assertTrue(component instanceof UITable);
UITable taskTable = (UITable) component;
assertNotNull(taskTable.getEntityDefinition());
assertEquals("task", taskTable.getEntityDefinition().getName());
// task/task
assertEquals(3, taskTable.getHeadingComponents().size());
UITableHeadingComponent heading = taskTable.getHeadingComponents().get(0);
assertTrue(heading instanceof UIColumn);
UIColumn col = (UIColumn) heading;
assertEquals(Integer.valueOf(729), col.getAttributeDefinitionId());
}
}
// plot form
{
UIForm plotForm = forms.get(1);
List<UIFormComponent> plotFormChildren = plotForm.getChildren();
assertEquals(1, plotFormChildren.size());
UIFormComponent plotMultipleEntityComponent = plotFormChildren.get(0);
assertTrue(plotMultipleEntityComponent instanceof UIFormSection);
UIFormSection plotMultipleEntityFormSection = (UIFormSection) plotMultipleEntityComponent;
List<UIForm> subforms = plotMultipleEntityFormSection.getForms();
assertEquals(6, subforms.size());
UIForm detailForm = subforms.get(0);
List<UIFormComponent> children = detailForm.getChildren();
assertEquals(34, children.size());
{
// plot_no
{
UIFormComponent component = children.get(0);
assertTrue(component instanceof UIField);
UIField plotNoField = (UIField) component;
assertEquals(Integer.valueOf(749), plotNoField.getAttributeDefinitionId());
}
// time study (single entity -> form section)
{
UIFormComponent component = children.get(2);
assertTrue(component instanceof UIFormSection);
UIFormSection section = (UIFormSection) component;
assertEquals(3, section.getChildren().size());
// start time
UIFormComponent startTimeComp = section.getChildren().get(1);
assertTrue(startTimeComp instanceof UIField);
UIField startTimeField = (UIField) startTimeComp;
assertEquals(Integer.valueOf(753), startTimeField.getAttributeDefinitionId());
}
}
}
}
}
use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.
the class CollectRecordIntegrationTest method createMultipleLevelCodeListTestSurvey.
private CollectSurvey createMultipleLevelCodeListTestSurvey() {
CollectSurvey survey = surveyManager.createTemporarySurvey("test", "en");
CodeList codeList = survey.createCodeList();
{
CodeListLevel codeListLevel = new CodeListLevel();
codeListLevel.setName("level1");
codeList.addLevel(codeListLevel);
}
{
CodeListLevel codeListLevel = new CodeListLevel();
codeListLevel.setName("level2");
codeList.addLevel(codeListLevel);
}
{
CodeListLevel codeListLevel = new CodeListLevel();
codeListLevel.setName("level3");
codeList.addLevel(codeListLevel);
}
{
CodeListItem item = codeList.createItem(1);
item.setCode("A");
codeList.addItem(item);
{
CodeListItem child = codeList.createItem(2);
child.setCode("1");
item.addChildItem(child);
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("a");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("b");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("c");
child.addChildItem(child2);
}
}
{
CodeListItem child = codeList.createItem(2);
child.setCode("2");
item.addChildItem(child);
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("a");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("b");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("c");
child.addChildItem(child2);
}
}
{
CodeListItem child = codeList.createItem(2);
child.setCode("3");
item.addChildItem(child);
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("a");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("b");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("c");
child.addChildItem(child2);
}
}
}
{
CodeListItem item = codeList.createItem(1);
item.setCode("B");
codeList.addItem(item);
{
CodeListItem child = codeList.createItem(2);
child.setCode("1");
item.addChildItem(child);
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("a");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("b");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("c");
child.addChildItem(child2);
}
}
{
CodeListItem child = codeList.createItem(2);
child.setCode("2");
item.addChildItem(child);
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("a");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("b");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("c");
child.addChildItem(child2);
}
}
{
CodeListItem child = codeList.createItem(2);
child.setCode("3");
item.addChildItem(child);
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("a");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("b");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("c");
child.addChildItem(child2);
}
}
}
survey.addCodeList(codeList);
Schema schema = survey.getSchema();
EntityDefinition root = schema.createEntityDefinition();
root.setName("root");
schema.addRootEntityDefinition(root);
{
CodeAttributeDefinition codeAttrDefn = schema.createCodeAttributeDefinition();
codeAttrDefn.setList(codeList);
codeAttrDefn.setName("code1");
root.addChildDefinition(codeAttrDefn);
}
{
CodeAttributeDefinition codeAttrDefn = schema.createCodeAttributeDefinition();
codeAttrDefn.setList(codeList);
codeAttrDefn.setName("code2");
codeAttrDefn.setParentExpression("code1");
root.addChildDefinition(codeAttrDefn);
}
{
CodeAttributeDefinition codeAttrDefn = schema.createCodeAttributeDefinition();
codeAttrDefn.setList(codeList);
codeAttrDefn.setName("code3");
codeAttrDefn.setParentExpression("code2");
root.addChildDefinition(codeAttrDefn);
}
survey.init();
return survey;
}
use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.
the class ModelDaoIntegrationTest method testLoadRecordSummaries.
// @Test
public void testLoadRecordSummaries() {
// get the first root entity
EntityDefinition rootEntity = survey.getSchema().getFirstRootEntityDefinition();
String rootEntityName = rootEntity.getName();
int offset = 0;
int maxNumberOfRecords = 1;
RecordSummarySortField sortField = new RecordSummarySortField(Sortable.KEY1);
RecordFilter filter = new RecordFilter(survey);
filter.setRootEntityId(survey.getSchema().getRootEntityDefinition(rootEntityName).getId());
filter.setOffset(offset);
filter.setMaxNumberOfRecords(maxNumberOfRecords);
List<CollectRecordSummary> list = this.recordDao.loadSummaries(filter, Arrays.asList(sortField));
assertNotNull(list);
assertEquals(1, list.size());
CollectRecordSummary summary = list.get(0);
assertEquals(Step.ENTRY, summary.getStep());
}
use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.
the class EntityKeyValidator method evaluate.
@Override
public ValidationResultFlag evaluate(Attribute<?, ?> keyAttribute) {
Entity multipleEntity = keyAttribute.getNearestMultipleEntityAncestor();
EntityDefinition multipleEntityDef = multipleEntity.getDefinition();
if (multipleEntityDef.isRoot()) {
return ValidationResultFlag.OK;
}
Value[] keyValues = multipleEntity.getKeyAttributeValues();
if (keyValues == null) {
return null;
}
List<Entity> entities = multipleEntity.getParent().findChildEntitiesByKeys(multipleEntityDef, keyValues);
if (entities.size() > 1) {
return ValidationResultFlag.ERROR;
} else {
return ValidationResultFlag.OK;
}
}
use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.
the class Validator method getChildDefinition.
private NodeDefinition getChildDefinition(Entity entity, String childName) {
EntityDefinition entityDefn = entity.getDefinition();
NodeDefinition childDefn = entityDefn.getChildDefinition(childName);
return childDefn;
}
Aggregations