List of usage examples for com.fasterxml.jackson.databind ObjectMapper createArrayNode
@Override
public ArrayNode createArrayNode()
Note: return type is co-variant, as basic ObjectCodec abstraction can not refer to concrete node types (as it's part of core package, whereas impls are part of mapper package)
From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java
public static void createUserRolesWithPrevilages(String roleName, String... privNames) { try {//from w ww .j ava2 s.c o m DefaultHttpClient client = new DefaultHttpClient(); client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8002), new UsernamePasswordCredentials("admin", "admin")); HttpGet getrequest = new HttpGet("http://localhost:8002/manage/v2/roles/" + roleName); HttpResponse resp = client.execute(getrequest); if (resp.getStatusLine().getStatusCode() == 200) { System.out.println("Role already exist"); } else { System.out.println("Role dont exist, will create now"); String[] roleNames = { "rest-reader", "rest-writer" }; client = new DefaultHttpClient(); client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8002), new UsernamePasswordCredentials("admin", "admin")); ObjectMapper mapper = new ObjectMapper(); ObjectNode mainNode = mapper.createObjectNode(); ArrayNode roleArray = mapper.createArrayNode(); ArrayNode privArray = mapper.createArrayNode(); ArrayNode permArray = mapper.createArrayNode(); mainNode.put("role-name", roleName); mainNode.put("description", "role discription"); for (String rolename : roleNames) roleArray.add(rolename); mainNode.withArray("role").addAll(roleArray); for (String privName : privNames) { ObjectNode privNode = mapper.createObjectNode(); privNode.put("privilege-name", privName); privNode.put("action", "http://marklogic.com/xdmp/privileges/" + privName.replace(":", "-")); privNode.put("kind", "execute"); privArray.add(privNode); } mainNode.withArray("privilege").addAll(privArray); permArray.add(getPermissionNode(roleNames[0], Capability.READ).get("permission").get(0)); permArray.add(getPermissionNode(roleNames[1], Capability.READ).get("permission").get(0)); permArray.add(getPermissionNode(roleNames[1], Capability.EXECUTE).get("permission").get(0)); permArray.add(getPermissionNode(roleNames[1], Capability.UPDATE).get("permission").get(0)); mainNode.withArray("permission").addAll(permArray); System.out.println(mainNode.toString()); HttpPost post = new HttpPost("http://localhost:8002" + "/manage/v2/roles?format=json"); post.addHeader("Content-type", "application/json"); post.setEntity(new StringEntity(mainNode.toString())); HttpResponse response = client.execute(post); HttpEntity respEntity = response.getEntity(); if (response.getStatusLine().getStatusCode() == 400) { System.out.println("creation of role got a problem"); } else if (respEntity != null) { // EntityUtils to get the response content String content = EntityUtils.toString(respEntity); System.out.println(content); } else { System.out.println("No Proper Response"); } } } catch (Exception e) { // writing error to Log e.printStackTrace(); } }
From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java
public static void addGeospatialPathIndexes(String dbName, String pathExpression, String coordinateSystem, String pointFormat, boolean rangeValuePositions, String invalidValues) throws Exception { ObjectMapper mapper = new ObjectMapper(); // ObjectNode mainNode = mapper.createObjectNode(); ObjectNode childNode = mapper.createObjectNode(); ArrayNode childArray = mapper.createArrayNode(); ObjectNode childNodeObject = mapper.createObjectNode(); childNodeObject.put("path-expression", pathExpression); childNodeObject.put("coordinate-system", coordinateSystem); childNodeObject.put("range-value-positions", false); childNodeObject.put("invalid-values", invalidValues); childNodeObject.put("point-format", pointFormat); childArray.add(childNodeObject);// w ww . j av a2s. c om childNode.putArray("geospatial-path-index").addAll(childArray); // mainNode.put("geospatial-path-indexes", childNode); // System.out.println(type + mainNode.path("range-path-indexes").path("range-path-index").toString()); setDatabaseProperties(dbName, "geospatial-path-index", childNode); }
From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java
public static void addRangeElementIndex(String dbName, String type, String namespace, String localname, boolean positions) throws Exception { ObjectMapper mapper = new ObjectMapper(); ObjectNode mainNode = mapper.createObjectNode(); // ObjectNode childNode = mapper.createObjectNode(); ArrayNode childArray = mapper.createArrayNode(); ObjectNode childNodeObject = mapper.createObjectNode(); childNodeObject.put("scalar-type", type); childNodeObject.put("namespace-uri", namespace); childNodeObject.put("localname", localname); childNodeObject.put("collation", ""); childNodeObject.put("range-value-positions", positions); childNodeObject.put("invalid-values", "reject"); childArray.add(childNodeObject);/*from w ww. ja v a 2s . co m*/ mainNode.putArray("range-element-index").addAll(childArray); // mainNode.put("range-element-indexes", childNode); // System.out.println(type + mainNode.path("range-element-indexes").path("range-element-index").toString()); setDatabaseProperties(dbName, "range-element-index", mainNode); }
From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java
public static void addRangeElementIndex(String dbName, String type, String namespace, String localname, String collation) throws Exception { ObjectMapper mapper = new ObjectMapper(); ObjectNode mainNode = mapper.createObjectNode(); // ObjectNode childNode = mapper.createObjectNode(); ArrayNode childArray = mapper.createArrayNode(); ObjectNode childNodeObject = mapper.createObjectNode(); childNodeObject.put("scalar-type", type); childNodeObject.put("namespace-uri", namespace); childNodeObject.put("localname", localname); childNodeObject.put("collation", collation); childNodeObject.put("range-value-positions", false); childNodeObject.put("invalid-values", "reject"); childArray.add(childNodeObject);// w w w .j a v a2 s .c o m mainNode.putArray("range-element-index").addAll(childArray); // System.out.println(type + mainNode.path("range-element-indexes").path("range-element-index").toString()); setDatabaseProperties(dbName, "range-element-index", mainNode); }
From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java
public static void addRangeElementAttributeIndex(String dbName, String type, String parentnamespace, String parentlocalname, String namespace, String localname) throws Exception { ObjectMapper mapper = new ObjectMapper(); //ObjectNode mainNode = mapper.createObjectNode(); ObjectNode childNode = mapper.createObjectNode(); ArrayNode childArray = mapper.createArrayNode(); ObjectNode childNodeObject = mapper.createObjectNode(); childNodeObject.put("scalar-type", type); childNodeObject.put("collation", ""); childNodeObject.put("parent-namespace-uri", parentnamespace); childNodeObject.put("parent-localname", parentlocalname); childNodeObject.put("namespace-uri", namespace); childNodeObject.put("localname", localname); childNodeObject.put("range-value-positions", false); childNodeObject.put("invalid-values", "reject"); childArray.add(childNodeObject);/* ww w . j ava2s.c om*/ childNode.putArray("range-element-attribute-index").addAll(childArray); // mainNode.put("range-element-attribute-indexes", childNode); // System.out.println(type + mainNode.path("range-element-attribute-indexes").path("range-element-attribute-index").toString()); setDatabaseProperties(dbName, "range-element-attribute-index", childNode); }
From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java
public static void addFieldExcludeRoot(String dbName, String fieldName) throws Exception { ObjectMapper mapper = new ObjectMapper(); // ObjectNode mainNode = mapper.createObjectNode(); ObjectNode childNode = mapper.createObjectNode(); ArrayNode arrNode = mapper.createArrayNode(); ObjectNode childNodeObject = mapper.createObjectNode(); childNodeObject.put("field-name", fieldName); childNodeObject.put("include-root", false); childNodeObject.putNull("included-elements"); childNodeObject.putNull("excluded-elements"); childNodeObject.putNull("tokenizer-overrides"); arrNode.add(childNodeObject);//from w w w . j a va2 s. co m childNode.putArray("field").addAll(arrNode); // mainNode.put("fields", childNode); // System.out.println( childNode.toString()); setDatabaseProperties(dbName, "field", childNode); }
From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java
public static void addRangePathIndex(String dbName, String type, String pathexpr, String collation, String invalidValues, boolean positions) throws Exception { ObjectMapper mapper = new ObjectMapper(); // ObjectNode mainNode = mapper.createObjectNode(); ObjectNode childNode = mapper.createObjectNode(); ArrayNode childArray = mapper.createArrayNode(); ObjectNode childNodeObject = mapper.createObjectNode(); childNodeObject.put("scalar-type", type); childNodeObject.put("collation", collation); childNodeObject.put("path-expression", pathexpr); childNodeObject.put("range-value-positions", false); childNodeObject.put("invalid-values", invalidValues); childArray.add(childNodeObject);/* w w w . j a v a 2 s. co m*/ childNode.putArray("range-path-index").addAll(childArray); // mainNode.put("range-path-indexes", childNode); // System.out.println(type + mainNode.path("range-path-indexes").path("range-path-index").toString()); setDatabaseProperties(dbName, "range-path-index", childNode); }
From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java
public static void addGeospatialElementIndexes(String dbName, String localname, String namespace, String coordinateSystem, String pointFormat, boolean rangeValuePositions, String invalidValues) throws Exception { ObjectMapper mapper = new ObjectMapper(); // ObjectNode mainNode = mapper.createObjectNode(); ObjectNode childNode = mapper.createObjectNode(); ArrayNode childArray = mapper.createArrayNode(); ObjectNode childNodeObject = mapper.createObjectNode(); childNodeObject.put("namespace-uri", namespace); childNodeObject.put("localname", localname); childNodeObject.put("coordinate-system", coordinateSystem); childNodeObject.put("range-value-positions", false); childNodeObject.put("invalid-values", invalidValues); childNodeObject.put("point-format", pointFormat); childArray.add(childNodeObject);//from w ww . j ava 2 s . c o m childNode.putArray("geospatial-element-index").addAll(childArray); // mainNode.put("geospatial-element-indexes", childNode); // System.out.println(type + mainNode.path("range-path-indexes").path("range-path-index").toString()); setDatabaseProperties(dbName, "geospatial-element-index", childNode); }
From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java
public static void addRangeElementAttributeIndex(String dbName, String type, String parentnamespace, String parentlocalname, String namespace, String localname, String collation) throws Exception { ObjectMapper mapper = new ObjectMapper(); // ObjectNode mainNode = mapper.createObjectNode(); ObjectNode childNode = mapper.createObjectNode(); ArrayNode childArray = mapper.createArrayNode(); ObjectNode childNodeObject = mapper.createObjectNode(); childNodeObject.put("scalar-type", type); childNodeObject.put("collation", collation); childNodeObject.put("parent-namespace-uri", parentnamespace); childNodeObject.put("parent-localname", parentlocalname); childNodeObject.put("namespace-uri", namespace); childNodeObject.put("localname", localname); childNodeObject.put("range-value-positions", false); childNodeObject.put("invalid-values", "reject"); childArray.add(childNodeObject);/*from ww w. j a v a 2 s . com*/ childNode.putArray("range-element-attribute-index").addAll(childArray); // mainNode.put("range-element-attribute-indexes", childNode); // System.out.println(type + mainNode.path("range-element-attribute-indexes").path("range-element-attribute-index").toString()); setDatabaseProperties(dbName, "range-element-attribute-index", childNode); }
From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java
public static void addGeoSpatialElementChildIndexes(String dbName, String parentNamespaceUri, String parentLocalName, String namespace, String localname, String coordinateSystem, String pointFormat, boolean rangeValuePositions, String invalidValues) throws Exception { ObjectMapper mapper = new ObjectMapper(); // ObjectNode mainNode = mapper.createObjectNode(); ObjectNode childNode = mapper.createObjectNode(); ArrayNode childArray = mapper.createArrayNode(); ObjectNode childNodeObject = mapper.createObjectNode(); childNodeObject.put("parent-namespace-uri", parentNamespaceUri); childNodeObject.put("parent-localname", parentLocalName); childNodeObject.put("namespace-uri", namespace); childNodeObject.put("localname", localname); childNodeObject.put("coordinate-system", coordinateSystem); childNodeObject.put("range-value-positions", false); childNodeObject.put("invalid-values", invalidValues); childNodeObject.put("point-format", pointFormat); childArray.add(childNodeObject);/*from w w w. j av a 2 s .c o m*/ childNode.putArray("geospatial-element-child-index").addAll(childArray); // mainNode.put("geospatial-element-child-indexes", childNode); // System.out.println(type + mainNode.path("range-path-indexes").path("range-path-index").toString()); setDatabaseProperties(dbName, "geospatial-element-child-index", childNode); }