Search in sources :

Example 11 with ArrayNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project jackson-databind by FasterXML.

the class ArrayNodeTest method testArrayViaMapper.

public void testArrayViaMapper() throws Exception {
    final String JSON = "[[[-0.027512,51.503221],[-0.008497,51.503221],[-0.008497,51.509744],[-0.027512,51.509744]]]";
    JsonNode n = objectMapper().readTree(JSON);
    assertNotNull(n);
    assertTrue(n.isArray());
    ArrayNode an = (ArrayNode) n;
    assertEquals(1, an.size());
    ArrayNode an2 = (ArrayNode) n.get(0);
    assertTrue(an2.isArray());
    assertEquals(4, an2.size());
}
Also used : ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 12 with ArrayNode

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

the class BpmnJsonConverter method convertToJson.

public ObjectNode convertToJson(BpmnModel model) {
    ObjectNode modelNode = objectMapper.createObjectNode();
    double maxX = 0.0;
    double maxY = 0.0;
    for (GraphicInfo flowInfo : model.getLocationMap().values()) {
        if ((flowInfo.getX() + flowInfo.getWidth()) > maxX) {
            maxX = flowInfo.getX() + flowInfo.getWidth();
        }
        if ((flowInfo.getY() + flowInfo.getHeight()) > maxY) {
            maxY = flowInfo.getY() + flowInfo.getHeight();
        }
    }
    maxX += 50;
    maxY += 50;
    if (maxX < 1485) {
        maxX = 1485;
    }
    if (maxY < 700) {
        maxY = 700;
    }
    modelNode.put("bounds", BpmnJsonConverterUtil.createBoundsNode(maxX, maxY, 0, 0));
    modelNode.put("resourceId", "canvas");
    ObjectNode stencilNode = objectMapper.createObjectNode();
    stencilNode.put("id", "BPMNDiagram");
    modelNode.put("stencil", stencilNode);
    ObjectNode stencilsetNode = objectMapper.createObjectNode();
    stencilsetNode.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#");
    stencilsetNode.put("url", "../editor/stencilsets/bpmn2.0/bpmn2.0.json");
    modelNode.put("stencilset", stencilsetNode);
    ArrayNode shapesArrayNode = objectMapper.createArrayNode();
    Process mainProcess = null;
    if (model.getPools().size() > 0) {
        mainProcess = model.getProcess(model.getPools().get(0).getId());
    } else {
        mainProcess = model.getMainProcess();
    }
    ObjectNode propertiesNode = objectMapper.createObjectNode();
    if (StringUtils.isNotEmpty(mainProcess.getId())) {
        propertiesNode.put(PROPERTY_PROCESS_ID, mainProcess.getId());
    }
    if (StringUtils.isNotEmpty(mainProcess.getName())) {
        propertiesNode.put(PROPERTY_NAME, mainProcess.getName());
    }
    if (StringUtils.isNotEmpty(mainProcess.getDocumentation())) {
        propertiesNode.put(PROPERTY_DOCUMENTATION, mainProcess.getDocumentation());
    }
    if (mainProcess.isExecutable() == false) {
        propertiesNode.put(PROPERTY_PROCESS_EXECUTABLE, "No");
    }
    if (StringUtils.isNoneEmpty(model.getTargetNamespace())) {
        propertiesNode.put(PROPERTY_PROCESS_NAMESPACE, model.getTargetNamespace());
    }
    BpmnJsonConverterUtil.convertMessagesToJson(model.getMessages(), propertiesNode);
    BpmnJsonConverterUtil.convertListenersToJson(mainProcess.getExecutionListeners(), true, propertiesNode);
    BpmnJsonConverterUtil.convertEventListenersToJson(mainProcess.getEventListeners(), propertiesNode);
    BpmnJsonConverterUtil.convertSignalDefinitionsToJson(model, propertiesNode);
    BpmnJsonConverterUtil.convertMessagesToJson(model, propertiesNode);
    if (CollectionUtils.isNotEmpty(mainProcess.getDataObjects())) {
        BpmnJsonConverterUtil.convertDataPropertiesToJson(mainProcess.getDataObjects(), propertiesNode);
    }
    modelNode.put(EDITOR_SHAPE_PROPERTIES, propertiesNode);
    boolean poolHasDI = false;
    if (model.getPools().size() > 0) {
        for (Pool pool : model.getPools()) {
            GraphicInfo graphicInfo = model.getGraphicInfo(pool.getId());
            if (graphicInfo != null) {
                poolHasDI = true;
                break;
            }
        }
    }
    if (model.getPools().size() > 0 && poolHasDI) {
        for (Pool pool : model.getPools()) {
            GraphicInfo graphicInfo = model.getGraphicInfo(pool.getId());
            if (graphicInfo == null)
                continue;
            ObjectNode poolNode = BpmnJsonConverterUtil.createChildShape(pool.getId(), STENCIL_POOL, graphicInfo.getX() + graphicInfo.getWidth(), graphicInfo.getY() + graphicInfo.getHeight(), graphicInfo.getX(), graphicInfo.getY());
            shapesArrayNode.add(poolNode);
            ObjectNode poolPropertiesNode = objectMapper.createObjectNode();
            poolPropertiesNode.put(PROPERTY_OVERRIDE_ID, pool.getId());
            poolPropertiesNode.put(PROPERTY_PROCESS_ID, pool.getProcessRef());
            if (pool.isExecutable() == false) {
                poolPropertiesNode.put(PROPERTY_PROCESS_EXECUTABLE, PROPERTY_VALUE_NO);
            }
            if (StringUtils.isNotEmpty(pool.getName())) {
                poolPropertiesNode.put(PROPERTY_NAME, pool.getName());
            }
            poolNode.put(EDITOR_SHAPE_PROPERTIES, poolPropertiesNode);
            ArrayNode laneShapesArrayNode = objectMapper.createArrayNode();
            poolNode.put(EDITOR_CHILD_SHAPES, laneShapesArrayNode);
            ArrayNode outgoingArrayNode = objectMapper.createArrayNode();
            poolNode.put("outgoing", outgoingArrayNode);
            Process process = model.getProcess(pool.getId());
            if (process != null) {
                Map<String, ArrayNode> laneMap = new HashMap<String, ArrayNode>();
                for (Lane lane : process.getLanes()) {
                    GraphicInfo laneGraphicInfo = model.getGraphicInfo(lane.getId());
                    if (laneGraphicInfo == null)
                        continue;
                    ObjectNode laneNode = BpmnJsonConverterUtil.createChildShape(lane.getId(), STENCIL_LANE, laneGraphicInfo.getX() + laneGraphicInfo.getWidth(), laneGraphicInfo.getY() + laneGraphicInfo.getHeight(), laneGraphicInfo.getX(), laneGraphicInfo.getY());
                    laneShapesArrayNode.add(laneNode);
                    ObjectNode lanePropertiesNode = objectMapper.createObjectNode();
                    lanePropertiesNode.put(PROPERTY_OVERRIDE_ID, lane.getId());
                    if (StringUtils.isNotEmpty(lane.getName())) {
                        lanePropertiesNode.put(PROPERTY_NAME, lane.getName());
                    }
                    laneNode.put(EDITOR_SHAPE_PROPERTIES, lanePropertiesNode);
                    ArrayNode elementShapesArrayNode = objectMapper.createArrayNode();
                    laneNode.put(EDITOR_CHILD_SHAPES, elementShapesArrayNode);
                    laneNode.put("outgoing", objectMapper.createArrayNode());
                    laneMap.put(lane.getId(), elementShapesArrayNode);
                }
                for (FlowElement flowElement : process.getFlowElements()) {
                    Lane laneForElement = null;
                    GraphicInfo laneGraphicInfo = null;
                    FlowElement lookForElement = null;
                    if (flowElement instanceof SequenceFlow) {
                        SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
                        lookForElement = model.getFlowElement(sequenceFlow.getSourceRef());
                    } else {
                        lookForElement = flowElement;
                    }
                    for (Lane lane : process.getLanes()) {
                        if (lane.getFlowReferences().contains(lookForElement.getId())) {
                            laneGraphicInfo = model.getGraphicInfo(lane.getId());
                            if (laneGraphicInfo != null) {
                                laneForElement = lane;
                            }
                            break;
                        }
                    }
                    if (flowElement instanceof SequenceFlow || laneForElement != null) {
                        processFlowElement(flowElement, process, model, laneMap.get(laneForElement.getId()), laneGraphicInfo.getX(), laneGraphicInfo.getY());
                    }
                }
                processArtifacts(process, model, shapesArrayNode, 0.0, 0.0);
            }
            for (MessageFlow messageFlow : model.getMessageFlows().values()) {
                if (messageFlow.getSourceRef().equals(pool.getId())) {
                    outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(messageFlow.getId()));
                }
            }
        }
        processMessageFlows(model, shapesArrayNode);
    } else {
        processFlowElements(model.getMainProcess(), model, shapesArrayNode, 0.0, 0.0);
        processMessageFlows(model, shapesArrayNode);
    }
    modelNode.put(EDITOR_CHILD_SHAPES, shapesArrayNode);
    return modelNode;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) GraphicInfo(org.activiti.bpmn.model.GraphicInfo) Lane(org.activiti.bpmn.model.Lane) Process(org.activiti.bpmn.model.Process) SubProcess(org.activiti.bpmn.model.SubProcess) MessageFlow(org.activiti.bpmn.model.MessageFlow) FlowElement(org.activiti.bpmn.model.FlowElement) Pool(org.activiti.bpmn.model.Pool) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 13 with ArrayNode

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

