List of usage examples for com.google.gson JsonParser JsonParser
@Deprecated
public JsonParser()
From source file:com.apothesource.pillfill.service.drug.impl.DefaultDrugAlertServiceImpl.java
License:Open Source License
private List<DrugAlertType> deserializeDrugAlerts(Collection<PrescriptionType> rxs, String msg) { try {//from w w w.j a v a 2 s. com JsonObject returnValue = new JsonParser().parse(msg).getAsJsonObject(); if (!returnValue.has("fullInteractionTypeGroup")) { return Collections.emptyList(); } else { Gson gson = new Gson(); TypeToken<List<FullInteractionTypeGroup>> interactionGroupListType = new TypeToken<List<FullInteractionTypeGroup>>() { }; List<FullInteractionTypeGroup> group = gson.fromJson(returnValue.get("fullInteractionTypeGroup"), interactionGroupListType.getType()); ArrayList<DrugAlertType> alerts = processDrugInteractions(rxs, group); return alerts; } } catch (Exception e) { log.log(Level.SEVERE, "Invalid drug interaction alert response.", e); throw new RuntimeException(e); } }
From source file:com.apothesource.pillfill.service.drug.impl.DefaultDrugServiceImpl.java
License:Open Source License
/** * <a href="http://rxnav.nlm.nih.gov/RxNormAPIs.html#">NIH Service</a>: Get avaliable RxNorm IDs associated with an 11 digit National Drug Code (NDC). * * @param ndc The 11-digit NDC without dashes or spaces * @return A list of RxNorm IDs associated with this NDC (should normally return 0 or 1) */// w w w . j a va 2s .c om @Override public Observable<String> getRxNormIdForDrugNdc(String ndc) { return subscribeIoObserveImmediate(subscriber -> { String urlStr = String.format(URL_RXNORM_BRAND_NAME_BY_NDC, ndc); try { String responseStr = PFNetworkManager.doPinnedGetForUrl(urlStr); JsonParser parser = new JsonParser(); JsonObject response = parser.parse(responseStr).getAsJsonObject().get("idGroup").getAsJsonObject(); if (response.has("rxnormId")) { JsonArray array = response.getAsJsonArray("rxnormId"); for (JsonElement e : array) { subscriber.onNext(e.getAsString()); } subscriber.onCompleted(); } else { Timber.e("No rxnormIds found for NDC: %s", ndc); subscriber.onError(new RuntimeException("Could not find NDC->RxNorm for NDC.")); } } catch (IOException e) { e.printStackTrace(); } }); }
From source file:com.apothesource.pillfill.service.drug.impl.DefaultDrugServiceImpl.java
License:Open Source License
/** * An experimental method to enable a list of generic concepts to be retrieved without a method-specific implementation. Use with caution. * @param type The {@link Type} of class to be returned. Must be mapped in the <code>/src/main/resources/PFResourceMapping.properties</code> file or a RuntimeException will occur. * @param ids The list of IDs to retrieve * @return An observable that emits instances of the provided type based on the requested IDs *///from www .j av a 2s . c o m protected <T> Observable<T> getConceptList(Class<T> type, String... ids) { if (ids == null || ids.length == 0) return Observable.empty(); String urlTemplate = getUrlForType(type); String url = String.format(urlTemplate, Joiner.on(",").join(ids)); String typeName = type.getSimpleName(); Timber.d("Requesting %s list from URL: %s", typeName, url); return subscribeIoObserveImmediate(subscriber -> { try { String listJson = PFNetworkManager.doPinnedGetForUrl(url); JsonParser parser = new JsonParser(); JsonArray array = parser.parse(listJson).getAsJsonArray(); for (JsonElement elem : array) { subscriber.onNext(gson.fromJson(elem, type)); } subscriber.onCompleted(); } catch (IOException e) { Timber.e("Error retrieving %s list with ids %s - %s", typeName, ids, e.getMessage()); subscriber.onError(e); } }); }
From source file:com.app.smarthome.SmartHomeApplication.java
private void Sdkinit() { JsonObject initJsonObjectIn = new JsonObject(); JsonObject initJsonObjectOut = new JsonObject(); String initOut;/*from w w w .java2s . c om*/ initJsonObjectIn.addProperty("typelicense", typelicense); initJsonObjectIn.addProperty("userlicense", userlicense); initJsonObjectIn.addProperty("filepath", filepath); String string = initJsonObjectIn.toString(); initOut = mBlNetwork.SDKInit(string); initJsonObjectOut = new JsonParser().parse(initOut).getAsJsonObject(); if (initJsonObjectOut.get("code").getAsInt() != 0) { Log.i("Sdkinit failed", initJsonObjectOut.get("msg").getAsString()); } // ?? HC_DVRManager.getInstance().initSDK(); }
From source file:com.appdynamics.extensions.couchbase.CouchBaseWrapper.java
License:Apache License
/** * Returns JsonElement after parsing HttpResponse from given uri * /*from ww w. j a v a 2 s . co m*/ * @param httpClient * @param uri * @return */ private JsonElement getResponse(SimpleHttpClient httpClient, String uri) { String response = getResponseString(httpClient, uri); JsonElement jsonElement = null; try { jsonElement = new JsonParser().parse(response); } catch (JsonParseException e) { logger.error("Response from " + uri + "is not a json"); } return jsonElement; }
From source file:com.appdynamics.extensions.couchdb.CouchDBWrapper.java
License:Apache License
private JsonObject getResponse(SimpleHttpClient httpClient, String uri) { String response = getResponseString(httpClient, uri); JsonObject jsonObject = null;//from w w w . j a v a 2s .c om try { jsonObject = new JsonParser().parse(response).getAsJsonObject(); } catch (JsonParseException e) { logger.error("Response from " + uri + "is not a json"); } return jsonObject; }
From source file:com.appdynamics.monitors.boundary.BoundaryWrapper.java
License:Apache License
/** * Retrieves observation domain ids from the /meters REST request * @return Map A map containing the name of the meter and it's corresponding observationDomainId *//*from w w w. j a v a2s . co m*/ private void populateObservationDomainIds() throws Exception { HttpGet httpGet = new HttpGet(constructMetersURL()); httpGet.addHeader(BasicScheme.authenticate(new UsernamePasswordCredentials(apiKey, ""), "UTF-8", false)); HttpClient httpClient = new DefaultHttpClient(); HttpResponse response = httpClient.execute(httpGet); HttpEntity entity = response.getEntity(); BufferedReader bufferedReader2 = new BufferedReader(new InputStreamReader(entity.getContent())); StringBuilder responseString = new StringBuilder(); String line = ""; while ((line = bufferedReader2.readLine()) != null) { responseString.append(line); } JsonArray responseArray = new JsonParser().parse(responseString.toString()).getAsJsonArray(); for (int i = 0; i < responseArray.size(); i++) { JsonObject obj = responseArray.get(i).getAsJsonObject(); meterIds.put(obj.get("name").getAsString(), obj.get("obs_domain_id").getAsString()); } }
From source file:com.appdynamics.monitors.boundary.BoundaryWrapper.java
License:Apache License
/** * Retrieves network traffic data in the past minute from Boundary * @param observationIds A comma separated list of valid observationIds needed to make the historical API REST request * @return responseData A JsonArray containing all the ip_addresses, and their respective network traffic metrics */// w w w . j ava2s .c om private JsonArray getResponseData(String observationIds) throws Exception { String metricsURL = constructMetricsURL(); HttpPost httpPost = new HttpPost(metricsURL); httpPost.addHeader(BasicScheme.authenticate(new UsernamePasswordCredentials(apiKey, ""), "UTF-8", false)); // Request parameters and other properties. List<NameValuePair> params = new ArrayList<NameValuePair>(2); params.add(new BasicNameValuePair("aggregations", "observationDomainId")); params.add(new BasicNameValuePair("observationDomainIds", observationIds)); Long currentTime = System.currentTimeMillis(); Long oneMinuteAgo = currentTime - 60000; params.add(new BasicNameValuePair("from", oneMinuteAgo.toString())); params.add(new BasicNameValuePair("to", currentTime.toString())); httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); HttpClient httpClient = new DefaultHttpClient(); HttpResponse response = httpClient.execute(httpPost); HttpEntity entity = response.getEntity(); BufferedReader bufferedReader2 = new BufferedReader(new InputStreamReader(entity.getContent())); StringBuilder responseString = new StringBuilder(); String line = ""; while ((line = bufferedReader2.readLine()) != null) { responseString.append(line); } JsonObject responseObject = new JsonParser().parse(responseString.toString()).getAsJsonObject(); JsonArray responseData = responseObject.getAsJsonArray("data"); return responseData; }
From source file:com.appdynamics.monitors.varnish.VarnishWrapper.java
License:Apache License
/** * Gets the JsonObject by parsing the JSON return from hitting the /stats url * @return JsonObject containing the response from hitting the /stats url for Varnish * @throws Exception// ww w. j a va2 s.c om */ private JsonObject getResponseData() throws Exception { String metricsURL = constructVarnishStatsURL(); HttpGet httpGet = new HttpGet(metricsURL); httpGet.addHeader( BasicScheme.authenticate(new UsernamePasswordCredentials(username, password), "UTF-8", false)); HttpClient httpClient = new DefaultHttpClient(); HttpResponse response = httpClient.execute(httpGet); HttpEntity entity = response.getEntity(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(entity.getContent())); StringBuilder responseString = new StringBuilder(); String line = ""; while ((line = bufferedReader.readLine()) != null) { responseString.append(line); } JsonObject responseData = new JsonParser().parse(responseString.toString()).getAsJsonObject(); return responseData; }
From source file:com.appunity.ant.Utils.java
License:Apache License
protected static ProjectProfile getProfile(Task task, String profilePath) { ProjectProfile profile = null;//from w w w . j av a2s. c o m try { Gson gson = new Gson(); JsonParser parser = new JsonParser(); InputStreamReader reader = new InputStreamReader( new FileInputStream(obtainValidPath(task, profilePath, "project.profile")), "UTF-8"); JsonReader jsonReader = new JsonReader(reader); JsonObject asJsonObject = parser.parse(jsonReader).getAsJsonObject(); profile = gson.fromJson(asJsonObject.get("project"), ProjectProfile.class); } catch (FileNotFoundException ex) { Logger.getLogger(InitProjectTask.class.getName()).log(Level.SEVERE, null, ex); } catch (UnsupportedEncodingException ex) { Logger.getLogger(InitProjectTask.class.getName()).log(Level.SEVERE, null, ex); } catch (JsonIOException ex) { Logger.getLogger(InitProjectTask.class.getName()).log(Level.SEVERE, null, ex); } catch (JsonSyntaxException ex) { Logger.getLogger(InitProjectTask.class.getName()).log(Level.SEVERE, null, ex); } return profile; }