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.runtime.TaskVariableResourceTest.java

/**
 * Test updating a single task variable in all scopes, including "not found" check.
 * //from   w w  w. ja v a2  s  .co m
 * PUT runtime/tasks/{taskId}/variables/{variableName}
 */
@CmmnDeployment(resources = { "org/flowable/cmmn/rest/service/api/repository/oneHumanTaskCase.cmmn" })
public void testUpdateTaskVariable() throws Exception {
    CaseInstance caseInstance = runtimeService.createCaseInstanceBuilder().caseDefinitionKey("oneHumanTaskCase")
            .variable("overlappingVariable", "processValue").start();
    Task task = taskService.createTaskQuery().caseInstanceId(caseInstance.getId()).singleResult();
    taskService.setVariableLocal(task.getId(), "overlappingVariable", "taskValue");

    // Update variable without scope, local should be presumed -> local
    // updated and global should be retained
    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("name", "overlappingVariable");
    requestNode.put("value", "updatedLocalValue");
    requestNode.put("type", "string");

    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + CmmnRestUrls
            .createRelativeResourceUrl(CmmnRestUrls.URL_TASK_VARIABLE, task.getId(), "overlappingVariable"));
    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("updatedLocalValue", responseNode.get("value").asText());
    assertEquals("local", responseNode.get("scope").asText());
    // Check local value is changed in engine and global one remains
    // unchanged
    assertEquals("updatedLocalValue", taskService.getVariableLocal(task.getId(), "overlappingVariable"));
    assertEquals("processValue", runtimeService.getVariable(task.getScopeId(), "overlappingVariable"));

    // Update variable in local scope
    requestNode = objectMapper.createObjectNode();
    requestNode.put("name", "overlappingVariable");
    requestNode.put("value", "updatedLocalValueOnceAgain");
    requestNode.put("type", "string");
    requestNode.put("scope", "local");
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    response = executeRequest(httpPut, HttpStatus.SC_OK);
    responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals("updatedLocalValueOnceAgain", responseNode.get("value").asText());
    assertEquals("local", responseNode.get("scope").asText());
    // Check local value is changed in engine and global one remains unchanged
    assertEquals("updatedLocalValueOnceAgain",
            taskService.getVariableLocal(task.getId(), "overlappingVariable"));
    assertEquals("processValue", runtimeService.getVariable(task.getScopeId(), "overlappingVariable"));

    // Update variable in global scope
    requestNode = objectMapper.createObjectNode();
    requestNode.put("name", "overlappingVariable");
    requestNode.put("value", "updatedInGlobalScope");
    requestNode.put("type", "string");
    requestNode.put("scope", "global");
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    response = executeRequest(httpPut, HttpStatus.SC_OK);
    responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals("updatedInGlobalScope", responseNode.get("value").asText());
    assertEquals("global", responseNode.get("scope").asText());
    // Check global value is changed in engine and local one remains unchanged
    assertEquals("updatedLocalValueOnceAgain",
            taskService.getVariableLocal(task.getId(), "overlappingVariable"));
    assertEquals("updatedInGlobalScope", runtimeService.getVariable(task.getScopeId(), "overlappingVariable"));

    // Try updating with mismatch between URL and body variableName unexisting property
    requestNode.put("name", "unexistingVariable");
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPut, HttpStatus.SC_BAD_REQUEST));

    // Try updating unexisting property
    requestNode.put("name", "unexistingVariable");
    httpPut = new HttpPut(SERVER_URL_PREFIX + CmmnRestUrls
            .createRelativeResourceUrl(CmmnRestUrls.URL_TASK_VARIABLE, task.getId(), "unexistingVariable"));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPut, HttpStatus.SC_NOT_FOUND));
}

From source file:org.apache.olingo.fit.utils.AbstractJSONUtilities.java

