List of usage examples for com.fasterxml.jackson.databind JsonNode toString
public abstract String toString();
From source file:com.amazonaws.services.iot.client.shadow.AwsIotDeviceDeltaListener.java
@Override public void onMessage(AWSIotMessage message) { String payload = message.getStringPayload(); if (payload == null) { LOGGER.warning("Received empty delta for device " + device.getThingName()); return;// ww w .j a v a2s . c om } JsonNode rootNode; try { rootNode = device.getJsonObjectMapper().readTree(payload); if (!rootNode.isObject()) { throw new IOException(); } } catch (IOException e) { LOGGER.warning("Received invalid delta for device " + device.getThingName()); return; } if (device.enableVersioning) { JsonNode node = rootNode.get("version"); if (node == null) { LOGGER.warning("Missing version field in delta for device " + device.getThingName()); return; } long receivedVersion = node.longValue(); long localVersion = device.getLocalVersion().get(); if (receivedVersion < localVersion) { LOGGER.warning("An old version of delta received for " + device.getThingName() + ", local " + localVersion + ", received " + receivedVersion); return; } device.getLocalVersion().set(receivedVersion); LOGGER.info("Local version number updated to " + receivedVersion); } JsonNode node = rootNode.get("state"); if (node == null) { LOGGER.warning("Missing state field in delta for device " + device.getThingName()); return; } device.onShadowUpdate(node.toString()); }
From source file:com.spoiledmilk.ibikecph.map.MapActivity.java
public void startRouting(Location start, Location end, JsonNode jsonRoot, String startName, String endName) { Intent i = new Intent(this, getNavigationClass()); i.putExtra("start_lat", start.getLatitude()); i.putExtra("start_lng", start.getLongitude()); i.putExtra("end_lat", end.getLatitude()); i.putExtra("end_lng", end.getLongitude()); if (jsonRoot != null) i.putExtra("json_root", jsonRoot.toString()); i.putExtra("source", source); i.putExtra("destination", destination); if (jsonRoot != null && jsonRoot.has("route_summary")) { i.putExtra("start_name", jsonRoot.get("route_summary").get("start_point").asText()); i.putExtra("end_name", jsonRoot.get("route_summary").get("end_point").asText()); } else {//from ww w . j ava 2s . c o m i.putExtra("start_name", startName); i.putExtra("end_name", endName); } i.putExtra("overlays", getOverlaysShown()); new DB(MapActivity.this).saveSearchHistory( new HistoryData(infoLine1, end.getLatitude(), end.getLongitude()), new HistoryData(IbikeApplication.getString("current_position"), start.getLatitude(), start.getLongitude()), MapActivity.this); this.startActivityForResult(i, 1); overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left); LOG.d("route found"); }
From source file:controllers.AnyplaceMapping.java
public static Result getRadioHeatmap() { OAuth2Request anyReq = new OAuth2Request(request(), response()); if (!anyReq.assertJsonBody()) { return AnyResponseHelper.bad_request(AnyResponseHelper.CANNOT_PARSE_BODY_AS_JSON); }/*from w w w. j a va 2 s . c o m*/ JsonNode json = anyReq.getJsonBody(); LPLogger.info("AnyplaceMapping::getRadioHeatmap(): " + json.toString()); try { List<JsonNode> radioPoints = ProxyDataSource.getIDatasource().getRadioHeatmap(); if (radioPoints == null) { return AnyResponseHelper.bad_request("Building does not exist or could not be retrieved!"); } ObjectNode res = JsonUtils.createObjectNode(); res.put("radioPoints", JsonUtils.getJsonFromList(radioPoints)); return AnyResponseHelper.ok(res, "Successfully retrieved all radio points!"); } catch (DatasourceException e) { return AnyResponseHelper.internal_server_error("Server Internal Error [" + e.getMessage() + "]"); } }
From source file:controllers.AnyplaceMapping.java
public static Result deleteRadiosInBox() { OAuth2Request anyReq = new OAuth2Request(request(), response()); if (!anyReq.assertJsonBody()) { return AnyResponseHelper.bad_request(AnyResponseHelper.CANNOT_PARSE_BODY_AS_JSON); }// w ww . ja va 2 s . c om JsonNode json = anyReq.getJsonBody(); LPLogger.info("AnyplaceMapping::deleteRadiosInBox(): " + json.toString()); try { if (!ProxyDataSource.getIDatasource().deleteRadiosInBox()) { return AnyResponseHelper.bad_request("Building already exists or could not be added!"); } return AnyResponseHelper.ok("Success"); } catch (DatasourceException e) { return AnyResponseHelper.internal_server_error("Server Internal Error [" + e.getMessage() + "]"); } }
From source file:controllers.AnyplaceMapping.java
/** * Retrieve all the buildings./* w w w.j a v a2s.c o m*/ * * @return */ public static Result buildingAll() { OAuth2Request anyReq = new OAuth2Request(request(), response()); if (!anyReq.assertJsonBody()) { return AnyResponseHelper.bad_request(AnyResponseHelper.CANNOT_PARSE_BODY_AS_JSON); } JsonNode json = anyReq.getJsonBody(); LPLogger.info("AnyplaceMapping::buildingAll(): " + json.toString()); try { List<JsonNode> buildings = ProxyDataSource.getIDatasource().getAllBuildings(); ObjectNode res = JsonUtils.createObjectNode(); res.put("buildings", JsonUtils.getJsonFromList(buildings)); try { // if (request().getHeader("Accept-Encoding") != null && request().getHeader("Accept-Encoding").contains("gzip")) { return gzippedJSONOk(res.toString()); // } // return AnyResponseHelper.ok(res.toString()); } catch (IOException ioe) { return AnyResponseHelper.ok(res, "Successfully retrieved all buildings!"); } } catch (DatasourceException e) { return AnyResponseHelper.internal_server_error("Server Internal Error [" + e.getMessage() + "]"); } }
From source file:com.ikanow.aleph2.analytics.storm.services.MockAnalyticsContext.java
@Override public Validation<BasicMessageBean, JsonNode> sendObjectToStreamingPipeline( final Optional<DataBucketBean> bucket, final AnalyticThreadJobBean job, final Either<JsonNode, Map<String, Object>> object, final Optional<AnnotationBean> annotations) { if (annotations.isPresent()) { throw new RuntimeException(ErrorUtils.NOT_YET_IMPLEMENTED); }/*from ww w. j a v a 2s. c o m*/ final JsonNode obj_json = object.either(__ -> __, map -> (JsonNode) _mapper.convertValue(map, JsonNode.class)); return this.getOutputTopic(bucket, job).<Validation<BasicMessageBean, JsonNode>>map(topic -> { if (_distributed_services.doesTopicExist(topic)) { // (ie someone is listening in on our output data, so duplicate it for their benefit) _distributed_services.produce(topic, obj_json.toString()); return Validation.success(obj_json); } else { return Validation.fail(ErrorUtils.buildSuccessMessage(this.getClass().getSimpleName(), "sendObjectToStreamingPipeline", "Bucket:job {0}:{1} topic {2} has no listeners", bucket.map(b -> b.full_name()).orElse("(unknown)"), job.name(), topic)); } }).orElseGet(() -> { return Validation.fail(ErrorUtils.buildErrorMessage(this.getClass().getSimpleName(), "sendObjectToStreamingPipeline", "Bucket:job {0}:{1} has no output topic", bucket.map(b -> b.full_name()).orElse("(unknown)"), job.name())); }); }
From source file:controllers.AnyplaceMapping.java
/** * Returns the floor plan (png) for the requested building floor in binary format. * Used by the Android client - NOT ANYMORE * * @param buid Building id/*from ww w . j a v a 2s .c om*/ * @param floor_number floor number inside the above building * @return the file or an error */ public static Result serveFloorPlanBinary(String buid, String floor_number) { OAuth2Request anyReq = new OAuth2Request(request(), response()); if (!anyReq.assertJsonBody()) { return AnyResponseHelper.bad_request(AnyResponseHelper.CANNOT_PARSE_BODY_AS_JSON); } JsonNode json = anyReq.getJsonBody(); LPLogger.info("AnyplaceMapping::serveFloorPlan(): " + json.toString()); String filePath = AnyPlaceTilerHelper.getFloorPlanFor(buid, floor_number); LPLogger.info("requested: " + filePath); try { File file = new java.io.File(filePath); if (!file.exists() || !file.canRead()) { return AnyResponseHelper.bad_request( "Requested floor plan does not exist or cannot be read! (" + floor_number + ")"); } InputStream a = new FileInputStream(file); return ok(a); } catch (FileNotFoundException e) { // cannot get in here i think cause of the check if canRead() return AnyResponseHelper.internal_server_error("Could not read floor plan."); } }
From source file:controllers.AnyplaceMapping.java
/** * Retrieve all the floors of a building. * * @return//from w w w . j a v a 2 s . c om */ public static Result floorAll() { OAuth2Request anyReq = new OAuth2Request(request(), response()); if (!anyReq.assertJsonBody()) { return AnyResponseHelper.bad_request(AnyResponseHelper.CANNOT_PARSE_BODY_AS_JSON); } JsonNode json = anyReq.getJsonBody(); LPLogger.info("AnyplaceMapping::floorAll(): " + json.toString()); List<String> requiredMissing = JsonUtils.requirePropertiesInJson(json, "buid"); if (!requiredMissing.isEmpty()) { return AnyResponseHelper.requiredFieldsMissing(requiredMissing); } String buid = json.findPath("buid").textValue(); try { List<JsonNode> buildings = ProxyDataSource.getIDatasource().floorsByBuildingAsJson(buid); ObjectNode res = JsonUtils.createObjectNode(); res.put("floors", JsonUtils.getJsonFromList(buildings)); try { // if (request().getHeader("Accept-Encoding") != null && request().getHeader("Accept-Encoding").contains("gzip")) { return gzippedJSONOk(res.toString()); // } // return AnyResponseHelper.ok(res.toString()); } catch (IOException ioe) { return AnyResponseHelper.ok(res, "Successfully retrieved all floors!"); } } catch (DatasourceException e) { return AnyResponseHelper.internal_server_error("Server Internal Error [" + e.getMessage() + "]"); } }
From source file:controllers.AnyplaceMapping.java
/** * Retrieve all the pois of a building/floor combination. * * @return/* ww w . jav a 2s . com*/ */ public static Result poisByBuid() { OAuth2Request anyReq = new OAuth2Request(request(), response()); if (!anyReq.assertJsonBody()) { return AnyResponseHelper.bad_request(AnyResponseHelper.CANNOT_PARSE_BODY_AS_JSON); } JsonNode json = anyReq.getJsonBody(); LPLogger.info("AnyplaceMapping::poisByBuid(): " + json.toString()); List<String> requiredMissing = JsonUtils.requirePropertiesInJson(json, "buid"); if (!requiredMissing.isEmpty()) { return AnyResponseHelper.requiredFieldsMissing(requiredMissing); } String buid = json.findPath("buid").textValue(); try { List<JsonNode> pois = ProxyDataSource.getIDatasource().poisByBuildingAsJson(buid); ObjectNode res = JsonUtils.createObjectNode(); res.put("pois", JsonUtils.getJsonFromList(pois)); try { // if (request().getHeader("Accept-Encoding") != null && request().getHeader("Accept-Encoding").contains("gzip")) { return gzippedJSONOk(res.toString()); // } // return AnyResponseHelper.ok(res.toString()); } catch (IOException ioe) { return AnyResponseHelper.ok(res, "Successfully retrieved all pois from building."); } } catch (DatasourceException e) { return AnyResponseHelper.internal_server_error("Server Internal Error [" + e.getMessage() + "]"); } }
From source file:controllers.AnyplaceMapping.java
public static Result buildingByBucode() { OAuth2Request anyReq = new OAuth2Request(request(), response()); if (!anyReq.assertJsonBody()) { return AnyResponseHelper.bad_request(AnyResponseHelper.CANNOT_PARSE_BODY_AS_JSON); }//from w w w . j av a 2 s .c om JsonNode json = anyReq.getJsonBody(); LPLogger.info("AnyplaceMapping::buildingAll(): " + json.toString()); List<String> requiredMissing = JsonUtils.requirePropertiesInJson(json, "bucode"); if (!requiredMissing.isEmpty()) { return AnyResponseHelper.requiredFieldsMissing(requiredMissing); } String bucode = json.findValue("bucode").textValue(); try { List<JsonNode> buildings = ProxyDataSource.getIDatasource().getAllBuildingsByBucode(bucode); ObjectNode res = JsonUtils.createObjectNode(); res.put("buildings", JsonUtils.getJsonFromList(buildings)); try { // if (request().getHeader("Accept-Encoding") != null && request().getHeader("Accept-Encoding").contains("gzip")) { return gzippedJSONOk(res.toString()); // } // return AnyResponseHelper.ok(res.toString()); } catch (IOException ioe) { return AnyResponseHelper.ok(res, "Successfully retrieved all buildings!"); } } catch (DatasourceException e) { return AnyResponseHelper.internal_server_error("Server Internal Error [" + e.getMessage() + "]"); } }