Search in sources :

Example 21 with CaseDefinition

use of org.jbpm.casemgmt.api.model.CaseDefinition in project jbpm by kiegroup.

the class StageCompletionConditionTest method testAutoCompleteNoAutoStartTaskNotExistingAdHocInStage.

@Test
public void testAutoCompleteNoAutoStartTaskNotExistingAdHocInStage() {
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_NO_AUTOSTART);
    assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
    assertCaseInstanceActive(caseId);
    List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
    assertThat(tasks).isEmpty();
    CaseDefinition caseDef = caseRuntimeDataService.getCase(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_NO_AUTOSTART);
    Collection<CaseStage> stages = caseDef.getCaseStages();
    assertThat(stages).hasSize(1);
    String stageId = stages.iterator().next().getId();
    assertThatExceptionOfType(AdHocFragmentNotFoundException.class).isThrownBy(() -> {
        caseService.triggerAdHocFragment(caseId, stageId, "not existing", null);
    }).withMessageContaining("AdHoc fragment 'not existing' not found in case " + caseId + " and stage " + stageId);
    assertCaseInstanceActive(caseId);
    tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
    assertThat(tasks).hasSize(0);
    caseService.cancelCase(caseId);
    assertCaseInstanceNotActive(caseId);
}
Also used : QueryFilter(org.kie.internal.query.QueryFilter) CaseStage(org.jbpm.casemgmt.api.model.CaseStage) CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) TaskSummary(org.kie.api.task.model.TaskSummary) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 22 with CaseDefinition

use of org.jbpm.casemgmt.api.model.CaseDefinition in project jbpm by kiegroup.

the class CaseRuntimeDataServiceImpl method getCaseInstanceStages.

@Override
public Collection<CaseStageInstance> getCaseInstanceStages(String caseId, boolean activeOnly, QueryContext queryContext) {
    ProcessInstanceDesc pi = runtimeDataService.getProcessInstanceByCorrelationKey(correlationKeyFactory.newCorrelationKey(caseId));
    if (pi == null || !pi.getState().equals(ProcessInstance.STATE_ACTIVE)) {
        throw new CaseNotFoundException("No case instance found with id " + caseId + " or it's not active anymore");
    }
    CaseDefinition caseDef = getCase(pi.getDeploymentId(), pi.getProcessId());
    List<CaseStageInstance> stages = internalGetCaseStages(caseDef, caseId, activeOnly, queryContext);
    return applyPagination(stages, queryContext);
}
Also used : CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException)

Example 23 with CaseDefinition

use of org.jbpm.casemgmt.api.model.CaseDefinition in project jbpm by kiegroup.

the class CaseRuntimeDataServiceImpl method getCaseInstanceMilestones.

