@Test public void testParseRisks() { InputStream inputStream = getClass().getResourceAsStream("risks.json"); List<Risk> risks = converter.parseRisks(inputStream); assertNotNull(risks); assertEquals(2, risks.size()); Risk risk0 = risks.get(0); assertNotNull(risk0); assertEquals("c4480ba411939067", risk0.getProfileId()); assertEquals("atrialfib", risk0.getReportId()); assertEquals("Atrial Fibrillation", risk0.getDescription()); assertEquals(0.4164d, risk0.getRisk(), 0.1d); assertEquals(0.2715d, risk0.getPopulationRisk(), 0.1d); Risk risk1 = risks.get(1); assertNotNull(risk1); assertEquals("c4480ba411939067", risk1.getProfileId()); assertEquals("prostate", risk1.getReportId()); assertEquals("Prostate Cancer", risk1.getDescription()); assertEquals(0.2585d, risk1.getRisk(), 0.1d); assertEquals(0.1783d, risk1.getPopulationRisk(), 0.1d); }
@Override public List<Risk> parseRisks(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String reportId = null; String description = null; double risk = 0.0d; double populationRisk = 0.0d; List<Risk> risks = new ArrayList<Risk>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("risks".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String riskField = parser.getCurrentName(); parser.nextToken(); if ("report_id".equals(riskField)) { reportId = parser.getText(); } else if ("description".equals(riskField)) { description = parser.getText(); } else if ("risk".equals(riskField)) { risk = Double.parseDouble(parser.getText()); } else if ("population_risk".equals(riskField)) { populationRisk = Double.parseDouble(parser.getText()); } } risks.add(new Risk(id, reportId, description, risk, populationRisk)); reportId = null; description = null; risk = 0.0d; populationRisk = 0.0d; } } } return risks; } catch (IOException e) { logger.warn("could not parse risks", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public List<Risk> parseRisks(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String reportId = null; String description = null; double risk = 0.0d; double populationRisk = 0.0d; List<Risk> risks = new ArrayList<Risk>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("risks".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String riskField = parser.getCurrentName(); parser.nextToken(); if ("report_id".equals(riskField)) { reportId = parser.getText(); } else if ("description".equals(riskField)) { description = parser.getText(); } else if ("risk".equals(riskField)) { risk = Double.parseDouble(parser.getText()); } else if ("population_risk".equals(riskField)) { populationRisk = Double.parseDouble(parser.getText()); } } risks.add(new Risk(id, reportId, description, risk, populationRisk)); reportId = null; description = null; risk = 0.0d; populationRisk = 0.0d; } } } return risks; } catch (IOException e) { logger.warn("could not parse risks", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; } }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public List<Risk> parseRisks(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String reportId = null; String description = null; double risk = 0.0d; double populationRisk = 0.0d; List<Risk> risks = new ArrayList<Risk>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("risks".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String riskField = parser.getCurrentName(); parser.nextToken(); if ("report_id".equals(riskField)) { reportId = parser.getText(); } else if ("description".equals(riskField)) { description = parser.getText(); } else if ("risk".equals(riskField)) { risk = Double.parseDouble(parser.getText()); } else if ("population_risk".equals(riskField)) { populationRisk = Double.parseDouble(parser.getText()); } } risks.add(new Risk(id, reportId, description, risk, populationRisk)); reportId = null; description = null; risk = 0.0d; populationRisk = 0.0d; } } } return risks; } catch (IOException e) { logger.warn("could not parse risks", 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<Risk> parseRisks(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String reportId = null; String description = null; double risk = 0.0d; double populationRisk = 0.0d; List<Risk> risks = new ArrayList<Risk>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("risks".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String riskField = parser.getCurrentName(); parser.nextToken(); if ("report_id".equals(riskField)) { reportId = parser.getText(); } else if ("description".equals(riskField)) { description = parser.getText(); } else if ("risk".equals(riskField)) { risk = Double.parseDouble(parser.getText()); } else if ("population_risk".equals(riskField)) { populationRisk = Double.parseDouble(parser.getText()); } } risks.add(new Risk(id, reportId, description, risk, populationRisk)); reportId = null; description = null; risk = 0.0d; populationRisk = 0.0d; } } } return risks; } catch (IOException e) { logger.warn("could not parse risks", 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<Risk> parseRisks(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String reportId = null; String description = null; double risk = 0.0d; double populationRisk = 0.0d; List<Risk> risks = new ArrayList<Risk>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("risks".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String riskField = parser.getCurrentName(); parser.nextToken(); if ("report_id".equals(riskField)) { reportId = parser.getText(); } else if ("description".equals(riskField)) { description = parser.getText(); } else if ("risk".equals(riskField)) { risk = Double.parseDouble(parser.getText()); } else if ("population_risk".equals(riskField)) { populationRisk = Double.parseDouble(parser.getText()); } } risks.add(new Risk(id, reportId, description, risk, populationRisk)); reportId = null; description = null; risk = 0.0d; populationRisk = 0.0d; } } } return risks; } catch (IOException e) { logger.warn("could not parse risks", 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);  }