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;
}
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());
}
}
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());
}
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());
}
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);
}
Aggregations