aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-web-db/src/main/java
diff options
context:
space:
mode:
authorAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-12-01 12:23:47 +0100
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-12-02 10:09:35 +0100
commite929b5f4c6d9351b29150e6c1843f06806ee7b00 (patch)
treec6ecc4e5f6c3da6ef381a3d852c0a2211ca060e2 /pdf-as-web-db/src/main/java
parent6398c85d80213f316dd0f9e4be10e34b54b1f5f9 (diff)
downloadpdf-as-4-e929b5f4c6d9351b29150e6c1843f06806ee7b00.tar.gz
pdf-as-4-e929b5f4c6d9351b29150e6c1843f06806ee7b00.tar.bz2
pdf-as-4-e929b5f4c6d9351b29150e6c1843f06806ee7b00.zip
added status servlet to pdf-as-web
Diffstat (limited to 'pdf-as-web-db/src/main/java')
-rw-r--r--pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/db/status/DBTest.java45
-rw-r--r--pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/db/status/DBTestFactory.java18
-rw-r--r--pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/store/DBRequestStore.java23
3 files changed, 86 insertions, 0 deletions
diff --git a/pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/db/status/DBTest.java b/pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/db/status/DBTest.java
new file mode 100644
index 00000000..e1cc1a8d
--- /dev/null
+++ b/pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/db/status/DBTest.java
@@ -0,0 +1,45 @@
+package at.gv.egiz.pdfas.web.db.status;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import at.gv.egiz.pdfas.web.store.DBRequestStore;
+import at.gv.egiz.status.Test;
+import at.gv.egiz.status.TestResult;
+import at.gv.egiz.status.TestStatus;
+import at.gv.egiz.status.impl.BaseTestResult;
+
+public class DBTest implements Test {
+
+ private DBRequestStore requestStore;
+
+ public DBTest() {
+ requestStore = new DBRequestStore();
+ }
+
+ @Override
+ public String getName() {
+ return "DB";
+ }
+
+ @Override
+ public long getCacheDelay() {
+ return 300000;
+ }
+
+ @Override
+ public TestResult runTest() {
+ BaseTestResult result = new BaseTestResult();
+ try {
+ this.requestStore.cleanOldRequestException();
+ result.setStatus(TestStatus.OK);
+ } catch(Throwable e) {
+ result.setStatus(TestStatus.FAILED);
+ List<String> details = new ArrayList<String>();
+ details.add(e.getMessage());
+ result.setDetails(details);
+ }
+ return result;
+ }
+
+}
diff --git a/pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/db/status/DBTestFactory.java b/pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/db/status/DBTestFactory.java
new file mode 100644
index 00000000..bc0112a2
--- /dev/null
+++ b/pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/db/status/DBTestFactory.java
@@ -0,0 +1,18 @@
+package at.gv.egiz.pdfas.web.db.status;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import at.gv.egiz.status.Test;
+import at.gv.egiz.status.TestFactory;
+
+public class DBTestFactory implements TestFactory {
+
+ @Override
+ public List<Test> createTests() {
+ List<Test> testList = new ArrayList<Test>();
+ testList.add(new DBTest());
+ return testList;
+ }
+
+}
diff --git a/pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/store/DBRequestStore.java b/pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/store/DBRequestStore.java
index a1b88270..df006f02 100644
--- a/pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/store/DBRequestStore.java
+++ b/pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/store/DBRequestStore.java
@@ -64,6 +64,29 @@ public class DBRequestStore implements IRequestStore {
}
}
+ public void cleanOldRequestException() {
+ int seconds = WebConfiguration.getDBTimeout();
+ Calendar calendar = Calendar.getInstance();
+ calendar.add(Calendar.SECOND, (-1)* seconds);
+ Date date = calendar.getTime();
+ SimpleDateFormat dt = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
+ logger.info("Clearing Entries before: " + dt.format(date));
+ Session session = null;
+ Transaction tx = null;
+ try {
+ session = sessions.openSession();
+ tx = session.beginTransaction();
+ Query query = session.createQuery("delete from Request as req" +
+ " where req.created < :date");
+ query.setCalendar("date", calendar);
+ query.executeUpdate();
+ } finally {
+ if(session != null) {
+ session.close();
+ }
+ }
+ }
+
public String createNewStoreEntry(PDFASSignRequest request) {
// Clean Old Requests
this.cleanOldRequests();