Skip to content

Commit

Permalink
BZ-1084686 - separation between process/task engine and audit trail p…
Browse files Browse the repository at this point in the history
…ersistence
  • Loading branch information
mswiderski committed Feb 11, 2015
1 parent 55d2239 commit 999c5c6
Show file tree
Hide file tree
Showing 36 changed files with 914 additions and 426 deletions.
13 changes: 6 additions & 7 deletions jbpm-human-task/jbpm-human-task-audit/pom.xml
Expand Up @@ -16,8 +16,12 @@

<dependencies>
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-human-task-core</artifactId>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-human-task-core</artifactId>
</dependency>
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-human-task-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.kie</groupId>
Expand Down Expand Up @@ -111,11 +115,6 @@
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-human-task-jpa</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jbpm</groupId>
Expand Down

Large diffs are not rendered by default.

Expand Up @@ -19,6 +19,7 @@
import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
Expand Down Expand Up @@ -63,14 +64,15 @@ public class AuditTaskImpl implements Serializable, AuditTask {
private long processSessionId;
private long parentId;
private String deploymentId;
private Long workItemId;

public AuditTaskImpl() {
}

public AuditTaskImpl(long taskId, String name, String status, Date activationTime,
String actualOwner , String description, int priority, String createdBy,
Date createdOn, Date dueDate, long processInstanceId, String processId,
long processSessionId, String deploymentId, long parentId) {
long processSessionId, String deploymentId, long parentId, long workItemId) {
this.taskId = taskId;
this.status = status;
this.activationTime = activationTime;
Expand All @@ -86,6 +88,7 @@ public AuditTaskImpl(long taskId, String name, String status, Date activationTim
this.processSessionId = processSessionId;
this.deploymentId = deploymentId;
this.parentId = parentId;
this.workItemId = workItemId;
}

public Long getId() {
Expand Down Expand Up @@ -242,8 +245,15 @@ public String getDeploymentId() {
public void setDeploymentId(String deploymentId) {
this.deploymentId = deploymentId;
}



@Override
public long getWorkItemId() {
return workItemId;
}

@Override
public void setWorkItemId(long workItemId) {
this.workItemId = workItemId;
}

}
Expand Up @@ -122,13 +122,52 @@ public Long getWorkItemId() {
@Override
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
// TODO Auto-generated method stub
id = in.readLong();

processInstanceId = in.readLong();

taskId = in.readLong();

type = TaskEventType.valueOf(in.readUTF());

userId = in.readUTF();

workItemId = in.readLong();

if (in.readBoolean()) {
logTime = new Date(in.readLong());
}

}

@Override
public void writeExternal(ObjectOutput out) throws IOException {
// TODO Auto-generated method stub
out.writeLong( id );

out.writeLong( processInstanceId );

out.writeLong( taskId );

if (type != null) {
out.writeUTF(type.name());
} else {
out.writeUTF("");
}

if (userId != null) {
out.writeUTF(userId);
} else {
out.writeUTF("");
}

out.writeLong( workItemId );

if (logTime != null) {
out.writeBoolean(true);
out.writeLong(logTime.getTime());
} else {
out.writeBoolean(false);
}

}

Expand Down
Expand Up @@ -18,7 +18,10 @@
import java.util.Comparator;
import java.util.Date;

import javax.persistence.EntityManagerFactory;

import org.jbpm.services.task.audit.impl.model.BAMTaskSummaryImpl;
import org.jbpm.services.task.persistence.PersistableEventListener;
import org.kie.api.task.TaskEvent;
import org.kie.api.task.model.Status;
import org.kie.api.task.model.Task;
Expand Down Expand Up @@ -60,12 +63,17 @@
* <li>Obsolete - Error</li>
* </ul>
*/
public class BAMTaskEventListener implements org.kie.api.task.TaskLifeCycleEventListener {
public class BAMTaskEventListener extends PersistableEventListener {

/** Class logger. */
private static final Logger logger = LoggerFactory.getLogger(BAMTaskEventListener.class);

public BAMTaskEventListener(boolean flag) {
super(null);
}

public BAMTaskEventListener(EntityManagerFactory emf) {
super(emf);
}

public void afterTaskStartedEvent(TaskEvent event) {
Expand Down Expand Up @@ -223,58 +231,65 @@ protected BAMTaskSummaryImpl createOrUpdateTask(TaskEvent event, Status newStatu
protected BAMTaskSummaryImpl createTask(TaskEvent event, Status newStatus, BAMTaskWorker worker) {
BAMTaskSummaryImpl result = null;
Task ti = event.getTask();
TaskPersistenceContext persistenceContext = ((TaskContext)event.getTaskContext()).getPersistenceContext();

if (ti == null) {
logger.error("The task instance does not exist.");
return result;
}

Status status = newStatus != null ? newStatus : ti.getTaskData().getStatus();

String actualOwner = "";
if (ti.getTaskData().getActualOwner() != null) {
actualOwner = ti.getTaskData().getActualOwner().getId();
TaskPersistenceContext persistenceContext = getPersistenceContext(((TaskContext)event.getTaskContext()).getPersistenceContext());
try {
if (ti == null) {
logger.error("The task instance does not exist.");
return result;
}

Status status = newStatus != null ? newStatus : ti.getTaskData().getStatus();

String actualOwner = "";
if (ti.getTaskData().getActualOwner() != null) {
actualOwner = ti.getTaskData().getActualOwner().getId();
}

result = new BAMTaskSummaryImpl(ti.getId(), ti.getName(), status.toString(), new Date(), actualOwner, ti.getTaskData().getProcessInstanceId());
if (worker != null) worker.createTask(result, ti);
persistenceContext.persist(result);


return result;
} finally {
cleanup(persistenceContext);
}

result = new BAMTaskSummaryImpl(ti.getId(), ti.getName(), status.toString(), new Date(), actualOwner, ti.getTaskData().getProcessInstanceId());
if (worker != null) worker.createTask(result, ti);
persistenceContext.persist(result);


return result;
}

protected BAMTaskSummaryImpl updateTask(TaskEvent event, Status newStatus, BAMTaskWorker worker) {
BAMTaskSummaryImpl result = null;
Task ti = event.getTask();
TaskPersistenceContext persistenceContext = ((TaskContext)event.getTaskContext()).getPersistenceContext();

if (ti == null) {
logger.error("The task instance does not exist.");
return result;
}

Status status = newStatus != null ? newStatus : ti.getTaskData().getStatus();
TaskPersistenceContext persistenceContext = getPersistenceContext(((TaskContext)event.getTaskContext()).getPersistenceContext());
try {

result = persistenceContext.queryStringWithParametersInTransaction("select bts from BAMTaskSummaryImpl bts where bts.taskId=:taskId", true,
persistenceContext.addParametersToMap("taskId", ti.getId()),
BAMTaskSummaryImpl.class);

if (result == null) {
logger.warn("Unable find bam task entry for task id {} '{}', skipping bam task update", ti.getId(), ti.getName());
return null;
}

result.setStatus(status.toString());
if (ti.getTaskData().getActualOwner() != null) {
result.setUserId(ti.getTaskData().getActualOwner().getId());
}
if (worker != null) worker.updateTask(result, ti);
persistenceContext.merge(result);
if (ti == null) {
logger.error("The task instance does not exist.");
return result;
}

Status status = newStatus != null ? newStatus : ti.getTaskData().getStatus();

result = persistenceContext.queryStringWithParametersInTransaction("select bts from BAMTaskSummaryImpl bts where bts.taskId=:taskId", true,
persistenceContext.addParametersToMap("taskId", ti.getId()),
BAMTaskSummaryImpl.class);

if (result == null) {
logger.warn("Unable find bam task entry for task id {} '{}', skipping bam task update", ti.getId(), ti.getName());
return null;
}

result.setStatus(status.toString());
if (ti.getTaskData().getActualOwner() != null) {
result.setUserId(ti.getTaskData().getActualOwner().getId());
}
if (worker != null) worker.updateTask(result, ti);
persistenceContext.merge(result);


return result;
return result;
} finally {
cleanup(persistenceContext);
}
}

/**
Expand Down
@@ -0,0 +1,40 @@
package org.jbpm.services.task.persistence;

import javax.persistence.EntityManagerFactory;

import org.kie.api.task.TaskLifeCycleEventListener;
import org.kie.internal.task.api.TaskPersistenceContext;

public abstract class PersistableEventListener implements TaskLifeCycleEventListener {

private EntityManagerFactory emf;

public PersistableEventListener(EntityManagerFactory emf) {
this.emf = emf;
}

protected TaskPersistenceContext getPersistenceContext(TaskPersistenceContext persistenceContext) {
if (emf != null) {
return new JPATaskPersistenceContext(emf.createEntityManager()) {

@Override
public void close() {
em.flush();
super.close();
}

};
}

return persistenceContext;
}

protected void cleanup(TaskPersistenceContext persistenceContext) {
if (emf != null) {
persistenceContext.close();
}
}



}
1 change: 1 addition & 0 deletions jbpm-installer/db/ddl-scripts/db2/db2-jbpm-schema.sql
Expand Up @@ -28,6 +28,7 @@
processSessionId integer not null,
status varchar(255),
taskId bigint,
workItemId bigint not null,
primary key (id)
);

Expand Down
1 change: 1 addition & 0 deletions jbpm-installer/db/ddl-scripts/derby/derby-jbpm-schema.sql
Expand Up @@ -28,6 +28,7 @@
processSessionId integer not null,
status varchar(255),
taskId bigint,
workItemId bigint not null,
primary key (id)
);

Expand Down
1 change: 1 addition & 0 deletions jbpm-installer/db/ddl-scripts/h2/h2-jbpm-schema.sql
Expand Up @@ -28,6 +28,7 @@
processSessionId integer not null,
status varchar(255),
taskId bigint,
workItemId bigint not null,
primary key (id)
);

Expand Down
Expand Up @@ -28,6 +28,7 @@
processSessionId integer not null,
status varchar(255),
taskId bigint,
workItemId bigint not null,
primary key (id)
);

Expand Down
Expand Up @@ -28,6 +28,7 @@
processSessionId integer not null,
status varchar(255),
taskId bigint,
workItemId bigint not null,
primary key (id)
);

Expand Down
Expand Up @@ -28,6 +28,7 @@
processSessionId integer not null,
status varchar(255),
taskId bigint,
workItemId bigint not null,
primary key (id)
) ENGINE=InnoDB;

Expand Down
Expand Up @@ -28,6 +28,7 @@
processSessionId number(10,0) not null,
status varchar2(255 char),
taskId number(19,0),
workItemId number(19,0) not null,
primary key (id)
);

Expand Down
Expand Up @@ -28,6 +28,7 @@
processSessionId int4 not null,
status varchar(255),
taskId int8,
workItemId int8 not null,
primary key (id)
);

Expand Down
Expand Up @@ -28,6 +28,7 @@
processSessionId int not null,
status varchar(255),
taskId numeric(19,0),
workItemId numeric(19,0) not null,
primary key (id)
);

Expand Down
Expand Up @@ -28,6 +28,7 @@
processSessionId int not null,
status varchar(255),
taskId bigint,
workItemId bigint not null,
primary key (id)
);

Expand Down

0 comments on commit 999c5c6

Please sign in to comment.