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.rest.service.api.form.FormDataResourceTest.java

@Deployment
public void testSubmitFormData() throws Exception {
    Map<String, Object> variableMap = new HashMap<String, Object>();
    variableMap.put("SpeakerName", "John Doe");
    Address address = new Address();
    variableMap.put("address", address);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variableMap);
    String processInstanceId = processInstance.getId();
    String processDefinitionId = processInstance.getProcessDefinitionId();
    Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();

    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("taskId", task.getId());
    ArrayNode propertyArray = objectMapper.createArrayNode();
    requestNode.set("properties", propertyArray);
    ObjectNode propNode = objectMapper.createObjectNode();
    propNode.put("id", "room");
    propNode.put("value", 123L);
    propertyArray.add(propNode);//w  w  w .j av a 2s  .c  om

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

    propNode = objectMapper.createObjectNode();
    propNode.put("id", "street");
    propNode.put("value", "test");
    propertyArray.add(propNode);

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

    task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
    assertNull(task);
    processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId)
            .singleResult();
    assertNull(processInstance);
    List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery()
            .processInstanceId(processInstanceId).list();
    Map<String, HistoricVariableInstance> historyMap = new HashMap<String, HistoricVariableInstance>();
    for (HistoricVariableInstance historicVariableInstance : variables) {
        historyMap.put(historicVariableInstance.getVariableName(), historicVariableInstance);
    }

    assertEquals("123", historyMap.get("room").getValue());
    assertEquals(processInstanceId, historyMap.get("room").getProcessInstanceId());

    processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variableMap);
    processInstanceId = processInstance.getId();
    task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();

    requestNode.put("taskId", task.getId());
    propNode = objectMapper.createObjectNode();
    propNode.put("id", "direction");
    propNode.put("value", "nowhere");
    propertyArray.add(propNode);
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPost, HttpStatus.SC_BAD_REQUEST));

    propNode.put("value", "up");
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPost, HttpStatus.SC_NO_CONTENT));

    task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
    assertNull(task);
    processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId)
            .singleResult();
    assertNull(processInstance);
    variables = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId)
            .list();
    historyMap.clear();
    for (HistoricVariableInstance historicVariableInstance : variables) {
        historyMap.put(historicVariableInstance.getVariableName(), historicVariableInstance);
    }

    assertEquals("123", historyMap.get("room").getValue());
    assertEquals(processInstanceId, historyMap.get("room").getProcessInstanceId());
    assertEquals("up", historyMap.get("direction").getValue());

    requestNode = objectMapper.createObjectNode();
    requestNode.put("processDefinitionId", processDefinitionId);
    propertyArray = objectMapper.createArrayNode();
    requestNode.set("properties", propertyArray);
    propNode = objectMapper.createObjectNode();
    propNode.put("id", "number");
    propNode.put("value", 123);
    propertyArray.add(propNode);

    httpPost.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode.get("id").asText());
    assertEquals(processDefinitionId, responseNode.get("processDefinitionId").asText());
    task = taskService.createTaskQuery().processInstanceId(responseNode.get("id").asText()).singleResult();
    assertNotNull(task);
}

From source file:io.gs2.timer.Gs2TimerClient.java

/**
 * ???<br>//from  w w w.  java  2  s.  c o m
 * <br>
 *
 * @param request 
        
 * @return ?
        
 */

public UpdateTimerPoolResult updateTimerPool(UpdateTimerPoolRequest request) {

    ObjectNode body = JsonNodeFactory.instance.objectNode();
    if (request.getDescription() != null)
        body.put("description", request.getDescription());
    HttpPut put = createHttpPut(
            Gs2Constant.ENDPOINT_HOST + "/timerPool/"
                    + (request.getTimerPoolName() == null || request.getTimerPoolName().equals("") ? "null"
                            : request.getTimerPoolName())
                    + "",
            credential, ENDPOINT, UpdateTimerPoolRequest.Constant.MODULE,
            UpdateTimerPoolRequest.Constant.FUNCTION, body.toString());
    if (request.getRequestId() != null) {
        put.setHeader("X-GS2-REQUEST-ID", request.getRequestId());
    }

    return doRequest(put, UpdateTimerPoolResult.class);

}