@Override
public Collection<CaseMilestoneInstance> getCaseInstanceMilestones(String caseId, boolean achievedOnly, QueryContext queryContext) {
    ProcessInstanceDesc pi = runtimeDataService.getProcessInstanceByCorrelationKey(correlationKeyFactory.newCorrelationKey(caseId));
    if (pi == null || !pi.getState().equals(ProcessInstance.STATE_ACTIVE)) {
        throw new CaseNotFoundException("No case instance found with id " + caseId + " or it's not active anymore");
    }
    CorrelationKey correlationKey = correlationKeyFactory.newCorrelationKey(caseId);
    Collection<org.jbpm.services.api.model.NodeInstanceDesc> nodes = runtimeDataService.getNodeInstancesByCorrelationKeyNodeType(correlationKey, Arrays.asList(ProcessInstance.STATE_ACTIVE), Arrays.asList("MilestoneNode"), queryContext);
    Collection<Long> completedNodes = nodes.stream().filter(n -> ((NodeInstanceDesc) n).getType() == 1).map(n -> n.getId()).collect(toList());
    Predicate<org.jbpm.services.api.model.NodeInstanceDesc> filterNodes = null;
    if (achievedOnly) {
        filterNodes = n -> ((NodeInstanceDesc) n).getType() == 1;
    } else {
        filterNodes = n -> ((NodeInstanceDesc) n).getType() == 0;
    }
    List<String> foundMilestones = new ArrayList<>();
    List<CaseMilestoneInstance> milestones = nodes.stream().filter(filterNodes).map(n -> {
        foundMilestones.add(n.getName());
        return new CaseMilestoneInstanceImpl(String.valueOf(n.getId()), n.getName(), completedNodes.contains(n.getId()), n.getDataTimeStamp());
    }).collect(toList());
    if (!achievedOnly) {
        // add other milestones that are present in the definition
        CaseDefinition caseDef = getCase(pi.getDeploymentId(), pi.getProcessId());
        caseDef.getCaseMilestones().stream().filter(cm -> !foundMilestones.contains(cm.getName())).map(cm -> new CaseMilestoneInstanceImpl(cm.getId(), cm.getName(), false, null)).forEach(cmi -> milestones.add(cmi));
    }
    return applyPagination(milestones, queryContext);
}
Also used : TaskSummary(org.kie.api.task.model.TaskSummary) Arrays(java.util.Arrays) CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) WorkflowProcess(org.jbpm.workflow.core.WorkflowProcess) ProcessDefinition(org.jbpm.services.api.model.ProcessDefinition) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) DynamicNode(org.jbpm.workflow.core.node.DynamicNode) StartNode(org.jbpm.workflow.core.node.StartNode) CaseRuntimeDataService(org.jbpm.casemgmt.api.CaseRuntimeDataService) CaseDefinitionComparator(org.jbpm.casemgmt.impl.model.CaseDefinitionComparator) Collectors.toMap(java.util.stream.Collectors.toMap) NodeInstanceDesc(org.jbpm.kie.services.impl.model.NodeInstanceDesc) Map(java.util.Map) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) KieInternalServices(org.kie.internal.KieInternalServices) AuthorizationManager(org.jbpm.casemgmt.api.auth.AuthorizationManager) CaseMilestoneInstance(org.jbpm.casemgmt.api.model.instance.CaseMilestoneInstance) CaseMilestone(org.jbpm.casemgmt.api.model.CaseMilestone) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Process(org.kie.api.definition.process.Process) FILTER(org.kie.internal.query.QueryParameterIdentifiers.FILTER) Set(java.util.Set) DeploymentRolesManager(org.jbpm.kie.services.impl.security.DeploymentRolesManager) QueryContext(org.kie.api.runtime.query.QueryContext) Collectors(java.util.stream.Collectors) CaseMilestoneInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseMilestoneInstanceImpl) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) ProcessAssetDesc(org.jbpm.kie.services.impl.model.ProcessAssetDesc) CaseFileItem(org.jbpm.casemgmt.api.model.CaseFileItem) List(java.util.List) DeployedAsset(org.jbpm.services.api.model.DeployedAsset) MilestoneNode(org.jbpm.workflow.core.node.MilestoneNode) AdHocFragment(org.jbpm.casemgmt.api.model.AdHocFragment) ServiceRegistry(org.jbpm.services.api.service.ServiceRegistry) CorrelationKeyFactory(org.kie.internal.process.CorrelationKeyFactory) Status(org.kie.api.task.model.Status) NodeContainer(org.kie.api.definition.process.NodeContainer) AdHocFragmentImpl(org.jbpm.casemgmt.impl.model.AdHocFragmentImpl) CaseDefinitionImpl(org.jbpm.casemgmt.impl.model.CaseDefinitionImpl) CaseRole(org.jbpm.casemgmt.api.model.CaseRole) CaseRoleImpl(org.jbpm.casemgmt.impl.model.CaseRoleImpl) CaseStageInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseStageInstanceImpl) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) HashMap(java.util.HashMap) DeploymentEventListener(org.jbpm.services.api.DeploymentEventListener) TransactionalCommandService(org.jbpm.shared.services.impl.TransactionalCommandService) ArrayList(java.util.ArrayList) ProcessDefinitionComparator(org.jbpm.casemgmt.impl.model.ProcessDefinitionComparator) HashSet(java.util.HashSet) CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) DeploymentEvent(org.jbpm.services.api.DeploymentEvent) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) StageStatus(org.jbpm.casemgmt.api.model.instance.StageStatus) CaseStage(org.jbpm.casemgmt.api.model.CaseStage) CaseStageImpl(org.jbpm.casemgmt.impl.model.CaseStageImpl) KieBase(org.kie.api.KieBase) IdentityProvider(org.kie.internal.identity.IdentityProvider) QueryManager(org.jbpm.shared.services.impl.QueryManager) CorrelationKey(org.kie.internal.process.CorrelationKey) QueryNameCommand(org.jbpm.shared.services.impl.commands.QueryNameCommand) CaseIdGenerator(org.jbpm.casemgmt.api.generator.CaseIdGenerator) Collectors.toList(java.util.stream.Collectors.toList) Node(org.kie.api.definition.process.Node) RuntimeDataService(org.jbpm.services.api.RuntimeDataService) CaseStatus(org.jbpm.casemgmt.api.model.CaseStatus) CaseMilestoneImpl(org.jbpm.casemgmt.impl.model.CaseMilestoneImpl) CommonUtils.getAuthenticatedUserRoles(org.jbpm.kie.services.impl.CommonUtils.getAuthenticatedUserRoles) Collections(java.util.Collections) CaseMilestoneInstance(org.jbpm.casemgmt.api.model.instance.CaseMilestoneInstance) ArrayList(java.util.ArrayList) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) CorrelationKey(org.kie.internal.process.CorrelationKey) CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) CaseMilestoneInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseMilestoneInstanceImpl) NodeInstanceDesc(org.jbpm.kie.services.impl.model.NodeInstanceDesc)