the class BpmnJsonConverter method convertToBpmnModel.

public BpmnModel convertToBpmnModel(JsonNode modelNode) {
    BpmnModel bpmnModel = new BpmnModel();
    bpmnModel.setTargetNamespace("http://activiti.org/test");
    Map<String, JsonNode> shapeMap = new HashMap<String, JsonNode>();
    Map<String, JsonNode> sourceRefMap = new HashMap<String, JsonNode>();
    Map<String, JsonNode> edgeMap = new HashMap<String, JsonNode>();
    Map<String, List<JsonNode>> sourceAndTargetMap = new HashMap<String, List<JsonNode>>();
    readShapeDI(modelNode, 0, 0, shapeMap, sourceRefMap, bpmnModel);
    filterAllEdges(modelNode, edgeMap, sourceAndTargetMap, shapeMap, sourceRefMap);
    readEdgeDI(edgeMap, sourceAndTargetMap, bpmnModel);
    ArrayNode shapesArrayNode = (ArrayNode) modelNode.get(EDITOR_CHILD_SHAPES);
    if (shapesArrayNode == null || shapesArrayNode.size() == 0)
        return bpmnModel;
    boolean nonEmptyPoolFound = false;
    Map<String, Lane> elementInLaneMap = new HashMap<String, Lane>();
    // first create the pool structure
    for (JsonNode shapeNode : shapesArrayNode) {
        String stencilId = BpmnJsonConverterUtil.getStencilId(shapeNode);
        if (STENCIL_POOL.equals(stencilId)) {
            Pool pool = new Pool();
            pool.setId(BpmnJsonConverterUtil.getElementId(shapeNode));
            pool.setName(JsonConverterUtil.getPropertyValueAsString(PROPERTY_NAME, shapeNode));
            pool.setProcessRef(JsonConverterUtil.getPropertyValueAsString(PROPERTY_PROCESS_ID, shapeNode));
            pool.setExecutable(JsonConverterUtil.getPropertyValueAsBoolean(PROPERTY_PROCESS_EXECUTABLE, shapeNode, true));
            bpmnModel.getPools().add(pool);
            Process process = new Process();
            process.setId(pool.getProcessRef());
            process.setName(pool.getName());
            process.setExecutable(pool.isExecutable());
            bpmnModel.addProcess(process);
            ArrayNode laneArrayNode = (ArrayNode) shapeNode.get(EDITOR_CHILD_SHAPES);
            for (JsonNode laneNode : laneArrayNode) {
                // should be a lane, but just check to be certain
                String laneStencilId = BpmnJsonConverterUtil.getStencilId(laneNode);
                if (STENCIL_LANE.equals(laneStencilId)) {
                    nonEmptyPoolFound = true;
                    Lane lane = new Lane();
                    lane.setId(BpmnJsonConverterUtil.getElementId(laneNode));
                    lane.setName(JsonConverterUtil.getPropertyValueAsString(PROPERTY_NAME, laneNode));
                    lane.setParentProcess(process);
                    process.getLanes().add(lane);
                    processJsonElements(laneNode.get(EDITOR_CHILD_SHAPES), modelNode, lane, shapeMap, bpmnModel);
                    if (CollectionUtils.isNotEmpty(lane.getFlowReferences())) {
                        for (String elementRef : lane.getFlowReferences()) {
                            elementInLaneMap.put(elementRef, lane);
                        }
                    }
                }
            }
        }
    }
    // Signal Definitions exist on the root level
    JsonNode signalDefinitionNode = BpmnJsonConverterUtil.getProperty(PROPERTY_SIGNAL_DEFINITIONS, modelNode);
    signalDefinitionNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(signalDefinitionNode);
    // no idea why this needs to be done twice ..
    signalDefinitionNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(signalDefinitionNode);
    if (signalDefinitionNode != null) {
        if (signalDefinitionNode instanceof ArrayNode) {
            ArrayNode signalDefinitionArrayNode = (ArrayNode) signalDefinitionNode;
            Iterator<JsonNode> signalDefinitionIterator = signalDefinitionArrayNode.iterator();
            while (signalDefinitionIterator.hasNext()) {
                JsonNode signalDefinitionJsonNode = signalDefinitionIterator.next();
                String signalId = signalDefinitionJsonNode.get(PROPERTY_SIGNAL_DEFINITION_ID).asText();
                String signalName = signalDefinitionJsonNode.get(PROPERTY_SIGNAL_DEFINITION_NAME).asText();
                String signalScope = signalDefinitionJsonNode.get(PROPERTY_SIGNAL_DEFINITION_SCOPE).asText();
                Signal signal = new Signal();
                signal.setId(signalId);
                signal.setName(signalName);
                signal.setScope((signalScope.toLowerCase().equals("processinstance")) ? Signal.SCOPE_PROCESS_INSTANCE : Signal.SCOPE_GLOBAL);
                bpmnModel.addSignal(signal);
            }
        }
    }
    if (nonEmptyPoolFound == false) {
        Process process = new Process();
        bpmnModel.getProcesses().add(process);
        process.setId(BpmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_PROCESS_ID, modelNode));
        process.setName(BpmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_NAME, modelNode));
        String namespace = BpmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_PROCESS_NAMESPACE, modelNode);
        if (StringUtils.isNotEmpty(namespace)) {
            bpmnModel.setTargetNamespace(namespace);
        }
        process.setDocumentation(BpmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_DOCUMENTATION, modelNode));
        JsonNode processExecutableNode = JsonConverterUtil.getProperty(PROPERTY_PROCESS_EXECUTABLE, modelNode);
        if (processExecutableNode != null && StringUtils.isNotEmpty(processExecutableNode.asText())) {
            process.setExecutable(JsonConverterUtil.getPropertyValueAsBoolean(PROPERTY_PROCESS_EXECUTABLE, modelNode));
        }
        BpmnJsonConverterUtil.convertJsonToMessages(modelNode, bpmnModel);
        BpmnJsonConverterUtil.convertJsonToListeners(modelNode, process);
        JsonNode eventListenersNode = BpmnJsonConverterUtil.getProperty(PROPERTY_EVENT_LISTENERS, modelNode);
        if (eventListenersNode != null) {
            eventListenersNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(eventListenersNode);
            BpmnJsonConverterUtil.parseEventListeners(eventListenersNode.get(PROPERTY_EVENTLISTENER_VALUE), process);
        }
        JsonNode processDataPropertiesNode = modelNode.get(EDITOR_SHAPE_PROPERTIES).get(PROPERTY_DATA_PROPERTIES);
        if (processDataPropertiesNode != null) {
            List<ValuedDataObject> dataObjects = BpmnJsonConverterUtil.convertJsonToDataProperties(processDataPropertiesNode, process);
            process.setDataObjects(dataObjects);
            process.getFlowElements().addAll(dataObjects);
        }
        processJsonElements(shapesArrayNode, modelNode, process, shapeMap, bpmnModel);
    } else {
        // sequence flows are on root level so need additional parsing for pools
        for (JsonNode shapeNode : shapesArrayNode) {
            if (STENCIL_SEQUENCE_FLOW.equalsIgnoreCase(BpmnJsonConverterUtil.getStencilId(shapeNode)) || STENCIL_ASSOCIATION.equalsIgnoreCase(BpmnJsonConverterUtil.getStencilId(shapeNode))) {
                String sourceRef = BpmnJsonConverterUtil.lookForSourceRef(shapeNode.get(EDITOR_SHAPE_ID).asText(), modelNode.get(EDITOR_CHILD_SHAPES));
                if (sourceRef != null) {
                    Lane lane = elementInLaneMap.get(sourceRef);
                    SequenceFlowJsonConverter flowConverter = new SequenceFlowJsonConverter();
                    if (lane != null) {
                        flowConverter.convertToBpmnModel(shapeNode, modelNode, this, lane, shapeMap, bpmnModel);
                    } else {
                        flowConverter.convertToBpmnModel(shapeNode, modelNode, this, bpmnModel.getProcesses().get(0), shapeMap, bpmnModel);
                    }
                }
            }
        }
    }
    // sequence flows are now all on root level
    Map<String, SubProcess> subShapesMap = new HashMap<String, SubProcess>();
    for (Process process : bpmnModel.getProcesses()) {
        for (FlowElement flowElement : process.findFlowElementsOfType(SubProcess.class)) {
            SubProcess subProcess = (SubProcess) flowElement;
            fillSubShapes(subShapesMap, subProcess);
        }
        if (subShapesMap.size() > 0) {
            List<String> removeSubFlowsList = new ArrayList<String>();
            for (FlowElement flowElement : process.findFlowElementsOfType(SequenceFlow.class)) {
                SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
                if (subShapesMap.containsKey(sequenceFlow.getSourceRef())) {
                    SubProcess subProcess = subShapesMap.get(sequenceFlow.getSourceRef());
                    if (subProcess.getFlowElement(sequenceFlow.getId()) == null) {
                        subProcess.addFlowElement(sequenceFlow);
                        removeSubFlowsList.add(sequenceFlow.getId());
                    }
                }
            }
            for (String flowId : removeSubFlowsList) {
                process.removeFlowElement(flowId);
            }
        }
    }
    Map<String, FlowWithContainer> allFlowMap = new HashMap<String, FlowWithContainer>();
    List<Gateway> gatewayWithOrderList = new ArrayList<Gateway>();
    // post handling of process elements
    for (Process process : bpmnModel.getProcesses()) {
        postProcessElements(process, process.getFlowElements(), edgeMap, bpmnModel, allFlowMap, gatewayWithOrderList);
    }
    // sort the sequence flows
    for (Gateway gateway : gatewayWithOrderList) {
        List<ExtensionElement> orderList = gateway.getExtensionElements().get("EDITOR_FLOW_ORDER");
        if (CollectionUtils.isNotEmpty(orderList)) {
            for (ExtensionElement orderElement : orderList) {
                String flowValue = orderElement.getElementText();
                if (StringUtils.isNotEmpty(flowValue)) {
                    if (allFlowMap.containsKey(flowValue)) {
                        FlowWithContainer flowWithContainer = allFlowMap.get(flowValue);
                        flowWithContainer.getFlowContainer().removeFlowElement(flowWithContainer.getSequenceFlow().getId());
                        flowWithContainer.getFlowContainer().addFlowElement(flowWithContainer.getSequenceFlow());
                    }
                }
            }
        }
        gateway.getExtensionElements().remove("EDITOR_FLOW_ORDER");
    }
    return bpmnModel;
}
Also used : ValuedDataObject(org.activiti.bpmn.model.ValuedDataObject) HashMap(java.util.HashMap) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) ArrayList(java.util.ArrayList) ExtensionElement(org.activiti.bpmn.model.ExtensionElement) JsonNode(com.fasterxml.jackson.databind.JsonNode) Process(org.activiti.bpmn.model.Process) SubProcess(org.activiti.bpmn.model.SubProcess) BpmnModel(org.activiti.bpmn.model.BpmnModel) Signal(org.activiti.bpmn.model.Signal) Gateway(org.activiti.bpmn.model.Gateway) ArrayList(java.util.ArrayList) List(java.util.List) Pool(org.activiti.bpmn.model.Pool) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) SubProcess(org.activiti.bpmn.model.SubProcess) Lane(org.activiti.bpmn.model.Lane) FlowElement(org.activiti.bpmn.model.FlowElement)

