@Test public void testParseDrugResponses() { InputStream inputStream = getClass().getResourceAsStream("drugResponses.json"); List<DrugResponse> drugResponses = converter.parseDrugResponses(inputStream); assertNotNull(drugResponses); assertEquals(2, drugResponses.size()); DrugResponse drugResponse0 = drugResponses.get(0); assertNotNull(drugResponse0); assertEquals("c4480ba411939067", drugResponse0.getProfileId()); assertEquals("alcohol_esophageal_pgx", drugResponse0.getReportId()); assertEquals("Alcohol Consumption, Smoking and Risk of Esophageal Cancer", drugResponse0.getDescription()); assertEquals("typical", drugResponse0.getStatus()); DrugResponse drugResponse1 = drugResponses.get(1); assertNotNull(drugResponse1); assertEquals("c4480ba411939067", drugResponse1.getProfileId()); assertEquals("hepc_peginf_ribavirin", drugResponse1.getReportId()); assertEquals("Response to Hepatitis C Treatment", drugResponse1.getDescription()); assertEquals("reduced", drugResponse1.getStatus()); }
@Override public List<DrugResponse> parseDrugResponses(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 status = null; List<DrugResponse> drugResponses = new ArrayList<DrugResponse>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("drug_responses".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String drugResponseField = parser.getCurrentName(); parser.nextToken(); if ("report_id".equals(drugResponseField)) { reportId = parser.getText(); } else if ("description".equals(drugResponseField)) { description = parser.getText(); } else if ("status".equals(drugResponseField)) { status = parser.getText(); } } drugResponses.add(new DrugResponse(id, reportId, description, status)); reportId = null; description = null; status = null; } } } return drugResponses; } catch (IOException e) { logger.warn("could not parse drug responses", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public List<DrugResponse> parseDrugResponses(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 status = null; List<DrugResponse> drugResponses = new ArrayList<DrugResponse>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("drug_responses".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String drugResponseField = parser.getCurrentName(); parser.nextToken(); if ("report_id".equals(drugResponseField)) { reportId = parser.getText(); } else if ("description".equals(drugResponseField)) { description = parser.getText(); } else if ("status".equals(drugResponseField)) { status = parser.getText(); } } drugResponses.add(new DrugResponse(id, reportId, description, status)); reportId = null; description = null; status = null; } } } return drugResponses; } catch (IOException e) { logger.warn("could not parse drug responses", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; } }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public List<DrugResponse> parseDrugResponses(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 status = null; List<DrugResponse> drugResponses = new ArrayList<DrugResponse>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("drug_responses".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String drugResponseField = parser.getCurrentName(); parser.nextToken(); if ("report_id".equals(drugResponseField)) { reportId = parser.getText(); } else if ("description".equals(drugResponseField)) { description = parser.getText(); } else if ("status".equals(drugResponseField)) { status = parser.getText(); } } drugResponses.add(new DrugResponse(id, reportId, description, status)); reportId = null; description = null; status = null; } } } return drugResponses; } catch (IOException e) { logger.warn("could not parse drug responses", 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<DrugResponse> parseDrugResponses(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 status = null; List<DrugResponse> drugResponses = new ArrayList<DrugResponse>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("drug_responses".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String drugResponseField = parser.getCurrentName(); parser.nextToken(); if ("report_id".equals(drugResponseField)) { reportId = parser.getText(); } else if ("description".equals(drugResponseField)) { description = parser.getText(); } else if ("status".equals(drugResponseField)) { status = parser.getText(); } } drugResponses.add(new DrugResponse(id, reportId, description, status)); reportId = null; description = null; status = null; } } } return drugResponses; } catch (IOException e) { logger.warn("could not parse drug responses", 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<DrugResponse> parseDrugResponses(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 status = null; List<DrugResponse> drugResponses = new ArrayList<DrugResponse>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("drug_responses".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String drugResponseField = parser.getCurrentName(); parser.nextToken(); if ("report_id".equals(drugResponseField)) { reportId = parser.getText(); } else if ("description".equals(drugResponseField)) { description = parser.getText(); } else if ("status".equals(drugResponseField)) { status = parser.getText(); } } drugResponses.add(new DrugResponse(id, reportId, description, status)); reportId = null; description = null; status = null; } } } return drugResponses; } catch (IOException e) { logger.warn("could not parse drug responses", 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);  }