@Test public void testParseCarriers() { InputStream inputStream = getClass().getResourceAsStream("carriers.json"); List<Carrier> carriers = converter.parseCarriers(inputStream); assertNotNull(carriers); assertEquals(2, carriers.size()); Carrier carrier0 = carriers.get(0); assertNotNull(carrier0); assertEquals("c4480ba411939067", carrier0.getProfileId()); assertEquals("tay_sachs", carrier0.getReportId()); assertEquals("Tay-Sachs Disease", carrier0.getDescription()); assertEquals(1, carrier0.getMutations()); Carrier carrier1 = carriers.get(1); assertNotNull(carrier1); assertEquals("c4480ba411939067", carrier1.getProfileId()); assertEquals("cf_panel", carrier1.getReportId()); assertEquals("Cystic Fibrosis", carrier1.getDescription()); assertEquals(2, carrier1.getMutations()); }
@Override public List<Carrier> parseCarriers(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String reportId = null; String description = null; int mutations = 0; List<Carrier> carriers = new ArrayList<Carrier>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("carriers".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String carrierField = parser.getCurrentName(); parser.nextToken(); if ("report_id".equals(carrierField)) { reportId = parser.getText(); } else if ("description".equals(carrierField)) { description = parser.getText(); } else if ("mutations".equals(carrierField)) { mutations = Integer.parseInt(parser.getText()); } } carriers.add(new Carrier(id, reportId, description, mutations)); reportId = null; description = null; mutations = 0; } } } return carriers; } catch (IOException e) { logger.warn("could not parse carriers", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public List<Carrier> parseCarriers(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String reportId = null; String description = null; int mutations = 0; List<Carrier> carriers = new ArrayList<Carrier>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("carriers".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String carrierField = parser.getCurrentName(); parser.nextToken(); if ("report_id".equals(carrierField)) { reportId = parser.getText(); } else if ("description".equals(carrierField)) { description = parser.getText(); } else if ("mutations".equals(carrierField)) { mutations = Integer.parseInt(parser.getText()); } } carriers.add(new Carrier(id, reportId, description, mutations)); reportId = null; description = null; mutations = 0; } } } return carriers; } catch (IOException e) { logger.warn("could not parse carriers", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; } }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public List<Carrier> parseCarriers(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String reportId = null; String description = null; int mutations = 0; List<Carrier> carriers = new ArrayList<Carrier>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("carriers".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String carrierField = parser.getCurrentName(); parser.nextToken(); if ("report_id".equals(carrierField)) { reportId = parser.getText(); } else if ("description".equals(carrierField)) { description = parser.getText(); } else if ("mutations".equals(carrierField)) { mutations = Integer.parseInt(parser.getText()); } } carriers.add(new Carrier(id, reportId, description, mutations)); reportId = null; description = null; mutations = 0; } } } return carriers; } catch (IOException e) { logger.warn("could not parse carriers", 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<Carrier> parseCarriers(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String reportId = null; String description = null; int mutations = 0; List<Carrier> carriers = new ArrayList<Carrier>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("carriers".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String carrierField = parser.getCurrentName(); parser.nextToken(); if ("report_id".equals(carrierField)) { reportId = parser.getText(); } else if ("description".equals(carrierField)) { description = parser.getText(); } else if ("mutations".equals(carrierField)) { mutations = Integer.parseInt(parser.getText()); } } carriers.add(new Carrier(id, reportId, description, mutations)); reportId = null; description = null; mutations = 0; } } } return carriers; } catch (IOException e) { logger.warn("could not parse carriers", 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<Carrier> parseCarriers(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String reportId = null; String description = null; int mutations = 0; List<Carrier> carriers = new ArrayList<Carrier>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("carriers".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String carrierField = parser.getCurrentName(); parser.nextToken(); if ("report_id".equals(carrierField)) { reportId = parser.getText(); } else if ("description".equals(carrierField)) { description = parser.getText(); } else if ("mutations".equals(carrierField)) { mutations = Integer.parseInt(parser.getText()); } } carriers.add(new Carrier(id, reportId, description, mutations)); reportId = null; description = null; mutations = 0; } } } return carriers; } catch (IOException e) { logger.warn("could not parse carriers", 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);  }