List of usage examples for com.fasterxml.jackson.databind.node ObjectNode toString
public String toString()
From source file:controllers.AnyplaceMapping.java
/** * Retrieve all the buildings that are inside the bounding box of the specified coordinates. * * @return/*from www. j a v a 2 s. c om*/ */ public static Result buildingCoordinates() { 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::buildingCoordinates(): " + json.toString()); List<String> requiredMissing = JsonUtils.requirePropertiesInJson(json, "coordinates_lat", "coordinates_lon"); if (!requiredMissing.isEmpty()) { return AnyResponseHelper.requiredFieldsMissing(requiredMissing); } try { List<JsonNode> buildings = ProxyDataSource.getIDatasource().getAllBuildingsNearMe( Double.parseDouble(json.path("coordinates_lat").textValue()), Double.parseDouble(json.path("coordinates_lon").textValue())); 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 near your position!"); } } catch (DatasourceException e) { return AnyResponseHelper.internal_server_error("Server Internal Error [" + e.getMessage() + "]"); } }
From source file:controllers.AnyplaceMapping.java
public static Result buildingGetOne() { OAuth2Request anyReq = new OAuth2Request(request(), response()); if (!anyReq.assertJsonBody()) { return AnyResponseHelper.bad_request(AnyResponseHelper.CANNOT_PARSE_BODY_AS_JSON); }//from w w w .jav a 2s . c om JsonNode json = anyReq.getJsonBody(); LPLogger.info("AnyplaceMapping::buildingGet(): " + json.toString()); List<String> requiredMissing = JsonUtils.requirePropertiesInJson(json, "buid"); if (!requiredMissing.isEmpty()) { return AnyResponseHelper.requiredFieldsMissing(requiredMissing); } String buid = json.findPath("buid").textValue(); try { JsonNode building = ProxyDataSource.getIDatasource().getFromKeyAsJson(buid); if (building != null && building.get("buid") != null && building.get("coordinates_lat") != null && building.get("coordinates_lon") != null && building.get("owner_id") != null && building.get("name") != null && building.get("description") != null && building.get("puid") == null && building.get("floor_number") == null) { ((ObjectNode) building).remove("owner_id"); ((ObjectNode) building).remove("co_owners"); ObjectNode res = JsonUtils.createObjectNode(); res.put("building", building); 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!"); } } return AnyResponseHelper.not_found("Building not found."); } catch (DatasourceException e) { return AnyResponseHelper.internal_server_error("Server Internal Error [" + e.getMessage() + "]"); } }
From source file:org.activiti.rest.service.api.runtime.TaskCollectionResourceTest.java
/** * Test creating a task. POST runtime/tasks *//*ww w . j av a2 s . c om*/ public void testCreateTask() throws Exception { try { Task parentTask = taskService.newTask(); taskService.saveTask(parentTask); ObjectNode requestNode = objectMapper.createObjectNode(); Calendar dueDate = Calendar.getInstance(); String dueDateString = getISODateString(dueDate.getTime()); requestNode.put("name", "New task name"); requestNode.put("description", "New task description"); requestNode.put("assignee", "assignee"); requestNode.put("owner", "owner"); requestNode.put("priority", 20); requestNode.put("delegationState", "resolved"); requestNode.put("dueDate", dueDateString); requestNode.put("parentTaskId", parentTask.getId()); requestNode.put("formKey", "testKey"); requestNode.put("tenantId", "test"); // Execute the request HttpPost httpPost = new HttpPost( SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION)); httpPost.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); String createdTaskId = responseNode.get("id").asText(); // Check if task is created with right arguments Task task = taskService.createTaskQuery().taskId(createdTaskId).singleResult(); assertEquals("New task name", task.getName()); assertEquals("New task description", task.getDescription()); assertEquals("assignee", task.getAssignee()); assertEquals("owner", task.getOwner()); assertEquals(20, task.getPriority()); assertEquals(DelegationState.RESOLVED, task.getDelegationState()); assertEquals(dateFormat.parse(dueDateString), task.getDueDate()); assertEquals(parentTask.getId(), task.getParentTaskId()); assertEquals("testKey", task.getFormKey()); assertEquals("test", task.getTenantId()); } finally { // Clean adhoc-tasks even if test fails List<Task> tasks = taskService.createTaskQuery().list(); for (Task task : tasks) { taskService.deleteTask(task.getId(), true); } } }
From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java
public static void includeElementField(String dbName, String field_name, String namespace, String elementName) throws Exception { ObjectMapper mapper = new ObjectMapper(); // ObjectNode mainNode = mapper.createObjectNode(); ObjectNode childNode = mapper.createObjectNode(); ArrayNode arrNode = mapper.createArrayNode(); ObjectNode childNodeObject = mapper.createObjectNode(); childNodeObject.put("namespace-uri", namespace); childNodeObject.put("localname", elementName); childNodeObject.put("weight", 1.0); arrNode.add(childNodeObject);/*from w w w . j av a2s. co m*/ childNode.putArray("included-element").addAll(arrNode); // mainNode.put("included-elements", childNode); System.out.println(childNode.toString()); setDatabaseFieldProperties(dbName, field_name, "included-element", childNode); }
From source file:controllers.AnyplaceMapping.java
public static Result getRadioHeatmapByBuildingFloor() { OAuth2Request anyReq = new OAuth2Request(request(), response()); if (!anyReq.assertJsonBody()) { return AnyResponseHelper.bad_request(AnyResponseHelper.CANNOT_PARSE_BODY_AS_JSON); }/*from ww w.ja v a2s . co m*/ JsonNode json = anyReq.getJsonBody(); LPLogger.info("AnyplaceMapping::getRadioHeatmap(): " + json.toString()); List<String> requiredMissing = JsonUtils.requirePropertiesInJson(json, "buid", "floor"); if (!requiredMissing.isEmpty()) { return AnyResponseHelper.requiredFieldsMissing(requiredMissing); } String buid = json.path("buid").textValue(); String floor = json.path("floor").textValue(); try { List<JsonNode> radioPoints = ProxyDataSource.getIDatasource().getRadioHeatmapByBuildingFloor(buid, floor); 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)); 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 radio points!"); } } catch (DatasourceException e) { return AnyResponseHelper.internal_server_error("Server Internal Error [" + e.getMessage() + "]"); } }
From source file:com.hrm.controller.RegisterController.java
/** * author qwc//from ww w . j a v a 2s . c om * 201741?12:49:43 * @param request * @param response * @throws IOException * ??? */ @RequestMapping("checkComName") public void checkComName(HttpServletRequest request, HttpServletResponse response) throws IOException { PrintWriter out = response.getWriter(); ObjectMapper mapper = new ObjectMapper(); ObjectNode checkStatus = mapper.createObjectNode(); int checkAmount = 0; String account = null; String enterpriseName = request.getParameter("enterpriseName"); if (enterpriseName != null) { account = enterpriseName; checkAmount = RTestDao.checkConName(account); } if (checkAmount > 0) { checkStatus.put("valid", false); out.write(checkStatus.toString());/*?*/ } else { checkStatus.put("valid", true); out.write(checkStatus.toString());/*?*/ } }
From source file:controllers.AnyplaceMapping.java
public static Result buildingAllByOwner() { OAuth2Request anyReq = new OAuth2Request(request(), response()); if (!anyReq.assertJsonBody()) { return AnyResponseHelper.bad_request(AnyResponseHelper.CANNOT_PARSE_BODY_AS_JSON); }// w w w . ja v a2s .c o m JsonNode json = anyReq.getJsonBody(); LPLogger.info("AnyplaceMapping::buildingAll(): " + json.toString()); List<String> requiredMissing = JsonUtils.requirePropertiesInJson(json, "access_token"); if (!requiredMissing.isEmpty()) { return AnyResponseHelper.requiredFieldsMissing(requiredMissing); } // get access token from url and check it against google's service if (json.findValue("access_token") == null) { return AnyResponseHelper.forbidden("Unauthorized"); } String owner_id = verifyOwnerId(json.findValue("access_token").textValue()); if (owner_id == null) { return AnyResponseHelper.forbidden("Unauthorized"); } owner_id = appendToOwnerId(owner_id); ((ObjectNode) json).put("owner_id", owner_id); if (owner_id == null || owner_id.isEmpty()) { return AnyResponseHelper.requiredFieldsMissing(requiredMissing); } try { List<JsonNode> buildings = ProxyDataSource.getIDatasource().getAllBuildingsByOwner(owner_id); 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.almende.eve.test.agents.Test2Agent.java
/** * Call myself./*w ww.j ava 2 s . co m*/ * * @param method * the method * @param params * the params * @return the string * @throws IOException * Signals that an I/O exception has occurred. * @throws JSONRPCException * the jSONRPC exception * @throws Exception * the exception */ public String callMyself(@Name("method") final String method, @Name("params") final ObjectNode params) throws IOException, JSONRPCException, Exception { final String resp = send(getMyUrl(), method, params, String.class); System.out.println("callMyself method=" + method + ", params=" + params.toString() + ", resp=" + resp); return resp; }
From source file:com.almende.eve.test.agents.Test2Agent.java
/** * On event./* www. j a v a 2 s. com*/ * * @param subscriptionId * the subscription id * @param agent * the agent * @param event * the event * @param params * the params * @throws Exception * the exception */ public void onEvent(@Optional @Name("subscriptionId") final String subscriptionId, @Optional @Name("agent") final String agent, @Optional @Name("event") final String event, @Optional @Name("params") final ObjectNode params) throws Exception { System.out.println("onEvent " + "subscriptionId=" + subscriptionId + ", " + "agent=" + agent + ", " + "event=" + event + ", " + "params=" + ((params != null) ? params.toString() : null)); final ObjectNode data = JOM.createObjectNode(); data.put("subscriptionId", subscriptionId); data.put("agent", agent); data.put("event", event); data.put("params", params); getEventsFactory().trigger("onEvent", data); }
From source file:com.almende.eve.test.agents.Test2Agent.java
/** * Call other agent./* w ww.j a va 2 s . c om*/ * * @param url * the url * @param method * the method * @param params * the params * @return the string * @throws IOException * Signals that an I/O exception has occurred. * @throws JSONRPCException * the jSONRPC exception * @throws Exception * the exception */ public String callOtherAgent(@Name("url") final String url, @Name("method") final String method, @Name("params") final ObjectNode params) throws IOException, JSONRPCException, Exception { final String resp = send(URI.create(url), method, params, String.class); System.out.println("callOtherAgent url=" + url + " method=" + method + ", params=" + params.toString() + ", resp=" + resp); return resp; }