From e929b5f4c6d9351b29150e6c1843f06806ee7b00 Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Mon, 1 Dec 2014 12:23:47 +0100 Subject: added status servlet to pdf-as-web --- .../at/gv/egiz/pdfas/web/db/status/DBTest.java | 45 ++++++++++++++++++++++ .../gv/egiz/pdfas/web/db/status/DBTestFactory.java | 18 +++++++++ .../at/gv/egiz/pdfas/web/store/DBRequestStore.java | 23 +++++++++++ .../services/at.gv.egiz.status.TestFactory | 1 + 4 files changed, 87 insertions(+) create mode 100644 pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/db/status/DBTest.java create mode 100644 pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/db/status/DBTestFactory.java create mode 100644 pdf-as-web-db/src/main/resources/META-INF/services/at.gv.egiz.status.TestFactory (limited to 'pdf-as-web-db/src') 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 details = new ArrayList(); + 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 createTests() { + List testList = new ArrayList(); + 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(); diff --git a/pdf-as-web-db/src/main/resources/META-INF/services/at.gv.egiz.status.TestFactory b/pdf-as-web-db/src/main/resources/META-INF/services/at.gv.egiz.status.TestFactory new file mode 100644 index 00000000..40ad6651 --- /dev/null +++ b/pdf-as-web-db/src/main/resources/META-INF/services/at.gv.egiz.status.TestFactory @@ -0,0 +1 @@ +at.gv.egiz.pdfas.web.db.status.DBTestFactory \ No newline at end of file -- cgit v1.2.3