aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-web-db/src
diff options
context:
space:
mode:
authorThomas <>2023-01-11 23:23:30 +0100
committerThomas <>2023-01-11 23:23:30 +0100
commit42e68c8f3e53b34663d2fe9c434b0b034ff9ddf0 (patch)
treede9aceb59655ff02fcbc4100f07fe33d035f34f1 /pdf-as-web-db/src
parent989f7685e730255a08c32e7a10c090f2ffc22d26 (diff)
downloadpdf-as-4-42e68c8f3e53b34663d2fe9c434b0b034ff9ddf0.tar.gz
pdf-as-4-42e68c8f3e53b34663d2fe9c434b0b034ff9ddf0.tar.bz2
pdf-as-4-42e68c8f3e53b34663d2fe9c434b0b034ff9ddf0.zip
feat(web): add bulk-light functionality into PDF-AS-Web
Diffstat (limited to 'pdf-as-web-db/src')
-rw-r--r--pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/store/DBRequestStore.java387
-rw-r--r--pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/store/db/Request.java9
-rw-r--r--pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/store/db/Response.java54
3 files changed, 284 insertions, 166 deletions
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 1499b8ba..5afb28e4 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
@@ -14,172 +14,237 @@ import org.hibernate.service.ServiceRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import at.gv.egiz.pdfas.api.ws.PDFASSignRequest;
+import at.gv.egiz.pdfas.api.processing.PdfasSignRequest;
+import at.gv.egiz.pdfas.api.processing.PdfasSignResponse;
import at.gv.egiz.pdfas.web.config.WebConfiguration;
import at.gv.egiz.pdfas.web.stats.StatisticEvent;
-import at.gv.egiz.pdfas.web.store.IRequestStore;
import at.gv.egiz.pdfas.web.store.db.Request;
+import at.gv.egiz.pdfas.web.store.db.Response;
import at.gv.egiz.pdfas.web.store.db.StatisticRequest;
public class DBRequestStore implements IRequestStore {
- private static final Logger logger = LoggerFactory
- .getLogger(DBRequestStore.class);
-
- private SessionFactory sessions;
- private ServiceRegistry serviceRegistry;
-
- public DBRequestStore() {
- Configuration cfg = new Configuration();
- cfg.addAnnotatedClass(Request.class);
- cfg.setProperties(WebConfiguration.getHibernateProps());
-
- serviceRegistry = new StandardServiceRegistryBuilder().applySettings(
- cfg.getProperties()).build();
-
- sessions = cfg.buildSessionFactory(serviceRegistry);
- }
-
- private void cleanOldRequests() {
- 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();
- } catch (Throwable e) {
- logger.error("Failed to save Request", e);
- tx.rollback();
- } finally {
- if (session != null) {
- session.close();
- }
- }
- }
-
- 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;
- try {
- session = sessions.openSession();
- Query query = session.createQuery("delete from Request as req"
- + " where req.created < :date");
- query.setCalendar("date", calendar);
- query.executeUpdate();
-
- Query queryStat = session.createQuery("delete from StatisticRequest as req"
- + " where req.created < :date");
- queryStat.setCalendar("date", calendar);
- queryStat.executeUpdate();
- } finally {
- if (session != null) {
- session.close();
- }
- }
- }
-
- public String createNewStoreEntry(PDFASSignRequest request,
- StatisticEvent event) {
- // Clean Old Requests
- this.cleanOldRequests();
- Session session = null;
- Transaction tx = null;
- try {
- session = sessions.openSession();
- tx = session.beginTransaction();
- Request dbRequest = new Request();
- dbRequest.setSignRequest(request);
- dbRequest.setCreated(Calendar.getInstance().getTime());
- session.save(dbRequest);
-
- StatisticRequest statisticRequest = new StatisticRequest();
- statisticRequest.setStatisticEvent(event);
- statisticRequest.setCreated(Calendar.getInstance().getTime());
- session.save(statisticRequest);
-
- tx.commit();
- return dbRequest.getId();
- } catch (Throwable e) {
- logger.error("Failed to save Request", e);
- tx.rollback();
- return null;
- } finally {
- if (session != null) {
- session.close();
- }
- }
- }
-
- public PDFASSignRequest fetchStoreEntry(String id) {
- // Clean Old Requests
- this.cleanOldRequests();
-
- Session session = null;
- Transaction tx = null;
- try {
- session = sessions.openSession();
- tx = session.beginTransaction();
- Request dbRequest = (Request) session.get(Request.class, id);
-
- PDFASSignRequest request = dbRequest.getSignRequest();
-
- session.delete(dbRequest);
-
- tx.commit();
- return request;
- } catch (Throwable e) {
- logger.error("Failed to fetch Request", e);
- tx.rollback();
- return null;
- } finally {
- if (session != null) {
- session.close();
- }
- }
-
- }
-
- @Override
- public StatisticEvent fetchStatisticEntry(String id) {
- // Clean Old Requests
- this.cleanOldRequests();
-
- Session session = null;
- Transaction tx = null;
- try {
- session = sessions.openSession();
- tx = session.beginTransaction();
- StatisticRequest dbRequest = (StatisticRequest) session.get(
- StatisticRequest.class, id);
-
- StatisticEvent request = dbRequest.getStatisticEvent();
-
- session.delete(dbRequest);
-
- tx.commit();
- return request;
- } catch (Throwable e) {
- logger.error("Failed to fetch Request", e);
- tx.rollback();
- return null;
- } finally {
- if (session != null) {
- session.close();
- }
- }
- }
+ private static final Logger logger = LoggerFactory
+ .getLogger(DBRequestStore.class);
+
+ private final SessionFactory sessions;
+ private final ServiceRegistry serviceRegistry;
+
+ public DBRequestStore() {
+ final Configuration cfg = new Configuration();
+ cfg.addAnnotatedClass(Request.class);
+ cfg.setProperties(WebConfiguration.getHibernateProps());
+
+ serviceRegistry = new StandardServiceRegistryBuilder().applySettings(
+ cfg.getProperties()).build();
+
+ sessions = cfg.buildSessionFactory(serviceRegistry);
+ }
+
+ private void cleanOldRequests() {
+ final int seconds = WebConfiguration.getDBTimeout();
+ final Calendar calendar = Calendar.getInstance();
+ calendar.add(Calendar.SECOND, -1 * seconds);
+ final Date date = calendar.getTime();
+ final 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();
+ final Query query = session.createQuery("delete from Request as req"
+ + " where req.created < :date");
+ query.setCalendar("date", calendar);
+ query.executeUpdate();
+ } catch (final Throwable e) {
+ logger.error("Failed to save Request", e);
+ tx.rollback();
+ } finally {
+ if (session != null) {
+ session.close();
+ }
+ }
+ }
+
+ public void cleanOldRequestException() {
+ final int seconds = WebConfiguration.getDBTimeout();
+ final Calendar calendar = Calendar.getInstance();
+ calendar.add(Calendar.SECOND, -1 * seconds);
+ final Date date = calendar.getTime();
+ final SimpleDateFormat dt = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
+ logger.info("Clearing Entries before: " + dt.format(date));
+ Session session = null;
+ try {
+ session = sessions.openSession();
+ final Query query = session.createQuery("delete from Request as req"
+ + " where req.created < :date");
+ query.setCalendar("date", calendar);
+ query.executeUpdate();
+
+ final Query queryStat = session.createQuery("delete from StatisticRequest as req"
+ + " where req.created < :date");
+ queryStat.setCalendar("date", calendar);
+ queryStat.executeUpdate();
+
+ final Query queryResponse = session.createQuery("delete from Response as req"
+ + " where req.created < :date");
+ queryResponse.setCalendar("date", calendar);
+ queryResponse.executeUpdate();
+
+ } finally {
+ if (session != null) {
+ session.close();
+ }
+ }
+ }
+
+ @Override
+ public String createNewStoreEntry(PdfasSignRequest request,
+ StatisticEvent event) {
+ // Clean Old Requests
+ this.cleanOldRequests();
+ Session session = null;
+ Transaction tx = null;
+ try {
+ session = sessions.openSession();
+ tx = session.beginTransaction();
+ final Request dbRequest = new Request();
+ dbRequest.setSignRequest(request);
+ dbRequest.setCreated(Calendar.getInstance().getTime());
+ session.save(dbRequest);
+
+ final StatisticRequest statisticRequest = new StatisticRequest();
+ statisticRequest.setStatisticEvent(event);
+ statisticRequest.setCreated(Calendar.getInstance().getTime());
+ session.save(statisticRequest);
+
+ tx.commit();
+ return dbRequest.getId();
+ } catch (final Throwable e) {
+ logger.error("Failed to save Request", e);
+ tx.rollback();
+ return null;
+ } finally {
+ if (session != null) {
+ session.close();
+ }
+ }
+ }
+
+ @Override
+ public PdfasSignRequest fetchStoreEntry(String id) {
+ // Clean Old Requests
+ this.cleanOldRequests();
+
+ Session session = null;
+ Transaction tx = null;
+ try {
+ session = sessions.openSession();
+ tx = session.beginTransaction();
+ final Request dbRequest = session.get(Request.class, id);
+
+ final PdfasSignRequest request = dbRequest.getSignRequest();
+
+ session.delete(dbRequest);
+
+ tx.commit();
+ return request;
+ } catch (final Throwable e) {
+ logger.error("Failed to fetch Request", e);
+ tx.rollback();
+ return null;
+ } finally {
+ if (session != null) {
+ session.close();
+ }
+ }
+
+ }
+
+ @Override
+ public StatisticEvent fetchStatisticEntry(String id) {
+ // Clean Old Requests
+ this.cleanOldRequests();
+
+ Session session = null;
+ Transaction tx = null;
+ try {
+ session = sessions.openSession();
+ tx = session.beginTransaction();
+ final StatisticRequest dbRequest = session.get(
+ StatisticRequest.class, id);
+
+ final StatisticEvent request = dbRequest.getStatisticEvent();
+
+ session.delete(dbRequest);
+
+ tx.commit();
+ return request;
+ } catch (final Throwable e) {
+ logger.error("Failed to fetch Request", e);
+ tx.rollback();
+ return null;
+ } finally {
+ if (session != null) {
+ session.close();
+ }
+ }
+ }
+
+ @Override
+ public String createNewResponseEntry(PdfasSignResponse response) {
+ // Clean Old Requests
+ this.cleanOldRequests();
+ Session session = null;
+ Transaction tx = null;
+ try {
+ session = sessions.openSession();
+ tx = session.beginTransaction();
+ final Response dbRequest = new Response();
+ dbRequest.setSignedResponse(response);
+ dbRequest.setCreated(Calendar.getInstance().getTime());
+ session.save(dbRequest);
+
+ tx.commit();
+ return dbRequest.getId();
+ } catch (final Throwable e) {
+ logger.error("Failed to save Request", e);
+ tx.rollback();
+ return null;
+ } finally {
+ if (session != null) {
+ session.close();
+ }
+ }
+ }
+
+ @Override
+ public PdfasSignResponse fetchStoreResponse(String id) {
+ // Clean Old Requests
+ this.cleanOldRequests();
+
+ Session session = null;
+ Transaction tx = null;
+ try {
+ session = sessions.openSession();
+ tx = session.beginTransaction();
+ final Response dbResponse = session.get(Response.class, id);
+
+ final PdfasSignResponse request = dbResponse.getSignedResponse();
+
+ session.delete(dbResponse);
+
+ tx.commit();
+ return request;
+ } catch (final Throwable e) {
+ logger.error("Failed to fetch Response", e);
+ tx.rollback();
+ return null;
+ } finally {
+ if (session != null) {
+ session.close();
+ }
+ }
+ }
}
diff --git a/pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/store/db/Request.java b/pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/store/db/Request.java
index 54870365..f8a169c3 100644
--- a/pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/store/db/Request.java
+++ b/pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/store/db/Request.java
@@ -10,8 +10,7 @@ import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
-import at.gv.egiz.pdfas.api.ws.PDFASSignRequest;
-import at.gv.egiz.pdfas.web.stats.StatisticEvent;
+import at.gv.egiz.pdfas.api.processing.PdfasSignRequest;
@Entity
@Table(name = "requests")
@@ -19,7 +18,7 @@ public class Request {
private String uuid;
private Date created;
- private PDFASSignRequest signRequest;
+ private PdfasSignRequest signRequest;
@Id
@GeneratedValue(generator = "uuid")
@@ -43,11 +42,11 @@ public class Request {
}
@Column(name = "signRequest", nullable = false, length = 52428800)
- public PDFASSignRequest getSignRequest() {
+ public PdfasSignRequest getSignRequest() {
return this.signRequest;
}
- public void setSignRequest(PDFASSignRequest signRequest) {
+ public void setSignRequest(PdfasSignRequest signRequest) {
this.signRequest = signRequest;
}
diff --git a/pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/store/db/Response.java b/pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/store/db/Response.java
new file mode 100644
index 00000000..a47f532c
--- /dev/null
+++ b/pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/store/db/Response.java
@@ -0,0 +1,54 @@
+package at.gv.egiz.pdfas.web.store.db;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import org.hibernate.annotations.GenericGenerator;
+
+import at.gv.egiz.pdfas.api.processing.PdfasSignResponse;
+
+@Entity
+@Table(name = "response")
+public class Response {
+
+ private String uuid;
+ private Date created;
+ private PdfasSignResponse signResponse;
+
+ @Id
+ @GeneratedValue(generator = "uuid")
+ @GenericGenerator(name = "uuid", strategy = "uuid2")
+ @Column(name = "id", unique = true)
+ public String getId() {
+ return this.uuid;
+ }
+
+ public void setId(String uuid) {
+ this.uuid = uuid;
+ }
+
+ @Column(name = "created", nullable = false)
+ public Date getCreated() {
+ return this.created;
+ }
+
+ public void setCreated(Date created) {
+ this.created = created;
+ }
+
+ @Column(name = "signedResponse", nullable = false, length = 52428800)
+ public PdfasSignResponse getSignedResponse() {
+ return this.signResponse;
+ }
+
+ public void setSignedResponse(PdfasSignResponse signResponse) {
+ this.signResponse = signResponse;
+ }
+
+
+}