LimsFactory { @NotNull @VisibleForTesting static Map<String, LimsJsonSampleData> readLimsJsonSamples(@NotNull String limsJsonPath) throws FileNotFoundException { Gson gson = LimsGsonAdapter.buildSampleGson(); JsonObject jsonObject = new JsonParser().parse(new FileReader(limsJsonPath)).getAsJsonObject(); Set<Map.Entry<String, JsonElement>> jsonSamples = jsonObject.getAsJsonObject("samples").entrySet(); Map<String, LimsJsonSampleData> limsDataPerSampleBarcode = Maps.newHashMap(); jsonSamples.forEach(jsonSample -> { String barcode = jsonSample.getKey(); JsonObject jsonSampleObject = jsonSample.getValue().getAsJsonObject(); String analysisType = jsonSampleObject.get("analysis_type").getAsString(); String label = jsonSampleObject.get("label").getAsString(); if (analysisType != null && analysisType.toLowerCase().contains("somatic") && !label.equalsIgnoreCase("research")) { try { LimsJsonSampleData limsJsonSampleData = gson.fromJson(jsonSample.getValue(), LimsJsonSampleData.class); if (limsDataPerSampleBarcode.containsKey(barcode)) { LOGGER.warn("LIMS contains duplicate entries for {} ({})", barcode, limsJsonSampleData.sampleId()); } limsDataPerSampleBarcode.put(barcode, limsJsonSampleData); } catch (JsonSyntaxException exception) { LOGGER.warn("Could not convert JSON element to LimsJsonSampleData: {} - message: {}", jsonSample.getValue(), exception.getMessage()); } } }); return limsDataPerSampleBarcode; } private  LimsFactory(); @NotNull static Lims fromLimsDirectory(@NotNull String limsDirectory); @NotNull static Lims empty();  }
@Test public void readSamplesCorrectlyFromJsonFile() throws FileNotFoundException { Map<String, LimsJsonSampleData> dataPerSampleBarcode = LimsFactory.readLimsJsonSamples(LIMS_DIRECTORY + File.separator + "lims.json"); assertEquals(3, dataPerSampleBarcode.size()); String refSampleBarcode = "FR1234"; LimsJsonSampleData refData = dataPerSampleBarcode.get(refSampleBarcode); assertNull(refData.hospitalPatientId()); assertEquals("SAMP01010003R", refData.sampleId()); assertEquals("2016-01-03", refData.arrivalDate()); assertEquals("143", refData.dnaConcentration()); assertEquals("2016-01-02", refData.samplingDate()); assertEquals("NA", refData.pathologyTumorPercentage()); assertEquals("NA", refData.primaryTumor()); assertEquals("PREP013V23-QC037V20-SEQ008V25", refData.labProcedures()); assertEquals("HMFregCPCT", refData.submission()); String tumorSampleBarcode = "FR1236"; LimsJsonSampleData tumorData = dataPerSampleBarcode.get(tumorSampleBarcode); assertEquals(tumorSampleBarcode, tumorData.tumorBarcode()); assertEquals("SAMP01010003T", tumorData.sampleId()); assertEquals("something", tumorData.hospitalPatientId()); assertEquals("2016-02-05", tumorData.arrivalDate()); assertEquals("143", tumorData.dnaConcentration()); assertEquals("2016-01-04", tumorData.samplingDate()); assertEquals("30", tumorData.pathologyTumorPercentage()); assertEquals("NA", tumorData.primaryTumor()); assertEquals("N/A", tumorData.labProcedures()); assertEquals("PREPV-QC037V20-SEQ008V25", tumorData.labSopVersions()); assertEquals("HMFregCPCT", tumorData.submission()); assertEquals("", tumorData.hospitalPathologySampleId()); assertEquals("", tumorData.germlineReportingLevel()); }