Skip to content

Commit

Permalink
BZ-1065005, JBPM-4233 - Provide access to actual process variable via…
Browse files Browse the repository at this point in the history
… remote api

(cherry picked from commit 11e16ba0d2198921796b95fa188dc34559696dc9)
  • Loading branch information
Marco Rietveld committed Feb 15, 2014
1 parent 9d4c082 commit 0d989ca
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Expand Up @@ -4,14 +4,17 @@
import javax.inject.Inject;

import org.jboss.resteasy.spi.InternalServerErrorException;
import org.jboss.resteasy.spi.NotFoundException;
import org.jboss.resteasy.spi.UnauthorizedException;
import org.jbpm.services.task.commands.CompleteTaskCommand;
import org.jbpm.services.task.commands.TaskCommand;
import org.jbpm.services.task.exception.PermissionDeniedException;
import org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl;
import org.kie.api.command.Command;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.manager.RuntimeEngine;
import org.kie.api.runtime.manager.RuntimeManager;
import org.kie.api.runtime.process.ProcessInstance;
import org.kie.api.task.TaskService;
import org.kie.api.task.model.Task;
import org.kie.internal.task.api.InternalTaskService;
Expand Down Expand Up @@ -159,4 +162,31 @@ public Object doNonDeploymentTaskOperation(TaskCommand<?> cmd, String errorMsg)
}
return result;
}

public Object getVariableObjectInstanceFromRuntime(String deploymentId, long processInstanceId, String varName) {
String errorMsg = "Unable to retrieve variable '" + varName + "' from process instance " + processInstanceId;
Object procVar = null;
RuntimeEngine runtimeEngine = null;
try {
runtimeEngine = runtimeMgrMgr.getRuntimeEngine(deploymentId, processInstanceId);
KieSession kieSession = runtimeEngine.getKieSession();
ProcessInstance procInst = kieSession.getProcessInstance(processInstanceId);
if( procInst == null ) {
throw new NotFoundException("Process instance " + processInstanceId + " could not be found!");
}
procVar = ((WorkflowProcessInstanceImpl) procInst).getVariable(varName);
if( procVar == null ) {
throw new NotFoundException("Variable " + varName + " does not exist in process instance " + processInstanceId + "!");
}
} catch (Exception e) {
if( e instanceof RuntimeException ) {
throw (RuntimeException) e;
} else {
throw new InternalServerErrorException(errorMsg, e);
}
} finally {
runtimeMgrMgr.disposeRuntimeEngine(runtimeEngine);
}
return procVar;
}
}
Expand Up @@ -182,6 +182,14 @@ public Response process_instance_procInstId_variables(@PathParam("procInstId") L
return createCorrectVariant(new JaxbVariablesResponse(vars, request), headers);
}

@GET
@Path("/process/instance/{procInstId: [0-9]+}/variable/{varName: [\\w\\.-]+")
public Response process_instance_procInstId_variable_varName(@PathParam("procInstId") Long procInstId,
@PathParam("varName") String varName) {
Object procVar = processRequestBean.getVariableObjectInstanceFromRuntime(deploymentId, procInstId, varName);
return createCorrectVariant(procVar, headers);
}

@POST
@Path("/signal")
public Response signal() {
Expand Down

0 comments on commit 0d989ca

Please sign in to comment.