@Test public void testParseTraits() { InputStream inputStream = getClass().getResourceAsStream("traits.json"); List<Trait> traits = converter.parseTraits(inputStream); assertNotNull(traits); assertEquals(2, traits.size()); Trait trait0 = traits.get(0); assertNotNull(trait0); assertEquals("c4480ba411939067", trait0.getProfileId()); assertEquals("muscleperformance", trait0.getReportId()); assertEquals("Muscle Performance", trait0.getDescription()); assertEquals("Unlikely Sprinter", trait0.getTrait()); assertNotNull(trait0.getPossibleTraits()); assertEquals(2, trait0.getPossibleTraits().size()); assertTrue(trait0.getPossibleTraits().contains("Likely Sprinter")); assertTrue(trait0.getPossibleTraits().contains("Unlikely Sprinter")); Trait trait1 = traits.get(1); assertNotNull(trait1); assertEquals("c4480ba411939067", trait1.getProfileId()); assertEquals("hiv", trait1.getReportId()); assertEquals("Resistance to HIV/AIDS", trait1.getDescription()); assertEquals("Not Resistant", trait1.getTrait()); assertNotNull(trait1.getPossibleTraits()); assertEquals(2, trait1.getPossibleTraits().size()); assertTrue(trait1.getPossibleTraits().contains("Not Resistant")); assertTrue(trait1.getPossibleTraits().contains("Partially Resistant")); }
@Override public List<Trait> parseTraits(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String reportId = null; String description = null; String trait = null; Set<String> possibleTraits = new HashSet<String>(); List<Trait> traits = new ArrayList<Trait>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("traits".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String traitField = parser.getCurrentName(); parser.nextToken(); if ("report_id".equals(traitField)) { reportId = parser.getText(); } else if ("description".equals(traitField)) { description = parser.getText(); } else if ("trait".equals(traitField)) { trait = parser.getText(); } else if ("possible_traits".equals(traitField)) { while (parser.nextToken() != JsonToken.END_ARRAY) { possibleTraits.add(parser.getText()); } } } traits.add(new Trait(id, reportId, description, trait, possibleTraits)); reportId = null; description = null; trait = null; possibleTraits.clear(); } } } return traits; } catch (IOException e) { logger.warn("could not parse traits", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public List<Trait> parseTraits(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String reportId = null; String description = null; String trait = null; Set<String> possibleTraits = new HashSet<String>(); List<Trait> traits = new ArrayList<Trait>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("traits".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String traitField = parser.getCurrentName(); parser.nextToken(); if ("report_id".equals(traitField)) { reportId = parser.getText(); } else if ("description".equals(traitField)) { description = parser.getText(); } else if ("trait".equals(traitField)) { trait = parser.getText(); } else if ("possible_traits".equals(traitField)) { while (parser.nextToken() != JsonToken.END_ARRAY) { possibleTraits.add(parser.getText()); } } } traits.add(new Trait(id, reportId, description, trait, possibleTraits)); reportId = null; description = null; trait = null; possibleTraits.clear(); } } } return traits; } catch (IOException e) { logger.warn("could not parse traits", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; } }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public List<Trait> parseTraits(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String reportId = null; String description = null; String trait = null; Set<String> possibleTraits = new HashSet<String>(); List<Trait> traits = new ArrayList<Trait>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("traits".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String traitField = parser.getCurrentName(); parser.nextToken(); if ("report_id".equals(traitField)) { reportId = parser.getText(); } else if ("description".equals(traitField)) { description = parser.getText(); } else if ("trait".equals(traitField)) { trait = parser.getText(); } else if ("possible_traits".equals(traitField)) { while (parser.nextToken() != JsonToken.END_ARRAY) { possibleTraits.add(parser.getText()); } } } traits.add(new Trait(id, reportId, description, trait, possibleTraits)); reportId = null; description = null; trait = null; possibleTraits.clear(); } } } return traits; } catch (IOException e) { logger.warn("could not parse traits", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; } JacksonPersonalGenomeConverter(final JsonFactory jsonFactory); }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public List<Trait> parseTraits(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String reportId = null; String description = null; String trait = null; Set<String> possibleTraits = new HashSet<String>(); List<Trait> traits = new ArrayList<Trait>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("traits".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String traitField = parser.getCurrentName(); parser.nextToken(); if ("report_id".equals(traitField)) { reportId = parser.getText(); } else if ("description".equals(traitField)) { description = parser.getText(); } else if ("trait".equals(traitField)) { trait = parser.getText(); } else if ("possible_traits".equals(traitField)) { while (parser.nextToken() != JsonToken.END_ARRAY) { possibleTraits.add(parser.getText()); } } } traits.add(new Trait(id, reportId, description, trait, possibleTraits)); reportId = null; description = null; trait = null; possibleTraits.clear(); } } } return traits; } catch (IOException e) { logger.warn("could not parse traits", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; } JacksonPersonalGenomeConverter(final JsonFactory jsonFactory); @Override PersonalGenomeClientException parseException(final InputStream inputStream); @Override User parseUser(final InputStream inputStream); @Override UserName parseNames(final InputStream inputStream); @Override Haplogroup parseHaplogroups(final InputStream inputStream); @Override Genotype parseGenotypes(final InputStream inputStream); @Override Genome parseGenomes(final InputStream inputStream); @Override Ancestry parseAncestry(final InputStream inputStream); @Override double parseNeanderthalProportion(final InputStream inputStream); @Override List<Relative> parseRelatives(final InputStream inputStream); @Override List<Risk> parseRisks(final InputStream inputStream); @Override List<Carrier> parseCarriers(final InputStream inputStream); @Override List<DrugResponse> parseDrugResponses(final InputStream inputStream); @Override List<Trait> parseTraits(final InputStream inputStream); }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public List<Trait> parseTraits(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String reportId = null; String description = null; String trait = null; Set<String> possibleTraits = new HashSet<String>(); List<Trait> traits = new ArrayList<Trait>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("traits".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String traitField = parser.getCurrentName(); parser.nextToken(); if ("report_id".equals(traitField)) { reportId = parser.getText(); } else if ("description".equals(traitField)) { description = parser.getText(); } else if ("trait".equals(traitField)) { trait = parser.getText(); } else if ("possible_traits".equals(traitField)) { while (parser.nextToken() != JsonToken.END_ARRAY) { possibleTraits.add(parser.getText()); } } } traits.add(new Trait(id, reportId, description, trait, possibleTraits)); reportId = null; description = null; trait = null; possibleTraits.clear(); } } } return traits; } catch (IOException e) { logger.warn("could not parse traits", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; } JacksonPersonalGenomeConverter(final JsonFactory jsonFactory); @Override PersonalGenomeClientException parseException(final InputStream inputStream); @Override User parseUser(final InputStream inputStream); @Override UserName parseNames(final InputStream inputStream); @Override Haplogroup parseHaplogroups(final InputStream inputStream); @Override Genotype parseGenotypes(final InputStream inputStream); @Override Genome parseGenomes(final InputStream inputStream); @Override Ancestry parseAncestry(final InputStream inputStream); @Override double parseNeanderthalProportion(final InputStream inputStream); @Override List<Relative> parseRelatives(final InputStream inputStream); @Override List<Risk> parseRisks(final InputStream inputStream); @Override List<Carrier> parseCarriers(final InputStream inputStream); @Override List<DrugResponse> parseDrugResponses(final InputStream inputStream); @Override List<Trait> parseTraits(final InputStream inputStream);  }