Skip to content

Commit

Permalink
JBPM-5757 - Replace status List<Integer> with List<Status> in CaseRun…
Browse files Browse the repository at this point in the history
…timeDataService operations (#781)
  • Loading branch information
Tihomir Surdilovic authored and mswiderski committed Mar 21, 2017
1 parent bb5efe8 commit 0877c9f
Show file tree
Hide file tree
Showing 5 changed files with 300 additions and 69 deletions.
Expand Up @@ -21,6 +21,7 @@

import org.jbpm.casemgmt.api.model.AdHocFragment;
import org.jbpm.casemgmt.api.model.CaseDefinition;
import org.jbpm.casemgmt.api.model.CaseStatus;
import org.jbpm.casemgmt.api.model.instance.CaseInstance;
import org.jbpm.casemgmt.api.model.instance.CaseMilestoneInstance;
import org.jbpm.casemgmt.api.model.instance.CaseStageInstance;
Expand Down Expand Up @@ -118,11 +119,11 @@ public interface CaseRuntimeDataService {
/**
* Returns process instances found for given case id.
* @param caseId unique id of the case
* @param states states representing process instance (active, completed, aborted)
* @param processStates states representing process instance (active, completed, aborted)
* @param queryContext control parameters for the result e.g. sorting, paging
*
*/
Collection<ProcessInstanceDesc> getProcessInstancesForCase(String caseId, List<Integer> states, QueryContext queryContext);
Collection<ProcessInstanceDesc> getProcessInstancesForCase(String caseId, List<Integer> processStates, QueryContext queryContext);

/**
* Returns milestones for given case instance, identified by case id.
Expand Down Expand Up @@ -189,45 +190,48 @@ public interface CaseRuntimeDataService {
* @param queryContext control parameters for the result e.g. sorting, paging
*
*/
Collection<CaseInstance> getCaseInstances(List<Integer> statuses, QueryContext queryContext);
Collection<CaseInstance> getCaseInstances(List<CaseStatus> statuses, QueryContext queryContext);

/**
* Returns all available case instances;
* @param deploymentId deployment identifier that case instance is part of
* @param statuses list of statuses that case should be in to match
* @param queryContext control parameters for the result e.g. sorting, paging
*
*/
Collection<CaseInstance> getCaseInstancesByDeployment(String deploymentId, List<Integer> statuses, QueryContext queryContext);
Collection<CaseInstance> getCaseInstancesByDeployment(String deploymentId, List<CaseStatus> statuses, QueryContext queryContext);

/**
* Returns all available case instances;
* @param caseDefinitionId case definition id
* @param statuses list of statuses that case should be in to match
* @param queryContext control parameters for the result e.g. sorting, paging
*
*/
Collection<CaseInstance> getCaseInstancesByDefinition(String caseDefinitionId, List<Integer> statuses, QueryContext queryContext);
Collection<CaseInstance> getCaseInstancesByDefinition(String caseDefinitionId, List<CaseStatus> statuses, QueryContext queryContext);

/**
* Returns all case instances owned by given user
* @param statuses list of statuses that case should be in to match
* @param queryContext control parameters for the result e.g. sorting, paging
*
*/
Collection<CaseInstance> getCaseInstancesOwnedBy(String owner, List<Integer> statuses, QueryContext queryContext);
Collection<CaseInstance> getCaseInstancesOwnedBy(String owner, List<CaseStatus> statuses, QueryContext queryContext);

/**
* Returns cases instances that given user (via identity provider) has access to with given role.
* @param roleName name of the role that user should be
* @param statuses statuses of the case instances
* @param queryContext control parameters for the result e.g. sorting, paging
*/
Collection<CaseInstance> getCaseInstancesByRole(String roleName, List<Integer> statuses, QueryContext queryContext);
Collection<CaseInstance> getCaseInstancesByRole(String roleName, List<CaseStatus> statuses, QueryContext queryContext);

/**
* Returns case instances that given user (via identity provider) is involved in in any role.
* @param statuses statuses of the case instances
* @param queryContext control parameters for the result e.g. sorting, paging
*/
Collection<CaseInstance> getCaseInstancesAnyRole(List<Integer> statuses, QueryContext queryContext);
Collection<CaseInstance> getCaseInstancesAnyRole(List<CaseStatus> statuses, QueryContext queryContext);

/**
* Returns all tasks associated with given case id that are eligible for user to see.
Expand Down
@@ -0,0 +1,70 @@
package org.jbpm.casemgmt.api.model;

/*
* Copyright 2016 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import java.util.List;
import java.util.stream.Collectors;

public enum CaseStatus {
OPEN(1, "open"),
CLOSED(2, "closed"),
CANCELLED(3, "cancelled");

private final int id;
private final String name;

CaseStatus( int id, String name ) {
this.id = id;
this.name = name;
}

public int getId() { return id; }

public String getName() {
return name;
}

public static CaseStatus fromId( int id ) {
switch ( id ) {
case 1 : return OPEN;
case 2 : return CLOSED;
case 3 : return CANCELLED;
default: return null;
}
}

public static CaseStatus fromName( String name ) {
if ("open".equalsIgnoreCase( name )) {
return OPEN;
} else if ("closed".equalsIgnoreCase( name )) {
return CLOSED;
} else if ("cancelled".equalsIgnoreCase( name )) {
return CANCELLED;
} else {
return valueOf(name);
}
}

public static List<CaseStatus> fromIdList( List<Integer> idList ) {
return idList != null ? idList.stream().map(event -> fromId( event )).collect(Collectors.toList()) : null;
}

public static List<CaseStatus> fromNameList( List<String> nameList ) {
return nameList != null ? nameList.stream().map(event -> fromName( event )).collect(Collectors.toList()) : null;
}
}

Expand Up @@ -31,6 +31,7 @@
import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import org.jbpm.casemgmt.api.CaseNotFoundException;
import org.jbpm.casemgmt.api.CaseRuntimeDataService;
Expand All @@ -41,6 +42,7 @@
import org.jbpm.casemgmt.api.model.CaseMilestone;
import org.jbpm.casemgmt.api.model.CaseRole;
import org.jbpm.casemgmt.api.model.CaseStage;
import org.jbpm.casemgmt.api.model.CaseStatus;
import org.jbpm.casemgmt.api.model.instance.CaseInstance;
import org.jbpm.casemgmt.api.model.instance.CaseMilestoneInstance;
import org.jbpm.casemgmt.api.model.instance.CaseStageInstance;
Expand Down Expand Up @@ -102,7 +104,7 @@ public class CaseRuntimeDataServiceImpl implements CaseRuntimeDataService, Deplo
private DeploymentRolesManager deploymentRolesManager = new DeploymentRolesManager();

// default statuses set to active only
private List<Integer> statuses = Arrays.asList(ProcessInstance.STATE_ACTIVE);
private List<CaseStatus> statuses = Arrays.asList(CaseStatus.OPEN);

private static final List<Status> allActiveStatus = Arrays.asList(
Status.Created,
Expand Down Expand Up @@ -324,10 +326,10 @@ public Collection<ProcessInstanceDesc> getProcessInstancesForCase(String caseId,


@Override
public Collection<ProcessInstanceDesc> getProcessInstancesForCase(String caseId, List<Integer> states, QueryContext queryContext) {
public Collection<ProcessInstanceDesc> getProcessInstancesForCase(String caseId, List<Integer> processStates, QueryContext queryContext) {
CorrelationKey correlationKey = correlationKeyFactory.newCorrelationKey(caseId);

return runtimeDataService.getProcessInstancesByCorrelationKeyAndStatus(correlationKey, states, queryContext);
return runtimeDataService.getProcessInstancesByCorrelationKeyAndStatus(correlationKey, processStates, queryContext);
}


Expand Down Expand Up @@ -419,10 +421,10 @@ public Collection<CaseInstance> getCaseInstances(QueryContext queryContext) {
}

@Override
public Collection<CaseInstance> getCaseInstances(List<Integer> statuses, QueryContext queryContext) {
public Collection<CaseInstance> getCaseInstances(List<CaseStatus> statuses, QueryContext queryContext) {

Map<String, Object> params = new HashMap<String, Object>();
params.put("statuses", statuses);
params.put("statuses", resolveCaseStatuses(statuses));
applyQueryContext(params, queryContext);
applyDeploymentFilter(params);
List<CaseInstance> processInstances = commandService.execute(new QueryNameCommand<List<CaseInstance>>("getCaseInstances", params));
Expand All @@ -432,10 +434,10 @@ public Collection<CaseInstance> getCaseInstances(List<Integer> statuses, QueryCo


@Override
public Collection<CaseInstance> getCaseInstancesByDeployment(String deploymentId, List<Integer> statuses, QueryContext queryContext) {
public Collection<CaseInstance> getCaseInstancesByDeployment(String deploymentId, List<CaseStatus> statuses, QueryContext queryContext) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("deploymentId", deploymentId);
params.put("statuses", statuses);
params.put("statuses", resolveCaseStatuses(statuses));
params.put("entities", collectUserAuthInfo());
applyQueryContext(params, queryContext);
applyDeploymentFilter(params);
Expand All @@ -446,10 +448,10 @@ public Collection<CaseInstance> getCaseInstancesByDeployment(String deploymentId


@Override
public Collection<CaseInstance> getCaseInstancesByDefinition(String definitionId, List<Integer> statuses, QueryContext queryContext) {
public Collection<CaseInstance> getCaseInstancesByDefinition(String definitionId, List<CaseStatus> statuses, QueryContext queryContext) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("definitionId", definitionId);
params.put("statuses", statuses);
params.put("statuses", resolveCaseStatuses(statuses));
params.put("entities", collectUserAuthInfo());
applyQueryContext(params, queryContext);
applyDeploymentFilter(params);
Expand All @@ -460,10 +462,10 @@ public Collection<CaseInstance> getCaseInstancesByDefinition(String definitionId


@Override
public Collection<CaseInstance> getCaseInstancesOwnedBy(String owner, List<Integer> statuses, QueryContext queryContext) {
public Collection<CaseInstance> getCaseInstancesOwnedBy(String owner, List<CaseStatus> statuses, QueryContext queryContext) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("owner", owner);
params.put("statuses", statuses);
params.put("statuses", resolveCaseStatuses(statuses));
applyQueryContext(params, queryContext);
applyDeploymentFilter(params);
List<CaseInstance> processInstances = commandService.execute(new QueryNameCommand<List<CaseInstance>>("getCaseInstancesOwnedBy", params));
Expand All @@ -472,12 +474,12 @@ public Collection<CaseInstance> getCaseInstancesOwnedBy(String owner, List<Integ
}

@Override
public Collection<CaseInstance> getCaseInstancesByRole(String roleName, List<Integer> statuses, QueryContext queryContext) {
public Collection<CaseInstance> getCaseInstancesByRole(String roleName, List<CaseStatus> statuses, QueryContext queryContext) {

Map<String, Object> params = new HashMap<String, Object>();
params.put("roleName", roleName);
params.put("entities", collectUserAuthInfo());
params.put("statuses", statuses);
params.put("statuses", resolveCaseStatuses(statuses));
applyQueryContext(params, queryContext);
applyDeploymentFilter(params);
List<CaseInstance> processInstances = commandService.execute(new QueryNameCommand<List<CaseInstance>>("getCaseInstancesByRole", params));
Expand All @@ -486,11 +488,11 @@ public Collection<CaseInstance> getCaseInstancesByRole(String roleName, List<Int
}

@Override
public Collection<CaseInstance> getCaseInstancesAnyRole(List<Integer> statuses, QueryContext queryContext) {
public Collection<CaseInstance> getCaseInstancesAnyRole(List<CaseStatus> statuses, QueryContext queryContext) {

Map<String, Object> params = new HashMap<String, Object>();
params.put("entities", collectUserAuthInfo());
params.put("statuses", statuses);
params.put("statuses", resolveCaseStatuses(statuses));
applyQueryContext(params, queryContext);
applyDeploymentFilter(params);
List<CaseInstance> processInstances = commandService.execute(new QueryNameCommand<List<CaseInstance>>("getCaseInstancesAnyRole", params));
Expand Down Expand Up @@ -689,7 +691,9 @@ private Collection<CaseStage> collectCaseStages(String deploymentId, String proc
DynamicNode dynamicNode = (DynamicNode) node;
Collection<AdHocFragment> adHocFragments = collectAdHocFragments(dynamicNode);

result.add(new CaseStageImpl((String)((DynamicNode) node).getMetaData("UniqueId"), node.getName(), adHocFragments));
result.add(new CaseStageImpl((String) ((DynamicNode) node).getMetaData("UniqueId"),
node.getName(),
adHocFragments));
}
}
return result;
Expand Down Expand Up @@ -785,4 +789,8 @@ protected <T> Collection<T> applyPagination(List<T> input, QueryContext queryCon

return Collections.unmodifiableCollection(input);
}

protected List<Integer> resolveCaseStatuses(List<CaseStatus> caseStatusesList) {
return caseStatusesList != null ? caseStatusesList.stream().map(event -> event.getId()).collect(Collectors.toList()) : null;
}
}

0 comments on commit 0877c9f

Please sign in to comment.