Example usage for com.fasterxml.jackson.databind ObjectMapper createObjectNode

List of usage examples for com.fasterxml.jackson.databind ObjectMapper createObjectNode

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind ObjectMapper createObjectNode.

Prototype

@Override
public ObjectNode createObjectNode() 

Source Link

Document

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)

Usage

From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java

public static void createRESTUserWithPermissions(String usrName, String pass, ObjectNode perm,
        ObjectNode colections, String... roleNames) {
    try {/*from   w ww  .  j a  v a 2s . com*/
        DefaultHttpClient client = new DefaultHttpClient();
        client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8002),
                new UsernamePasswordCredentials("admin", "admin"));
        HttpGet getrequest = new HttpGet("http://localhost:8002" + "/manage/v2/users/" + usrName);
        HttpResponse resp = client.execute(getrequest);

        if (resp.getStatusLine().getStatusCode() == 200) {
            System.out.println("User already exist");
        } else {
            System.out.println("User dont exist");
            client = new DefaultHttpClient();
            client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8002),
                    new UsernamePasswordCredentials("admin", "admin"));

            ObjectMapper mapper = new ObjectMapper();
            ObjectNode mainNode = mapper.createObjectNode();
            //         ObjectNode childNode = mapper.createObjectNode();
            ArrayNode childArray = mapper.createArrayNode();
            mainNode.put("user-name", usrName);
            mainNode.put("description", "user discription");
            mainNode.put("password", pass);
            for (String rolename : roleNames)
                childArray.add(rolename);
            mainNode.withArray("role").addAll(childArray);
            mainNode.setAll(perm);
            mainNode.setAll(colections);
            //System.out.println(type + mainNode.path("range-element-indexes").path("range-element-index").toString());
            System.out.println(mainNode.toString());
            HttpPost post = new HttpPost("http://localhost:8002" + "/manage/v2/users?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("Bad User creation request");
            } 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 createUserRolesWithPrevilages(String roleName, String... privNames) {
    try {/*from   www.  j  av a 2s  . co 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.microsoft.azure.AzureVMManagementServiceDelegate.java

/**
 * Creates a new deployment of VMs based on the provided template
 *
 * @param template Template to deploy//  w ww . j  a  va  2s.  c o m
 * @param numberOfAgents Number of agents to create
 * @return The base name for the VMs that were created
 * @throws AzureCloudException
 * @throws java.io.IOException
 */
public static AzureVMDeploymentInfo createDeployment(final AzureVMAgentTemplate template,
        final int numberOfAgents) throws AzureCloudException, IOException {

    InputStream embeddedTemplate = null;
    InputStream fragmentStream = null;
    try {
        LOGGER.log(Level.INFO,
                "AzureVMManagementServiceDelegate: createDeployment: Initializing deployment for agentTemplate {0}",
                template.getTemplateName());

        Configuration config = ServiceDelegateHelper.getConfiguration(template);
        final ResourceManagementClient client = ServiceDelegateHelper.getResourceManagementClient(config);

        final Date timestamp = new Date(System.currentTimeMillis());
        final String deploymentName = AzureUtil.getDeploymentName(template.getTemplateName(), timestamp);
        final String vmBaseName = AzureUtil.getVMBaseName(template.getTemplateName(), deploymentName,
                template.getOsType(), numberOfAgents);
        final String locationName = getLocationName(template.getLocation());
        if (!template.getResourceGroupName().matches(Constants.DEFAULT_RESOURCE_GROUP_PATTERN)) {
            LOGGER.log(Level.SEVERE,
                    "AzureVMManagementServiceDelegate: createDeployment: ResourceGroup Name {0} is invalid. It should be 1-64 alphanumeric characters",
                    new Object[] { template.getResourceGroupName() });
            throw new Exception("ResourceGroup Name is invalid");
        }
        final String resourceGroupName = template.getResourceGroupName();
        LOGGER.log(Level.INFO,
                "AzureVMManagementServiceDelegate: createDeployment: Creating a new deployment {0} with VM base name {1}",
                new Object[] { deploymentName, vmBaseName });

        client.getResourceGroupsOperations().createOrUpdate(resourceGroupName, new ResourceGroup(locationName));

        final Deployment deployment = new Deployment();
        final DeploymentProperties properties = new DeploymentProperties();
        deployment.setProperties(properties);

        final boolean useCustomScriptExtension = template.getOsType().equals(Constants.OS_TYPE_WINDOWS)
                && !StringUtils.isBlank(template.getInitScript())
                && template.getAgentLaunchMethod().equals(Constants.LAUNCH_METHOD_JNLP);

        // check if a custom image id has been provided otherwise work with publisher and offer
        if (template.getImageReferenceType().equals(IMAGE_CUSTOM_REFERENCE)) {
            if (useCustomScriptExtension) {
                LOGGER.log(Level.INFO,
                        "AzureVMManagementServiceDelegate: createDeployment: Use embedded deployment template {0}",
                        EMBEDDED_TEMPLATE_IMAGE_WITH_SCRIPT_FILENAME);
                embeddedTemplate = AzureVMManagementServiceDelegate.class
                        .getResourceAsStream(EMBEDDED_TEMPLATE_IMAGE_WITH_SCRIPT_FILENAME);
            } else {
                LOGGER.log(Level.INFO,
                        "AzureVMManagementServiceDelegate: createDeployment: Use embedded deployment template (with script) {0}",
                        EMBEDDED_TEMPLATE_IMAGE_FILENAME);
                embeddedTemplate = AzureVMManagementServiceDelegate.class
                        .getResourceAsStream(EMBEDDED_TEMPLATE_IMAGE_FILENAME);
            }
        } else {
            if (useCustomScriptExtension) {
                LOGGER.log(Level.INFO,
                        "AzureVMManagementServiceDelegate: createDeployment: Use embedded deployment template (with script) {0}",
                        EMBEDDED_TEMPLATE_WITH_SCRIPT_FILENAME);
                embeddedTemplate = AzureVMManagementServiceDelegate.class
                        .getResourceAsStream(EMBEDDED_TEMPLATE_WITH_SCRIPT_FILENAME);
            } else {
                LOGGER.log(Level.INFO,
                        "AzureVMManagementServiceDelegate: createDeployment: Use embedded deployment template {0}",
                        EMBEDDED_TEMPLATE_FILENAME);
                embeddedTemplate = AzureVMManagementServiceDelegate.class
                        .getResourceAsStream(EMBEDDED_TEMPLATE_FILENAME);
            }
        }

        final ObjectMapper mapper = new ObjectMapper();
        final JsonNode tmp = mapper.readTree(embeddedTemplate);

        // Add count variable for loop....
        final ObjectNode count = mapper.createObjectNode();
        count.put("type", "int");
        count.put("defaultValue", numberOfAgents);
        ObjectNode.class.cast(tmp.get("parameters")).replace("count", count);

        ObjectNode.class.cast(tmp.get("variables")).put("vmName", vmBaseName);
        ObjectNode.class.cast(tmp.get("variables")).put("location", locationName);

        if (StringUtils.isNotBlank(template.getImagePublisher())) {
            ObjectNode.class.cast(tmp.get("variables")).put("imagePublisher", template.getImagePublisher());
        }

        if (StringUtils.isNotBlank(template.getImageOffer())) {
            ObjectNode.class.cast(tmp.get("variables")).put("imageOffer", template.getImageOffer());
        }

        if (StringUtils.isNotBlank(template.getImageSku())) {
            ObjectNode.class.cast(tmp.get("variables")).put("imageSku", template.getImageSku());
        }

        if (StringUtils.isNotBlank(template.getOsType())) {
            ObjectNode.class.cast(tmp.get("variables")).put("osType", template.getOsType());
        }

        if (StringUtils.isNotBlank(template.getImage())) {
            ObjectNode.class.cast(tmp.get("variables")).put("image", template.getImage());
        }

        // If using the custom script extension (vs. SSH) to startup the powershell scripts,
        // add variables for that and upload the init script to the storage account
        if (useCustomScriptExtension) {
            ObjectNode.class.cast(tmp.get("variables")).put("jenkinsServerURL",
                    Jenkins.getInstance().getRootUrl());
            // Calculate the client secrets.  The secrets are based off the machine name, 
            ArrayNode clientSecretsNode = ObjectNode.class.cast(tmp.get("variables")).putArray("clientSecrets");
            for (int i = 0; i < numberOfAgents; i++) {
                clientSecretsNode
                        .add(JnlpSlaveAgentProtocol.SLAVE_SECRET.mac(String.format("%s%d", vmBaseName, i)));
            }
            // Upload the startup script to blob storage
            String scriptName = String.format("%s%s", deploymentName, "init.ps1");
            String scriptUri = uploadCustomScript(template, scriptName);
            ObjectNode.class.cast(tmp.get("variables")).put("startupScriptURI", scriptUri);
            ObjectNode.class.cast(tmp.get("variables")).put("startupScriptName", scriptName);

            String storageAccountKey = ServiceDelegateHelper.getStorageManagementClient(config)
                    .getStorageAccountsOperations()
                    .listKeys(template.getResourceGroupName(), template.getStorageAccountName())
                    .getStorageAccountKeys().getKey1();

            final ObjectNode storageAccountKeyNode = mapper.createObjectNode();
            storageAccountKeyNode.put("type", "secureString");
            storageAccountKeyNode.put("defaultValue", storageAccountKey);

            // Add the storage account key
            ObjectNode.class.cast(tmp.get("parameters")).replace("storageAccountKey", storageAccountKeyNode);
        }

        ObjectNode.class.cast(tmp.get("variables")).put("vmSize", template.getVirtualMachineSize());
        // Grab the username/pass
        StandardUsernamePasswordCredentials creds = AzureUtil.getCredentials(template.getCredentialsId());

        ObjectNode.class.cast(tmp.get("variables")).put("adminUsername", creds.getUsername());
        ObjectNode.class.cast(tmp.get("variables")).put("adminPassword", creds.getPassword().getPlainText());

        if (StringUtils.isNotBlank(template.getStorageAccountName())) {
            ObjectNode.class.cast(tmp.get("variables")).put("storageAccountName",
                    template.getStorageAccountName());
        }

        // Network properties.  If the vnet name isn't blank then
        // then subnet name can't be either (based on verification rules)
        if (StringUtils.isNotBlank(template.getVirtualNetworkName())) {
            ObjectNode.class.cast(tmp.get("variables")).put("virtualNetworkName",
                    template.getVirtualNetworkName());
            ObjectNode.class.cast(tmp.get("variables")).put("subnetName", template.getSubnetName());
        } else {
            // Add the definition of the vnet and subnet into the template
            final String virtualNetworkName = Constants.DEFAULT_VNET_NAME;
            final String subnetName = Constants.DEFAULT_SUBNET_NAME;
            ObjectNode.class.cast(tmp.get("variables")).put("virtualNetworkName", virtualNetworkName);
            ObjectNode.class.cast(tmp.get("variables")).put("subnetName", subnetName);

            // Read the vnet fragment
            fragmentStream = AzureVMManagementServiceDelegate.class
                    .getResourceAsStream(VIRTUAL_NETWORK_TEMPLATE_FRAGMENT_FILENAME);

            final JsonNode virtualNetworkFragment = mapper.readTree(fragmentStream);
            // Add the virtual network fragment
            ArrayNode.class.cast(tmp.get("resources")).add(virtualNetworkFragment);

            // Because we created/updated this in the template, we need to add the appropriate
            // dependsOn node to the networkInterface
            // Microsoft.Network/virtualNetworks/<vnet name>
            // Find the network interfaces node
            ArrayNode resourcesNodes = ArrayNode.class.cast(tmp.get("resources"));
            Iterator<JsonNode> resourcesNodesIter = resourcesNodes.elements();
            while (resourcesNodesIter.hasNext()) {
                JsonNode resourcesNode = resourcesNodesIter.next();
                JsonNode typeNode = resourcesNode.get("type");
                if (typeNode == null || !typeNode.asText().equals("Microsoft.Network/networkInterfaces")) {
                    continue;
                }
                // Find the dependsOn node
                ArrayNode dependsOnNode = ArrayNode.class.cast(resourcesNode.get("dependsOn"));
                // Add to the depends on node.
                dependsOnNode
                        .add("[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]");
                break;
            }
        }

        // Deployment ....
        properties.setMode(DeploymentMode.Incremental);
        properties.setTemplate(tmp.toString());

        // Register the deployment for cleanup
        AzureVMAgentCleanUpTask.registerDeployment(template.getAzureCloud().name,
                template.getResourceGroupName(), deploymentName);
        // Create the deployment
        client.getDeploymentsOperations().createOrUpdate(template.getResourceGroupName(), deploymentName,
                deployment);

        return new AzureVMDeploymentInfo(deploymentName, vmBaseName, numberOfAgents);
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "AzureVMManagementServiceDelegate: deployment: Unable to deploy", e);
        // Pass the info off to the template so that it can be queued for update.
        template.handleTemplateProvisioningFailure(e.getMessage(), FailureStage.PROVISIONING);
        throw new AzureCloudException(e);
    } finally {
        if (embeddedTemplate != null)
            embeddedTemplate.close();
        if (fragmentStream != null)
            fragmentStream.close();
    }
}

From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java

public static void addElementRangeIndexTemporalAxis(String dbName, String axisName, String namespaceStart,
        String localnameStart, String namespaceEnd, String localnameEnd) throws Exception {
    /**//from  w  w  w  .  ja v  a2s  . c o  m
     {
     "axis-name": "eri-json-system",
     "axis-start": {
         "element-reference": {
     "namespace-uri": "",
     "localname": "eri-system-start",
     "scalar-type": "dateTime"
         }
       },
       "axis-end": {
         "element-reference": {
     "namespace-uri": "",
     "localname": "eri-system-end",
     "scalar-type": "dateTime"
         }
       }
     }  
     */
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode rootNode = mapper.createObjectNode();

    rootNode.put("axis-name", axisName);

    // Set axis start
    ObjectNode axisStart = mapper.createObjectNode();
    ObjectNode elementReferenceStart = mapper.createObjectNode();
    elementReferenceStart.put("namespace-uri", namespaceStart);
    elementReferenceStart.put("localname", localnameStart);
    elementReferenceStart.put("scalar-type", "dateTime");

    axisStart.set("element-reference", elementReferenceStart);
    rootNode.set("axis-start", axisStart);

    // Set axis end
    ObjectNode axisEnd = mapper.createObjectNode();
    ObjectNode elementReferenceEnd = mapper.createObjectNode();
    elementReferenceEnd.put("namespace-uri", namespaceStart);
    elementReferenceEnd.put("localname", localnameEnd);
    elementReferenceEnd.put("scalar-type", "dateTime");

    axisEnd.set("element-reference", elementReferenceEnd);
    rootNode.set("axis-end", axisEnd);

    System.out.println(rootNode.toString());

    DefaultHttpClient client = new DefaultHttpClient();
    client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8002),
            new UsernamePasswordCredentials("admin", "admin"));

    HttpPost post = new HttpPost(
            "http://localhost:8002/manage/v2/databases/" + dbName + "/temporal/axes?format=json");

    post.addHeader("Content-type", "application/json");
    post.addHeader("accept", "application/json");
    post.setEntity(new StringEntity(rootNode.toString()));

    HttpResponse response = client.execute(post);
    HttpEntity respEntity = response.getEntity();
    if (response.getStatusLine().getStatusCode() == 400) {
        HttpEntity entity = response.getEntity();
        String responseString = EntityUtils.toString(entity, "UTF-8");
        System.out.println(responseString);
    } else if (respEntity != null) {
        // EntityUtils to get the response content
        String content = EntityUtils.toString(respEntity);
        System.out.println(content);

        System.out.println("Temporal axis: " + axisName + " created");
        System.out.println("==============================================================");
    } else {
        System.out.println("No Proper Response");
    }
}

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 a 2s. c  o 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: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);/*from w w w  .  j a va 2s  . co  m*/
    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 addField(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", true);
    childNodeObject.putNull("included-elements");
    childNodeObject.putNull("excluded-elements");
    childNodeObject.putNull("tokenizer-overrides");
    arrNode.add(childNodeObject);/*w ww.ja v  a2 s .co m*/
    childNode.putArray("field").addAll(arrNode);
    //      mainNode.put("fields", childNode);
    //          System.out.println("Entered field to make it true");
    setDatabaseProperties(dbName, "field", 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) 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);/* w ww  .j ava 2s .c o  m*/
    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 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);//from w  w  w.jav a2s. 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);/* w w  w.ja  v a2 s .com*/
    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);
}