From source file:io.gs2.stamina.Gs2StaminaClient.java

/**
 * ?????<br>//from   w  ww .j  av a 2  s .c  o  m
 * <br>
 * - : 5<br>
 * <br>
 *
 * @param request 
        
 * @return ?
        
 */

public ConsumeStaminaByStampTaskResult consumeStaminaByStampTask(ConsumeStaminaByStampTaskRequest request) {

    ObjectNode body = JsonNodeFactory.instance.objectNode().put("task", request.getTask())
            .put("keyName", request.getKeyName()).put("transactionId", request.getTransactionId())
            .put("maxValue", request.getMaxValue());

    HttpPost post = createHttpPost(Gs2Constant.ENDPOINT_HOST + "/stamina/consume", credential, ENDPOINT,
            ConsumeStaminaByStampTaskRequest.Constant.MODULE,
            ConsumeStaminaByStampTaskRequest.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, ConsumeStaminaByStampTaskResult.class);

}

From source file:com.glaf.dts.web.rest.MxTableResource.java

@GET
@POST/*from w ww . j  av a  2s . c o m*/
@Path("/tablePage")
@ResponseBody
@Produces({ MediaType.APPLICATION_OCTET_STREAM })
public byte[] tablePage(@Context HttpServletRequest request, @Context UriInfo uriInfo) {
    Map<String, Object> params = RequestUtils.getParameterMap(request);
    logger.debug(params);

    String tableName = request.getParameter("tableName");
    String tableName_enc = request.getParameter("tableName_enc");
    if (StringUtils.isNotEmpty(tableName_enc)) {
        tableName = RequestUtils.decodeString(tableName_enc);
    }

    ObjectNode responseJSON = new ObjectMapper().createObjectNode();

    if (!DBUtils.isAllowedTable(tableName)) {
        try {
            return responseJSON.toString().getBytes("UTF-8");
        } catch (IOException e) {
            return responseJSON.toString().getBytes();
        }
    }

    String gridType = ParamUtils.getString(params, "gridType");
    if (gridType == null) {
        gridType = "easyui";
    }

    int start = 0;
    int limit = 10;
    String orderName = null;
    String order = null;
    if ("easyui".equals(gridType)) {
        int pageNo = ParamUtils.getInt(params, "page");
        limit = ParamUtils.getInt(params, "rows");
        start = (pageNo - 1) * limit;
        orderName = ParamUtils.getString(params, "sort");
        order = ParamUtils.getString(params, "order");
    } else if ("extjs".equals(gridType)) {
        start = ParamUtils.getInt(params, "start");
        limit = ParamUtils.getInt(params, "limit");
        orderName = ParamUtils.getString(params, "sort");
        order = ParamUtils.getString(params, "dir");
    } else if ("yui".equals(gridType)) {
        start = ParamUtils.getInt(params, "startIndex");
        limit = ParamUtils.getInt(params, "results");
        orderName = ParamUtils.getString(params, "sort");
        order = ParamUtils.getString(params, "dir");
    }

    if (start < 0) {
        start = 0;
    }

    if (limit <= 0 || limit > 10000) {
        limit = Paging.DEFAULT_PAGE_SIZE;
    }

    TablePageQuery query = new TablePageQuery();
    query.setFirstResult(start);
    query.setMaxResults(limit);
    query.tableName(tableName);
    if (orderName != null) {
        if (StringUtils.equals(order, "asc")) {
            query.orderAsc(orderName);
        } else {
            query.orderDesc(orderName);
        }
    }

    int total = -1;
    List<Map<String, Object>> rows = null;

    try {
        total = tablePageService.getTableCount(query);
        if (total > 0) {
            rows = tablePageService.getTableData(query);
        }
    } catch (Exception ex) {
        logger.error(ex);
    }

    ArrayNode rowsJSON = new ObjectMapper().createArrayNode();
    if (rows != null && !rows.isEmpty()) {
        responseJSON.put("total", total);
        for (Map<String, Object> dataMap : rows) {
            ObjectNode rowJSON = new ObjectMapper().createObjectNode();
            if (dataMap != null && dataMap.size() > 0) {
                Set<Entry<String, Object>> entrySet = dataMap.entrySet();
                for (Entry<String, Object> entry : entrySet) {
                    String name = entry.getKey();
                    Object value = entry.getValue();
                    if (value != null) {
                        if (value instanceof Date) {
                            Date date = (Date) value;
                            rowJSON.put(name, DateUtils.getDateTime(date));
                        } else {
                            rowJSON.put(name, value.toString());
                        }
                    } else {
                        rowJSON.put(name, "");
                    }
                }
            }
            rowsJSON.add(rowJSON);
        }
    }

    if ("yui".equals(gridType)) {
        responseJSON.set("records", rowsJSON);
    } else {
        responseJSON.set("rows", rowsJSON);
    }

    try {
        return responseJSON.toString().getBytes("UTF-8");
    } catch (IOException e) {
        return responseJSON.toString().getBytes();
    }
}

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