Example 24 with CaseDefinition

use of org.jbpm.casemgmt.api.model.CaseDefinition in project jbpm by kiegroup.

the class CaseServiceImpl method newCaseFileInstanceWithRestrictions.

@Override
public CaseFileInstance newCaseFileInstanceWithRestrictions(String deploymentId, String caseDefinition, Map<String, Object> data, Map<String, List<String>> accessRestrictions) {
    CaseDefinition def = caseRuntimeDataService.getCase(deploymentId, caseDefinition);
    if (def == null) {
        throw new CaseDefinitionNotFoundException("Case definition " + caseDefinition + " does not exist in deployment " + deploymentId);
    }
    CaseFileInstanceImpl caseFile = new CaseFileInstanceImpl(caseDefinition, data);
    caseFile.setupRoles(def.getCaseRoles());
    Map<String, List<String>> combinedAccessRestrictions = def.getDataAccessRestrictions();
    if (accessRestrictions != null) {
        combinedAccessRestrictions.putAll(accessRestrictions);
    }
    caseFile.setAccessRestrictions(combinedAccessRestrictions);
    return caseFile;
}
Also used : CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) CaseFileInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl) List(java.util.List) ArrayList(java.util.ArrayList) CaseDefinitionNotFoundException(org.jbpm.casemgmt.api.CaseDefinitionNotFoundException)

Example 25 with CaseDefinition

use of org.jbpm.casemgmt.api.model.CaseDefinition in project jbpm by kiegroup.

the class CaseServiceImpl method newCaseFileInstanceWithRestrictions.

@Override
public CaseFileInstance newCaseFileInstanceWithRestrictions(String deploymentId, String caseDefinition, Map<String, Object> data, Map<String, OrganizationalEntity> rolesAssignment, Map<String, List<String>> accessRestrictions) {
    CaseDefinition def = caseRuntimeDataService.getCase(deploymentId, caseDefinition);
    if (def == null) {
        throw new CaseDefinitionNotFoundException("Case definition " + caseDefinition + " does not exist in deployment " + deploymentId);
    }
    CaseFileInstanceImpl caseFile = new CaseFileInstanceImpl(caseDefinition, data);
    caseFile.setupRoles(def.getCaseRoles());
    Map<String, List<String>> combinedAccessRestrictions = def.getDataAccessRestrictions();
    if (accessRestrictions != null) {
        combinedAccessRestrictions.putAll(accessRestrictions);
    }
    caseFile.setAccessRestrictions(combinedAccessRestrictions);
    rolesAssignment.entrySet().stream().forEach(entry -> caseFile.assign(entry.getKey(), entry.getValue()));
    return caseFile;
}
Also used : CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) CaseFileInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl) List(java.util.List) ArrayList(java.util.ArrayList) CaseDefinitionNotFoundException(org.jbpm.casemgmt.api.CaseDefinitionNotFoundException)

Aggregations

CaseDefinition (org.jbpm.casemgmt.api.model.CaseDefinition)27 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)17 Test (org.junit.Test)17 QueryContext (org.kie.api.runtime.query.QueryContext)13 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)10 CaseStage (org.jbpm.casemgmt.api.model.CaseStage)10 ArrayList (java.util.ArrayList)9 AdHocFragment (org.jbpm.casemgmt.api.model.AdHocFragment)9 HashMap (java.util.HashMap)7 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)7 AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)6 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)6 TaskSummary (org.kie.api.task.model.TaskSummary)6 CaseActiveException (org.jbpm.casemgmt.api.CaseActiveException)5 CaseCommentNotFoundException (org.jbpm.casemgmt.api.CaseCommentNotFoundException)5 CaseRole (org.jbpm.casemgmt.api.model.CaseRole)5 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)5 CaseStageInstance (org.jbpm.casemgmt.api.model.instance.CaseStageInstance)5 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)5 UserImpl (org.jbpm.services.task.impl.model.UserImpl)5