Search in sources :

Example 16 with CaseInstance

use of org.kie.server.api.model.cases.CaseInstance in project droolsjbpm-integration by kiegroup.

the class CaseServicesClientImpl method getCaseInstance.

@Override
public CaseInstance getCaseInstance(String containerId, String caseId, boolean withData, boolean withRoles, boolean withMilestones, boolean withStages) {
    CaseInstance caseInstance = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(CASE_ID, caseId);
        String queryString = "?withData=" + withData + "&withRoles=" + withRoles + "&withMilestones=" + withMilestones + "&withStages=" + withStages;
        caseInstance = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), CASE_URI + "/" + CASE_INSTANCE_GET_URI, valuesMap) + queryString, CaseInstance.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("CaseService", "getCaseInstance", marshaller.getFormat().getType(), new Object[] { containerId, caseId, withData, withRoles, withMilestones, withStages })));
        ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand(script, DescriptorCommand.class.getName(), KieServerConstants.CAPABILITY_CASE).getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        caseInstance = deserialize(response.getResult(), CaseInstance.class);
    }
    return caseInstance;
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) CaseInstance(org.kie.server.api.model.cases.CaseInstance) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) HashMap(java.util.HashMap) CommandScript(org.kie.server.api.commands.CommandScript)

Example 17 with CaseInstance

use of org.kie.server.api.model.cases.CaseInstance in project droolsjbpm-integration by kiegroup.

the class PrometheusKieServerExtension method init.

@Override
public void init(KieServerImpl kieServer, KieServerRegistry registry) {
    this.context = registry;
    customMetrics = new PrometheusCustomMetricsSupport(this);
    registerDefaultDescriptor();
    // Prometheus Monitoring
    KieServerExtension jBPMExtension = context.getServerExtension(JbpmKieServerExtension.EXTENSION_NAME);
    if (jBPMExtension != null) {
        final KModuleDeploymentService deploymentService = jBPMExtension.getAppComponents(KModuleDeploymentService.class);
        if (deploymentService != null) {
            List<DeploymentEventListener> metrics = customMetrics.getDeploymentEventListener();
            if (!metrics.isEmpty()) {
                List<DeploymentEventListener> listeners = new ArrayList<>(metrics);
                listeners.forEach(l -> deploymentService.addListener(l));
            }
            deploymentService.addListener(new PrometheusDeploymentEventListener());
        }
        final ExecutorServiceImpl executorService = jBPMExtension.getAppComponents(ExecutorServiceImpl.class);
        if (executorService != null) {
            List<AsynchronousJobListener> metrics = customMetrics.getAsynchronousJobListener();
            if (!metrics.isEmpty()) {
                List<AsynchronousJobListener> listeners = new ArrayList<>(metrics);
                listeners.forEach(l -> executorService.addAsyncJobListener(l));
            }
            executorService.addAsyncJobListener(new PrometheusJobListener());
        }
        final QueryServiceImpl queryService = jBPMExtension.getAppComponents(QueryServiceImpl.class);
        if (queryService != null) {
            final DataSetDefRegistry dataSetDefRegistry = queryService.getDataSetDefRegistry();
            final PrometheusDataSetListener listener = new PrometheusDataSetListener(dataSetDefRegistry);
            listener.init();
            dataSetDefRegistry.addListener(listener);
        }
        final RuntimeDataService dataService = jBPMExtension.getAppComponents(RuntimeDataService.class);
        if (dataService != null) {
            final Collection<ProcessInstanceDesc> processInstances = dataService.getProcessInstances(asList(ProcessInstance.STATE_ACTIVE), null, new QueryContext(0, Integer.MAX_VALUE));
            processInstances.forEach(pi -> recordRunningProcessInstance(pi.getDeploymentId(), pi.getProcessId()));
        }
    }
    KieServerExtension caseExtension = context.getServerExtension(CaseKieServerExtension.EXTENSION_NAME);
    if (caseExtension != null) {
        final CaseManagementRuntimeDataServiceBase caseRuntime = caseExtension.getAppComponents(CaseManagementRuntimeDataServiceBase.class);
        if (caseRuntime != null) {
            final CaseInstanceList caseInstances = caseRuntime.getCaseInstances(asList(CaseStatus.OPEN.getName()), 0, Integer.MAX_VALUE, null, false);
            for (CaseInstance instance : caseInstances.getCaseInstances()) {
                recordRunningCaseInstance(instance.getCaseDefinitionId());
            }
        }
    }
    initialized = true;
    if (!customMetrics.hasCustomMetrics()) {
        LOGGER.info("{} started", toString());
    } else {
        LOGGER.info("{} started with custom Prometheus metrics provider(s): {}", toString(), customMetrics.customMetricsProviders());
    }
}
Also used : RuntimeDataService(org.jbpm.services.api.RuntimeDataService) AsynchronousJobListener(org.jbpm.executor.AsynchronousJobListener) ExecutorServiceImpl(org.jbpm.executor.impl.ExecutorServiceImpl) JbpmKieServerExtension(org.kie.server.services.jbpm.JbpmKieServerExtension) KieServerExtension(org.kie.server.services.api.KieServerExtension) CaseKieServerExtension(org.kie.server.services.casemgmt.CaseKieServerExtension) CaseManagementRuntimeDataServiceBase(org.kie.server.services.casemgmt.CaseManagementRuntimeDataServiceBase) ArrayList(java.util.ArrayList) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) QueryContext(org.kie.api.runtime.query.QueryContext) DataSetDefRegistry(org.dashbuilder.dataset.def.DataSetDefRegistry) CaseInstanceList(org.kie.server.api.model.cases.CaseInstanceList) CaseInstance(org.kie.server.api.model.cases.CaseInstance) PrometheusCaseEventListener.recordRunningCaseInstance(org.kie.server.services.prometheus.PrometheusCaseEventListener.recordRunningCaseInstance) KModuleDeploymentService(org.jbpm.kie.services.impl.KModuleDeploymentService) DeploymentEventListener(org.jbpm.services.api.DeploymentEventListener) QueryServiceImpl(org.jbpm.kie.services.impl.query.QueryServiceImpl)

