-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to set variables async for bpmn and cmmn
- Loading branch information
1 parent
a586e9e
commit 5f1f990
Showing
21 changed files
with
1,131 additions
and
3 deletions.
There are no files selected for viewing
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
79 changes: 79 additions & 0 deletions
79
...n-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/AbstractSetVariableAsyncCmd.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,79 @@ | ||
/* 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.flowable.cmmn.engine.impl.cmd; | ||
|
||
import org.flowable.cmmn.engine.CmmnEngineConfiguration; | ||
import org.flowable.cmmn.engine.impl.job.SetAsyncVariablesJobHandler; | ||
import org.flowable.cmmn.engine.impl.persistence.entity.CaseInstanceEntity; | ||
import org.flowable.cmmn.engine.impl.persistence.entity.PlanItemInstanceEntity; | ||
import org.flowable.common.engine.api.scope.ScopeTypes; | ||
import org.flowable.job.service.JobService; | ||
import org.flowable.job.service.JobServiceConfiguration; | ||
import org.flowable.job.service.impl.persistence.entity.JobEntity; | ||
import org.flowable.variable.service.VariableService; | ||
import org.flowable.variable.service.impl.persistence.entity.VariableInstanceEntity; | ||
|
||
public abstract class AbstractSetVariableAsyncCmd { | ||
|
||
protected void addVariable(boolean isLocal, String scopeId, String subScopeId, String varName, Object varValue, | ||
String tenantId, VariableService variableService) { | ||
|
||
VariableInstanceEntity variableInstance = variableService.createVariableInstance(varName); | ||
variableInstance.setScopeId(scopeId); | ||
variableInstance.setSubScopeId(subScopeId); | ||
variableInstance.setScopeType(ScopeTypes.CMMN_ASYNC_VARIABLES); | ||
variableInstance.setMetaInfo(String.valueOf(isLocal)); | ||
|
||
variableService.insertVariableInstanceWithValue(variableInstance, varValue, tenantId); | ||
} | ||
|
||
protected void createSetAsyncVariablesJob(CaseInstanceEntity caseInstanceEntity, CmmnEngineConfiguration cmmnEngineConfiguration) { | ||
JobServiceConfiguration jobServiceConfiguration = cmmnEngineConfiguration.getJobServiceConfiguration(); | ||
JobService jobService = jobServiceConfiguration.getJobService(); | ||
|
||
JobEntity job = jobService.createJob(); | ||
job.setScopeId(caseInstanceEntity.getId()); | ||
job.setScopeDefinitionId(caseInstanceEntity.getCaseDefinitionId()); | ||
job.setScopeType(ScopeTypes.CMMN); | ||
job.setJobHandlerType(SetAsyncVariablesJobHandler.TYPE); | ||
|
||
// Inherit tenant id (if applicable) | ||
if (caseInstanceEntity.getTenantId() != null) { | ||
job.setTenantId(caseInstanceEntity.getTenantId()); | ||
} | ||
|
||
jobService.createAsyncJob(job, true); | ||
jobService.scheduleAsyncJob(job); | ||
} | ||
|
||
protected void createSetAsyncVariablesJob(PlanItemInstanceEntity planItemInstanceEntity, CmmnEngineConfiguration cmmnEngineConfiguration) { | ||
JobServiceConfiguration jobServiceConfiguration = cmmnEngineConfiguration.getJobServiceConfiguration(); | ||
JobService jobService = jobServiceConfiguration.getJobService(); | ||
|
||
JobEntity job = jobService.createJob(); | ||
job.setScopeId(planItemInstanceEntity.getCaseInstanceId()); | ||
job.setSubScopeId(planItemInstanceEntity.getId()); | ||
job.setScopeDefinitionId(planItemInstanceEntity.getCaseDefinitionId()); | ||
job.setScopeType(ScopeTypes.CMMN); | ||
job.setJobHandlerType(SetAsyncVariablesJobHandler.TYPE); | ||
|
||
// Inherit tenant id (if applicable) | ||
if (planItemInstanceEntity.getTenantId() != null) { | ||
job.setTenantId(planItemInstanceEntity.getTenantId()); | ||
} | ||
|
||
jobService.createAsyncJob(job, true); | ||
jobService.scheduleAsyncJob(job); | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
...cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/SetLocalVariableAsyncCmd.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,57 @@ | ||
/* 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.flowable.cmmn.engine.impl.cmd; | ||
|
||
import org.flowable.cmmn.engine.CmmnEngineConfiguration; | ||
import org.flowable.cmmn.engine.impl.persistence.entity.PlanItemInstanceEntity; | ||
import org.flowable.cmmn.engine.impl.util.CommandContextUtil; | ||
import org.flowable.common.engine.api.FlowableIllegalArgumentException; | ||
import org.flowable.common.engine.api.FlowableObjectNotFoundException; | ||
import org.flowable.common.engine.impl.interceptor.Command; | ||
import org.flowable.common.engine.impl.interceptor.CommandContext; | ||
|
||
public class SetLocalVariableAsyncCmd extends AbstractSetVariableAsyncCmd implements Command<Void> { | ||
|
||
protected String planItemInstanceId; | ||
protected String variableName; | ||
protected Object variableValue; | ||
|
||
public SetLocalVariableAsyncCmd(String planItemInstanceId, String variableName, Object variableValue) { | ||
this.planItemInstanceId = planItemInstanceId; | ||
this.variableName = variableName; | ||
this.variableValue = variableValue; | ||
} | ||
|
||
@Override | ||
public Void execute(CommandContext commandContext) { | ||
if (planItemInstanceId == null) { | ||
throw new FlowableIllegalArgumentException("planItemInstanceId is null"); | ||
} | ||
if (variableName == null) { | ||
throw new FlowableIllegalArgumentException("variable name is null"); | ||
} | ||
|
||
CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext); | ||
PlanItemInstanceEntity planItemInstanceEntity = cmmnEngineConfiguration.getPlanItemInstanceEntityManager().findById(planItemInstanceId); | ||
if (planItemInstanceEntity == null) { | ||
throw new FlowableObjectNotFoundException("No plan item instance found for id " + planItemInstanceId, PlanItemInstanceEntity.class); | ||
} | ||
|
||
addVariable(true, planItemInstanceEntity.getCaseInstanceId(), planItemInstanceEntity.getId(), variableName, variableValue, planItemInstanceEntity.getTenantId(), | ||
cmmnEngineConfiguration.getVariableServiceConfiguration().getVariableService()); | ||
createSetAsyncVariablesJob(planItemInstanceEntity, cmmnEngineConfiguration); | ||
|
||
return null; | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
...mmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/SetLocalVariablesAsyncCmd.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,63 @@ | ||
/* 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.flowable.cmmn.engine.impl.cmd; | ||
|
||
import java.util.Map; | ||
|
||
import org.flowable.cmmn.engine.CmmnEngineConfiguration; | ||
import org.flowable.cmmn.engine.impl.persistence.entity.PlanItemInstanceEntity; | ||
import org.flowable.cmmn.engine.impl.util.CommandContextUtil; | ||
import org.flowable.common.engine.api.FlowableIllegalArgumentException; | ||
import org.flowable.common.engine.api.FlowableObjectNotFoundException; | ||
import org.flowable.common.engine.impl.interceptor.Command; | ||
import org.flowable.common.engine.impl.interceptor.CommandContext; | ||
|
||
public class SetLocalVariablesAsyncCmd extends AbstractSetVariableAsyncCmd implements Command<Void> { | ||
|
||
protected String planItemInstanceId; | ||
protected Map<String, Object> variables; | ||
|
||
public SetLocalVariablesAsyncCmd(String planItemInstanceId, Map<String, Object> variables) { | ||
this.planItemInstanceId = planItemInstanceId; | ||
this.variables = variables; | ||
} | ||
|
||
@Override | ||
public Void execute(CommandContext commandContext) { | ||
if (planItemInstanceId == null) { | ||
throw new FlowableIllegalArgumentException("planItemInstanceId is null"); | ||
} | ||
if (variables == null) { | ||
throw new FlowableIllegalArgumentException("variables is null"); | ||
} | ||
if (variables.isEmpty()) { | ||
throw new FlowableIllegalArgumentException("variables is empty"); | ||
} | ||
|
||
CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext); | ||
PlanItemInstanceEntity planItemInstanceEntity = cmmnEngineConfiguration.getPlanItemInstanceEntityManager().findById(planItemInstanceId); | ||
if (planItemInstanceEntity == null) { | ||
throw new FlowableObjectNotFoundException("No plan item instance found for id " + planItemInstanceId, PlanItemInstanceEntity.class); | ||
} | ||
|
||
for (String variableName : variables.keySet()) { | ||
addVariable(true, planItemInstanceEntity.getCaseInstanceId(), planItemInstanceEntity.getId(), variableName, variables.get(variableName), | ||
planItemInstanceEntity.getTenantId(), cmmnEngineConfiguration.getVariableServiceConfiguration().getVariableService()); | ||
} | ||
|
||
createSetAsyncVariablesJob(planItemInstanceEntity, cmmnEngineConfiguration); | ||
|
||
return null; | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
...able-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/SetVariableAsyncCmd.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,57 @@ | ||
/* 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.flowable.cmmn.engine.impl.cmd; | ||
|
||
import org.flowable.cmmn.engine.CmmnEngineConfiguration; | ||
import org.flowable.cmmn.engine.impl.persistence.entity.CaseInstanceEntity; | ||
import org.flowable.cmmn.engine.impl.util.CommandContextUtil; | ||
import org.flowable.common.engine.api.FlowableIllegalArgumentException; | ||
import org.flowable.common.engine.api.FlowableObjectNotFoundException; | ||
import org.flowable.common.engine.impl.interceptor.Command; | ||
import org.flowable.common.engine.impl.interceptor.CommandContext; | ||
|
||
public class SetVariableAsyncCmd extends AbstractSetVariableAsyncCmd implements Command<Void> { | ||
|
||
protected String caseInstanceId; | ||
protected String variableName; | ||
protected Object variableValue; | ||
|
||
public SetVariableAsyncCmd(String caseInstanceId, String variableName, Object variableValue) { | ||
this.caseInstanceId = caseInstanceId; | ||
this.variableName = variableName; | ||
this.variableValue = variableValue; | ||
} | ||
|
||
@Override | ||
public Void execute(CommandContext commandContext) { | ||
if (caseInstanceId == null) { | ||
throw new FlowableIllegalArgumentException("caseInstanceId is null"); | ||
} | ||
if (variableName == null) { | ||
throw new FlowableIllegalArgumentException("variable name is null"); | ||
} | ||
|
||
CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext); | ||
CaseInstanceEntity caseInstanceEntity = cmmnEngineConfiguration.getCaseInstanceEntityManager().findById(caseInstanceId); | ||
if (caseInstanceEntity == null) { | ||
throw new FlowableObjectNotFoundException("No case instance found for id " + caseInstanceId, CaseInstanceEntity.class); | ||
} | ||
|
||
addVariable(false, caseInstanceId, null, variableName, variableValue, caseInstanceEntity.getTenantId(), | ||
cmmnEngineConfiguration.getVariableServiceConfiguration().getVariableService()); | ||
createSetAsyncVariablesJob(caseInstanceEntity, cmmnEngineConfiguration); | ||
|
||
return null; | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
...ble-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/SetVariablesAsyncCmd.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,63 @@ | ||
/* 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.flowable.cmmn.engine.impl.cmd; | ||
|
||
import java.util.Map; | ||
|
||
import org.flowable.cmmn.engine.CmmnEngineConfiguration; | ||
import org.flowable.cmmn.engine.impl.persistence.entity.CaseInstanceEntity; | ||
import org.flowable.cmmn.engine.impl.util.CommandContextUtil; | ||
import org.flowable.common.engine.api.FlowableIllegalArgumentException; | ||
import org.flowable.common.engine.api.FlowableObjectNotFoundException; | ||
import org.flowable.common.engine.impl.interceptor.Command; | ||
import org.flowable.common.engine.impl.interceptor.CommandContext; | ||
|
||
public class SetVariablesAsyncCmd extends AbstractSetVariableAsyncCmd implements Command<Void> { | ||
|
||
protected String caseInstanceId; | ||
protected Map<String, Object> variables; | ||
|
||
public SetVariablesAsyncCmd(String caseInstanceId, Map<String, Object> variables) { | ||
this.caseInstanceId = caseInstanceId; | ||
this.variables = variables; | ||
} | ||
|
||
@Override | ||
public Void execute(CommandContext commandContext) { | ||
if (caseInstanceId == null) { | ||
throw new FlowableIllegalArgumentException("caseInstanceId is null"); | ||
} | ||
if (variables == null) { | ||
throw new FlowableIllegalArgumentException("variables is null"); | ||
} | ||
if (variables.isEmpty()) { | ||
throw new FlowableIllegalArgumentException("variables is empty"); | ||
} | ||
|
||
CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext); | ||
CaseInstanceEntity caseInstanceEntity = cmmnEngineConfiguration.getCaseInstanceEntityManager().findById(caseInstanceId); | ||
if (caseInstanceEntity == null) { | ||
throw new FlowableObjectNotFoundException("No case instance found for id " + caseInstanceId, CaseInstanceEntity.class); | ||
} | ||
|
||
for (String variableName : variables.keySet()) { | ||
addVariable(false, caseInstanceId, null, variableName, variables.get(variableName), caseInstanceEntity.getTenantId(), | ||
cmmnEngineConfiguration.getVariableServiceConfiguration().getVariableService()); | ||
} | ||
|
||
createSetAsyncVariablesJob(caseInstanceEntity, cmmnEngineConfiguration); | ||
|
||
return null; | ||
} | ||
|
||
} |
Oops, something went wrong.