@Test public void writeJSONWithAllSelectedFieldsAddsContainerWithAllValues() throws ComponentLookupException { String datum1 = "datum1"; String datum2 = "datum2"; Map<String, String> map = new LinkedHashMap<>(); map.put(PROPERTY_1, datum1); map.put(PROPERTY_2, datum2); PatientData<String> patientData = new DictionaryPatientData<>(DATA_NAME, map); doReturn(patientData).when(this.patient).getData(DATA_NAME); JSONObject json = new JSONObject(); Collection<String> selectedFields = new LinkedList<>(); selectedFields.add(PROPERTY_1); selectedFields.add(PROPERTY_2); this.component.writeJSON(this.patient, json, selectedFields); Assert.assertNotNull(json.get(DATA_NAME)); Assert.assertTrue(json.get(DATA_NAME) instanceof JSONObject); JSONObject container = json.getJSONObject(DATA_NAME); Assert.assertEquals(datum1, container.get(PROPERTY_1)); Assert.assertEquals(datum2, container.get(PROPERTY_2)); }
@Override public void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames) { PatientData<T> data = patient.getData(getName()); String jsonPropertyName = getJsonPropertyName(); if (data == null || data.size() == 0) { return; } Iterator<Map.Entry<String, T>> iterator = data.dictionaryIterator(); JSONObject container = json.optJSONObject(jsonPropertyName); while (iterator.hasNext()) { Map.Entry<String, T> item = iterator.next(); String itemKey = item.getKey(); Object formattedValue = format(itemKey, item.getValue()); if (selectedFieldNames == null || selectedFieldNames.contains(getControllingFieldName(item.getKey()))) { if (container == null) { json.put(jsonPropertyName, new JSONObject()); container = json.optJSONObject(jsonPropertyName); } container.put(itemKey, formattedValue); } } }
AbstractComplexController implements PatientDataController<T> { @Override public void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames) { PatientData<T> data = patient.getData(getName()); String jsonPropertyName = getJsonPropertyName(); if (data == null || data.size() == 0) { return; } Iterator<Map.Entry<String, T>> iterator = data.dictionaryIterator(); JSONObject container = json.optJSONObject(jsonPropertyName); while (iterator.hasNext()) { Map.Entry<String, T> item = iterator.next(); String itemKey = item.getKey(); Object formattedValue = format(itemKey, item.getValue()); if (selectedFieldNames == null || selectedFieldNames.contains(getControllingFieldName(item.getKey()))) { if (container == null) { json.put(jsonPropertyName, new JSONObject()); container = json.optJSONObject(jsonPropertyName); } container.put(itemKey, formattedValue); } } } }
AbstractComplexController implements PatientDataController<T> { @Override public void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames) { PatientData<T> data = patient.getData(getName()); String jsonPropertyName = getJsonPropertyName(); if (data == null || data.size() == 0) { return; } Iterator<Map.Entry<String, T>> iterator = data.dictionaryIterator(); JSONObject container = json.optJSONObject(jsonPropertyName); while (iterator.hasNext()) { Map.Entry<String, T> item = iterator.next(); String itemKey = item.getKey(); Object formattedValue = format(itemKey, item.getValue()); if (selectedFieldNames == null || selectedFieldNames.contains(getControllingFieldName(item.getKey()))) { if (container == null) { json.put(jsonPropertyName, new JSONObject()); container = json.optJSONObject(jsonPropertyName); } container.put(itemKey, formattedValue); } } }  }
AbstractComplexController implements PatientDataController<T> { @Override public void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames) { PatientData<T> data = patient.getData(getName()); String jsonPropertyName = getJsonPropertyName(); if (data == null || data.size() == 0) { return; } Iterator<Map.Entry<String, T>> iterator = data.dictionaryIterator(); JSONObject container = json.optJSONObject(jsonPropertyName); while (iterator.hasNext()) { Map.Entry<String, T> item = iterator.next(); String itemKey = item.getKey(); Object formattedValue = format(itemKey, item.getValue()); if (selectedFieldNames == null || selectedFieldNames.contains(getControllingFieldName(item.getKey()))) { if (container == null) { json.put(jsonPropertyName, new JSONObject()); container = json.optJSONObject(jsonPropertyName); } container.put(itemKey, formattedValue); } } }  @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 public void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames) { PatientData<T> data = patient.getData(getName()); String jsonPropertyName = getJsonPropertyName(); if (data == null || data.size() == 0) { return; } Iterator<Map.Entry<String, T>> iterator = data.dictionaryIterator(); JSONObject container = json.optJSONObject(jsonPropertyName); while (iterator.hasNext()) { Map.Entry<String, T> item = iterator.next(); String itemKey = item.getKey(); Object formattedValue = format(itemKey, item.getValue()); if (selectedFieldNames == null || selectedFieldNames.contains(getControllingFieldName(item.getKey()))) { if (container == null) { json.put(jsonPropertyName, new JSONObject()); container = json.optJSONObject(jsonPropertyName); } container.put(itemKey, formattedValue); } } }  @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);  }