@Test public void loadConvertsCodeFieldsWhenControllerIsOnlyCodeFields() throws Exception { List<String> list1 = new LinkedList<>(); list1.add("HP:00000015"); doReturn(list1).when(this.baseProperty1).getValue(); List<String> list2 = new LinkedList<>(); list2.add("HP:00000120"); doReturn(list2).when(this.baseProperty2).getValue(); PatientData<List<VocabularyProperty>> result = this.codeFieldImplMocker.getComponentUnderTest().load(this.patient); List<VocabularyProperty> propertyOneList = result.get(PROPERTY_1); List<VocabularyProperty> propertyTwoList = result.get(PROPERTY_2); Assert.assertNotNull(propertyOneList); Assert.assertNotNull(propertyTwoList); Assert.assertThat(propertyOneList, hasSize(1)); Assert.assertThat(propertyTwoList, hasSize(1)); Assert.assertThat(propertyOneList, contains(hasProperty("id", is("HP:00000015")))); Assert.assertThat(propertyTwoList, contains(hasProperty("id", is("HP:00000120")))); }
@Override @SuppressWarnings("unchecked") public PatientData<T> load(Patient patient) { try { XWikiDocument doc = patient.getXDocument(); BaseObject data = doc.getXObject(getXClassReference()); if (data == null) { return null; } Map<String, T> result = new LinkedHashMap<>(); for (String propertyName : getProperties()) { BaseProperty<ObjectPropertyReference> field = (BaseProperty<ObjectPropertyReference>) data.getField(propertyName); if (field != null) { Object propertyValue = field.getValue(); if (getCodeFields().contains(propertyName) && isCodeFieldsOnly()) { List<VocabularyProperty> propertyValuesList = new LinkedList<>(); List<String> terms = (List<String>) propertyValue; for (String termId : terms) { propertyValuesList.add(new QuickVocabularyProperty(termId)); } propertyValue = propertyValuesList; } result.put(propertyName, (T) propertyValue); } } return new DictionaryPatientData<>(getName(), result); } catch (Exception e) { this.logger.error(ERROR_MESSAGE_LOAD_FAILED, e.getMessage()); } return null; }
AbstractComplexController implements PatientDataController<T> { @Override @SuppressWarnings("unchecked") public PatientData<T> load(Patient patient) { try { XWikiDocument doc = patient.getXDocument(); BaseObject data = doc.getXObject(getXClassReference()); if (data == null) { return null; } Map<String, T> result = new LinkedHashMap<>(); for (String propertyName : getProperties()) { BaseProperty<ObjectPropertyReference> field = (BaseProperty<ObjectPropertyReference>) data.getField(propertyName); if (field != null) { Object propertyValue = field.getValue(); if (getCodeFields().contains(propertyName) && isCodeFieldsOnly()) { List<VocabularyProperty> propertyValuesList = new LinkedList<>(); List<String> terms = (List<String>) propertyValue; for (String termId : terms) { propertyValuesList.add(new QuickVocabularyProperty(termId)); } propertyValue = propertyValuesList; } result.put(propertyName, (T) propertyValue); } } return new DictionaryPatientData<>(getName(), result); } catch (Exception e) { this.logger.error(ERROR_MESSAGE_LOAD_FAILED, e.getMessage()); } return null; } }
AbstractComplexController implements PatientDataController<T> { @Override @SuppressWarnings("unchecked") public PatientData<T> load(Patient patient) { try { XWikiDocument doc = patient.getXDocument(); BaseObject data = doc.getXObject(getXClassReference()); if (data == null) { return null; } Map<String, T> result = new LinkedHashMap<>(); for (String propertyName : getProperties()) { BaseProperty<ObjectPropertyReference> field = (BaseProperty<ObjectPropertyReference>) data.getField(propertyName); if (field != null) { Object propertyValue = field.getValue(); if (getCodeFields().contains(propertyName) && isCodeFieldsOnly()) { List<VocabularyProperty> propertyValuesList = new LinkedList<>(); List<String> terms = (List<String>) propertyValue; for (String termId : terms) { propertyValuesList.add(new QuickVocabularyProperty(termId)); } propertyValue = propertyValuesList; } result.put(propertyName, (T) propertyValue); } } return new DictionaryPatientData<>(getName(), result); } catch (Exception e) { this.logger.error(ERROR_MESSAGE_LOAD_FAILED, e.getMessage()); } return null; }  }
AbstractComplexController implements PatientDataController<T> { @Override @SuppressWarnings("unchecked") public PatientData<T> load(Patient patient) { try { XWikiDocument doc = patient.getXDocument(); BaseObject data = doc.getXObject(getXClassReference()); if (data == null) { return null; } Map<String, T> result = new LinkedHashMap<>(); for (String propertyName : getProperties()) { BaseProperty<ObjectPropertyReference> field = (BaseProperty<ObjectPropertyReference>) data.getField(propertyName); if (field != null) { Object propertyValue = field.getValue(); if (getCodeFields().contains(propertyName) && isCodeFieldsOnly()) { List<VocabularyProperty> propertyValuesList = new LinkedList<>(); List<String> terms = (List<String>) propertyValue; for (String termId : terms) { propertyValuesList.add(new QuickVocabularyProperty(termId)); } propertyValue = propertyValuesList; } result.put(propertyName, (T) propertyValue); } } return new DictionaryPatientData<>(getName(), result); } catch (Exception e) { this.logger.error(ERROR_MESSAGE_LOAD_FAILED, e.getMessage()); } return null; }  @Override @SuppressWarnings("unchecked") PatientData<T> load(Patient patient); @Override void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames); @Override void writeJSON(Patient patient, JSONObject json); @Override void save(Patient patient); @Override void save(@Nonnull final Patient patient, @Nonnull final PatientWritePolicy policy); @Override PatientData<T> readJSON(JSONObject json); }
AbstractComplexController implements PatientDataController<T> { @Override @SuppressWarnings("unchecked") public PatientData<T> load(Patient patient) { try { XWikiDocument doc = patient.getXDocument(); BaseObject data = doc.getXObject(getXClassReference()); if (data == null) { return null; } Map<String, T> result = new LinkedHashMap<>(); for (String propertyName : getProperties()) { BaseProperty<ObjectPropertyReference> field = (BaseProperty<ObjectPropertyReference>) data.getField(propertyName); if (field != null) { Object propertyValue = field.getValue(); if (getCodeFields().contains(propertyName) && isCodeFieldsOnly()) { List<VocabularyProperty> propertyValuesList = new LinkedList<>(); List<String> terms = (List<String>) propertyValue; for (String termId : terms) { propertyValuesList.add(new QuickVocabularyProperty(termId)); } propertyValue = propertyValuesList; } result.put(propertyName, (T) propertyValue); } } return new DictionaryPatientData<>(getName(), result); } catch (Exception e) { this.logger.error(ERROR_MESSAGE_LOAD_FAILED, e.getMessage()); } return null; }  @Override @SuppressWarnings("unchecked") PatientData<T> load(Patient patient); @Override void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames); @Override void writeJSON(Patient patient, JSONObject json); @Override void save(Patient patient); @Override void save(@Nonnull final Patient patient, @Nonnull final PatientWritePolicy policy); @Override PatientData<T> readJSON(JSONObject json);  }