Skip to content

Commit

Permalink
[JBPM-9969] failure to create AsyncSignalEventCommand through REST API
Browse files Browse the repository at this point in the history
  • Loading branch information
elguardian committed Dec 14, 2021
1 parent 939e75a commit aa0ded6
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,24 @@ public ExecutionResults execute(CommandContext ctx) throws Exception {
if (deploymentId == null) {
deploymentId = (String) ctx.getData("DeploymentId");
}
Long processInstanceId = (Long) ctx.getData("processInstanceId");
Number processInstanceId = (Number) ctx.getData("processInstanceId");
if (processInstanceId == null) {
processInstanceId = (Long) ctx.getData("ProcessInstanceId");
processInstanceId = (Number) ctx.getData("ProcessInstanceId");
}
String signal = (String) ctx.getData("Signal");
Object event = ctx.getData("Event");

if (deploymentId == null || signal == null) {
throw new IllegalArgumentException("Deployment id and signal name is required");
if (deploymentId == null || signal == null || processInstanceId == null) {
throw new IllegalArgumentException("Deployment id, signal name and processInstanceId are required");
}

RuntimeManager runtimeManager = RuntimeManagerRegistry.get().getManager(deploymentId);
if (runtimeManager == null) {
throw new IllegalArgumentException("No runtime manager found for deployment id " + deploymentId);
}
RuntimeEngine engine = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
RuntimeEngine engine = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId.longValue()));
try {
engine.getKieSession().signalEvent(signal, event, processInstanceId);

engine.getKieSession().signalEvent(signal, event, processInstanceId.longValue());
return new ExecutionResults();
} finally {
runtimeManager.disposeRuntimeEngine(engine);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2021 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.process.core.async;

import org.junit.Test;
import org.kie.api.executor.CommandContext;

public class AsyncSignalEventCommandTest {

// check we don't get when processInstanceId comes from a REST call with json (non type-safe
@Test(expected=IllegalArgumentException.class)
public void testAsyncSignalEventInteger1Command() throws Exception {
AsyncSignalEventCommand command = new AsyncSignalEventCommand();
CommandContext ctx = new CommandContext();
ctx.setData("processInstanceId", Integer.valueOf(2));
command.execute(ctx);
}

@Test(expected=IllegalArgumentException.class)
public void testAsyncSignalEventInteger2Command() throws Exception {
AsyncSignalEventCommand command = new AsyncSignalEventCommand();
CommandContext ctx = new CommandContext();
ctx.setData("ProcessInstanceId", Integer.valueOf(2));
command.execute(ctx);
}

@Test(expected=IllegalArgumentException.class)
public void testAsyncSignalEventLong1Command() throws Exception {
AsyncSignalEventCommand command = new AsyncSignalEventCommand();
CommandContext ctx = new CommandContext();
ctx.setData("processInstanceId", Long.valueOf(2L));
command.execute(ctx);
}

@Test(expected=IllegalArgumentException.class)
public void testAsyncSignalEventLong2Command() throws Exception {
AsyncSignalEventCommand command = new AsyncSignalEventCommand();
CommandContext ctx = new CommandContext();
ctx.setData("ProcessInstanceId", Long.valueOf(2L));
command.execute(ctx);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,9 @@ protected void handleCompletion(boolean processReoccurring, Command cmd, Command
requestInfo.setTime(nextScheduleTime);
requestInfo.setMessage("Rescheduled reoccurring job");
requestInfo.setDeploymentId((String)ctx.getData("deploymentId"));
requestInfo.setProcessInstanceId((Long)ctx.getData("processInstanceId"));
if (ctx.getData("processInstanceId") != null) {
requestInfo.setProcessInstanceId(((Number) ctx.getData("processInstanceId")).longValue());
}
requestInfo.setOwner((String)ctx.getData("owner"));
if (ctx.getData("retries") != null) {
requestInfo.setRetries(Integer.valueOf(String.valueOf(ctx.getData("retries"))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void onCommandDone(CommandContext ctx, ExecutionResults results) {

// find the right runtime to do the complete
RuntimeManager manager = getRuntimeManager(ctx);
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get((Long) ctx.getData("processInstanceId")));
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(((Number) ctx.getData("processInstanceId")).longValue()));
try {
engine.getKieSession().getWorkItemManager().completeWorkItem(workItem.getId(), results == null? null : results.getData());
} finally {
Expand All @@ -74,7 +74,7 @@ public void onCommandDone(CommandContext ctx, ExecutionResults results) {
@Override
public void onCommandError(CommandContext ctx, final Throwable exception) {

final Long processInstanceId = (Long) ctx.getData("processInstanceId");
final Long processInstanceId = ((Number) ctx.getData("processInstanceId")).longValue();
final WorkItem workItem = (WorkItem) ctx.getData("workItem");


Expand Down

0 comments on commit aa0ded6

Please sign in to comment.