Example usage for com.fasterxml.jackson.databind.node ObjectNode toString

List of usage examples for com.fasterxml.jackson.databind.node ObjectNode toString

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node ObjectNode toString.

Prototype

public String toString() 

Source Link

Usage

From source file:org.flowable.cmmn.rest.service.api.history.HistoricTaskInstanceQueryResourceTest.java

protected void assertResultsPresentInPostDataResponse(String url, ObjectNode body, int numberOfResultsExpected,
        String... expectedTaskIds) throws JsonProcessingException, IOException {
    // Do the actual call
    HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + url);
    httpPost.setEntity(new StringEntity(body.toString()));
    CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_OK);
    JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
    closeResponse(response);/*from  www  .  j  a va2s  .  co m*/
    assertEquals(numberOfResultsExpected, dataNode.size());

    // Check presence of ID's
    if (expectedTaskIds != null) {
        List<String> toBeFound = new ArrayList<>(Arrays.asList(expectedTaskIds));
        Iterator<JsonNode> it = dataNode.iterator();
        while (it.hasNext()) {
            String id = it.next().get("id").textValue();
            toBeFound.remove(id);
        }
        assertTrue("Not all entries have been found in result, missing: " + StringUtils.join(toBeFound, ", "),
                toBeFound.isEmpty());
    }
}

From source file:com.almende.demo.tuneswarm.ConductorAgent.java

/**
 * Call other agent.// ww w  .jav  a2s .co m
 *
 * @param url
 *            the url
 * @param method
 *            the method
 * @param params
 *            the params
 * @return the object node
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public String callOtherAgent(@Name("url") String url, @Name("method") String method,
        @Name("params") ObjectNode params) throws IOException {
    LOG.warning("Call other agent called:" + url + " " + method + " params:" + params.toString());
    return caller.callSync(URI.create(url), method, params);
}

From source file:io.gs2.auth.Gs2AuthClient.java

/**
 * ????<br>//from w  w  w  . ja va  2 s .  c om
 * <br>
 *
 * @param request 
        
 * @return ?
        
 */

public LoginResult login(LoginRequest request) {

    ObjectNode body = JsonNodeFactory.instance.objectNode().put("serviceId", request.getServiceId())
            .put("userId", request.getUserId());

    HttpPost post = createHttpPost(Gs2Constant.ENDPOINT_HOST + "/login", credential, ENDPOINT,
            LoginRequest.Constant.MODULE, LoginRequest.Constant.FUNCTION, body.toString());
    if (request.getRequestId() != null) {
        post.setHeader("X-GS2-REQUEST-ID", request.getRequestId());
    }

    return doRequest(post, LoginResult.class);

}

From source file:org.apache.syncope.core.workflow.activiti.ActivitiDefinitionLoader.java

@Override
public void load() {
    byte[] wfDef = new byte[0];

    InputStream wfIn = null;/*from   w w w  . java  2s .c o  m*/
    try {
        wfIn = userWorkflowDef.getResource().getInputStream();
        wfDef = IOUtils.toByteArray(wfIn);
    } catch (IOException e) {
        LOG.error("While loading " + ActivitiUserWorkflowAdapter.WF_PROCESS_RESOURCE, e);
    } finally {
        IOUtils.closeQuietly(wfIn);
    }

    for (Map.Entry<String, ProcessEngine> entry : dpEngine.getEngines().entrySet()) {
        List<ProcessDefinition> processes = entry.getValue().getRepositoryService()
                .createProcessDefinitionQuery().processDefinitionKey(ActivitiUserWorkflowAdapter.WF_PROCESS_ID)
                .list();
        LOG.debug(ActivitiUserWorkflowAdapter.WF_PROCESS_ID + " Activiti processes in repository: {}",
                processes);

        // Only loads process definition from file if not found in repository
        if (processes.isEmpty()) {
            entry.getValue().getRepositoryService().createDeployment().addInputStream(
                    ActivitiUserWorkflowAdapter.WF_PROCESS_RESOURCE, new ByteArrayInputStream(wfDef)).deploy();

            ProcessDefinition procDef = entry.getValue().getRepositoryService().createProcessDefinitionQuery()
                    .processDefinitionKey(ActivitiUserWorkflowAdapter.WF_PROCESS_ID).latestVersion()
                    .singleResult();

            Model model = entry.getValue().getRepositoryService().newModel();
            ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
            modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, procDef.getName());
            modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
            modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, procDef.getDescription());
            model.setMetaInfo(modelObjectNode.toString());
            model.setName(procDef.getName());
            model.setDeploymentId(procDef.getDeploymentId());
            ActivitiImportUtils.fromJSON(entry.getValue(), procDef, model);

            LOG.debug("Activiti Workflow definition loaded for domain {}", entry.getKey());
        }

        // jump to the next ID block
        for (int i = 0; i < entry.getValue().getProcessEngineConfiguration().getIdBlockSize(); i++) {
            SpringProcessEngineConfiguration.class.cast(entry.getValue().getProcessEngineConfiguration())
                    .getIdGenerator().getNextId();
        }
    }
}

From source file:com.flipkart.foxtrot.core.querystore.impl.ElasticsearchQueryStore.java

private String convert(Document translatedDocuement) {
    JsonNode metaNode = mapper.valueToTree(translatedDocuement.getMetadata());
    ObjectNode dataNode = translatedDocuement.getData().deepCopy();
    dataNode.put(ElasticsearchUtils.DOCUMENT_META_FIELD_NAME, metaNode);
    return dataNode.toString();
}

From source file:io.gs2.auth.Gs2AuthClient.java

