List of usage examples for com.google.gson JsonObject getAsJsonArray
public JsonArray getAsJsonArray(String memberName)
From source file:eu.betaas.taas.securitymanager.taastrustmanager.taasproxy.TaaSCMClient.java
License:Apache License
public ArrayList<String> getEquivalentThingServices(String feature, ThingLocation location, String thingServiceId) {//from w ww . j av a 2 s .c om logger.debug("Loooking for equivalents related to " + thingServiceId); logger.debug("Calling Get Thing Services to the CM with feature " + feature + " in " + location.getLocationIdentifier()); ArrayList<String> myList = new ArrayList<String>(); try { // Retrieve the JasonArray object with the list String resList = null; if (location.getEnvironment()) { resList = myClient.getContextThingServices(feature, location.getLocationIdentifier(), location.getLocationKeyword(), location.getLatitude(), location.getLongitude(), location.getAltitude(), Float.toString(100.0f)); } else { resList = myClient.getContextThingServices(feature, location.getLocationIdentifier(), location.getLocationKeyword(), location.getFloor()); } logger.debug("Data received: " + resList); JsonElement jelement = new JsonParser().parse(resList); JsonObject parsedRes = jelement.getAsJsonObject(); JsonArray listArray = parsedRes.getAsJsonArray("list"); JsonArray listEqArray = parsedRes.getAsJsonArray("eq_list"); // Transform the JasonArray in an ArrayList and look for the current thing service int position = -1; for (int i = 0; i < listArray.size(); i++) { if (listArray.get(i).getAsString().equalsIgnoreCase(thingServiceId)) { // We found our thing service, so we take the position for the equivalents list position = i; break; } } if (position == -1) { // If the thing service didn't appear, then provide empty list logger.error("The thing service wasn't retrieved. Unable to find equivalents!"); return myList; } // Transform the Equivalent Services matrix in an ArrayList of ArrayList JsonArray currentList = listEqArray.get(position).getAsJsonArray(); for (int j = 0; j < currentList.size(); j++) { String currentEquivalent = currentList.get(j).getAsString(); if (!currentEquivalent.equalsIgnoreCase(thingServiceId)) { myList.add(currentEquivalent); } } } catch (Exception ex) { ex.printStackTrace(); return null; } logger.debug("Invocation done! Equivalents found: " + myList.size()); return myList; }
From source file:eu.betaas.taas.taasresourcesmanager.taasrmclient.TaaSCMClient.java
License:Apache License
public ThingServiceList getThingServices(String feature, Location location, String mode) { logger.info("Calling Get Thing Services to the CM with feature " + feature + " in " + location.getLocationIdentifier()); ThingServiceList myList = null;/*from w w w. j a v a2 s .co m*/ try { // Retrieve the JasonArray object with the list String resList = null; if (location.getEnvironment()) { resList = myClient.getContextThingServices(feature, location.getLocationIdentifier(), location.getLocationKeyword(), location.getLatitude(), location.getLongitude(), location.getAltitude(), Float.toString(location.getRadius())); } else { resList = myClient.getContextThingServices(feature, location.getLocationIdentifier(), location.getLocationKeyword(), location.getFloor()); } logger.debug("Data received: " + resList); JsonElement jelement = new JsonParser().parse(resList); JsonObject parsedRes = jelement.getAsJsonObject(); JsonArray listArray = parsedRes.getAsJsonArray("list"); JsonArray listEqArray = parsedRes.getAsJsonArray("eq_list"); String operator = parsedRes.get("operator").getAsString(); // Transform the JasonArray in an ArrayList ArrayList<String> myThingServicesList = new ArrayList<String>(); for (int i = 0; i < listArray.size(); i++) { myThingServicesList.add(listArray.get(i).getAsString()); } // Transform the Equivalent Services matrix in an ArrayList of ArrayList ArrayList<ArrayList<String>> myEqThingServicesList = new ArrayList<ArrayList<String>>(); for (int i = 0; i < listEqArray.size(); i++) { JsonArray currentList = listEqArray.get(i).getAsJsonArray(); ArrayList<String> currentResList = new ArrayList<String>(); for (int j = 0; j < currentList.size(); j++) { currentResList.add(currentList.get(j).getAsString()); } myEqThingServicesList.add(currentResList); } // Create ThingServiceList object myList = new ThingServiceList(); myList.setsOperator(operator); myList.setCMThingServicesList(myThingServicesList); myList.setCMThingServicesListEq(myEqThingServicesList); } catch (Exception ex) { ex.printStackTrace(); return null; } logger.info("Invocation done!"); logger.info("Operator: " + myList.getsOperator()); return myList; }
From source file:eu.betaas.taas.taasresourcesmanager.taasrmclient.TaaSCMClient.java
License:Apache License
public ArrayList<String> getThingServices() { logger.info("Calling Get Thing Services to the CM for getting the full list"); ArrayList<String> myList = null; try {/*from w w w .ja va 2 s . c o m*/ // Retrieve the JasonArray object with the list String resList = myClient.getContextThingServices(); JsonElement jelement = new JsonParser().parse(resList); JsonObject parsedRes = jelement.getAsJsonObject(); JsonArray listArray = parsedRes.getAsJsonArray("list"); // Transform the JasonArray in an ArrayList myList = new ArrayList<String>(); for (int i = 0; i < listArray.size(); i++) { myList.add(listArray.get(i).getAsString()); } } catch (Exception ex) { ex.printStackTrace(); return null; } logger.info("Invocation done! Retrieved: " + myList.size()); return myList; }
From source file:eu.over9000.skadi.remote.VersionRetriever.java
License:Open Source License
public static RemoteVersionResult getLatestVersion() { try {/*from w w w . j a va 2s . co m*/ final URI URL = new URI(API_URL); final HttpResponse response = httpClient.execute(new HttpGet(URL)); final String responseString = new BasicResponseHandler().handleResponse(response); final JsonArray tagsArray = parser.parse(responseString).getAsJsonArray(); final JsonObject latest = tagsArray.get(0).getAsJsonObject(); final JsonObject latestFiles = latest.getAsJsonArray("assets").get(0).getAsJsonObject(); final String downloadURL = latestFiles.get("browser_download_url").getAsString(); final int downloadSize = latestFiles.get("size").getAsInt(); final String version = latest.get("tag_name").getAsString(); final String published = latest.get("published_at").getAsString(); final String changeLog = latest.get("body").getAsString(); return new RemoteVersionResult(version, published, downloadURL, changeLog, downloadSize); } catch (Exception e) { LOGGER.error("VersionRetriever exception", e); return null; } }
From source file:eu.over9000.skadi.service.ImportFollowedService.java
License:Open Source License
private void parseAndAddChannelsToSet(final Set<String> channels, final JsonObject responseObject) { final JsonArray follows = responseObject.getAsJsonArray("follows"); for (final JsonElement jsonElement : follows) { final String followed_url = jsonElement.getAsJsonObject().getAsJsonObject("channel").get("name") .getAsString();//from www. jav a2 s. c om channels.add(followed_url); } }
From source file:eu.seaclouds.platform.dashboard.resources.SlaResource.java
License:Apache License
@GET @Path("agreements/{id}/status") public Response getAgreementStatus(@PathParam("id") String id) { if (id != null) { try {/* w w w . ja v a 2 s . co m*/ // Get guarantee status String slaResponse = new HttpGetRequestBuilder().host(sla.getEndpoint()) .path("/agreements/" + id + "/guaranteestatus") .addHeader("Content-Type", "application/json").addHeader("Accept", "application/json") .build(); JsonObject agreementStatusJson = new JsonParser().parse(slaResponse).getAsJsonObject(); JsonArray terms = agreementStatusJson.getAsJsonArray("guaranteeterms"); for (JsonElement term : terms) { String guaranteeTermName = term.getAsJsonObject().get("name").getAsString(); String guaranteeTermStatus = term.getAsJsonObject().get("status").getAsString(); if (guaranteeTermStatus.equals("VIOLATED")) { slaResponse = new HttpGetRequestBuilder().host(sla.getEndpoint()) .addParam("agreementId", id).addParam("guaranteeTerm", guaranteeTermName) .path("/violations").addHeader("Content-Type", "application/json") .addHeader("Accept", "application/json").build(); term.getAsJsonObject().add("violations", new JsonParser().parse(slaResponse)); } else { term.getAsJsonObject().add("violations", new JsonArray()); } } return Response.ok(agreementStatusJson.toString()).build(); } catch (IOException | URISyntaxException e) { log.error(e.getMessage()); return Response.status(Response.Status.NOT_FOUND).build(); } } else { return Response.status(Response.Status.NOT_FOUND).build(); } }
From source file:eu.smartfp7.terrier.sensor.ParserUtility.java
License:Mozilla Public License
public static EdgeNodeSnapShot parseJSON(String json) throws Exception { /*/*w w w . j av a2 s . co m*/ * {"activity":{"name":"#lab_visits","isActive":"false","date":"26-07-2012","temporalHint":["07:00","08:00"]},"crowd":{"time":"2012-07-26T07:25:50.650Z","density":"0.000560","motion_horizontal":"-1","motion_vertical":"-1", * "motion_spread":"-1.000000","color":["6316128.087100","2097152.068100","4219008.049900", * "14729408.046900","2105376.042900","8256.041800","2113632.037800","0.037500","4210752.033700","10526944.032100", * "10535136.029100","8429792.028800","8224.027900","2105408.027500","4210784.026400","4202592.022200"]}}}, * * */ JsonElement jelement = new JsonParser().parse(json); JsonObject jobject = jelement.getAsJsonObject().getAsJsonObject("crowd"); String time = (String) jobject.get("time").getAsString(); DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); Calendar c = Calendar.getInstance(); ; c.setTime(df.parse(time)); String density = (String) jobject.get("density").toString(); double[] colors = null; if (jobject.has("color")) { JsonArray jarray = jobject.getAsJsonArray("color"); colors = new double[jarray.size()]; for (int i = 0; i < jarray.size(); i++) { String v = jarray.get(0).getAsString(); colors[i] = new Double(v); } } String activity = null; if (jelement.getAsJsonObject().has("activity")) { activity = jelement.getAsJsonObject().getAsJsonObject("activity").get("name").getAsString(); } CrowdReport crowdReport = new CrowdReport(null, new Double(density), 0.0, colors); EdgeNodeSnapShot snapShot = new EdgeNodeSnapShot(null, null, c, crowdReport); snapShot.setText((activity != null ? activity : StringUtils.EMPTY)); return snapShot; }
From source file:fi.vtt.nubomedia.armodule.Ar3DHandler.java
License:Open Source License
private java.util.List<ArThing> createArThings(JsonObject jsonObjects) { System.err.println("*createARThings:#" + jsonObjects + "#"); List<ArThing> arThings = new ArrayList<ArThing>(); JsonArray jsonArray = jsonObjects.getAsJsonArray("augmentables"); Iterator<JsonElement> itr = jsonArray.iterator(); while (itr.hasNext()) { JsonElement jsonElm = itr.next(); if (jsonElm.isJsonNull()) { System.err.println("Really Skip null"); continue; }/*from ww w .j a va 2s . c o m*/ System.err.println("Got: " + jsonElm); JsonObject jsonObject = jsonElm.getAsJsonObject(); int id = jsonObject.get("id").getAsInt(); OverlayType augmentableType; switch (jsonObject.get("type").getAsString()) { case "2D": augmentableType = OverlayType.TYPE2D; break; case "3D": augmentableType = OverlayType.TYPE3D; break; default: throw new RuntimeException("Bizarre OverlayType: " + jsonObject.get("type").getAsString()); } List<ArKvpString> strings = new ArrayList<ArKvpString>(); List<ArKvpFloat> floats = new ArrayList<ArKvpFloat>(); List<ArKvpInteger> integers = new ArrayList<ArKvpInteger>(); createKVPs(jsonObject, strings, integers, floats); ArThing arThing = new ArThing(id, augmentableType, strings, integers, floats); arThings.add(arThing); } System.err.println("*ResultArThigs: " + arThings.size() + "#" + arThings); return arThings; }
From source file:fi.vtt.nubomedia.armodule.Ar3DHandler.java
License:Open Source License
private void pose(WebSocketSession session, JsonObject jsonMessage) { try {/*from ww w. ja v a2 s . c o m*/ System.err.println("json POSE from browser"); ArMarkerdetector arFilter = getArFilter(session); if (arFilter == null) { log.error("Start the filter first"); return; } String json = jsonMessage.getAsJsonPrimitive("pose").getAsString(); System.err.println("json:\n" + json); JsonObject jsonObjects = gson.fromJson(json, JsonObject.class); JsonArray jsonArray = jsonObjects.getAsJsonArray("pose"); Iterator<JsonElement> itr = jsonArray.iterator(); while (itr.hasNext()) { JsonElement jsonElm = itr.next(); if (jsonElm.isJsonNull()) { System.err.println("Really Skip null"); continue; } System.err.println("Got: " + jsonElm); JsonObject jsonObject = jsonElm.getAsJsonObject(); int id = jsonObject.get("id").getAsInt(); int type = jsonObject.get("type").getAsInt(); //String id = jsonObject.get("id").getAsString(); //String type = jsonObject.get("type").getAsString(); float value = jsonObject.get("value").getAsFloat(); System.err.println("" + id + "#" + type + "#" + value); arFilter.setPose(id, type, value); } } catch (Throwable t) { t.printStackTrace(); error(session, t.getMessage()); } }
From source file:fi.vtt.nubomedia.kurento.Ar3DHandler.java
License:Open Source License
private java.util.List<ArThing> createArThings(JsonObject jsonObjects) { System.err.println(jsonObjects); List<ArThing> arThings = new ArrayList<ArThing>(); JsonArray jsonArray = jsonObjects.getAsJsonArray("augmentables"); Iterator<JsonElement> itr = jsonArray.iterator(); while (itr.hasNext()) { JsonElement jsonElm = itr.next(); if (jsonElm.isJsonNull()) { System.err.println("Really Skip null"); continue; }// w w w. j av a 2 s.c o m System.err.println("Skip: " + jsonElm); JsonObject jsonObject = jsonElm.getAsJsonObject(); int id = jsonObject.get("id").getAsInt(); OverlayType augmentableType; switch (jsonObject.get("type").getAsString()) { case "2D": augmentableType = OverlayType.TYPE2D; break; case "3D": augmentableType = OverlayType.TYPE3D; break; default: throw new RuntimeException("Bizarre OverlayType: " + jsonObject.get("type").getAsString()); } List<ArKvpString> strings = new ArrayList<ArKvpString>(); List<ArKvpFloat> floats = new ArrayList<ArKvpFloat>(); List<ArKvpInteger> integers = new ArrayList<ArKvpInteger>(); createKVPs(jsonObject, strings, integers, floats); ArThing arThing = new ArThing(id, augmentableType, strings, integers, floats); arThings.add(arThing); } return arThings; // return createArThings(new int[]{ // 0, // 1, // 2 // }, // new OverlayType[]{ // OverlayType.TYPE3D, // OverlayType.TYPE3D, // OverlayType.TYPE2D // }, // new String[]{ // // //"http://130.188.198.150:9090/icosahedron.ply", // "/opt/teapot.ply", // "/opt/cube.ply", // "/opt/propex.png" // }, // new float[]{ // 1.0f, // 0.05f, // 1.0f // }, // new String[]{ // "", // "", // "snafu" // }); }