@Test public void testBuildDescription() { try { ObjectMapper mapper = new ObjectMapper(); DepositionSampleService service = new DepositionSampleService(); String json = "{\n" + "\t\"study_tag\": \"Study1\",\n" + "\t\"size\": 500,\n" + "\t\"sample_description\": \"Sample description\",\n" + "\t\"ancestry_category\": \"European\",\n" + "\t\"ancestry\": \"Italian\",\n" + "\t\"ancestry_description\": \"Val Borbera\",\n" + "\t\"country_recruitement\": \"Italy\",\n" + "\t\"stage\": \"discovery\"\n" + "}"; DepositionSampleDto dto = null; dto = mapper.readValue(json, DepositionSampleDto.class); String description = service.buildDescription(dto); assertEquals("500 Italian ancestry individuals", description); json = "{\n" + "\t\"study_tag\": \"Study1\",\n" + "\t\"size\": 200,\n" + "\t\"sample_description\": \"Sample description\",\n" + "\t\"ancestry_category\": \"European\",\n" + "\t\"ancestry\": \"French|Spanish\",\n" + "\t\"country_recruitement\": \"France|Spain\",\n" + "\t\"stage\": \"replication\"\n" + "}"; dto = mapper.readValue(json, DepositionSampleDto.class); description = service.buildDescription(dto); assertEquals("200 French ancestry, Spanish ancestry individuals", description); json = "{\n" + "\t\"study_tag\": \"Study2\",\n" + "\t\"size\": 500,\n" + "\t\"cases\": 300,\n" + "\t\"controls\": 200,\n" + "\t\"sample_description\": \"Sample description\",\n" + "\t\"ancestry_category\": \"Asian unspecified\",\n" + "\t\"country_recruitement\": \"NR\",\n" + "\t\"stage\": \"discovery\"\n" + "}"; dto = mapper.readValue(json, DepositionSampleDto.class); description = service.buildDescription(dto); assertEquals("300 Asian ancestry cases, 200 Asian ancestry controls", description); json = "{\n" + "\t\"study_tag\": \"Study1\",\n" + "\t\"size\": 200,\n" + "\t\"sample_description\": \"Sample description\",\n" + "\t\"ancestry_category\": \"African American or Afro-Caribbean\",\n" + "\t\"country_recruitement\": \"U.S.\",\n" + "\t\"stage\": \"replication\"\n" + "}"; dto = mapper.readValue(json, DepositionSampleDto.class); description = service.buildDescription(dto); assertEquals("200 African American or Afro-Caribbean individuals", description); } catch (IOException e) { e.printStackTrace(); } }
String buildDescription(DepositionSampleDto sampleDto) { String ancestry; if (sampleDto.getAncestry() != null) { ancestry = sampleDto.getAncestry().trim(); } else { ancestry = sampleDto.getAncestryCategory().trim(); } if (ancestry.trim().equalsIgnoreCase("NR")) { if (sampleDto.getCases() != null && sampleDto.getControls() != null && sampleDto.getCases() != 0 && sampleDto.getControls() != 0) { ancestry = String.format("%,d", sampleDto.getCases()) + " " + AncestryConstants.CASES + ", " + String.format("%,d", sampleDto.getControls()) + " " + AncestryConstants.CONTROLS; } else { if (sampleDto.getSize() != -1) { ancestry = String.format("%,d", sampleDto.getSize()) + " " + AncestryConstants.INDIVIDUALS; } else { ancestry += " " + AncestryConstants.INDIVIDUALS; } } return ancestry; } List<String> ancestryList = Arrays.asList(ancestry.split("\\|")); ancestry = ""; for (String entry : ancestryList) { String adaptEntry = adaptEntry(entry); if (sampleDto.getCases() != null && sampleDto.getControls() != null && sampleDto.getCases() != 0 && sampleDto.getControls() != 0) { ancestry += String.format("%,d", sampleDto.getCases()) + " " + adaptEntry + " " + AncestryConstants.CASES + ", " + String.format("%,d", sampleDto.getControls()) + " " + adaptEntry + " " + AncestryConstants.CONTROLS; } else { ancestry += adaptEntry; } ancestry += ", "; } ancestry = ancestry.trim(); if (ancestry.endsWith(",")) { ancestry = ancestry.substring(0, ancestry.length() - 1).trim(); } if (!ancestry.endsWith(AncestryConstants.CONTROLS)) { ancestry += " " + AncestryConstants.INDIVIDUALS; if (sampleDto.getSize() != -1) { ancestry = String.format("%,d", sampleDto.getSize()) + " " + ancestry; } } return ancestry; }
DepositionSampleService { String buildDescription(DepositionSampleDto sampleDto) { String ancestry; if (sampleDto.getAncestry() != null) { ancestry = sampleDto.getAncestry().trim(); } else { ancestry = sampleDto.getAncestryCategory().trim(); } if (ancestry.trim().equalsIgnoreCase("NR")) { if (sampleDto.getCases() != null && sampleDto.getControls() != null && sampleDto.getCases() != 0 && sampleDto.getControls() != 0) { ancestry = String.format("%,d", sampleDto.getCases()) + " " + AncestryConstants.CASES + ", " + String.format("%,d", sampleDto.getControls()) + " " + AncestryConstants.CONTROLS; } else { if (sampleDto.getSize() != -1) { ancestry = String.format("%,d", sampleDto.getSize()) + " " + AncestryConstants.INDIVIDUALS; } else { ancestry += " " + AncestryConstants.INDIVIDUALS; } } return ancestry; } List<String> ancestryList = Arrays.asList(ancestry.split("\\|")); ancestry = ""; for (String entry : ancestryList) { String adaptEntry = adaptEntry(entry); if (sampleDto.getCases() != null && sampleDto.getControls() != null && sampleDto.getCases() != 0 && sampleDto.getControls() != 0) { ancestry += String.format("%,d", sampleDto.getCases()) + " " + adaptEntry + " " + AncestryConstants.CASES + ", " + String.format("%,d", sampleDto.getControls()) + " " + adaptEntry + " " + AncestryConstants.CONTROLS; } else { ancestry += adaptEntry; } ancestry += ", "; } ancestry = ancestry.trim(); if (ancestry.endsWith(",")) { ancestry = ancestry.substring(0, ancestry.length() - 1).trim(); } if (!ancestry.endsWith(AncestryConstants.CONTROLS)) { ancestry += " " + AncestryConstants.INDIVIDUALS; if (sampleDto.getSize() != -1) { ancestry = String.format("%,d", sampleDto.getSize()) + " " + ancestry; } } return ancestry; } }
DepositionSampleService { String buildDescription(DepositionSampleDto sampleDto) { String ancestry; if (sampleDto.getAncestry() != null) { ancestry = sampleDto.getAncestry().trim(); } else { ancestry = sampleDto.getAncestryCategory().trim(); } if (ancestry.trim().equalsIgnoreCase("NR")) { if (sampleDto.getCases() != null && sampleDto.getControls() != null && sampleDto.getCases() != 0 && sampleDto.getControls() != 0) { ancestry = String.format("%,d", sampleDto.getCases()) + " " + AncestryConstants.CASES + ", " + String.format("%,d", sampleDto.getControls()) + " " + AncestryConstants.CONTROLS; } else { if (sampleDto.getSize() != -1) { ancestry = String.format("%,d", sampleDto.getSize()) + " " + AncestryConstants.INDIVIDUALS; } else { ancestry += " " + AncestryConstants.INDIVIDUALS; } } return ancestry; } List<String> ancestryList = Arrays.asList(ancestry.split("\\|")); ancestry = ""; for (String entry : ancestryList) { String adaptEntry = adaptEntry(entry); if (sampleDto.getCases() != null && sampleDto.getControls() != null && sampleDto.getCases() != 0 && sampleDto.getControls() != 0) { ancestry += String.format("%,d", sampleDto.getCases()) + " " + adaptEntry + " " + AncestryConstants.CASES + ", " + String.format("%,d", sampleDto.getControls()) + " " + adaptEntry + " " + AncestryConstants.CONTROLS; } else { ancestry += adaptEntry; } ancestry += ", "; } ancestry = ancestry.trim(); if (ancestry.endsWith(",")) { ancestry = ancestry.substring(0, ancestry.length() - 1).trim(); } if (!ancestry.endsWith(AncestryConstants.CONTROLS)) { ancestry += " " + AncestryConstants.INDIVIDUALS; if (sampleDto.getSize() != -1) { ancestry = String.format("%,d", sampleDto.getSize()) + " " + ancestry; } } return ancestry; } DepositionSampleService(); }
DepositionSampleService { String buildDescription(DepositionSampleDto sampleDto) { String ancestry; if (sampleDto.getAncestry() != null) { ancestry = sampleDto.getAncestry().trim(); } else { ancestry = sampleDto.getAncestryCategory().trim(); } if (ancestry.trim().equalsIgnoreCase("NR")) { if (sampleDto.getCases() != null && sampleDto.getControls() != null && sampleDto.getCases() != 0 && sampleDto.getControls() != 0) { ancestry = String.format("%,d", sampleDto.getCases()) + " " + AncestryConstants.CASES + ", " + String.format("%,d", sampleDto.getControls()) + " " + AncestryConstants.CONTROLS; } else { if (sampleDto.getSize() != -1) { ancestry = String.format("%,d", sampleDto.getSize()) + " " + AncestryConstants.INDIVIDUALS; } else { ancestry += " " + AncestryConstants.INDIVIDUALS; } } return ancestry; } List<String> ancestryList = Arrays.asList(ancestry.split("\\|")); ancestry = ""; for (String entry : ancestryList) { String adaptEntry = adaptEntry(entry); if (sampleDto.getCases() != null && sampleDto.getControls() != null && sampleDto.getCases() != 0 && sampleDto.getControls() != 0) { ancestry += String.format("%,d", sampleDto.getCases()) + " " + adaptEntry + " " + AncestryConstants.CASES + ", " + String.format("%,d", sampleDto.getControls()) + " " + adaptEntry + " " + AncestryConstants.CONTROLS; } else { ancestry += adaptEntry; } ancestry += ", "; } ancestry = ancestry.trim(); if (ancestry.endsWith(",")) { ancestry = ancestry.substring(0, ancestry.length() - 1).trim(); } if (!ancestry.endsWith(AncestryConstants.CONTROLS)) { ancestry += " " + AncestryConstants.INDIVIDUALS; if (sampleDto.getSize() != -1) { ancestry = String.format("%,d", sampleDto.getSize()) + " " + ancestry; } } return ancestry; } DepositionSampleService(); String saveSamples(SecureUser currentUser, String studyTag, Study study, List<DepositionSampleDto> samples); }
DepositionSampleService { String buildDescription(DepositionSampleDto sampleDto) { String ancestry; if (sampleDto.getAncestry() != null) { ancestry = sampleDto.getAncestry().trim(); } else { ancestry = sampleDto.getAncestryCategory().trim(); } if (ancestry.trim().equalsIgnoreCase("NR")) { if (sampleDto.getCases() != null && sampleDto.getControls() != null && sampleDto.getCases() != 0 && sampleDto.getControls() != 0) { ancestry = String.format("%,d", sampleDto.getCases()) + " " + AncestryConstants.CASES + ", " + String.format("%,d", sampleDto.getControls()) + " " + AncestryConstants.CONTROLS; } else { if (sampleDto.getSize() != -1) { ancestry = String.format("%,d", sampleDto.getSize()) + " " + AncestryConstants.INDIVIDUALS; } else { ancestry += " " + AncestryConstants.INDIVIDUALS; } } return ancestry; } List<String> ancestryList = Arrays.asList(ancestry.split("\\|")); ancestry = ""; for (String entry : ancestryList) { String adaptEntry = adaptEntry(entry); if (sampleDto.getCases() != null && sampleDto.getControls() != null && sampleDto.getCases() != 0 && sampleDto.getControls() != 0) { ancestry += String.format("%,d", sampleDto.getCases()) + " " + adaptEntry + " " + AncestryConstants.CASES + ", " + String.format("%,d", sampleDto.getControls()) + " " + adaptEntry + " " + AncestryConstants.CONTROLS; } else { ancestry += adaptEntry; } ancestry += ", "; } ancestry = ancestry.trim(); if (ancestry.endsWith(",")) { ancestry = ancestry.substring(0, ancestry.length() - 1).trim(); } if (!ancestry.endsWith(AncestryConstants.CONTROLS)) { ancestry += " " + AncestryConstants.INDIVIDUALS; if (sampleDto.getSize() != -1) { ancestry = String.format("%,d", sampleDto.getSize()) + " " + ancestry; } } return ancestry; } DepositionSampleService(); String saveSamples(SecureUser currentUser, String studyTag, Study study, List<DepositionSampleDto> samples);  }