/**
 * 1???????<br>//from   ww  w .  j a  va  2  s.  c o m
 * ?????????????????????1???????????<br>
 * <br>
 *
 * @param request 
        
 * @return ?
        
 */

public CreateTimeOnetimeTokenResult createTimeOnetimeToken(CreateTimeOnetimeTokenRequest request) {

    ObjectNode body = JsonNodeFactory.instance.objectNode().put("scriptName", request.getScriptName());

    HttpPost post = createHttpPost(Gs2Constant.ENDPOINT_HOST + "/onetime/time/token", credential, ENDPOINT,
            CreateTimeOnetimeTokenRequest.Constant.MODULE, CreateTimeOnetimeTokenRequest.Constant.FUNCTION,
            body.toString());
    if (request.getRequestId() != null) {
        post.setHeader("X-GS2-REQUEST-ID", request.getRequestId());
    }

    return doRequest(post, CreateTimeOnetimeTokenResult.class);

}

From source file:org.activiti.rest.service.api.runtime.SignalsResourceTest.java

@Deployment(resources = {
        "org/activiti/rest/service/api/runtime/SignalsResourceTest.process-signal-start.bpmn20.xml" })
public void testSignalEventReceivedSync() throws Exception {

    org.activiti.engine.repository.Deployment tenantDeployment = repositoryService.createDeployment()
            .addClasspathResource(/*from  w w w . j a v a  2s  . c  o  m*/
                    "org/activiti/rest/service/api/runtime/SignalsResourceTest.process-signal-start.bpmn20.xml")
            .tenantId("my tenant").deploy();

    try {

        // Signal without vars, without tenant
        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("signalName", "The Signal");

        HttpPost httpPost = new HttpPost(
                SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_SIGNALS));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPost, HttpStatus.SC_NO_CONTENT));

        // Check if process is started as a result of the signal without
        // tenant ID set
        assertEquals(1, runtimeService.createProcessInstanceQuery().processInstanceWithoutTenantId()
                .processDefinitionKey("processWithSignalStart1").count());

        // Signal with tenant
        requestNode.put("tenantId", "my tenant");
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPost, HttpStatus.SC_NO_CONTENT));

        // Check if process is started as a result of the signal, in the
        // right tenant
        assertEquals(1, runtimeService.createProcessInstanceQuery().processInstanceTenantId("my tenant")
                .processDefinitionKey("processWithSignalStart1").count());

        // Signal with tenant AND variables
        ArrayNode vars = requestNode.putArray("variables");
        ObjectNode var = vars.addObject();
        var.put("name", "testVar");
        var.put("value", "test");

        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPost, HttpStatus.SC_NO_CONTENT));

        // Check if process is started as a result of the signal, in the
        // right tenant and with var set
        assertEquals(1,
                runtimeService.createProcessInstanceQuery().processInstanceTenantId("my tenant")
                        .processDefinitionKey("processWithSignalStart1").variableValueEquals("testVar", "test")
                        .count());

        // Signal without tenant AND variables
        requestNode.remove("tenantId");

        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPost, HttpStatus.SC_NO_CONTENT));

        // Check if process is started as a result of the signal, witout
        // tenant and with var set
        assertEquals(1,
                runtimeService.createProcessInstanceQuery().processInstanceWithoutTenantId()
                        .processDefinitionKey("processWithSignalStart1").variableValueEquals("testVar", "test")
                        .count());

    } finally {
        // Clean up tenant-specific deployment
        if (tenantDeployment != null) {
            repositoryService.deleteDeployment(tenantDeployment.getId(), true);
        }
    }
}

From source file:org.activiti.rest.service.api.identity.GroupResourceTest.java

/**
 * Test updating a single group passing in no fields in the json, user should remain unchanged.
 *//*  w w  w .j  av  a 2s .  co m*/
public void testUpdateGroupNoFields() throws Exception {
    try {
        Group testGroup = identityService.newGroup("testgroup");
        testGroup.setName("Test group");
        testGroup.setType("Test type");
        identityService.saveGroup(testGroup);

        ObjectNode requestNode = objectMapper.createObjectNode();

        HttpPut httpPut = new HttpPut(
                SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, "testgroup"));
        httpPut.setEntity(new StringEntity(requestNode.toString()));
        CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);

        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertNotNull(responseNode);
        assertEquals("testgroup", responseNode.get("id").textValue());
        assertEquals("Test group", responseNode.get("name").textValue());
        assertEquals("Test type", responseNode.get("type").textValue());
        assertTrue(responseNode.get("url").textValue()
                .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, testGroup.getId())));

        Group createdGroup = identityService.createGroupQuery().groupId("testgroup").singleResult();
        assertNotNull(createdGroup);
        assertEquals("Test group", createdGroup.getName());
        assertEquals("Test type", createdGroup.getType());

    } finally {
        try {
            identityService.deleteGroup("testgroup");
        } catch (Throwable ignore) {
            // Ignore, since the group may not have been created in the test
            // or already deleted
        }
    }
}

From source file:com.mirth.connect.client.ui.components.rsta.RSTAPreferences.java

String getToggleOptionsJSON() {
    ObjectNode toggleOptionsNode = JsonNodeFactory.instance.objectNode();
    for (Entry<String, Boolean> entry : getToggleOptions().entrySet()) {
        toggleOptionsNode.put(entry.getKey(), entry.getValue());
    }//  w  w w.  ja  v  a 2s.  com
    return toggleOptionsNode.toString();
}

From source file:controllers.CommentController.java

private String failJson(String msg) {
    ObjectNode response = Json.newObject();
    response.put("success", false);
    response.put("message", msg);

    return response.toString();
}