/**
 * Explicitly testing the statelessness of the Rest API.
 *///ww w .j a v  a 2s  . c o  m
@Deployment(resources = {
        "org/activiti/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" })
public void testStartProcessWithSameHttpClient() throws Exception {
    ObjectNode requestNode = objectMapper.createObjectNode();

    // Start using process definition key
    requestNode.put("processDefinitionKey", "processOne");

    HttpPost httpPost = new HttpPost(
            SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION));
    httpPost.setEntity(new StringEntity(requestNode.toString()));

    // First call
    closeResponse(executeRequest(httpPost, HttpStatus.SC_CREATED));

    // Second call
    closeResponse(executeRequest(httpPost, HttpStatus.SC_CREATED));

    List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().list();
    assertEquals(2, processInstances.size());
    for (ProcessInstance processInstance : processInstances) {
        HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery()
                .processInstanceId(processInstance.getId()).singleResult();
        assertNotNull(historicProcessInstance);
        assertEquals("kermit", historicProcessInstance.getStartUserId());
    }

}

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

/**
 * Explicitly testing the statelessness of the Rest API.
 *//*from w ww  .  j  av  a  2s  . c  om*/
@Deployment(resources = {
        "org/flowable/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" })
public void testStartProcessWithSameHttpClient() throws Exception {
    ObjectNode requestNode = objectMapper.createObjectNode();

    // Start using process definition key
    requestNode.put("processDefinitionKey", "processOne");

    HttpPost httpPost = new HttpPost(
            SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION));
    httpPost.setEntity(new StringEntity(requestNode.toString()));

    // First call
    closeResponse(executeRequest(httpPost, HttpStatus.SC_CREATED));

    // Second call
    closeResponse(executeRequest(httpPost, HttpStatus.SC_CREATED));

    List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().list();
    assertEquals(2, processInstances.size());
    for (ProcessInstance processInstance : processInstances) {
        HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery()
                .processInstanceId(processInstance.getId()).singleResult();
        assertNotNull(historicProcessInstance);
        assertEquals("kermit", historicProcessInstance.getStartUserId());
    }

}

From source file:org.flowable.app.service.editor.FlowableModelQueryService.java