Example 18 with CaseInstance

use of org.kie.server.api.model.cases.CaseInstance in project droolsjbpm-integration by kiegroup.

the class CaseRuntimeDataServiceIntegrationTest method testGetCaseInstanceUserTaskCaseWithData.

@Test
public void testGetCaseInstanceUserTaskCaseWithData() {
    String caseId = startUserTaskCase(USER_YODA, USER_JOHN);
    caseClient.triggerAdHocFragment(CONTAINER_ID, caseId, "Milestone1", null);
    CaseInstance caseInstance = caseClient.getCaseInstance(CONTAINER_ID, caseId, true, true, true, true);
    assertHrCaseInstance(caseInstance, caseId, USER_YODA);
    KieServerAssert.assertNullOrEmpty("Stages should be empty.", caseInstance.getStages());
    // Assert case file
    assertNotNull(caseInstance.getCaseFile());
    assertEquals("first case started", caseInstance.getCaseFile().getData().get("s"));
    // Assert role assignments
    assertNotNull(caseInstance.getRoleAssignments());
    assertEquals(3, caseInstance.getRoleAssignments().size());
    CaseRoleAssignment ownerRole = caseInstance.getRoleAssignments().get(0);
    assertEquals("owner", ownerRole.getName());
    assertEquals(1, ownerRole.getUsers().size());
    assertEquals(USER_YODA, ownerRole.getUsers().get(0));
    KieServerAssert.assertNullOrEmpty("Groups should be empty.", ownerRole.getGroups());
    CaseRoleAssignment contactRole = caseInstance.getRoleAssignments().get(1);
    assertEquals("contact", contactRole.getName());
    assertEquals(1, contactRole.getUsers().size());
    assertEquals(USER_JOHN, contactRole.getUsers().get(0));
    KieServerAssert.assertNullOrEmpty("Groups should be empty.", contactRole.getGroups());
    CaseRoleAssignment participantRole = caseInstance.getRoleAssignments().get(2);
    assertEquals("participant", participantRole.getName());
    KieServerAssert.assertNullOrEmpty("Users should be empty.", participantRole.getUsers());
    KieServerAssert.assertNullOrEmpty("Groups should be empty.", participantRole.getGroups());
    // Assert milestones
    assertNotNull(caseInstance.getMilestones());
    assertEquals(2, caseInstance.getMilestones().size());
    CaseMilestone milestone = caseInstance.getMilestones().get(0);
    assertNotNull(milestone.getIdentifier());
    assertEquals("Milestone2", milestone.getName());
    assertEquals("Available", milestone.getStatus());
    assertNull(milestone.getAchievedAt());
    assertFalse(milestone.isAchieved());
    milestone = caseInstance.getMilestones().get(1);
    assertEquals("2", milestone.getIdentifier());
    assertEquals("Milestone1", milestone.getName());
    assertEquals("Completed", milestone.getStatus());
    assertNotNull(milestone.getAchievedAt());
    assertTrue(milestone.isAchieved());
}
Also used : CaseInstance(org.kie.server.api.model.cases.CaseInstance) CaseRoleAssignment(org.kie.server.api.model.cases.CaseRoleAssignment) CaseMilestone(org.kie.server.api.model.cases.CaseMilestone) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest) Test(org.junit.Test)

