Skip to content

Commit

Permalink
unification of persistence and transaction handling for jbpm and huma…
Browse files Browse the repository at this point in the history
…n task
  • Loading branch information
mswiderski committed Dec 17, 2013
1 parent a69396c commit d9cd9b1
Show file tree
Hide file tree
Showing 17 changed files with 341 additions and 190 deletions.
Expand Up @@ -138,4 +138,13 @@ public int getStatus() {
public void registerTransactionSynchronization(TransactionSynchronization ts) {
TransactionSynchronizationManager.registerSynchronization( new SpringTransactionSynchronizationAdapter( ts ) );
}

@Override
public void putResource(Object key, Object resource) {
}

@Override
public Object getResource(Object key) {
return null;
}
}
Expand Up @@ -130,4 +130,13 @@ public int getStatus() {
public void registerTransactionSynchronization(TransactionSynchronization ts) {
TransactionSynchronizationManager.registerSynchronization( new SpringTransactionSynchronizationAdapter( ts ) );
}

@Override
public void putResource(Object key, Object resource) {
}

@Override
public Object getResource(Object key) {
return null;
}
}
10 changes: 10 additions & 0 deletions kie-aries-blueprint/pom.xml
Expand Up @@ -75,6 +75,16 @@
<artifactId>jbpm-persistence-jpa</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-runtime-manager</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
Expand Down
Expand Up @@ -2,8 +2,10 @@

