Search in sources :

Example 61 with ObjectNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project Activiti by Activiti.

the class GroupCollectionResourceTest method testCreateGroupExceptions.

public void testCreateGroupExceptions() throws Exception {
    // Create without ID
    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("name", "Test group");
    requestNode.put("type", "Test type");
    HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPost, HttpStatus.SC_BAD_REQUEST));
    // Create when group already exists
    requestNode = objectMapper.createObjectNode();
    requestNode.put("id", "admin");
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPost, HttpStatus.SC_CONFLICT));
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode)

Example 62 with ObjectNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project Activiti by Activiti.

the class GroupResourceTest method testUpdateGroupNullFields.

/**
   * Test updating a single user passing in null-values.
   */
public void testUpdateGroupNullFields() throws Exception {
    try {
        Group testGroup = identityService.newGroup("testgroup");
        testGroup.setName("Test group");
        testGroup.setType("Test type");
        identityService.saveGroup(testGroup);
        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("name", (JsonNode) null);
        requestNode.put("type", (JsonNode) null);
        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());
        assertNull(responseNode.get("name").textValue());
        assertNull(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);
        assertNull(createdGroup.getName());
        assertNull(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
        }
    }
}
Also used : Group(org.activiti.engine.identity.Group) StringEntity(org.apache.http.entity.StringEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) HttpPut(org.apache.http.client.methods.HttpPut)

Example 63 with ObjectNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project Activiti by Activiti.

the class GroupResourceTest method testUpdateGroup.

/**
   * Test updating a single group.
   */
public void testUpdateGroup() throws Exception {
    try {
        Group testGroup = identityService.newGroup("testgroup");
        testGroup.setName("Test group");
        testGroup.setType("Test type");
        identityService.saveGroup(testGroup);
        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("name", "Updated group");
        requestNode.put("type", "Updated type");
        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("Updated group", responseNode.get("name").textValue());
        assertEquals("Updated 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("Updated group", createdGroup.getName());
        assertEquals("Updated 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
        }
    }
}
Also used : Group(org.activiti.engine.identity.Group) StringEntity(org.apache.http.entity.StringEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) HttpPut(org.apache.http.client.methods.HttpPut)

Example 64 with ObjectNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project Activiti by Activiti.

the class GroupResourceTest method testUpdateGroupNoFields.

/**
   * Test updating a single group passing in no fields in the json, user should remain unchanged.
   */
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
        }
    }
}
Also used : Group(org.activiti.engine.identity.Group) StringEntity(org.apache.http.entity.StringEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) HttpPut(org.apache.http.client.methods.HttpPut)

Example 65 with ObjectNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project Activiti by Activiti.

the class BaseProcessDefinitionDiagramLayoutResource method getDiagramNode.

