Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JBPM-4646 - Case management - support for reopening the case, refacto…
…r after move of CaseData and CaseAssignment, support for new methods of ProcessContext (#629)
- Loading branch information
1 parent
f745036
commit 1066b47
Showing
21 changed files
with
650 additions
and
17 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...case-mgmt/jbpm-case-mgmt-api/src/main/java/org/jbpm/casemgmt/api/CaseActiveException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.jbpm.casemgmt.api; | ||
|
||
/** | ||
* Thrown then reopening a case that is already started/reopened | ||
* | ||
*/ | ||
public class CaseActiveException extends RuntimeException { | ||
|
||
private static final long serialVersionUID = -6105558767536810447L; | ||
|
||
public CaseActiveException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public CaseActiveException(String message) { | ||
super(message); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...se-mgmt/jbpm-case-mgmt-api/src/main/java/org/jbpm/casemgmt/api/event/CaseReopenEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.jbpm.casemgmt.api.event; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Represents occurrence of start case operation | ||
*/ | ||
public class CaseReopenEvent extends CaseEvent { | ||
|
||
private String deploymentId; | ||
private String caseDefinitionId; | ||
private Map<String, Object> data; | ||
private Long processInstanceId; | ||
|
||
public CaseReopenEvent(String caseId, String deploymentId, String caseDefinitionId, Map<String, Object> data) { | ||
super(caseId); | ||
this.deploymentId = deploymentId; | ||
this.caseDefinitionId = caseDefinitionId; | ||
this.data = data; | ||
} | ||
|
||
public CaseReopenEvent(String caseId, String deploymentId, String caseDefinitionId, Map<String, Object> data, Long processInstanceId) { | ||
super(caseId); | ||
this.deploymentId = deploymentId; | ||
this.caseDefinitionId = caseDefinitionId; | ||
this.data = data; | ||
this.processInstanceId = processInstanceId; | ||
} | ||
|
||
/** | ||
* Returns deployment id that case belongs to | ||
*/ | ||
public String getDeploymentId() { | ||
return deploymentId; | ||
} | ||
|
||
/** | ||
* Returns case definition id | ||
*/ | ||
public String getCaseDefinitionId() { | ||
return caseDefinitionId; | ||
} | ||
|
||
/** | ||
* Returns case file associated with the case | ||
*/ | ||
public Map<String, Object> getData() { | ||
return data; | ||
} | ||
|
||
/** | ||
* Returns process instance id of the case process instance | ||
*/ | ||
public Long getProcessInstanceId() { | ||
return processInstanceId; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "StartCaseEvent [deploymentId=" + deploymentId + ", caseDefinitionId=" + caseDefinitionId + ", caseId=" + getCaseId() + "]"; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...t/jbpm-case-mgmt-impl/src/main/java/org/jbpm/casemgmt/impl/command/ReopenCaseCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.jbpm.casemgmt.impl.command; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.drools.core.ClassObjectFilter; | ||
import org.drools.core.command.impl.KnowledgeCommandContext; | ||
import org.jbpm.casemgmt.api.CaseNotFoundException; | ||
import org.jbpm.casemgmt.api.model.instance.CaseFileInstance; | ||
import org.jbpm.casemgmt.impl.event.CaseEventSupport; | ||
import org.jbpm.services.api.ProcessService; | ||
import org.kie.api.runtime.EnvironmentName; | ||
import org.kie.api.runtime.KieSession; | ||
import org.kie.api.runtime.rule.FactHandle; | ||
import org.kie.internal.KieInternalServices; | ||
import org.kie.internal.command.Context; | ||
import org.kie.internal.process.CorrelationKey; | ||
import org.kie.internal.process.CorrelationKeyFactory; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class ReopenCaseCommand extends CaseCommand<Void> { | ||
|
||
private static final long serialVersionUID = 6811181095390934146L; | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(ReopenCaseCommand.class); | ||
|
||
private static CorrelationKeyFactory correlationKeyFactory = KieInternalServices.Factory.get().newCorrelationKeyFactory(); | ||
|
||
private String caseId; | ||
private String deploymentId; | ||
private String caseDefinitionId; | ||
private Map<String, Object> data; | ||
|
||
private transient ProcessService processService; | ||
|
||
public ReopenCaseCommand(String caseId, String deploymentId, String caseDefinitionId, Map<String, Object> data, ProcessService processService) { | ||
this.caseId = caseId; | ||
this.deploymentId = deploymentId; | ||
this.caseDefinitionId = caseDefinitionId; | ||
this.data = data; | ||
this.processService = processService; | ||
} | ||
|
||
@Override | ||
public Void execute(Context context) { | ||
|
||
CaseEventSupport caseEventSupport = getCaseEventSupport(context); | ||
caseEventSupport.fireBeforeCaseReopened(caseId, deploymentId, caseDefinitionId, data); | ||
KieSession ksession = ((KnowledgeCommandContext) context).getKieSession(); | ||
|
||
if (data != null && !data.isEmpty()) { | ||
logger.debug("Updating case file in working memory"); | ||
Collection<? extends Object> caseFiles = ksession.getObjects(new ClassObjectFilter(CaseFileInstance.class)); | ||
if (caseFiles.size() == 0) { | ||
throw new CaseNotFoundException("Case with id " + caseId + " was not found"); | ||
} | ||
CaseFileInstance caseFile = (CaseFileInstance) caseFiles.iterator().next(); | ||
FactHandle factHandle = ksession.getFactHandle(caseFile); | ||
|
||
caseFile.addAll(data); | ||
|
||
ksession.update(factHandle, caseFile); | ||
} | ||
logger.debug("Starting process instance for case {} and case definition {}", caseId, caseDefinitionId); | ||
CorrelationKey correlationKey = correlationKeyFactory.newCorrelationKey(caseId); | ||
Map<String, Object> params = new HashMap<>(); | ||
// set case id to allow it to use CaseContext when creating runtime engine | ||
params.put(EnvironmentName.CASE_ID, caseId); | ||
long processInstanceId = processService.startProcess(deploymentId, caseDefinitionId, correlationKey, params); | ||
logger.debug("Case {} successfully reopened (process instance id {})", caseId, processInstanceId); | ||
caseEventSupport.fireAfterCaseReopened(caseId, deploymentId, caseDefinitionId, data, processInstanceId); | ||
return null; | ||
} | ||
|
||
public void setProcessService(ProcessService processService) { | ||
this.processService = processService; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.