Skip to content

Commit

Permalink
BZ-1188702 - AuditService: data parameters handled internally as time…
Browse files Browse the repository at this point in the history
…stamp
  • Loading branch information
mswiderski committed Feb 4, 2015
1 parent 8d5b222 commit da07397
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 11 deletions.
Expand Up @@ -4,6 +4,7 @@
import static org.kie.internal.query.QueryParameterIdentifiers.PROCESS_ID_LIST;
import static org.kie.internal.query.QueryParameterIdentifiers.PROCESS_INSTANCE_ID_LIST;

import java.sql.Timestamp;
import java.util.Date;

import org.jbpm.process.audit.JPAAuditLogService;
Expand Down Expand Up @@ -93,5 +94,18 @@ protected boolean checkIfNotNull(Object...parameter) {

return false;
}

protected Date[] ensureDateNotTimestamp(Date...date) {
Date[] validated = new Date[date.length];
for (int i = 0; i < date.length; ++i) {
if (date[i] instanceof Timestamp) {
validated[i] = new Date(date[i].getTime());
} else {
validated[i] = date[i];
}
}

return validated;
}

}
Expand Up @@ -32,7 +32,8 @@ public ErrorInfoLogDeleteBuilder date(Date... date) {
if (checkIfNotNull(date)) {
return this;
}
addObjectParameter(EXECUTOR_TIME_ID, "date", date);

addObjectParameter(EXECUTOR_TIME_ID, "date", ensureDateNotTimestamp(date));
return this;
}

Expand All @@ -41,7 +42,7 @@ public ErrorInfoLogDeleteBuilder dateRangeStart(Date rangeStart) {
if (checkIfNotNull(rangeStart)) {
return this;
}
addRangeParameter(EXECUTOR_TIME_ID, "date range end", rangeStart, true);
addRangeParameter(EXECUTOR_TIME_ID, "date range end", ensureDateNotTimestamp(rangeStart)[0], true);
return this;
}

Expand All @@ -50,7 +51,7 @@ public ErrorInfoLogDeleteBuilder dateRangeEnd(Date rangeStart) {
if (checkIfNotNull(rangeStart)) {
return this;
}
addRangeParameter(EXECUTOR_TIME_ID, "date range end", rangeStart, false);
addRangeParameter(EXECUTOR_TIME_ID, "date range end", ensureDateNotTimestamp(rangeStart)[0], false);
return this;
}

Expand Down
Expand Up @@ -35,7 +35,7 @@ public RequestInfoLogDeleteBuilder date(Date... date) {
if (checkIfNotNull(date)) {
return this;
}
addObjectParameter(EXECUTOR_TIME_ID, "on date", date);
addObjectParameter(EXECUTOR_TIME_ID, "on date", ensureDateNotTimestamp(date));
return this;
}

Expand All @@ -44,7 +44,7 @@ public RequestInfoLogDeleteBuilder dateRangeStart(Date rangeStart) {
if (checkIfNotNull(rangeStart)) {
return this;
}
addRangeParameter(EXECUTOR_TIME_ID, "date range end", rangeStart, true);
addRangeParameter(EXECUTOR_TIME_ID, "date range end", ensureDateNotTimestamp(rangeStart)[0], true);
return this;
}

Expand All @@ -53,7 +53,7 @@ public RequestInfoLogDeleteBuilder dateRangeEnd(Date rangeStart) {
if (checkIfNotNull(rangeStart)) {
return this;
}
addRangeParameter(EXECUTOR_TIME_ID, "date range end", rangeStart, false);
addRangeParameter(EXECUTOR_TIME_ID, "date range end", ensureDateNotTimestamp(rangeStart)[0], false);
return this;
}

Expand Down
Expand Up @@ -22,6 +22,7 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
Expand All @@ -30,7 +31,9 @@
import java.util.concurrent.atomic.AtomicLong;

import javax.inject.Inject;
import javax.persistence.EntityManagerFactory;

import org.jbpm.executor.impl.jpa.ExecutorJPAAuditService;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -39,6 +42,7 @@
import org.kie.internal.executor.api.ExecutionResults;
import org.kie.internal.executor.api.ExecutorService;
import org.kie.internal.executor.api.RequestInfo;
import org.kie.internal.executor.api.STATUS;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -50,7 +54,7 @@ public abstract class BasicExecutorBaseTest {
protected ExecutorService executorService;
public static final Map<String, Object> cachedEntities = new HashMap<String, Object>();


protected EntityManagerFactory emf = null;

@Before
public void setUp() {
Expand Down Expand Up @@ -321,10 +325,10 @@ public void reoccurringExcecutionTest() throws InterruptedException {
public void cleanupLogExcecutionTest() throws InterruptedException {
CommandContext ctxCMD = new CommandContext();
ctxCMD.setData("businessKey", UUID.randomUUID().toString());

Long requestId = executorService.scheduleRequest("org.jbpm.executor.commands.ReoccurringPrintOutCommand", ctxCMD);

Thread.sleep(10000);
Thread.sleep(9000);

List<RequestInfo> inErrorRequests = executorService.getInErrorRequests();
assertEquals(0, inErrorRequests.size());
Expand All @@ -334,6 +338,24 @@ public void cleanupLogExcecutionTest() throws InterruptedException {
assertEquals(3, executedRequests.size());

executorService.cancelRequest(requestId+3);

List<RequestInfo> canceled = executorService.getCancelledRequests();

ExecutorJPAAuditService auditService = new ExecutorJPAAuditService(emf);
int resultCount = auditService.requestInfoLogDeleteBuilder()
.date(canceled.get(0).getTime())
.status(STATUS.ERROR)
.build()
.execute();

assertEquals(0, resultCount);

resultCount = auditService.errorInfoLogDeleteBuilder()
.date(canceled.get(0).getTime())
.build()
.execute();

assertEquals(0, resultCount);

ctxCMD = new CommandContext();
ctxCMD.setData("businessKey", UUID.randomUUID().toString());
Expand Down
Expand Up @@ -16,6 +16,8 @@

package org.jbpm.executor;

import javax.persistence.Persistence;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
Expand All @@ -24,6 +26,7 @@
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jbpm.test.util.TestUtil;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;

Expand Down Expand Up @@ -70,4 +73,9 @@ public static void beforeClass() {
public static void afterClass() {
pds.close();
}

@Before
public void setup() {
emf = Persistence.createEntityManagerFactory("org.jbpm.executor");
}
}
Expand Up @@ -15,7 +15,6 @@
*/
package org.jbpm.executor;

import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import org.jbpm.test.util.TestUtil;
Expand All @@ -28,7 +27,7 @@
public class NoCDISimpleExecutorTest extends BasicExecutorBaseTest{

private PoolingDataSource pds;
private EntityManagerFactory emf = null;


@Before
public void setUp() {
Expand Down

0 comments on commit da07397

Please sign in to comment.