public ObjectNode getDiagramNode(String processInstanceId, String processDefinitionId) {
    List<String> highLightedFlows = Collections.<String>emptyList();
    List<String> highLightedActivities = Collections.<String>emptyList();
    Map<String, ObjectNode> subProcessInstanceMap = new HashMap<String, ObjectNode>();
    ProcessInstance processInstance = null;
    if (processInstanceId != null) {
        processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
        if (processInstance == null) {
            throw new ActivitiObjectNotFoundException("Process instance could not be found");
        }
        processDefinitionId = processInstance.getProcessDefinitionId();
        List<ProcessInstance> subProcessInstances = runtimeService.createProcessInstanceQuery().superProcessInstanceId(processInstanceId).list();
        for (ProcessInstance subProcessInstance : subProcessInstances) {
            String subDefId = subProcessInstance.getProcessDefinitionId();
            String superExecutionId = ((ExecutionEntity) subProcessInstance).getSuperExecutionId();
            ProcessDefinitionEntity subDef = (ProcessDefinitionEntity) repositoryService.getProcessDefinition(subDefId);
            ObjectNode processInstanceJSON = new ObjectMapper().createObjectNode();
            processInstanceJSON.put("processInstanceId", subProcessInstance.getId());
            processInstanceJSON.put("superExecutionId", superExecutionId);
            processInstanceJSON.put("processDefinitionId", subDef.getId());
            processInstanceJSON.put("processDefinitionKey", subDef.getKey());
            processInstanceJSON.put("processDefinitionName", subDef.getName());
            subProcessInstanceMap.put(superExecutionId, processInstanceJSON);
        }
    }
    if (processDefinitionId == null) {
        throw new ActivitiObjectNotFoundException("No process definition id provided");
    }
    ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) repositoryService.getProcessDefinition(processDefinitionId);
    if (processDefinition == null) {
        throw new ActivitiException("Process definition " + processDefinitionId + " could not be found");
    }
    ObjectNode responseJSON = new ObjectMapper().createObjectNode();
    // Process definition
    JsonNode pdrJSON = getProcessDefinitionResponse(processDefinition);
    if (pdrJSON != null) {
        responseJSON.put("processDefinition", pdrJSON);
    }
    // Highlighted activities
    if (processInstance != null) {
        ArrayNode activityArray = new ObjectMapper().createArrayNode();
        ArrayNode flowsArray = new ObjectMapper().createArrayNode();
        highLightedActivities = runtimeService.getActiveActivityIds(processInstanceId);
        highLightedFlows = getHighLightedFlows(processInstanceId, processDefinition);
        for (String activityName : highLightedActivities) {
            activityArray.add(activityName);
        }
        for (String flow : highLightedFlows) flowsArray.add(flow);
        responseJSON.put("highLightedActivities", activityArray);
        responseJSON.put("highLightedFlows", flowsArray);
    }
    // Pool shape, if process is participant in collaboration
    if (processDefinition.getParticipantProcess() != null) {
        ParticipantProcess pProc = processDefinition.getParticipantProcess();
        ObjectNode participantProcessJSON = new ObjectMapper().createObjectNode();
        participantProcessJSON.put("id", pProc.getId());
        if (StringUtils.isNotEmpty(pProc.getName())) {
            participantProcessJSON.put("name", pProc.getName());
        } else {
            participantProcessJSON.put("name", "");
        }
        participantProcessJSON.put("x", pProc.getX());
        participantProcessJSON.put("y", pProc.getY());
        participantProcessJSON.put("width", pProc.getWidth());
        participantProcessJSON.put("height", pProc.getHeight());
        responseJSON.put("participantProcess", participantProcessJSON);
    }
    if (processDefinition.getLaneSets() != null && !processDefinition.getLaneSets().isEmpty()) {
        ArrayNode laneSetArray = new ObjectMapper().createArrayNode();
        for (LaneSet laneSet : processDefinition.getLaneSets()) {
            ArrayNode laneArray = new ObjectMapper().createArrayNode();
            if (laneSet.getLanes() != null && !laneSet.getLanes().isEmpty()) {
                for (Lane lane : laneSet.getLanes()) {
                    ObjectNode laneJSON = new ObjectMapper().createObjectNode();
                    laneJSON.put("id", lane.getId());
                    if (StringUtils.isNotEmpty(lane.getName())) {
                        laneJSON.put("name", lane.getName());
                    } else {
                        laneJSON.put("name", "");
                    }
                    laneJSON.put("x", lane.getX());
                    laneJSON.put("y", lane.getY());
                    laneJSON.put("width", lane.getWidth());
                    laneJSON.put("height", lane.getHeight());
                    List<String> flowNodeIds = lane.getFlowNodeIds();
                    ArrayNode flowNodeIdsArray = new ObjectMapper().createArrayNode();
                    for (String flowNodeId : flowNodeIds) {
                        flowNodeIdsArray.add(flowNodeId);
                    }
                    laneJSON.put("flowNodeIds", flowNodeIdsArray);
                    laneArray.add(laneJSON);
                }
            }
            ObjectNode laneSetJSON = new ObjectMapper().createObjectNode();
            laneSetJSON.put("id", laneSet.getId());
            if (StringUtils.isNotEmpty(laneSet.getName())) {
                laneSetJSON.put("name", laneSet.getName());
            } else {
                laneSetJSON.put("name", "");
            }
            laneSetJSON.put("lanes", laneArray);
            laneSetArray.add(laneSetJSON);
        }
        if (laneSetArray.size() > 0)
            responseJSON.put("laneSets", laneSetArray);
    }
    ArrayNode sequenceFlowArray = new ObjectMapper().createArrayNode();
    ArrayNode activityArray = new ObjectMapper().createArrayNode();
    for (ActivityImpl activity : processDefinition.getActivities()) {
        getActivity(processInstanceId, activity, activityArray, sequenceFlowArray, processInstance, highLightedFlows, subProcessInstanceMap);
    }
    responseJSON.put("activities", activityArray);
    responseJSON.put("sequenceFlows", sequenceFlowArray);
    return responseJSON;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) Lane(org.activiti.engine.impl.pvm.process.Lane) JsonNode(com.fasterxml.jackson.databind.JsonNode) LaneSet(org.activiti.engine.impl.pvm.process.LaneSet) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ParticipantProcess(org.activiti.engine.impl.pvm.process.ParticipantProcess) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2446 JsonNode (com.fasterxml.jackson.databind.JsonNode)556 Test (org.junit.Test)556 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)509 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)370 IOException (java.io.IOException)214 ArrayList (java.util.ArrayList)119 HashMap (java.util.HashMap)107 Map (java.util.Map)106 List (java.util.List)96 StringEntity (org.apache.http.entity.StringEntity)94 Deployment (org.activiti.engine.test.Deployment)85 Test (org.testng.annotations.Test)81 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)69 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)65 HttpPost (org.apache.http.client.methods.HttpPost)57 AbstractRpcLwM2MIntegrationTest (org.thingsboard.server.transport.lwm2m.rpc.AbstractRpcLwM2MIntegrationTest)54 TextNode (com.fasterxml.jackson.databind.node.TextNode)52 File (java.io.File)51 Task (org.activiti.engine.task.Task)51