List of usage examples for com.fasterxml.jackson.databind.node JsonNodeFactory instance
JsonNodeFactory instance
To view the source code for com.fasterxml.jackson.databind.node JsonNodeFactory instance.
Click Source Link
From source file:com.redhat.lightblue.metadata.parser.JSONMetadataParserTest.java
License:asdf
@Test public void testParseConvertValueGenerator() throws IOException { JsonNode object = loadJsonNode("JSONMetadataParserTest-valuegenerator.json"); EntitySchema em = parser.parseEntitySchema(object); SimpleField field = (SimpleField) em.resolve(new Path("name")); Assert.assertNotNull(field);/*from w w w. j a v a2 s.c o m*/ ValueGenerator vg = field.getValueGenerator(); Assert.assertNotNull(vg); Assert.assertEquals(ValueGenerator.ValueGeneratorType.IntSequence, vg.getValueGeneratorType()); Assert.assertEquals("seq", vg.getProperties().get("name")); Assert.assertEquals("1000", vg.getProperties().get("initialValue").toString()); ObjectNode obj = JsonNodeFactory.instance.objectNode(); parser.convertValueGenerator(vg, obj); obj = (ObjectNode) obj.get("valueGenerator"); System.out.println(obj); Assert.assertEquals(ValueGenerator.ValueGeneratorType.IntSequence.toString(), obj.get("type").asText()); ObjectNode props = (ObjectNode) obj.get("configuration"); Assert.assertEquals("seq", props.get("name").asText()); Assert.assertEquals("1000", props.get("initialValue").asText()); }
From source file:org.apache.usergrid.client.EntityTestCase.java
@Test public void testEntityInsertInArray() { String collectionName = "testEntityProperties" + System.currentTimeMillis(); String entityName = "testEntity1"; //should set properties for a given object, overwriting properties that exist and creating those that don\'t UsergridEntity entity = new UsergridEntity(collectionName, entityName); entity.save();//from w w w . ja v a 2 s.co m ArrayList<Object> lenArr = new ArrayList<>(); lenArr.add(1); lenArr.add(2); lenArr.add(3); lenArr.add(4); entity.putProperty("lenArray", lenArr); entity.save(); ArrayList<Object> lenArr2 = new ArrayList<>(); lenArr2.add(6); lenArr2.add(7); entity.insert("lenArray", lenArr2, 6); entity.save(); UsergridEntity eLookUp = Usergrid.GET(collectionName, entityName).first(); assertNotNull("The entity returned is not null.", eLookUp); ArrayNode toCompare = new ArrayNode(JsonNodeFactory.instance); toCompare.add(1).add(2).add(3).add(4).add(6).add(7); assertEquals("The two arrays should be equal.", eLookUp.getJsonNodeProperty("lenArray"), toCompare); //should merge an array of values into an existing array at the specified index lenArr = new ArrayList<>(); lenArr.add(1); lenArr.add(2); lenArr.add(3); lenArr.add(4); entity.putProperty("lenArray", lenArr); entity.save(); lenArr2 = new ArrayList<>(); lenArr2.add(5); lenArr2.add(6); lenArr2.add(7); lenArr2.add(8); entity.insert("lenArray", lenArr2, 2); entity.save(); eLookUp = Usergrid.GET(collectionName, entityName).first(); assertNotNull("The entity returned is not null.", eLookUp); toCompare = new ArrayNode(JsonNodeFactory.instance); toCompare.add(1).add(2).add(5).add(6).add(7).add(8).add(3).add(4); assertEquals("The two arrays should be equal.", eLookUp.getJsonNodeProperty("lenArray"), toCompare); //should convert an existing value into an array when inserting a second value entity.putProperty("foo", "test"); entity.insert("foo", "test1", 1); entity.save(); eLookUp = Usergrid.GET(collectionName, entityName).first(); assertNotNull("The entity returned is not null.", eLookUp); toCompare = new ArrayNode(JsonNodeFactory.instance); toCompare.add("test").add("test1"); assertEquals("The two arrays should be equal.", eLookUp.getJsonNodeProperty("foo"), toCompare); //should create a new array when a property does not exist entity.insert("foo1", "test2", 1); entity.save(); eLookUp = Usergrid.GET(collectionName, entityName).first(); assertNotNull("The entity returned is not null.", eLookUp); toCompare = new ArrayNode(JsonNodeFactory.instance); toCompare.add("test2"); assertEquals("The two arrays should be equal.", eLookUp.getJsonNodeProperty("foo1"), toCompare); //should gracefully handle index out of positive range entity.putProperty("ArrayIndex", "test1"); entity.insert("ArrayIndex", "test2", 1000); entity.save(); eLookUp = Usergrid.GET(collectionName, entityName).first(); assertNotNull("The entity returned is not null.", eLookUp); toCompare = new ArrayNode(JsonNodeFactory.instance); toCompare.add("test1").add("test2"); assertEquals("The two arrays should be equal.", eLookUp.getJsonNodeProperty("ArrayIndex"), toCompare); //should gracefully handle index out of negative range entity.insert("ArrayIndex", "test3", -1000); entity.save(); eLookUp = Usergrid.GET(collectionName, entityName).first(); assertNotNull("The entity returned is not null.", eLookUp); toCompare = new ArrayNode(JsonNodeFactory.instance); toCompare.add("test3").add("test1").add("test2"); assertEquals("The two arrays should be equal.", eLookUp.getJsonNodeProperty("ArrayIndex"), toCompare); }
From source file:org.jetbrains.webdemo.database.MySqlConnector.java
public ArrayNode getProjectHeaders(UserInfo userInfo, String projectType) throws DatabaseOperationException { PreparedStatement st = null;// ww w.j av a 2 s .c o m ResultSet rs = null; try (Connection connection = dataSource.getConnection()) { st = connection.prepareStatement("SELECT projects.public_id, projects.name FROM projects JOIN " + "users ON projects.owner_id = users.id WHERE " + "(users.client_id = ? AND users.provider = ? AND projects.type = ?)"); st.setString(1, userInfo.getId()); st.setString(2, userInfo.getType()); st.setString(3, projectType); rs = st.executeQuery(); ArrayNode projects = new ArrayNode(JsonNodeFactory.instance); while (rs.next()) { ObjectNode object = new ObjectNode(JsonNodeFactory.instance); object.put("name", unEscape(rs.getString("name"))); object.put("publicId", rs.getString("public_id")); object.put("modified", false); projects.add(object); } return projects; } catch (Throwable e) { ErrorWriter.ERROR_WRITER.writeExceptionToExceptionAnalyzer(e, SessionInfo.TypeOfRequest.WORK_WITH_DATABASE.name(), "unknown", userInfo.getId() + " " + userInfo.getType() + " " + userInfo.getName()); throw new DatabaseOperationException("Unknown error while loading list of your programs"); } finally { closeStatementAndResultSet(st, rs); } }
From source file:com.spotify.docker.client.DefaultDockerClient.java
@Override public InputStream copyContainer(String containerId, String path) throws DockerException, InterruptedException { final WebTarget resource = resource().path("containers").path(containerId).path("copy"); // Internal JSON object; not worth it to create class for this JsonNodeFactory nf = JsonNodeFactory.instance; final JsonNode params = nf.objectNode().set("Resource", nf.textNode(path)); return request(POST, InputStream.class, resource, resource.request(APPLICATION_OCTET_STREAM_TYPE), Entity.json(params)); }
From source file:io.gs2.matchmaking.Gs2MatchmakingClient.java
/** * ????<br>/* w w w . j a v a 2 s . c o m*/ * <br> * * @param request * @return ? */ public UpdateMatchmakingResult updateMatchmaking(UpdateMatchmakingRequest request) { ObjectNode body = JsonNodeFactory.instance.objectNode().put("serviceClass", request.getServiceClass()); if (request.getDescription() != null) body.put("description", request.getDescription()); if (request.getGatheringPoolName() != null) body.put("gatheringPoolName", request.getGatheringPoolName()); if (request.getCallback() != null) body.put("callback", request.getCallback()); if (request.getNotificationGameName() != null) body.put("notificationGameName", request.getNotificationGameName()); if (request.getCreateGatheringTriggerScript() != null) body.put("createGatheringTriggerScript", request.getCreateGatheringTriggerScript()); if (request.getCreateGatheringDoneTriggerScript() != null) body.put("createGatheringDoneTriggerScript", request.getCreateGatheringDoneTriggerScript()); if (request.getJoinGatheringTriggerScript() != null) body.put("joinGatheringTriggerScript", request.getJoinGatheringTriggerScript()); if (request.getJoinGatheringDoneTriggerScript() != null) body.put("joinGatheringDoneTriggerScript", request.getJoinGatheringDoneTriggerScript()); if (request.getLeaveGatheringTriggerScript() != null) body.put("leaveGatheringTriggerScript", request.getLeaveGatheringTriggerScript()); if (request.getLeaveGatheringDoneTriggerScript() != null) body.put("leaveGatheringDoneTriggerScript", request.getLeaveGatheringDoneTriggerScript()); if (request.getBreakupGatheringTriggerScript() != null) body.put("breakupGatheringTriggerScript", request.getBreakupGatheringTriggerScript()); if (request.getMatchmakingCompleteTriggerScript() != null) body.put("matchmakingCompleteTriggerScript", request.getMatchmakingCompleteTriggerScript()); HttpPut put = createHttpPut( Gs2Constant.ENDPOINT_HOST + "/matchmaking/" + (request.getMatchmakingName() == null || request.getMatchmakingName().equals("") ? "null" : request.getMatchmakingName()) + "", credential, ENDPOINT, UpdateMatchmakingRequest.Constant.MODULE, UpdateMatchmakingRequest.Constant.FUNCTION, body.toString()); if (request.getRequestId() != null) { put.setHeader("X-GS2-REQUEST-ID", request.getRequestId()); } return doRequest(put, UpdateMatchmakingResult.class); }
From source file:io.gs2.matchmaking.Gs2MatchmakingClient.java
/** * ???????<br>//from ww w . j av a2 s . c o m * <br> * ?8????????????<br> * ???100??????????<br> * ???????????<br> * <br> * - : 10<br> * <br> * * @param request * @return ? */ public PasscodeCreateGatheringResult passcodeCreateGathering(PasscodeCreateGatheringRequest request) { ObjectNode body = JsonNodeFactory.instance.objectNode(); HttpPost post = createHttpPost( Gs2Constant.ENDPOINT_HOST + "/matchmaking/" + (request.getMatchmakingName() == null || request.getMatchmakingName().equals("") ? "null" : request.getMatchmakingName()) + "/passcode", credential, ENDPOINT, PasscodeCreateGatheringRequest.Constant.MODULE, PasscodeCreateGatheringRequest.Constant.FUNCTION, body.toString()); if (request.getRequestId() != null) { post.setHeader("X-GS2-REQUEST-ID", request.getRequestId()); } post.setHeader("X-GS2-ACCESS-TOKEN", request.getAccessToken()); return doRequest(post, PasscodeCreateGatheringResult.class); }
From source file:com.heliosapm.tsdblite.json.JSON.java
/** * Returns a shareable node factory * @return a json node factory */ public static JsonNodeFactory getNodeFactory() { return JsonNodeFactory.instance; }
From source file:com.redhat.lightblue.metadata.mongo.MongoMetadata.java
@Override public Response getAccess(String entityName, String version) { List<String> entityNames = new ArrayList<>(); // accessMap: <role, <operation, List<path>>> Map<String, Map<String, List<String>>> accessMap = new HashMap<>(); if (null != entityName && !entityName.isEmpty()) { entityNames.add(entityName);//from w ww . j ava 2 s . c om } else { // force version to be null version = null; entityNames.addAll(Arrays.asList(getEntityNames())); } // initialize response, assume will be completely successful Response response = new Response(JsonNodeFactory.instance); response.setStatus(OperationStatus.COMPLETE); // for each name get metadata for (String name : entityNames) { EntityMetadata metadata; try { metadata = getEntityMetadata(name, version); } catch (Exception e) { response.setStatus(OperationStatus.PARTIAL); // construct error data ObjectNode obj = new ObjectNode(JsonNodeFactory.instance); obj.put(LITERAL_NAME, name); if (null != version) { obj.put("version", version); } List<Error> errors = new ArrayList<>(); errors.add(Error.get("ERR_NO_METADATA", "Could not get metadata for given input. Error message: " + e.getMessage())); DataError error = new DataError(obj, errors); response.getDataErrors().add(error); // skip to next entity name continue; } EntityAccess ea = metadata.getAccess(); Map<FieldAccess, Path> fa = new HashMap<>(); FieldCursor fc = metadata.getFieldCursor(); // collect field access while (fc.next()) { FieldTreeNode ftn = fc.getCurrentNode(); if (ftn instanceof Field) { // add access if there is anything to extract later Field f = (Field) ftn; if (!f.getAccess().getFind().isEmpty() || !f.getAccess().getInsert().isEmpty() || !f.getAccess().getUpdate().isEmpty()) { fa.put(f.getAccess(), f.getFullPath()); } } } // key is role, value is all associated paths. // accessMap: <role, <operation, List<path>>> // collect entity access helperAddRoles(ea.getDelete().getRoles(), "delete", name, accessMap); helperAddRoles(ea.getFind().getRoles(), "find", name, accessMap); helperAddRoles(ea.getInsert().getRoles(), "insert", name, accessMap); helperAddRoles(ea.getUpdate().getRoles(), "update", name, accessMap); // collect field access for (Map.Entry<FieldAccess, Path> entry : fa.entrySet()) { FieldAccess access = entry.getKey(); String pathString = name + "." + entry.getValue().toString(); helperAddRoles(access.getFind().getRoles(), "find", pathString, accessMap); helperAddRoles(access.getInsert().getRoles(), "insert", pathString, accessMap); helperAddRoles(access.getUpdate().getRoles(), "update", pathString, accessMap); } } // finally, populate response with valid output if (!accessMap.isEmpty()) { ArrayNode root = new ArrayNode(JsonNodeFactory.instance); response.setEntityData(root); for (Map.Entry<String, Map<String, List<String>>> entry : accessMap.entrySet()) { String role = entry.getKey(); Map<String, List<String>> opPathMap = entry.getValue(); ObjectNode roleJson = new ObjectNode(JsonNodeFactory.instance); root.add(roleJson); roleJson.put("role", role); for (Map.Entry<String, List<String>> operationMap : opPathMap.entrySet()) { String operation = operationMap.getKey(); List<String> paths = opPathMap.get(operation); ArrayNode pathNode = new ArrayNode(JsonNodeFactory.instance); for (String path : paths) { pathNode.add(path); } roleJson.put(operation, pathNode); } } } else { // nothing successful! set status to error response.setStatus(OperationStatus.ERROR); } return response; }
From source file:services.echannel.EchannelServiceImpl.java
/** * Perform a call.//w w w .j ava 2s . co m * * @param httpMethod * the HTTP method (GET, POST...) * @param action * the action name * @param queryParams * the query parameters * @param content * the request content (for POST) */ private JsonNode call(HttpMethod httpMethod, String action, List<NameValuePair> queryParams, JsonNode content) throws EchannelException { String url = this.getActionUrl(action); Logger.debug("URL: " + url); WSRequest request = WS.url(url).setHeader("Content-Type", "application/octet-stream"); request.setHeader(HTTP_HEADER_API_KEY, this.getApiSecretKey()); if (queryParams != null) { for (NameValuePair param : queryParams) { request.setQueryParameter(param.getName(), param.getValue()); } } Promise<WSResponse> response = null; String contentString = null; if (content != null) { try { contentString = getMapper().writeValueAsString(content); Logger.info("contentString: " + contentString); } catch (JsonProcessingException e) { throw new EchannelException(e.getMessage()); } } switch (httpMethod) { case GET: response = request.get(); break; case POST: response = request.post(contentString); break; case PUT: response = request.put(contentString); break; } Promise<Pair<Integer, JsonNode>> jsonPromise = response .map(new Function<WSResponse, Pair<Integer, JsonNode>>() { public Pair<Integer, JsonNode> apply(WSResponse response) { try { return Pair.of(response.getStatus(), response.asJson()); } catch (Exception e) { JsonNode error = JsonNodeFactory.instance.textNode(e.getMessage()); return Pair.of(response.getStatus(), error); } } }); Pair<Integer, JsonNode> responseContent = jsonPromise.get(WS_TIMEOUT); Logger.debug("STATUS CODE: " + responseContent.getLeft()); if (responseContent.getLeft().equals(200) || responseContent.getLeft().equals(204)) { return responseContent.getRight(); } else { String errorMessage = "eChannel service call error / url: " + url + " / status: " + responseContent.getLeft() + " / errors: " + responseContent.getRight().toString(); throw new EchannelException(errorMessage); } }
From source file:io.gs2.matchmaking.Gs2MatchmakingClient.java
/** * ????<br>/*from w w w. jav a2 s . co m*/ * <br> * - : 10<br> * <br> * * @param request */ public void passcodeEarlyCompleteGathering(PasscodeEarlyCompleteGatheringRequest request) { ObjectNode body = JsonNodeFactory.instance.objectNode(); HttpPost post = createHttpPost( Gs2Constant.ENDPOINT_HOST + "/matchmaking/" + (request.getMatchmakingName() == null || request.getMatchmakingName().equals("") ? "null" : request.getMatchmakingName()) + "/passcode/" + (request.getGatheringId() == null || request.getGatheringId().equals("") ? "null" : request.getGatheringId()) + "/complete", credential, ENDPOINT, PasscodeEarlyCompleteGatheringRequest.Constant.MODULE, PasscodeEarlyCompleteGatheringRequest.Constant.FUNCTION, body.toString()); if (request.getRequestId() != null) { post.setHeader("X-GS2-REQUEST-ID", request.getRequestId()); } post.setHeader("X-GS2-ACCESS-TOKEN", request.getAccessToken()); doRequest(post, null); }