Search in sources :

Example 66 with EntityDefinition

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());
                }
            }
        }
    }
}
Also used : Schema(org.openforis.idm.metamodel.Schema) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) List(java.util.List) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 67 with EntityDefinition

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;
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CodeListLevel(org.openforis.idm.metamodel.CodeListLevel) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) Schema(org.openforis.idm.metamodel.Schema) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 68 with EntityDefinition

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());
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) RecordSummarySortField(org.openforis.collect.model.RecordSummarySortField) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) RecordFilter(org.openforis.collect.model.RecordFilter)

Example 69 with EntityDefinition

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;
    }
}
Also used : Entity(org.openforis.idm.model.Entity) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Value(org.openforis.idm.model.Value)

Example 70 with EntityDefinition

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;
}
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