@Test public void writeJSONAddsContainerWithOnlySelectedFields() throws ComponentLookupException { List<Map<String, String>> internalList = new LinkedList<>(); Map<String, String> item = new LinkedHashMap<>(); item.put(VARIANT_KEY, "variantName"); item.put(GENE_KEY, "gene"); item.put(PROTEIN_KEY, "Protein"); item.put(TRANSCRIPT_KEY, "Transcript"); item.put(DBSNP_KEY, "DBSNP"); item.put(EFFECT_KEY, "Effect"); item.put(INTERPRETATION_KEY, "Interpretation"); item.put(INHERITANCE_KEY, "Inheritance"); item.put(EVIDENCE_KEY, "Evidence"); item.put(SANGER_KEY, "Sanger"); item.put(SEGREGATION_KEY, "Segregation"); item.put(ZYGOSITY_KEY, "Zygosity"); internalList.add(item); PatientData<Map<String, String>> patientData = new IndexedPatientData<>(CONTROLLER_NAME, internalList); doReturn(patientData).when(this.patient).getData(CONTROLLER_NAME); JSONObject json = new JSONObject(); Collection<String> selectedFields = new LinkedList<>(); selectedFields.add(VARIANTS_ENABLING_FIELD_NAME); this.mocker.getComponentUnderTest().writeJSON(this.patient, json, selectedFields); Assert.assertNotNull(json.get(CONTROLLER_NAME)); Assert.assertTrue(json.get(CONTROLLER_NAME) instanceof JSONArray); JSONObject result = json.getJSONArray(CONTROLLER_NAME).getJSONObject(0); Assert.assertEquals("variantName", result.get(VARIANT_KEY)); Assert.assertEquals("gene", result.get(GENE_KEY)); Assert.assertEquals("Protein", result.get(PROTEIN_KEY)); Assert.assertEquals("Transcript", result.get(TRANSCRIPT_KEY)); Assert.assertEquals("DBSNP", result.get(DBSNP_KEY)); Assert.assertEquals("Zygosity", result.get(ZYGOSITY_KEY)); json = new JSONObject(); internalList = new LinkedList<>(); item = new LinkedHashMap<>(); item.put(VARIANT_KEY, "variantName"); item.put(GENE_KEY, "gene"); item.put(PROTEIN_KEY, "Protein"); item.put(TRANSCRIPT_KEY, "Transcript"); item.put(DBSNP_KEY, "DBSNP"); item.put(EFFECT_KEY, "Effect"); item.put(INTERPRETATION_KEY, "Interpretation"); item.put(INHERITANCE_KEY, "Inheritance"); item.put(EVIDENCE_KEY, "Evidence"); item.put(SANGER_KEY, "Sanger"); item.put(SEGREGATION_KEY, "Segregation"); item.put(ZYGOSITY_KEY, "Zygosity"); internalList.add(item); patientData = new IndexedPatientData<>(CONTROLLER_NAME, internalList); doReturn(patientData).when(this.patient).getData(CONTROLLER_NAME); selectedFields = new LinkedList<>(); selectedFields.add(VARIANTS_ENABLING_FIELD_NAME); this.mocker.getComponentUnderTest().writeJSON(this.patient, json, selectedFields); Assert.assertNotNull(json.get(CONTROLLER_NAME)); Assert.assertTrue(json.get(CONTROLLER_NAME) instanceof JSONArray); result = json.getJSONArray(CONTROLLER_NAME).getJSONObject(0); Assert.assertEquals("variantName", result.get(VARIANT_KEY)); Assert.assertEquals(12, result.length()); }
@SuppressWarnings("checkstyle:CyclomaticComplexity") @Override public void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames) { if (selectedFieldNames != null && !selectedFieldNames.contains(VARIANTS_ENABLING_FIELD_NAME)) { return; } PatientData<Map<String, String>> data = patient.getData(getName()); if (data == null || data.size() == 0) { if (selectedFieldNames != null && selectedFieldNames.contains(VARIANTS_ENABLING_FIELD_NAME)) { json.put(getJsonPropertyName(), new JSONArray()); } return; } Iterator<Map<String, String>> iterator = data.iterator(); json.put(getJsonPropertyName(), new JSONArray()); JSONArray container = json.getJSONArray(getJsonPropertyName()); while (iterator.hasNext()) { Map<String, String> item = iterator.next(); if (!StringUtils.isBlank(item.get(INTERNAL_VARIANT_KEY))) { JSONObject nextVariant = new JSONObject(); for (String key : INTERNAL_TO_JSON_KEYS.keySet()) { if (!StringUtils.isBlank(item.get(key))) { if (INTERNAL_EVIDENCE_KEY.equals(key)) { nextVariant.put(key, new JSONArray(item.get(INTERNAL_TO_JSON_KEYS.get(key)).split("\\|"))); } else { nextVariant.put(key, item.get(INTERNAL_TO_JSON_KEYS.get(key))); } } } container.put(nextVariant); } } }
VariantListController extends AbstractComplexController<Map<String, String>> { @SuppressWarnings("checkstyle:CyclomaticComplexity") @Override public void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames) { if (selectedFieldNames != null && !selectedFieldNames.contains(VARIANTS_ENABLING_FIELD_NAME)) { return; } PatientData<Map<String, String>> data = patient.getData(getName()); if (data == null || data.size() == 0) { if (selectedFieldNames != null && selectedFieldNames.contains(VARIANTS_ENABLING_FIELD_NAME)) { json.put(getJsonPropertyName(), new JSONArray()); } return; } Iterator<Map<String, String>> iterator = data.iterator(); json.put(getJsonPropertyName(), new JSONArray()); JSONArray container = json.getJSONArray(getJsonPropertyName()); while (iterator.hasNext()) { Map<String, String> item = iterator.next(); if (!StringUtils.isBlank(item.get(INTERNAL_VARIANT_KEY))) { JSONObject nextVariant = new JSONObject(); for (String key : INTERNAL_TO_JSON_KEYS.keySet()) { if (!StringUtils.isBlank(item.get(key))) { if (INTERNAL_EVIDENCE_KEY.equals(key)) { nextVariant.put(key, new JSONArray(item.get(INTERNAL_TO_JSON_KEYS.get(key)).split("\\|"))); } else { nextVariant.put(key, item.get(INTERNAL_TO_JSON_KEYS.get(key))); } } } container.put(nextVariant); } } } }
VariantListController extends AbstractComplexController<Map<String, String>> { @SuppressWarnings("checkstyle:CyclomaticComplexity") @Override public void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames) { if (selectedFieldNames != null && !selectedFieldNames.contains(VARIANTS_ENABLING_FIELD_NAME)) { return; } PatientData<Map<String, String>> data = patient.getData(getName()); if (data == null || data.size() == 0) { if (selectedFieldNames != null && selectedFieldNames.contains(VARIANTS_ENABLING_FIELD_NAME)) { json.put(getJsonPropertyName(), new JSONArray()); } return; } Iterator<Map<String, String>> iterator = data.iterator(); json.put(getJsonPropertyName(), new JSONArray()); JSONArray container = json.getJSONArray(getJsonPropertyName()); while (iterator.hasNext()) { Map<String, String> item = iterator.next(); if (!StringUtils.isBlank(item.get(INTERNAL_VARIANT_KEY))) { JSONObject nextVariant = new JSONObject(); for (String key : INTERNAL_TO_JSON_KEYS.keySet()) { if (!StringUtils.isBlank(item.get(key))) { if (INTERNAL_EVIDENCE_KEY.equals(key)) { nextVariant.put(key, new JSONArray(item.get(INTERNAL_TO_JSON_KEYS.get(key)).split("\\|"))); } else { nextVariant.put(key, item.get(INTERNAL_TO_JSON_KEYS.get(key))); } } } container.put(nextVariant); } } }  }
VariantListController extends AbstractComplexController<Map<String, String>> { @SuppressWarnings("checkstyle:CyclomaticComplexity") @Override public void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames) { if (selectedFieldNames != null && !selectedFieldNames.contains(VARIANTS_ENABLING_FIELD_NAME)) { return; } PatientData<Map<String, String>> data = patient.getData(getName()); if (data == null || data.size() == 0) { if (selectedFieldNames != null && selectedFieldNames.contains(VARIANTS_ENABLING_FIELD_NAME)) { json.put(getJsonPropertyName(), new JSONArray()); } return; } Iterator<Map<String, String>> iterator = data.iterator(); json.put(getJsonPropertyName(), new JSONArray()); JSONArray container = json.getJSONArray(getJsonPropertyName()); while (iterator.hasNext()) { Map<String, String> item = iterator.next(); if (!StringUtils.isBlank(item.get(INTERNAL_VARIANT_KEY))) { JSONObject nextVariant = new JSONObject(); for (String key : INTERNAL_TO_JSON_KEYS.keySet()) { if (!StringUtils.isBlank(item.get(key))) { if (INTERNAL_EVIDENCE_KEY.equals(key)) { nextVariant.put(key, new JSONArray(item.get(INTERNAL_TO_JSON_KEYS.get(key)).split("\\|"))); } else { nextVariant.put(key, item.get(INTERNAL_TO_JSON_KEYS.get(key))); } } } container.put(nextVariant); } } }  @Override String getName(); @Override PatientData<Map<String, String>> load(Patient patient); @SuppressWarnings("checkstyle:CyclomaticComplexity") @Override void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames); @Override PatientData<Map<String, String>> readJSON(JSONObject json); @Override void save(Patient patient); @Override void save(@Nonnull final Patient patient, @Nonnull final PatientWritePolicy policy); }
VariantListController extends AbstractComplexController<Map<String, String>> { @SuppressWarnings("checkstyle:CyclomaticComplexity") @Override public void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames) { if (selectedFieldNames != null && !selectedFieldNames.contains(VARIANTS_ENABLING_FIELD_NAME)) { return; } PatientData<Map<String, String>> data = patient.getData(getName()); if (data == null || data.size() == 0) { if (selectedFieldNames != null && selectedFieldNames.contains(VARIANTS_ENABLING_FIELD_NAME)) { json.put(getJsonPropertyName(), new JSONArray()); } return; } Iterator<Map<String, String>> iterator = data.iterator(); json.put(getJsonPropertyName(), new JSONArray()); JSONArray container = json.getJSONArray(getJsonPropertyName()); while (iterator.hasNext()) { Map<String, String> item = iterator.next(); if (!StringUtils.isBlank(item.get(INTERNAL_VARIANT_KEY))) { JSONObject nextVariant = new JSONObject(); for (String key : INTERNAL_TO_JSON_KEYS.keySet()) { if (!StringUtils.isBlank(item.get(key))) { if (INTERNAL_EVIDENCE_KEY.equals(key)) { nextVariant.put(key, new JSONArray(item.get(INTERNAL_TO_JSON_KEYS.get(key)).split("\\|"))); } else { nextVariant.put(key, item.get(INTERNAL_TO_JSON_KEYS.get(key))); } } } container.put(nextVariant); } } }  @Override String getName(); @Override PatientData<Map<String, String>> load(Patient patient); @SuppressWarnings("checkstyle:CyclomaticComplexity") @Override void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames); @Override PatientData<Map<String, String>> readJSON(JSONObject json); @Override void save(Patient patient); @Override void save(@Nonnull final Patient patient, @Nonnull final PatientWritePolicy policy);  }