@Override public String queryVariantRaw( ExtendedFileInfo file, String chromosome, VariantFetchParams params) { params.setFormat(ReturnFormat.vcf); String rtn = queryVariantsInternal(file, chromosome, params); logger.info(rtn); return rtn; }
@Override public List<VariantRecord> queryVariantJSON( ExtendedFileInfo file, String chromosome, VariantFetchParams params) { try { params.setFormat(ReturnFormat.json); String rtn = queryVariantsInternal(file, chromosome, params); logger.info(rtn); JsonNode responseNode = mapper.readValue(rtn, JsonNode.class).findPath(ITEMS); List<VariantRecord> records = new ArrayList<VariantRecord>(); for (int i = 0; i < responseNode.size(); i++) { records.add( (VariantRecord) mapper.readValue(responseNode.get(i).toString(), VariantRecord.class)); } return records; } catch (BaseSpaceException bs) { throw bs; } catch (Throwable t) { throw new RuntimeException("Error during JSON query " + t); } }
protected String queryVariantsInternal( ExtendedFileInfo file, String chromosome, VariantFetchParams params) { if (file == null || file.getHrefVariants() == null) { throw new IllegalArgumentException( "null VariantFile or hrefVariants property for VariantFile object"); } try { MultivaluedMap<String, String> queryParams = params == null ? new MultivaluedMapImpl() : params.toMap(); WebResource resource = getClient() .resource( UriBuilder.fromUri(configuration.getApiRootUri()) .path(file.getHrefVariants()) .path("variants") .path(chromosome) .build()) .queryParams(queryParams); ClientResponse response = getClient() .resource(resource.getURI()) .accept(MediaType.APPLICATION_XHTML_XML, MediaType.APPLICATION_JSON) .get(ClientResponse.class); switch (response.getClientResponseStatus()) { case OK: return response.getEntity(String.class); default: BasicResponse status = mapper.readValue(response.getEntity(String.class), BasicResponse.class); throw new IllegalArgumentException(status.getResponseStatus().getMessage()); } } catch (BaseSpaceException bs) { throw bs; } catch (IllegalArgumentException iae) { throw iae; } catch (Throwable t) { throw new RuntimeException(t); } }