import org.drools.core.command.CommandService;
import org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession;
import org.drools.core.impl.EnvironmentFactory;
import org.jbpm.process.audit.AuditLogService;
import org.jbpm.process.audit.CommandBasedAuditLogService;
import org.jbpm.services.task.events.TaskEventSupport;
import org.jbpm.services.task.impl.command.CommandBasedTaskService;
import org.kie.api.runtime.CommandExecutor;
import org.kie.api.runtime.KieSession;
Expand All @@ -28,7 +30,7 @@ public KieSession getKieSession() {

public TaskService getTaskService() {
CommandExecutor executor = new RemoteTaskCommandExecutor(config);
return new CommandBasedTaskService(executor);
return new CommandBasedTaskService((CommandService)executor, new TaskEventSupport());
}

public AuditLogService getAuditLogService() {
Expand Down
@@ -1,12 +1,18 @@
package org.kie.services.client.api.command;

import org.drools.core.command.CommandService;
import org.kie.api.runtime.CommandExecutor;
import org.kie.internal.command.Context;

class RemoteTaskCommandExecutor extends AbstractRemoteCommandObject implements CommandExecutor {
class RemoteTaskCommandExecutor extends AbstractRemoteCommandObject implements CommandService {

RemoteTaskCommandExecutor(RemoteConfiguration configuration) {
super(configuration);
isTaskService = true;
}


@Override
public Context getContext() {
return null;
}
}
1 change: 0 additions & 1 deletion kie-remote/kie-services-remote/pom.xml
Expand Up @@ -102,7 +102,6 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<!-- TEST -->
<dependency>
<groupId>junit</groupId>
Expand Down

This file was deleted.

Expand Up @@ -41,10 +41,10 @@
import org.kie.services.client.serialization.jaxb.impl.JaxbCommandsRequest;
import org.kie.services.client.serialization.jaxb.impl.JaxbCommandsResponse;
import org.kie.services.remote.cdi.DeploymentInfoBean;
import org.kie.services.remote.cdi.TransactionalExecutor;
import org.kie.services.remote.exception.DomainNotFoundBadRequestException;
import org.kie.services.remote.exception.KieRemoteServicesInternalError;
import org.kie.services.remote.exception.KieRemoteServicesRuntimeException;
import org.kie.services.remote.util.ExecuteAndSerializeCommand;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -86,9 +86,6 @@ public class RequestMessageBean implements MessageListener {

@Inject
private TaskService taskService;

@Inject
private TransactionalExecutor executor;

// Constants / properties

Expand Down Expand Up @@ -360,7 +357,7 @@ private JaxbCommandsResponse processJaxbCommandsRequest(JaxbCommandsRequest requ
// that will cause message reception to be *NOT* acknowledged!
if( cmd instanceof TaskCommand<?>
&& ! AcceptedCommands.TASK_COMMANDS_THAT_INFLUENCE_KIESESSION.contains(cmd.getClass()) ) {
cmdResult = executor.executeAndSerialize((InternalTaskService) taskService, (TaskCommand<?>) cmd);
cmdResult = ((InternalTaskService) taskService).execute(new ExecuteAndSerializeCommand((TaskCommand < ? >) cmd));
} else {
String deploymentId = request.getDeploymentId();
if( deploymentId == null ) {
Expand All @@ -379,9 +376,9 @@ private JaxbCommandsResponse processJaxbCommandsRequest(JaxbCommandsRequest requ
// Synchronize around SSCS to avoid race-conditions with kie session cache clearing in afterCompletion
synchronized(sscs) {
if( cmd instanceof TaskCommand<?> ) {
cmdResult = executor.execute((InternalTaskService) taskService, (TaskCommand<?>) cmd);
cmdResult = ((InternalTaskService) taskService).execute((TaskCommand<?>) cmd);
} else {
cmdResult = executor.execute(kieSession, cmd);
cmdResult = kieSession.execute(cmd);
}
}
}
Expand Down
Expand Up @@ -22,13 +22,16 @@
import org.jboss.resteasy.spi.NotAcceptableException;
import org.jboss.resteasy.util.HttpHeaderNames;
import org.jbpm.services.task.commands.TaskCommand;
import org.jbpm.services.task.impl.model.GroupImpl;
import org.jbpm.services.task.impl.model.TaskImpl;
import org.jbpm.services.task.impl.model.UserImpl;
import org.jbpm.services.task.query.TaskSummaryImpl;
import org.kie.api.command.Command;
import org.kie.api.task.model.Group;
import org.kie.api.task.model.OrganizationalEntity;
import org.kie.api.task.model.Status;
import org.kie.api.task.model.Task;
import org.kie.api.task.model.User;
import org.kie.internal.task.api.TaskModelProvider;
import org.kie.internal.task.api.model.InternalOrganizationalEntity;
import org.kie.internal.task.api.model.InternalTask;
import org.kie.services.client.api.command.AcceptedCommands;
import org.kie.services.client.serialization.jaxb.impl.JaxbCommandsRequest;
import org.kie.services.client.serialization.jaxb.impl.JaxbCommandsResponse;
Expand Down Expand Up @@ -299,17 +302,21 @@ protected static List<OrganizationalEntity> getOrganizationalEntityListFromParam
throw new BadRequestException("At least 1 query parameter (either 'user' or 'group') is required for the '" + operation + "' operation.");
}

for( String user : users ) {
orgEntList.add(new UserImpl(user));
for( String user : users ) {
User newuser = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) newuser).setId(user);
orgEntList.add(newuser);
}
for( String group : groups ) {
orgEntList.add(new GroupImpl(group));
for( String group : groups ) {
Group newuser = TaskModelProvider.getFactory().newGroup();
((InternalOrganizationalEntity) newuser).setId(group);
orgEntList.add(newuser);
}

return orgEntList;
}

protected static TaskSummaryImpl convertTaskToTaskSummary(TaskImpl task) {
protected static TaskSummaryImpl convertTaskToTaskSummary(InternalTask task) {
TaskSummaryImpl taskSummary = new TaskSummaryImpl(
task.getId().longValue(),
task.getTaskData().getProcessInstanceId(),
Expand Down
Expand Up @@ -17,7 +17,7 @@
import org.kie.api.task.TaskService;
import org.kie.internal.task.api.InternalTaskService;
import org.kie.services.remote.cdi.DeploymentInfoBean;
import org.kie.services.remote.cdi.TransactionalExecutor;
import org.kie.services.remote.util.ExecuteAndSerializeCommand;

/**
* This class is used by both the {@link RuntimeResource} and {@link TaskResource} to do the core operations on
Expand All @@ -41,9 +41,6 @@ public class RestProcessRequestBean {
@Inject
private TaskService taskService;

@Inject
private TransactionalExecutor executor;

/**
* Executes a command on the {@link KieSession} from the proper {@link RuntimeManager}. This method
* ends up synchronizing around the retrieved {@link KieSession} in order to avoid race-conditions.
Expand All @@ -61,7 +58,7 @@ public Object doKieSessionOperation(Command<?> cmd, String deploymentId, Long pr
SingleSessionCommandService sscs
= (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) kieSession).getCommandService();
synchronized (sscs) {
result = executor.execute(kieSession, cmd);
result = kieSession.execute(cmd);
}
} catch (Exception e) {
if( e instanceof RuntimeException ) {
Expand Down Expand Up @@ -95,10 +92,10 @@ public Object doTaskOperationOnDeployment(TaskCommand<?> cmd, String deploymentI
SingleSessionCommandService sscs
= (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) kieSession).getCommandService();
synchronized (sscs) {
result = executor.execute((InternalTaskService) taskService, cmd);
result = ((InternalTaskService) taskService).execute(cmd);
}
} else {
result = executor.execute((InternalTaskService) taskService, cmd);
result = ((InternalTaskService) taskService).execute(cmd);
}
} catch (PermissionDeniedException pde) {
throw new UnauthorizedException(pde.getMessage(), pde);
Expand Down Expand Up @@ -133,7 +130,7 @@ public Object doTaskOperation(TaskCommand<?> cmd, String errorMsg) {
public Object doTaskOperationAndSerializeResult(TaskCommand<?> cmd, String errorMsg) {
Object result = null;
try {
result = executor.executeAndSerialize((InternalTaskService) taskService, cmd);
result = ((InternalTaskService) taskService).execute(new ExecuteAndSerializeCommand((TaskCommand<?>) cmd));
} catch (PermissionDeniedException pde) {
throw new UnauthorizedException(pde.getMessage(), pde);
} catch (RuntimeException re) {
Expand Down
@@ -0,0 +1,35 @@
package org.kie.services.remote.util;

import org.jbpm.services.task.commands.TaskCommand;
import org.jbpm.services.task.impl.model.xml.JaxbContent;
import org.jbpm.services.task.impl.model.xml.JaxbTask;
import org.kie.api.task.model.Content;
import org.kie.api.task.model.Task;
import org.kie.internal.command.Context;

public class ExecuteAndSerializeCommand extends TaskCommand<Object>{

private TaskCommand command;

public ExecuteAndSerializeCommand(){

}

public ExecuteAndSerializeCommand(TaskCommand command) {
this.command = command;
}

@Override
public Object execute(Context context) {
Object cmdResult = command.execute(context);
if( cmdResult == null ) {
return null;
}
if( cmdResult instanceof Task) {
cmdResult = new JaxbTask((Task) cmdResult);
} else if( cmdResult instanceof Content) {
cmdResult = new JaxbContent((Content) cmdResult);
}
return cmdResult;
}
}
6 changes: 6 additions & 0 deletions kie-spring/pom.xml
Expand Up @@ -55,6 +55,12 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-human-task-jpa</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
Expand Down

0 comments on commit d9cd9b1

Please sign in to comment.