@Test public void testParseNames() { InputStream inputStream = getClass().getResourceAsStream("names.json"); UserName userName = converter.parseNames(inputStream); assertNotNull(userName); assertEquals("c3a110", userName.getId()); assertEquals("Gene", userName.getFirstName()); assertEquals("Mendel", userName.getLastName()); assertEquals(2, userName.getProfileNames().size()); assertEquals("83a112", userName.getProfileNames().get(0).getId()); assertEquals("Chip", userName.getProfileNames().get(0).getFirstName()); assertEquals("Mendel", userName.getProfileNames().get(0).getLastName()); assertEquals("c92839", userName.getProfileNames().get(1).getId()); assertEquals("Gene", userName.getProfileNames().get(1).getFirstName()); assertEquals("Mendel", userName.getProfileNames().get(1).getLastName()); }
@Override public UserName parseNames(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String firstName = null; String lastName = null; String profileId = null; String profileFirstName = null; String profileLastName = null; List<ProfileName> profileNames = new ArrayList<ProfileName>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("first_name".equals(field)) { firstName = parser.getText(); } else if ("last_name".equals(field)) { lastName = parser.getText(); } else if ("profiles".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String profileNameField = parser.getCurrentName(); parser.nextToken(); if ("id".equals(profileNameField)) { profileId = parser.getText(); } else if ("first_name".equals(profileNameField)) { profileFirstName = parser.getText(); } else if ("last_name".equals(profileNameField)) { profileLastName = parser.getText(); } } profileNames.add(new ProfileName(profileId, profileFirstName, profileLastName)); } } } return new UserName(id, firstName, lastName, profileNames); } catch (IOException e) { logger.warn("could not parse names", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public UserName parseNames(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String firstName = null; String lastName = null; String profileId = null; String profileFirstName = null; String profileLastName = null; List<ProfileName> profileNames = new ArrayList<ProfileName>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("first_name".equals(field)) { firstName = parser.getText(); } else if ("last_name".equals(field)) { lastName = parser.getText(); } else if ("profiles".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String profileNameField = parser.getCurrentName(); parser.nextToken(); if ("id".equals(profileNameField)) { profileId = parser.getText(); } else if ("first_name".equals(profileNameField)) { profileFirstName = parser.getText(); } else if ("last_name".equals(profileNameField)) { profileLastName = parser.getText(); } } profileNames.add(new ProfileName(profileId, profileFirstName, profileLastName)); } } } return new UserName(id, firstName, lastName, profileNames); } catch (IOException e) { logger.warn("could not parse names", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; } }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public UserName parseNames(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String firstName = null; String lastName = null; String profileId = null; String profileFirstName = null; String profileLastName = null; List<ProfileName> profileNames = new ArrayList<ProfileName>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("first_name".equals(field)) { firstName = parser.getText(); } else if ("last_name".equals(field)) { lastName = parser.getText(); } else if ("profiles".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String profileNameField = parser.getCurrentName(); parser.nextToken(); if ("id".equals(profileNameField)) { profileId = parser.getText(); } else if ("first_name".equals(profileNameField)) { profileFirstName = parser.getText(); } else if ("last_name".equals(profileNameField)) { profileLastName = parser.getText(); } } profileNames.add(new ProfileName(profileId, profileFirstName, profileLastName)); } } } return new UserName(id, firstName, lastName, profileNames); } catch (IOException e) { logger.warn("could not parse names", 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 UserName parseNames(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String firstName = null; String lastName = null; String profileId = null; String profileFirstName = null; String profileLastName = null; List<ProfileName> profileNames = new ArrayList<ProfileName>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("first_name".equals(field)) { firstName = parser.getText(); } else if ("last_name".equals(field)) { lastName = parser.getText(); } else if ("profiles".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String profileNameField = parser.getCurrentName(); parser.nextToken(); if ("id".equals(profileNameField)) { profileId = parser.getText(); } else if ("first_name".equals(profileNameField)) { profileFirstName = parser.getText(); } else if ("last_name".equals(profileNameField)) { profileLastName = parser.getText(); } } profileNames.add(new ProfileName(profileId, profileFirstName, profileLastName)); } } } return new UserName(id, firstName, lastName, profileNames); } catch (IOException e) { logger.warn("could not parse names", 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 UserName parseNames(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String firstName = null; String lastName = null; String profileId = null; String profileFirstName = null; String profileLastName = null; List<ProfileName> profileNames = new ArrayList<ProfileName>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("first_name".equals(field)) { firstName = parser.getText(); } else if ("last_name".equals(field)) { lastName = parser.getText(); } else if ("profiles".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String profileNameField = parser.getCurrentName(); parser.nextToken(); if ("id".equals(profileNameField)) { profileId = parser.getText(); } else if ("first_name".equals(profileNameField)) { profileFirstName = parser.getText(); } else if ("last_name".equals(profileNameField)) { profileLastName = parser.getText(); } } profileNames.add(new ProfileName(profileId, profileFirstName, profileLastName)); } } } return new UserName(id, firstName, lastName, profileNames); } catch (IOException e) { logger.warn("could not parse names", 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);  }