@Test public void readWorksCorrectly() throws ComponentLookupException { final JSONArray data = new JSONArray(); final JSONObject item = new JSONObject(); item.put(LABEL_KEY, "LABEL1"); item.put(VALUE_KEY, "value1"); data.put(item); final JSONObject item2 = new JSONObject(); item2.put(LABEL_KEY, "LABEL2"); item2.put(VALUE_KEY, "value2"); data.put(item2); final JSONObject item3 = new JSONObject(); item3.put(LABEL_KEY, ""); item3.put(VALUE_KEY, "value3"); data.put(item3); final JSONObject item4 = new JSONObject(); item4.put(LABEL_KEY, "LABEL4"); item4.put(VALUE_KEY, ""); data.put(item4); final JSONObject item5 = new JSONObject(); item5.put(LABEL_KEY, ""); item5.put(VALUE_KEY, ""); data.put(item5); final JSONObject json = new JSONObject(); json.put(CONTROLLER_NAME, data); final PatientData<Pair<String, String>> result = this.component.readJSON(json); Assert.assertNotNull(result); Assert.assertEquals(4, result.size()); Assert.assertTrue(result.isIndexed()); final Iterator<Pair<String, String>> it = result.iterator(); final Pair<String, String> identifier1 = it.next(); Assert.assertEquals("LABEL1", identifier1.getKey()); Assert.assertEquals("value1", identifier1.getValue()); final Pair<String, String> identifier2 = it.next(); Assert.assertEquals("LABEL2", identifier2.getKey()); Assert.assertEquals("value2", identifier2.getValue()); final Pair<String, String> identifier3 = it.next(); Assert.assertEquals(StringUtils.EMPTY, identifier3.getKey()); Assert.assertEquals("value3", identifier3.getValue()); final Pair<String, String> identifier4 = it.next(); Assert.assertEquals("LABEL4", identifier4.getKey()); Assert.assertEquals(StringUtils.EMPTY, identifier4.getValue()); }
@Override public PatientData<Pair<String, String>> readJSON(@Nullable final JSONObject json) { if (json == null || !json.has(IDENTIFIERS_STRING)) { return null; } List<Pair<String, String>> identifiers = toIdentifiers(json.optJSONArray(IDENTIFIERS_STRING)); if (identifiers == null || identifiers.isEmpty()) { return null; } return new IndexedPatientData<>(CONTROLLER_NAME, identifiers); }
LabeledExternalIdentifiersController implements PatientDataController<Pair<String, String>> { @Override public PatientData<Pair<String, String>> readJSON(@Nullable final JSONObject json) { if (json == null || !json.has(IDENTIFIERS_STRING)) { return null; } List<Pair<String, String>> identifiers = toIdentifiers(json.optJSONArray(IDENTIFIERS_STRING)); if (identifiers == null || identifiers.isEmpty()) { return null; } return new IndexedPatientData<>(CONTROLLER_NAME, identifiers); } }
LabeledExternalIdentifiersController implements PatientDataController<Pair<String, String>> { @Override public PatientData<Pair<String, String>> readJSON(@Nullable final JSONObject json) { if (json == null || !json.has(IDENTIFIERS_STRING)) { return null; } List<Pair<String, String>> identifiers = toIdentifiers(json.optJSONArray(IDENTIFIERS_STRING)); if (identifiers == null || identifiers.isEmpty()) { return null; } return new IndexedPatientData<>(CONTROLLER_NAME, identifiers); }  }
LabeledExternalIdentifiersController implements PatientDataController<Pair<String, String>> { @Override public PatientData<Pair<String, String>> readJSON(@Nullable final JSONObject json) { if (json == null || !json.has(IDENTIFIERS_STRING)) { return null; } List<Pair<String, String>> identifiers = toIdentifiers(json.optJSONArray(IDENTIFIERS_STRING)); if (identifiers == null || identifiers.isEmpty()) { return null; } return new IndexedPatientData<>(CONTROLLER_NAME, identifiers); }  @Override String getName(); @Override PatientData<Pair<String, String>> load(final Patient patient); @Override void writeJSON(@Nonnull final Patient patient, @Nonnull final JSONObject json,
        @Nullable final Collection<String> selectedFieldNames); @Override void writeJSON(@Nonnull final Patient patient, @Nonnull final JSONObject json); @Override PatientData<Pair<String, String>> readJSON(@Nullable final JSONObject json); @Override void save(@Nonnull final Patient patient); @Override void save(@Nonnull final Patient patient, @Nonnull final PatientWritePolicy policy); }
LabeledExternalIdentifiersController implements PatientDataController<Pair<String, String>> { @Override public PatientData<Pair<String, String>> readJSON(@Nullable final JSONObject json) { if (json == null || !json.has(IDENTIFIERS_STRING)) { return null; } List<Pair<String, String>> identifiers = toIdentifiers(json.optJSONArray(IDENTIFIERS_STRING)); if (identifiers == null || identifiers.isEmpty()) { return null; } return new IndexedPatientData<>(CONTROLLER_NAME, identifiers); }  @Override String getName(); @Override PatientData<Pair<String, String>> load(final Patient patient); @Override void writeJSON(@Nonnull final Patient patient, @Nonnull final JSONObject json,
        @Nullable final Collection<String> selectedFieldNames); @Override void writeJSON(@Nonnull final Patient patient, @Nonnull final JSONObject json); @Override PatientData<Pair<String, String>> readJSON(@Nullable final JSONObject json); @Override void save(@Nonnull final Patient patient); @Override void save(@Nonnull final Patient patient, @Nonnull final PatientWritePolicy policy);  }