@Override
public InputStream deleteProperty(final InputStream src, final List<String> path) throws Exception {
    final ObjectMapper mapper = new ObjectMapper();
    final ObjectNode srcNode = (ObjectNode) mapper.readTree(src);
    IOUtils.closeQuietly(src);//w  w w.ja  v  a  2  s  .c o  m

    JsonNode node = srcNode;
    for (int i = 0; i < path.size() - 1; i++) {
        node = node.get(path.get(i));
        if (node == null) {
            throw new NotFoundException();
        }
    }

    ((ObjectNode) node).set(path.get(path.size() - 1), null);

    return IOUtils.toInputStream(srcNode.toString());
}

From source file:org.activiti.editor.ui.NewModelPopupWindow.java

protected void addButtons() {

    // Create/*from  www. j av  a2 s . c  o m*/
    Button createButton = new Button(i18nManager.getMessage(Messages.PROCESS_NEW_POPUP_CREATE_BUTTON));
    createButton.setWidth("200px");
    createButton.addListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {

            if (StringUtils.isEmpty((String) nameTextField.getValue())) {
                nameTextField.setComponentError(new UserError("The name field is required."));
                return;
            }

            if (selectEditorComponent.isModelerPreferred()) {
                try {
                    ObjectMapper objectMapper = new ObjectMapper();
                    ObjectNode editorNode = objectMapper.createObjectNode();
                    editorNode.put("id", "canvas");
                    editorNode.put("resourceId", "canvas");
                    ObjectNode stencilSetNode = objectMapper.createObjectNode();
                    stencilSetNode.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#");
                    editorNode.put("stencilset", stencilSetNode);
                    Model modelData = repositoryService.newModel();

                    ObjectNode modelObjectNode = objectMapper.createObjectNode();
                    modelObjectNode.put(MODEL_NAME, (String) nameTextField.getValue());
                    modelObjectNode.put(MODEL_REVISION, 1);
                    String description = null;
                    if (StringUtils.isNotEmpty((String) descriptionTextArea.getValue())) {
                        description = (String) descriptionTextArea.getValue();
                    } else {
                        description = "";
                    }
                    modelObjectNode.put(MODEL_DESCRIPTION, description);
                    modelData.setMetaInfo(modelObjectNode.toString());
                    modelData.setName((String) nameTextField.getValue());

                    repositoryService.saveModel(modelData);
                    repositoryService.addModelEditorSource(modelData.getId(),
                            editorNode.toString().getBytes("utf-8"));

                    close();

                    ExplorerApp.get().getViewManager().showEditorProcessDefinitionPage(modelData.getId());
                    URL explorerURL = ExplorerApp.get().getURL();
                    URL url = new URL(explorerURL.getProtocol(), explorerURL.getHost(), explorerURL.getPort(),
                            explorerURL.getPath().replace("/ui", "") + "service/editor?id="
                                    + modelData.getId());
                    ExplorerApp.get().getMainWindow().open(new ExternalResource(url));

                } catch (Exception e) {
                    notificationManager.showErrorNotification("error", e);
                }
            } else {

                close();
                ExplorerApp.get().getViewManager().showSimpleTableProcessEditor(
                        (String) nameTextField.getValue(), (String) descriptionTextArea.getValue());

            }
        }
    });

    // Alignment
    HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    buttonLayout.addComponent(createButton);
    addComponent(buttonLayout);
    windowLayout.setComponentAlignment(buttonLayout, Alignment.MIDDLE_CENTER);
}

From source file:org.flowable.cmmn.rest.service.BaseSpringRestTestCase.java

