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.apache.syncope.core.workflow.user.activiti.ActivitiWorkflowLoader.java

@Override
public void load() {
    List<ProcessDefinition> processes = repositoryService.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()) {
        InputStream wfIn = null;/*w w w.j  a  va 2s .co m*/
        try {
            wfIn = getClass().getResourceAsStream("/" + ActivitiUserWorkflowAdapter.WF_PROCESS_RESOURCE);
            repositoryService.createDeployment().addInputStream(ActivitiUserWorkflowAdapter.WF_PROCESS_RESOURCE,
                    new ByteArrayInputStream(IOUtils.toByteArray(wfIn))).deploy();

            ProcessDefinition procDef = repositoryService.createProcessDefinitionQuery()
                    .processDefinitionKey(ActivitiUserWorkflowAdapter.WF_PROCESS_ID).latestVersion()
                    .singleResult();

            Model model = repositoryService.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());
            activitiJSONUtils.fromJSON(procDef, model);

            LOG.debug("Activiti Workflow definition loaded");
        } catch (IOException e) {
            LOG.error("While loading " + ActivitiUserWorkflowAdapter.WF_PROCESS_RESOURCE, e);
        } finally {
            IOUtils.closeQuietly(wfIn);
        }
    }
}

From source file:com.redhat.lightblue.query.ArrayAddExpression.java

/**
 * Parses an array update expression using the given json object
 *///from  ww w  .jav a 2 s  .c  om
public static ArrayAddExpression fromJson(ObjectNode node) {
    if (node.size() == 1) {
        UpdateOperator op = UpdateOperator._append;
        JsonNode arg = node.get(UpdateOperator._append.toString());
        if (arg == null) {
            arg = node.get(UpdateOperator._insert.toString());
            op = UpdateOperator._insert;
        }
        if (arg instanceof ObjectNode) {
            ObjectNode objArg = (ObjectNode) arg;
            if (objArg.size() == 1) {
                Map.Entry<String, JsonNode> item = objArg.fields().next();
                Path field = new Path(item.getKey());
                JsonNode valueNode = item.getValue();
                List<RValueExpression> rvalues = new ArrayList<>();
                if (valueNode instanceof ArrayNode) {
                    for (Iterator<JsonNode> itr = ((ArrayNode) valueNode).elements(); itr.hasNext();) {
                        rvalues.add(RValueExpression.fromJson(itr.next()));
                    }
                } else {
                    rvalues.add(RValueExpression.fromJson(valueNode));
                }
                return new ArrayAddExpression(field, op, rvalues);
            }
        }
    }
    throw Error.get(QueryConstants.ERR_INVALID_ARRAY_UPDATE_EXPRESSION, node.toString());
}

From source file:org.flowable.admin.service.engine.FormInstanceService.java

public JsonNode getFormInstanceFormFieldValues(ServerConfig serverConfig, String formInstanceId) {

    ObjectNode returnNode = null;/*from   w ww  .  j  a  v a 2 s  .  c o m*/

    try {
        returnNode = objectMapper.createObjectNode();

        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("formInstanceId", formInstanceId);

        URIBuilder builder = clientUtil.createUriBuilder("form/form-instance-model");
        HttpPost post = clientUtil.createPost(builder.toString(), serverConfig);
        post.setEntity(clientUtil.createStringEntity(requestNode.toString()));

        JsonNode resultNode = clientUtil.executeRequest(post, serverConfig);

        ArrayNode formFieldValues = objectMapper.createArrayNode();

        if (resultNode != null && resultNode.has("fields") && resultNode.get("fields").isArray()) {

            ArrayNode fieldsNode = (ArrayNode) resultNode.get("fields");
            for (JsonNode fieldNode : fieldsNode) {

                ObjectNode formFieldValue = objectMapper.createObjectNode();

                formFieldValue.set("id", fieldNode.get("id"));
                formFieldValue.set("name", fieldNode.get("name"));
                formFieldValue.set("type", fieldNode.get("type"));
                formFieldValue.set("value", fieldNode.get("value"));

                formFieldValues.add(formFieldValue);
            }
        }

        returnNode.put("size", formFieldValues.size());
        returnNode.put("total", formFieldValues.size());
        returnNode.set("data", formFieldValues);
    } catch (Exception ex) {
        throw new FlowableServiceException(ex.getMessage(), ex);
    }

    return returnNode;
}

From source file:io.sqp.transbase.TBTypeRepository.java

private String createDateTimeSchema(DateRangeSpecifier highField, DateRangeSpecifier lowField) {
    List<DateRangeSpecifier> fields = DateRangeSpecifier.range(highField, lowField);
    ObjectNode schema = createDateTimeSchemaSkeleton(highField, lowField);
    ArrayNode items = _objectMapper.createArrayNode();
    fields.forEach(f -> items.add(createTypeFromSpecifier(f)));
    schema.set("items", items);
    schema.put("minItems", fields.size());
    schema.put("additionalItems", false);
    return schema.toString();
}

