XMLEcrfDatamodelToEcrfFields { @NotNull public static List<EcrfDatamodelField> convert(@NotNull final XMLEcrfDatamodel datamodel) { List<EcrfDatamodelField> fields = Lists.newArrayList(); for (StudyEvent studyEvent : datamodel.studyEvents().values()) { for (String formOID : studyEvent.formOIDs()) { Form form = findByOID(datamodel.forms().values(), formOID); for (String itemGroupOID : form.itemGroupOIDs()) { ItemGroup itemGroup = findByOID(datamodel.itemGroups().values(), itemGroupOID); for (String itemOID : itemGroup.itemOIDs()) { Item item = findByOID(datamodel.items().values(), itemOID); Map<Integer, String> codeList = Maps.newHashMap(); String codeListOID = item.codeListOID(); if (codeListOID != null) { codeList = findByOID(datamodel.codeLists().values(), codeListOID).values(); } EcrfDatamodelField field = new ImmutableEcrfDatamodelField(studyEvent.oid(), form.oid(), itemGroup.oid(), item.oid(), item.name(), codeList); fields.add(field); } } } } return fields; } private  XMLEcrfDatamodelToEcrfFields(); @NotNull static List<EcrfDatamodelField> convert(@NotNull final XMLEcrfDatamodel datamodel);  }
@Test public void canConvertXMLObjectContainerToEcrfFields() { String studyOID = "SE.Study"; String formOID = "FRM.Form"; String itemGroupOID = "GRP.ItemGroup"; String itemOID = "GRP.Item"; String description = "bla"; String codeListOID = "list"; String option1 = "x"; String option2 = "y"; List<StudyEvent> studyEvents = Lists.newArrayList(new ImmutableStudyEvent(studyOID, description, Lists.newArrayList(formOID))); List<Form> forms = Lists.newArrayList(new ImmutableForm(formOID, description, Lists.newArrayList(itemGroupOID))); List<ItemGroup> itemGroups = Lists.newArrayList(new ImmutableItemGroup(itemGroupOID, description, Lists.newArrayList(itemOID))); List<Item> items = Lists.newArrayList(new ImmutableItem(itemOID, description, codeListOID)); Map<Integer, String> codeListItems = Maps.newHashMap(); codeListItems.put(1, option1); codeListItems.put(2, option2); List<CodeList> codeLists = Lists.newArrayList(new ImmutableCodeList(codeListOID, description, codeListItems)); XMLEcrfDatamodel datamodel = XMLEcrfDatamodel.of(studyEvents, forms, itemGroups, items, codeLists); List<EcrfDatamodelField> fields = XMLEcrfDatamodelToEcrfFields.convert(datamodel); assertEquals(1, fields.size()); EcrfDatamodelField field = fields.get(0); assertEquals("STUDY.FORM.ITEMGROUP.ITEM", field.name()); assertEquals(description, field.description()); Map<Integer, String> values = field.codeList(); assertEquals(option1, values.get(1)); assertEquals(option2, values.get(2)); }