protected void assertResultsPresentInPostDataResponseWithStatusCheck(String url, ObjectNode body,
        int expectedStatusCode, String... expectedResourceIds) throws IOException {
    int numberOfResultsExpected = 0;
    if (expectedResourceIds != null) {
        numberOfResultsExpected = expectedResourceIds.length;
    }/* www .  j ava 2  s .  com*/

    // Do the actual call
    HttpPost post = new HttpPost(SERVER_URL_PREFIX + url);
    post.setEntity(new StringEntity(body.toString()));
    CloseableHttpResponse response = executeRequest(post, expectedStatusCode);

    if (expectedStatusCode == HttpStatus.SC_OK) {
        // Check status and size
        JsonNode rootNode = objectMapper.readTree(response.getEntity().getContent());
        JsonNode dataNode = rootNode.get("data");
        assertEquals(numberOfResultsExpected, dataNode.size());

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

    closeResponse(response);
}

From source file:com.kumuluz.ee.security.KeycloakSecurityConfigurationUtilImpl.java

private String getKeycloakConfig(Class targetClass) {
    ObjectMapper mapper = new ObjectMapper();

    ConfigurationUtil configurationUtil = ConfigurationUtil.getInstance();

    Keycloak keycloakAnnotation = (Keycloak) targetClass.getAnnotation(Keycloak.class);

    String jsonString;//from w  ww . j a  v a  2 s . c om
    ObjectNode json;
    String authServerUrl;
    String sslRequired;

    jsonString = configurationUtil.get("kumuluzee.security.keycloak.json").orElse("{}");
    json = toJSONObject(jsonString);

    if (jsonString.isEmpty() && keycloakAnnotation != null) {
        jsonString = keycloakAnnotation.json();
        json = toJSONObject(jsonString);

        authServerUrl = keycloakAnnotation.authServerUrl();
        sslRequired = keycloakAnnotation.sslRequired();

        if (!authServerUrl.isEmpty()) {
            json.put("auth-server-url", authServerUrl);
        }

        if (!sslRequired.isEmpty()) {
            json.put("ssl-required", sslRequired);
        }
    }

    return json.toString();
}

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

/**
 * Test starting a process instance, covering all edge-cases.
 *//*  w ww  . j  av a  2 s. c om*/
public void testStartProcessExceptions() throws Exception {

    ObjectNode requestNode = objectMapper.createObjectNode();

    // Try starting without id and key
    HttpPost httpPost = new HttpPost(
            SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPost, HttpStatus.SC_BAD_REQUEST));

    // Try starting with both id and key
    requestNode = objectMapper.createObjectNode();
    requestNode.put("processDefinitionId", "123");
    requestNode.put("processDefinitionKey", "456");

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

    // Try starting with both message and key
    requestNode = objectMapper.createObjectNode();
    requestNode.put("processDefinitionId", "123");
    requestNode.put("message", "456");

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

    // Try starting with unexisting process definition key
    requestNode = objectMapper.createObjectNode();
    requestNode.put("processDefinitionKey", "123");

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

    // Try starting with unexisting process definition id
    requestNode = objectMapper.createObjectNode();
    requestNode.put("processDefinitionId", "123");

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

    // Try starting with unexisting message
    requestNode = objectMapper.createObjectNode();
    requestNode.put("message", "unexistingmessage");

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

From source file:io.gs2.identifier.Gs2IdentifierClient.java

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

public CreateSecurityPolicyResult createSecurityPolicy(CreateSecurityPolicyRequest request) {

    ObjectNode body = JsonNodeFactory.instance.objectNode().put("name", request.getName()).put("policy",
            request.getPolicy());

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

    return doRequest(post, CreateSecurityPolicyResult.class);

}

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

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

public ChangeStaminaByStampSheetResult changeStaminaByStampSheet(ChangeStaminaByStampSheetRequest request) {

    ObjectNode body = JsonNodeFactory.instance.objectNode().put("sheet", request.getSheet()).put("keyName",
            request.getKeyName());
    if (request.getMaxValue() != null)
        body.put("maxValue", request.getMaxValue());

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

}

From source file:org.activiti.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.put("properties", propertyArray);
    ObjectNode propNode = objectMapper.createObjectNode();
    propNode.put("id", "room");
    propNode.put("value", 123l);
    propertyArray.add(propNode);//from www  .ja v  a  2  s.  com

    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.put("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);
}