public ModelRepresentation importProcessModel(HttpServletRequest request, MultipartFile file) {

    String fileName = file.getOriginalFilename();
    if (fileName != null && (fileName.endsWith(".bpmn") || fileName.endsWith(".bpmn20.xml"))) {
        try {/*from  w  ww.  ja va 2s .co m*/
            XMLInputFactory xif = XmlUtil.createSafeXmlInputFactory();
            InputStreamReader xmlIn = new InputStreamReader(file.getInputStream(), "UTF-8");
            XMLStreamReader xtr = xif.createXMLStreamReader(xmlIn);
            BpmnModel bpmnModel = bpmnXmlConverter.convertToBpmnModel(xtr);
            if (CollectionUtils.isEmpty(bpmnModel.getProcesses())) {
                throw new BadRequestException("No process found in definition " + fileName);
            }

            if (bpmnModel.getLocationMap().size() == 0) {
                BpmnAutoLayout bpmnLayout = new BpmnAutoLayout(bpmnModel);
                bpmnLayout.execute();
            }

            ObjectNode modelNode = bpmnJsonConverter.convertToJson(bpmnModel);

            org.flowable.bpmn.model.Process process = bpmnModel.getMainProcess();
            String name = process.getId();
            if (StringUtils.isNotEmpty(process.getName())) {
                name = process.getName();
            }
            String description = process.getDocumentation();

            ModelRepresentation model = new ModelRepresentation();
            model.setKey(process.getId());
            model.setName(name);
            model.setDescription(description);
            model.setModelType(AbstractModel.MODEL_TYPE_BPMN);
            Model newModel = modelService.createModel(model, modelNode.toString(),
                    SecurityUtils.getCurrentUserObject());
            return new ModelRepresentation(newModel);

        } catch (BadRequestException e) {
            throw e;

        } catch (Exception e) {
            logger.error("Import failed for " + fileName, e);
            throw new BadRequestException(
                    "Import failed for " + fileName + ", error message " + e.getMessage());
        }
    } else {
        throw new BadRequestException(
                "Invalid file name, only .bpmn and .bpmn20.xml files are supported not " + fileName);
    }
}

From source file:com.netflix.metacat.usermetadata.mysql.MysqlUserMetadataService.java

@Override
public void saveDataMetadata(@Nonnull final String uri, @Nonnull final String userId,
        @Nonnull final Optional<ObjectNode> metadata, final boolean merge) {
    final Optional<ObjectNode> existingData = getDataMetadata(uri);
    final int count;
    if (existingData.isPresent() && metadata.isPresent()) {
        final ObjectNode merged = existingData.get();
        if (merge) {
            metacatJson.mergeIntoPrimary(merged, metadata.get());
        }/* w  w w  .  j ava  2  s .  c om*/
        count = executeUpdateForKey(SQL.UPDATE_DATA_METADATA, merged.toString(), userId, uri);
    } else if (metadata.isPresent()) {
        count = executeUpdateForKey(SQL.INSERT_DATA_METADATA, metadata.get().toString(), userId, userId, uri);
    } else {
        // Nothing to insert in this case
        count = 1;
    }

    if (count != 1) {
        throw new IllegalStateException("Expected one row to be insert or update for " + uri);
    }
}

From source file:io.gs2.realtime.Gs2RealtimeClient.java

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

public CreateGatheringResult createGathering(CreateGatheringRequest request) {

    ObjectNode body = JsonNodeFactory.instance.objectNode();
    if (request.getName() != null)
        body.put("name", request.getName());
    if (request.getUserIds() != null)
        body.put("userIds", request.getUserIds());

    HttpPost post = createHttpPost(Gs2Constant.ENDPOINT_HOST + "/gatheringPool/"
            + (request.getGatheringPoolName() == null || request.getGatheringPoolName().equals("") ? "null"
                    : request.getGatheringPoolName())
            + "/gathering", credential, ENDPOINT, CreateGatheringRequest.Constant.MODULE,
            CreateGatheringRequest.Constant.FUNCTION, body.toString());
    if (request.getRequestId() != null) {
        post.setHeader("X-GS2-REQUEST-ID", request.getRequestId());
    }

    return doRequest(post, CreateGatheringResult.class);

}