diff options
Diffstat (limited to 'pdf-as-web-db/src/main')
4 files changed, 87 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(); 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 |