Example 19 with CaseInstance

use of org.kie.server.api.model.cases.CaseInstance in project droolsjbpm-integration by kiegroup.

the class CaseRuntimeDataServiceIntegrationTest method testGetCaseInstance.

@Test
public void testGetCaseInstance() {
    String caseId = startUserTaskCase(USER_YODA, USER_JOHN);
    CaseInstance caseInstance = caseClient.getCaseInstance(CONTAINER_ID, caseId);
    assertHrCaseInstance(caseInstance, caseId, USER_YODA);
    assertNull(caseInstance.getCaseFile());
    assertNull(caseInstance.getRoleAssignments());
    assertNull(caseInstance.getMilestones());
    assertNull(caseInstance.getStages());
}
Also used : CaseInstance(org.kie.server.api.model.cases.CaseInstance) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest) Test(org.junit.Test)

Example 20 with CaseInstance

use of org.kie.server.api.model.cases.CaseInstance in project droolsjbpm-integration by kiegroup.

the class CaseRuntimeDataServiceIntegrationTest method testTriggerNotExistingAdHocFragments.

@Test
public void testTriggerNotExistingAdHocFragments() {
    String caseId = startUserTaskCase(USER_YODA, USER_JOHN);
    assertNotNull(caseId);
    assertTrue(caseId.startsWith(CASE_HR_ID_PREFIX));
    CaseInstance caseInstance = caseClient.getCaseInstance(CONTAINER_ID, caseId);
    assertHrCaseInstance(caseInstance, caseId, USER_YODA);
    List<CaseInstance> caseInstances = caseClient.getCaseInstancesOwnedBy(USER_YODA, null, 0, 10);
    assertEquals(1, caseInstances.size());
    List<CaseMilestone> milestones = caseClient.getMilestones(CONTAINER_ID, caseId, true, 0, 10);
    assertNotNull(milestones);
    assertEquals(0, milestones.size());
    final String nonExistingAdHocFragment = "not existing";
    assertClientException(() -> caseClient.triggerAdHocFragment(CONTAINER_ID, caseId, nonExistingAdHocFragment, Collections.EMPTY_MAP), 404, "AdHoc fragment '" + nonExistingAdHocFragment + "' not found in case " + caseId);
}
Also used : CaseInstance(org.kie.server.api.model.cases.CaseInstance) CaseMilestone(org.kie.server.api.model.cases.CaseMilestone) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest) Test(org.junit.Test)

Aggregations

CaseInstance (org.kie.server.api.model.cases.CaseInstance)30 Test (org.junit.Test)17 JbpmKieServerBaseIntegrationTest (org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)17 CaseStatus (org.jbpm.casemgmt.api.model.CaseStatus)9 CaseInstanceList (org.kie.server.api.model.cases.CaseInstanceList)9 HashMap (java.util.HashMap)8 TaskSummary (org.kie.server.api.model.instance.TaskSummary)7 CaseFile (org.kie.server.api.model.cases.CaseFile)5 ArrayList (java.util.ArrayList)4 CaseRoleAssignment (org.kie.server.api.model.cases.CaseRoleAssignment)4 CaseStage (org.kie.server.api.model.cases.CaseStage)3 NodeInstance (org.kie.server.api.model.instance.NodeInstance)3 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Map (java.util.Map)2 BiFunction (java.util.function.BiFunction)2 Function (java.util.function.Function)2