Example 14 with ArrayNode

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

the class TaskQueryResourceTest method testQueryTasks.

/**
   * Test querying tasks.
   * GET runtime/tasks
   */
@Deployment
public void testQueryTasks() throws Exception {
    try {
        Calendar adhocTaskCreate = Calendar.getInstance();
        adhocTaskCreate.set(Calendar.MILLISECOND, 0);
        Calendar processTaskCreate = Calendar.getInstance();
        processTaskCreate.add(Calendar.HOUR, 2);
        processTaskCreate.set(Calendar.MILLISECOND, 0);
        Calendar inBetweenTaskCreation = Calendar.getInstance();
        inBetweenTaskCreation.add(Calendar.HOUR, 1);
        processEngineConfiguration.getClock().setCurrentTime(adhocTaskCreate.getTime());
        Task adhocTask = taskService.newTask();
        adhocTask.setAssignee("gonzo");
        adhocTask.setOwner("owner");
        adhocTask.setDelegationState(DelegationState.PENDING);
        adhocTask.setDescription("Description one");
        adhocTask.setName("Name one");
        adhocTask.setDueDate(adhocTaskCreate.getTime());
        adhocTask.setPriority(100);
        adhocTask.setFormKey("myForm.json");
        adhocTask.setCategory("some-category");
        taskService.saveTask(adhocTask);
        taskService.addUserIdentityLink(adhocTask.getId(), "misspiggy", IdentityLinkType.PARTICIPANT);
        processEngineConfiguration.getClock().setCurrentTime(processTaskCreate.getTime());
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", "myBusinessKey");
        Task processTask = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
        processTask.setParentTaskId(adhocTask.getId());
        processTask.setPriority(50);
        processTask.setDueDate(processTaskCreate.getTime());
        taskService.saveTask(processTask);
        // Check filter-less to fetch all tasks
        String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_QUERY);
        ObjectNode requestNode = objectMapper.createObjectNode();
        assertResultsPresentInPostDataResponse(url, requestNode, processTask.getId(), adhocTask.getId());
        // Name filtering
        requestNode.removeAll();
        requestNode.put("name", "Name one");
        assertResultsPresentInPostDataResponse(url, requestNode, adhocTask.getId());
        // Name like filtering
        requestNode.removeAll();
        requestNode.put("nameLike", "%one");
        assertResultsPresentInPostDataResponse(url, requestNode, adhocTask.getId());
        // Description filtering
        requestNode.removeAll();
        requestNode.put("description", "Description one");
        assertResultsPresentInPostDataResponse(url, requestNode, adhocTask.getId());
        // Description like filtering
        requestNode.removeAll();
        requestNode.put("descriptionLike", "%one");
        assertResultsPresentInPostDataResponse(url, requestNode, adhocTask.getId());
        // Priority filtering
        requestNode.removeAll();
        requestNode.put("priority", 100);
        assertResultsPresentInPostDataResponse(url, requestNode, adhocTask.getId());
        // Mininmum Priority filtering
        requestNode.removeAll();
        requestNode.put("minimumPriority", 70);
        assertResultsPresentInPostDataResponse(url, requestNode, adhocTask.getId());
        // Maximum Priority filtering
        requestNode.removeAll();
        requestNode.put("maximumPriority", 70);
        assertResultsPresentInPostDataResponse(url, requestNode, processTask.getId());
        // Owner filtering
        requestNode.removeAll();
        requestNode.put("owner", "owner");
        assertResultsPresentInPostDataResponse(url, requestNode, adhocTask.getId());
        // Assignee filtering
        requestNode.removeAll();
        requestNode.put("assignee", "gonzo");
        assertResultsPresentInPostDataResponse(url, requestNode, adhocTask.getId());
        // Owner like filtering
        requestNode.removeAll();
        requestNode.put("ownerLike", "owne%");
        assertResultsPresentInPostDataResponse(url, requestNode, adhocTask.getId());
        // Assignee like filtering
        requestNode.removeAll();
        requestNode.put("assigneeLike", "%onzo");
        assertResultsPresentInPostDataResponse(url, requestNode, adhocTask.getId());
        // Unassigned filtering
        requestNode.removeAll();
        requestNode.put("unassigned", true);
        assertResultsPresentInPostDataResponse(url, requestNode, processTask.getId());
        // Delegation state filtering
        requestNode.removeAll();
        requestNode.put("delegationState", "pending");
        assertResultsPresentInPostDataResponse(url, requestNode, adhocTask.getId());
        // Candidate user filtering
        requestNode.removeAll();
        requestNode.put("candidateUser", "kermit");
        assertResultsPresentInPostDataResponse(url, requestNode, processTask.getId());
        // Candidate group filtering
        requestNode.removeAll();
        requestNode.put("candidateGroup", "sales");
        assertResultsPresentInPostDataResponse(url, requestNode, processTask.getId());
        // Candidate group In filtering
        requestNode.removeAll();
        ArrayNode arrayNode = requestNode.arrayNode();
        arrayNode.add("sales");
        arrayNode.add("someOtherGroup");
        requestNode.put("candidateGroupIn", arrayNode);
        assertResultsPresentInPostDataResponse(url, requestNode, processTask.getId());
        // Involved user filtering
        requestNode.removeAll();
        requestNode.put("involvedUser", "misspiggy");
        assertResultsPresentInPostDataResponse(url, requestNode, adhocTask.getId());
        // Process instance filtering
        requestNode.removeAll();
        requestNode.put("processInstanceId", processInstance.getId());
        assertResultsPresentInPostDataResponse(url, requestNode, processTask.getId());
        // Process instance id in filtering
        requestNode.removeAll();
        arrayNode = requestNode.arrayNode();
        arrayNode.add(processInstance.getId());
        requestNode.put("processInstanceIdIn", arrayNode);
        assertResultsPresentInPostDataResponse(url, requestNode, processTask.getId());
        // Execution filtering
        requestNode.removeAll();
        requestNode.put("executionId", processInstance.getId());
        assertResultsPresentInPostDataResponse(url, requestNode, processTask.getId());
        // Process instance businesskey filtering
        requestNode.removeAll();
        requestNode.put("processInstanceBusinessKey", "myBusinessKey");
        assertResultsPresentInPostDataResponse(url, requestNode, processTask.getId());
        // Process instance businesskey like filtering
        requestNode.removeAll();
        requestNode.put("processInstanceBusinessKeyLike", "myBusiness%");
        assertResultsPresentInPostDataResponse(url, requestNode, processTask.getId());
        // Process definition key
        requestNode.removeAll();
        requestNode.put("processDefinitionKey", "oneTaskProcess");
        assertResultsPresentInPostDataResponse(url, requestNode, processTask.getId());
        // Process definition key like
        requestNode.removeAll();
        requestNode.put("processDefinitionKeyLike", "%TaskProcess");
        assertResultsPresentInPostDataResponse(url, requestNode, processTask.getId());
        // Process definition name
        requestNode.removeAll();
        requestNode.put("processDefinitionName", "The One Task Process");
        assertResultsPresentInPostDataResponse(url, requestNode, processTask.getId());
        // Process definition name like
        requestNode.removeAll();
        requestNode.put("processDefinitionNameLike", "The One %");
        assertResultsPresentInPostDataResponse(url, requestNode, processTask.getId());
        // CeatedOn filtering
        requestNode.removeAll();
        requestNode.put("createdOn", getISODateString(adhocTaskCreate.getTime()));
        assertResultsPresentInPostDataResponse(url, requestNode, adhocTask.getId());
        // CreatedAfter filtering
        requestNode.removeAll();
        requestNode.put("createdAfter", getISODateString(inBetweenTaskCreation.getTime()));
        assertResultsPresentInPostDataResponse(url, requestNode, processTask.getId());
        // CreatedBefore filtering
        requestNode.removeAll();
        requestNode.put("createdBefore", getISODateString(inBetweenTaskCreation.getTime()));
        assertResultsPresentInPostDataResponse(url, requestNode, adhocTask.getId());
        // Subtask exclusion
        requestNode.removeAll();
        requestNode.put("excludeSubTasks", true);
        assertResultsPresentInPostDataResponse(url, requestNode, adhocTask.getId());
        // Task definition key filtering
        requestNode.removeAll();
        requestNode.put("taskDefinitionKey", "processTask");
        assertResultsPresentInPostDataResponse(url, requestNode, processTask.getId());
        // Task definition key like filtering
        requestNode.removeAll();
        requestNode.put("taskDefinitionKeyLike", "process%");
        assertResultsPresentInPostDataResponse(url, requestNode, processTask.getId());
        // Duedate filtering
        requestNode.removeAll();
        requestNode.put("dueDate", getISODateString(adhocTaskCreate.getTime()));
        assertResultsPresentInPostDataResponse(url, requestNode, adhocTask.getId());
        // Due after filtering
        requestNode.removeAll();
        requestNode.put("dueAfter", getISODateString(inBetweenTaskCreation.getTime()));
        assertResultsPresentInPostDataResponse(url, requestNode, processTask.getId());
        // Due before filtering
        requestNode.removeAll();
        requestNode.put("dueBefore", getISODateString(inBetweenTaskCreation.getTime()));
        assertResultsPresentInPostDataResponse(url, requestNode, adhocTask.getId());
        // Suspend process-instance to have a supended task
        runtimeService.suspendProcessInstanceById(processInstance.getId());
        // Suspended filering
        requestNode.removeAll();
        requestNode.put("active", false);
        assertResultsPresentInPostDataResponse(url, requestNode, processTask.getId());
        // Active filtering
        requestNode.removeAll();
        requestNode.put("active", true);
        assertResultsPresentInPostDataResponse(url, requestNode, adhocTask.getId());
        // Filtering by category
        requestNode.removeAll();
        requestNode.put("category", "some-category");
        assertResultsPresentInPostDataResponse(url, requestNode, adhocTask.getId());
        // Filtering without duedate
        requestNode.removeAll();
        requestNode.put("withoutDueDate", true);
        // No response should be returned, no tasks without a duedate yet 
        assertResultsPresentInPostDataResponse(url, requestNode);
        processTask = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
        processTask.setDueDate(null);
        taskService.saveTask(processTask);
        assertResultsPresentInPostDataResponse(url, requestNode, processTask.getId());
    } finally {
        // Clean adhoc-tasks even if test fails
        List<Task> tasks = taskService.createTaskQuery().list();
        for (Task task : tasks) {
            if (task.getExecutionId() == null) {
                taskService.deleteTask(task.getId(), true);
            }
        }
    }
}
Also used : Task(org.activiti.engine.task.Task) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Calendar(java.util.Calendar) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Deployment(org.activiti.engine.test.Deployment)