From source file:org.flowable.cmmn.rest.service.api.repository.CaseDefinitionResourceTest.java

@CmmnDeployment(resources = { "org/flowable/cmmn/rest/service/api/repository/oneHumanTaskCase.cmmn" })
public void testUpdateProcessDefinitionCategory() throws Exception {
    CaseDefinition caseDefinition = repositoryService.createCaseDefinitionQuery().singleResult();
    assertEquals(1, repositoryService.createCaseDefinitionQuery()
            .caseDefinitionCategory("http://flowable.org/cmmn").count());

    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("category", "updatedcategory");

    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX
            + CmmnRestUrls.createRelativeResourceUrl(CmmnRestUrls.URL_CASE_DEFINITION, caseDefinition.getId()));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);

    // Check "OK" status
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);//from w ww .  j  av a  2s . co m
    assertEquals("updatedcategory", responseNode.get("category").textValue());

    // Check actual entry in DB
    assertEquals(1,
            repositoryService.createCaseDefinitionQuery().caseDefinitionCategory("updatedcategory").count());

}

From source file:org.activiti.rest.content.service.api.content.ContentItemCollectionResourceTest.java

public void testCreateContentItemNoName() throws Exception {
    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("mimeType", "application/pdf");

    // Post JSON without name
    HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX
            + ContentRestUrls.createRelativeResourceUrl(ContentRestUrls.URL_CONTENT_ITEM_COLLECTION));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_BAD_REQUEST));
}

From source file:org.flowable.rest.service.api.runtime.ProcessInstanceResourceTest.java

/**
 * Test suspending a single process instance.
 *///from   w w w.  ja va  2s .c o m
@Deployment(resources = {
        "org/flowable/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" })
public void testSuspendProcessInstance() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne", "myBusinessKey");

    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "suspend");

    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX
            + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE, processInstance.getId()));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);

    // Check engine id instance is suspended
    assertEquals(1, runtimeService.createProcessInstanceQuery().suspended()
            .processInstanceId(processInstance.getId()).count());

    // Check resulting instance is suspended
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals(processInstance.getId(), responseNode.get("id").textValue());
    assertTrue(responseNode.get("suspended").booleanValue());

    // Suspending again should result in conflict
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPut, HttpStatus.SC_CONFLICT));
}

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

/**
 * Test suspending a single process instance.
 *///from www  .j  av a2s  .co m
@Deployment(resources = {
        "org/activiti/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" })
public void testSuspendProcessInstance() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne", "myBusinessKey");

    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "suspend");

    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX
            + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE, processInstance.getId()));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);

    // Check engine id instance is suspended
    assertEquals(1, runtimeService.createProcessInstanceQuery().suspended()
            .processInstanceId(processInstance.getId()).count());

    // Check resulting instance is suspended
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals(processInstance.getId(), responseNode.get("id").textValue());
    assertTrue(responseNode.get("suspended").booleanValue());

    // Suspending again should result in conflict
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPut, HttpStatus.SC_CONFLICT));
}

From source file:org.flowable.rest.service.api.runtime.ProcessInstanceResourceTest.java

/**
 * Test suspending a single process instance.
 *///from  w w w.  j a  v  a 2  s.c  om
@Deployment(resources = {
        "org/flowable/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" })
public void testActivateProcessInstance() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne", "myBusinessKey");
    runtimeService.suspendProcessInstanceById(processInstance.getId());

    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "activate");

    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX
            + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE, processInstance.getId()));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);

    // Check engine id instance is suspended
    assertEquals(1, runtimeService.createProcessInstanceQuery().active()
            .processInstanceId(processInstance.getId()).count());

    // Check resulting instance is suspended
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals(processInstance.getId(), responseNode.get("id").textValue());
    assertFalse(responseNode.get("suspended").booleanValue());

    // Activating again should result in conflict
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPut, HttpStatus.SC_CONFLICT));
}

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

/**
 * Test suspending a single process instance.
 *///from w  w w .  j  a v a 2s.c o m
@Deployment(resources = {
        "org/activiti/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" })
public void testActivateProcessInstance() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne", "myBusinessKey");
    runtimeService.suspendProcessInstanceById(processInstance.getId());

    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "activate");

    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX
            + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE, processInstance.getId()));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);

    // Check engine id instance is suspended
    assertEquals(1, runtimeService.createProcessInstanceQuery().active()
            .processInstanceId(processInstance.getId()).count());

    // Check resulting instance is suspended
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals(processInstance.getId(), responseNode.get("id").textValue());
    assertFalse(responseNode.get("suspended").booleanValue());

    // Activating again should result in conflict
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPut, HttpStatus.SC_CONFLICT));
}