From da07397dcd7ee29de60810cc01ce61c4315c66c8 Mon Sep 17 00:00:00 2001 From: Maciej Swiderski Date: Wed, 4 Feb 2015 14:09:58 +0100 Subject: [PATCH] BZ-1188702 - AuditService: data parameters handled internally as timestamp --- .../query/AbstractAuditDeleteBuilderImpl.java | 14 ++++++++++ .../jpa/ErrorInfoLogDeleteBuilderImpl.java | 7 +++-- .../jpa/RequestInfoLogDeleteBuilderImpl.java | 6 ++-- .../jbpm/executor/BasicExecutorBaseTest.java | 28 +++++++++++++++++-- .../jbpm/executor/CDISimpleExecutorTest.java | 8 ++++++ .../executor/NoCDISimpleExecutorTest.java | 3 +- 6 files changed, 55 insertions(+), 11 deletions(-) diff --git a/jbpm-audit/src/main/java/org/jbpm/process/audit/query/AbstractAuditDeleteBuilderImpl.java b/jbpm-audit/src/main/java/org/jbpm/process/audit/query/AbstractAuditDeleteBuilderImpl.java index 2b2eca63b5..50109350a9 100644 --- a/jbpm-audit/src/main/java/org/jbpm/process/audit/query/AbstractAuditDeleteBuilderImpl.java +++ b/jbpm-audit/src/main/java/org/jbpm/process/audit/query/AbstractAuditDeleteBuilderImpl.java @@ -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; @@ -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; + } } diff --git a/jbpm-services/jbpm-executor/src/main/java/org/jbpm/executor/impl/jpa/ErrorInfoLogDeleteBuilderImpl.java b/jbpm-services/jbpm-executor/src/main/java/org/jbpm/executor/impl/jpa/ErrorInfoLogDeleteBuilderImpl.java index 3d2ae1ff55..ee03895bc8 100644 --- a/jbpm-services/jbpm-executor/src/main/java/org/jbpm/executor/impl/jpa/ErrorInfoLogDeleteBuilderImpl.java +++ b/jbpm-services/jbpm-executor/src/main/java/org/jbpm/executor/impl/jpa/ErrorInfoLogDeleteBuilderImpl.java @@ -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; } @@ -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; } @@ -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; } diff --git a/jbpm-services/jbpm-executor/src/main/java/org/jbpm/executor/impl/jpa/RequestInfoLogDeleteBuilderImpl.java b/jbpm-services/jbpm-executor/src/main/java/org/jbpm/executor/impl/jpa/RequestInfoLogDeleteBuilderImpl.java index 628ef07936..84e2fdacf4 100644 --- a/jbpm-services/jbpm-executor/src/main/java/org/jbpm/executor/impl/jpa/RequestInfoLogDeleteBuilderImpl.java +++ b/jbpm-services/jbpm-executor/src/main/java/org/jbpm/executor/impl/jpa/RequestInfoLogDeleteBuilderImpl.java @@ -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; } @@ -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; } @@ -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; } diff --git a/jbpm-services/jbpm-executor/src/test/java/org/jbpm/executor/BasicExecutorBaseTest.java b/jbpm-services/jbpm-executor/src/test/java/org/jbpm/executor/BasicExecutorBaseTest.java index 6aa26971fc..97093d9e37 100644 --- a/jbpm-services/jbpm-executor/src/test/java/org/jbpm/executor/BasicExecutorBaseTest.java +++ b/jbpm-services/jbpm-executor/src/test/java/org/jbpm/executor/BasicExecutorBaseTest.java @@ -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; @@ -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; @@ -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; @@ -50,7 +54,7 @@ public abstract class BasicExecutorBaseTest { protected ExecutorService executorService; public static final Map cachedEntities = new HashMap(); - + protected EntityManagerFactory emf = null; @Before public void setUp() { @@ -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 inErrorRequests = executorService.getInErrorRequests(); assertEquals(0, inErrorRequests.size()); @@ -334,6 +338,24 @@ public void cleanupLogExcecutionTest() throws InterruptedException { assertEquals(3, executedRequests.size()); executorService.cancelRequest(requestId+3); + + List 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()); diff --git a/jbpm-services/jbpm-executor/src/test/java/org/jbpm/executor/CDISimpleExecutorTest.java b/jbpm-services/jbpm-executor/src/test/java/org/jbpm/executor/CDISimpleExecutorTest.java index abef267557..150f1a4472 100644 --- a/jbpm-services/jbpm-executor/src/test/java/org/jbpm/executor/CDISimpleExecutorTest.java +++ b/jbpm-services/jbpm-executor/src/test/java/org/jbpm/executor/CDISimpleExecutorTest.java @@ -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; @@ -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; @@ -70,4 +73,9 @@ public static void beforeClass() { public static void afterClass() { pds.close(); } + + @Before + public void setup() { + emf = Persistence.createEntityManagerFactory("org.jbpm.executor"); + } } \ No newline at end of file diff --git a/jbpm-services/jbpm-executor/src/test/java/org/jbpm/executor/NoCDISimpleExecutorTest.java b/jbpm-services/jbpm-executor/src/test/java/org/jbpm/executor/NoCDISimpleExecutorTest.java index 77d2b1d324..c9baea8c9f 100644 --- a/jbpm-services/jbpm-executor/src/test/java/org/jbpm/executor/NoCDISimpleExecutorTest.java +++ b/jbpm-services/jbpm-executor/src/test/java/org/jbpm/executor/NoCDISimpleExecutorTest.java @@ -15,7 +15,6 @@ */ package org.jbpm.executor; -import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; import org.jbpm.test.util.TestUtil; @@ -28,7 +27,7 @@ public class NoCDISimpleExecutorTest extends BasicExecutorBaseTest{ private PoolingDataSource pds; - private EntityManagerFactory emf = null; + @Before public void setUp() {