Example 15 with ArrayNode

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

the class TaskQueryResourceTest method testQueryTasksWithVariables.

/**
   * Test querying tasks using task and process variables. GET runtime/tasks
   */
@Deployment
public void testQueryTasksWithVariables() throws Exception {
    HashMap<String, Object> processVariables = new HashMap<String, Object>();
    processVariables.put("stringVar", "Azerty");
    processVariables.put("intVar", 67890);
    processVariables.put("booleanVar", false);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", processVariables);
    Task processTask = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    HashMap<String, Object> variables = new HashMap<String, Object>();
    variables.put("stringVar", "Abcdef");
    variables.put("intVar", 12345);
    variables.put("booleanVar", true);
    taskService.setVariablesLocal(processTask.getId(), variables);
    // Additional tasks to confirm it's filtered out
    runtimeService.startProcessInstanceByKey("oneTaskProcess");
    ObjectNode taskVariableRequestNode = objectMapper.createObjectNode();
    ArrayNode variableArray = objectMapper.createArrayNode();
    ObjectNode variableNode = objectMapper.createObjectNode();
    variableArray.add(variableNode);
    taskVariableRequestNode.put("taskVariables", variableArray);
    String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_QUERY);
    // String equals
    variableNode.put("name", "stringVar");
    variableNode.put("value", "Abcdef");
    variableNode.put("operation", "equals");
    assertResultsPresentInPostDataResponse(url, taskVariableRequestNode, processTask.getId());
    // Integer equals
    variableNode.removeAll();
    variableNode.put("name", "intVar");
    variableNode.put("value", 12345);
    variableNode.put("operation", "equals");
    assertResultsPresentInPostDataResponse(url, taskVariableRequestNode, processTask.getId());
    // Boolean equals
    variableNode.removeAll();
    variableNode.put("name", "booleanVar");
    variableNode.put("value", true);
    variableNode.put("operation", "equals");
    assertResultsPresentInPostDataResponse(url, taskVariableRequestNode, processTask.getId());
    // String not equals
    variableNode.removeAll();
    variableNode.put("name", "stringVar");
    variableNode.put("value", "ghijkl");
    variableNode.put("operation", "notEquals");
    assertResultsPresentInPostDataResponse(url, taskVariableRequestNode, processTask.getId());
    // Integer not equals
    variableNode.removeAll();
    variableNode.put("name", "intVar");
    variableNode.put("value", 45678);
    variableNode.put("operation", "notEquals");
    assertResultsPresentInPostDataResponse(url, taskVariableRequestNode, processTask.getId());
    // Boolean not equals
    variableNode.removeAll();
    variableNode.put("name", "booleanVar");
    variableNode.put("value", false);
    variableNode.put("operation", "notEquals");
    assertResultsPresentInPostDataResponse(url, taskVariableRequestNode, processTask.getId());
    // String equals ignore case
    variableNode.removeAll();
    variableNode.put("name", "stringVar");
    variableNode.put("value", "abCDEF");
    variableNode.put("operation", "equalsIgnoreCase");
    assertResultsPresentInPostDataResponse(url, taskVariableRequestNode, processTask.getId());
    // String not equals ignore case
    variableNode.removeAll();
    variableNode.put("name", "stringVar");
    variableNode.put("value", "HIJKLm");
    variableNode.put("operation", "notEqualsIgnoreCase");
    assertResultsPresentInPostDataResponse(url, taskVariableRequestNode, processTask.getId());
    // String equals without value
    variableNode.removeAll();
    variableNode.put("value", "Abcdef");
    variableNode.put("operation", "equals");
    assertResultsPresentInPostDataResponse(url, taskVariableRequestNode, processTask.getId());
    // Greater than
    variableNode.removeAll();
    variableNode.put("name", "intVar");
    variableNode.put("value", 12300);
    variableNode.put("operation", "greaterThan");
    assertResultsPresentInPostDataResponse(url, taskVariableRequestNode, processTask.getId());
    variableNode.put("value", 12345);
    variableNode.put("operation", "greaterThan");
    assertResultsPresentInPostDataResponse(url, taskVariableRequestNode);
    // Greater than or equal
    variableNode.removeAll();
    variableNode.put("name", "intVar");
    variableNode.put("value", 12300);
    variableNode.put("operation", "greaterThanOrEquals");
    assertResultsPresentInPostDataResponse(url, taskVariableRequestNode, processTask.getId());
    variableNode.put("value", 12345);
    assertResultsPresentInPostDataResponse(url, taskVariableRequestNode, processTask.getId());
    // Less than
    variableNode.removeAll();
    variableNode.put("name", "intVar");
    variableNode.put("value", 12400);
    variableNode.put("operation", "lessThan");
    assertResultsPresentInPostDataResponse(url, taskVariableRequestNode, processTask.getId());
    variableNode.put("value", 12345);
    variableNode.put("operation", "lessThan");
    assertResultsPresentInPostDataResponse(url, taskVariableRequestNode);
    // Less than or equal
    variableNode.removeAll();
    variableNode.put("name", "intVar");
    variableNode.put("value", 12400);
    variableNode.put("operation", "lessThanOrEquals");
    assertResultsPresentInPostDataResponse(url, taskVariableRequestNode, processTask.getId());
    variableNode.put("value", 12345);
    assertResultsPresentInPostDataResponse(url, taskVariableRequestNode, processTask.getId());
    // Like
    variableNode.removeAll();
    variableNode.put("name", "stringVar");
    variableNode.put("value", "Abcde%");
    variableNode.put("operation", "like");
    // Any other operation but equals without value
    variableNode.removeAll();
    variableNode.put("value", "abcdef");
    variableNode.put("operation", "notEquals");
    assertResultsPresentInPostDataResponseWithStatusCheck(url, taskVariableRequestNode, HttpStatus.SC_BAD_REQUEST);
    // Illegal (but existing) operation
    variableNode.removeAll();
    variableNode.put("name", "stringVar");
    variableNode.put("value", "abcdef");
    variableNode.put("operation", "operationX");
    assertResultsPresentInPostDataResponseWithStatusCheck(url, taskVariableRequestNode, HttpStatus.SC_BAD_REQUEST);
    // String like case does not match
    variableNode.removeAll();
    variableNode.put("name", "stringVar");
    variableNode.put("value", "%Abc%");
    variableNode.put("operation", "like");
    assertResultsPresentInPostDataResponse(url, taskVariableRequestNode, processTask.getId());
    // String like case does not match
    variableNode.removeAll();
    variableNode.put("name", "stringVar");
    variableNode.put("value", "%Bcde%");
    variableNode.put("operation", "like");
    assertResultsPresentInPostDataResponse(url, taskVariableRequestNode);
    // String like ignore case
    variableNode.removeAll();
    variableNode.put("name", "stringVar");
    variableNode.put("value", "%Bcde%");
    variableNode.put("operation", "likeIgnoreCase");
    assertResultsPresentInPostDataResponse(url, taskVariableRequestNode, processTask.getId());
    // String like ignore case process not found
    variableNode.removeAll();
    variableNode.put("name", "stringVar");
    variableNode.put("value", "%xyz%");
    variableNode.put("operation", "likeIgnoreCase");
    assertResultsPresentInPostDataResponse(url, taskVariableRequestNode);
    // Process variables
    ObjectNode processVariableRequestNode = objectMapper.createObjectNode();
    variableArray = objectMapper.createArrayNode();
    variableNode = objectMapper.createObjectNode();
    variableArray.add(variableNode);
    processVariableRequestNode.put("processInstanceVariables", variableArray);
    // String equals
    variableNode.put("name", "stringVar");
    variableNode.put("value", "Azerty");
    variableNode.put("operation", "equals");
    assertResultsPresentInPostDataResponse(url, processVariableRequestNode, processTask.getId());
    // Integer equals
    variableNode.removeAll();
    variableNode.put("name", "intVar");
    variableNode.put("value", 67890);
    variableNode.put("operation", "equals");
    assertResultsPresentInPostDataResponse(url, processVariableRequestNode, processTask.getId());
    // Boolean equals
    variableNode.removeAll();
    variableNode.put("name", "booleanVar");
    variableNode.put("value", false);
    variableNode.put("operation", "equals");
    assertResultsPresentInPostDataResponse(url, processVariableRequestNode, processTask.getId());
    // String not equals
    variableNode.removeAll();
    variableNode.put("name", "stringVar");
    variableNode.put("value", "ghijkl");
    variableNode.put("operation", "notEquals");
    assertResultsPresentInPostDataResponse(url, processVariableRequestNode, processTask.getId());
    // Integer not equals
    variableNode.removeAll();
    variableNode.put("name", "intVar");
    variableNode.put("value", 45678);
    variableNode.put("operation", "notEquals");
    assertResultsPresentInPostDataResponse(url, processVariableRequestNode, processTask.getId());
    // Boolean not equals
    variableNode.removeAll();
    variableNode.put("name", "booleanVar");
    variableNode.put("value", true);
    variableNode.put("operation", "notEquals");
    assertResultsPresentInPostDataResponse(url, processVariableRequestNode, processTask.getId());
    // String equals ignore case
    variableNode.removeAll();
    variableNode.put("name", "stringVar");
    variableNode.put("value", "azeRTY");
    variableNode.put("operation", "equalsIgnoreCase");
    assertResultsPresentInPostDataResponse(url, processVariableRequestNode, processTask.getId());
    // String not equals ignore case
    variableNode.removeAll();
    variableNode.put("name", "stringVar");
    variableNode.put("value", "HIJKLm");
    variableNode.put("operation", "notEqualsIgnoreCase");
    assertResultsPresentInPostDataResponse(url, processVariableRequestNode, processTask.getId());
    // String equals without value
    variableNode.removeAll();
    variableNode.put("value", "Azerty");
    variableNode.put("operation", "equals");
    assertResultsPresentInPostDataResponse(url, processVariableRequestNode, processTask.getId());
    // Greater than
    variableNode.removeAll();
    variableNode.put("name", "intVar");
    variableNode.put("value", 67800);
    variableNode.put("operation", "greaterThan");
    assertResultsPresentInPostDataResponse(url, processVariableRequestNode, processTask.getId());
    variableNode.put("value", 67890);
    variableNode.put("operation", "greaterThan");
    assertResultsPresentInPostDataResponse(url, processVariableRequestNode);
    // Greater than or equal
    variableNode.removeAll();
    variableNode.put("name", "intVar");
    variableNode.put("value", 67800);
    variableNode.put("operation", "greaterThanOrEquals");
    assertResultsPresentInPostDataResponse(url, processVariableRequestNode, processTask.getId());
    variableNode.put("value", 67890);
    assertResultsPresentInPostDataResponse(url, processVariableRequestNode, processTask.getId());
    // Less than
    variableNode.removeAll();
    variableNode.put("name", "intVar");
    variableNode.put("value", 67900);
    variableNode.put("operation", "lessThan");
    assertResultsPresentInPostDataResponse(url, processVariableRequestNode, processTask.getId());
    variableNode.put("value", 67890);
    variableNode.put("operation", "lessThan");
    assertResultsPresentInPostDataResponse(url, processVariableRequestNode);
    // Less than or equal
    variableNode.removeAll();
    variableNode.put("name", "intVar");
    variableNode.put("value", 67900);
    variableNode.put("operation", "lessThanOrEquals");
    assertResultsPresentInPostDataResponse(url, processVariableRequestNode, processTask.getId());
    variableNode.put("value", 67890);
    assertResultsPresentInPostDataResponse(url, processVariableRequestNode, processTask.getId());
    // Like
    variableNode.removeAll();
    variableNode.put("name", "stringVar");
    variableNode.put("value", "Azert%");
    variableNode.put("operation", "like");
    assertResultsPresentInPostDataResponse(url, processVariableRequestNode, processTask.getId());
    // incomplete Like missing wildcard does not match
    variableNode.removeAll();
    variableNode.put("name", "stringVar");
    variableNode.put("value", "Azert");
    variableNode.put("operation", "like");
    assertResultsPresentInPostDataResponse(url, processVariableRequestNode);
    // complete Like missing wildcard does match
    variableNode.removeAll();
    variableNode.put("name", "stringVar");
    variableNode.put("value", "Azerty");
    variableNode.put("operation", "like");
    assertResultsPresentInPostDataResponse(url, processVariableRequestNode, processTask.getId());
    // Like ignore case
    variableNode.removeAll();
    variableNode.put("name", "stringVar");
    variableNode.put("value", "%aZeRt%");
    variableNode.put("operation", "likeIgnoreCase");
    assertResultsPresentInPostDataResponse(url, processVariableRequestNode, processTask.getId());
}
Also used : Task(org.activiti.engine.task.Task) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Deployment(org.activiti.engine.test.Deployment)

Aggregations

ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)979 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)542 JsonNode (com.fasterxml.jackson.databind.JsonNode)402 Test (org.junit.Test)140 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)125 ArrayList (java.util.ArrayList)110 IOException (java.io.IOException)93 Map (java.util.Map)74 HashMap (java.util.HashMap)68 List (java.util.List)50 TextNode (com.fasterxml.jackson.databind.node.TextNode)38 Test (org.testng.annotations.Test)35 DefaultSerializerProvider (com.fasterxml.jackson.databind.ser.DefaultSerializerProvider)30 HashSet (java.util.HashSet)30 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)25 Deployment (org.activiti.engine.test.Deployment)23 File (java.io.File)22 InputStream (java.io.InputStream)20 Iterator (java.util.Iterator)20 StringEntity (org.apache.http.entity.StringEntity)20