diff options
| author | Jakob Heher <jakob.heher@iaik.tugraz.at> | 2026-06-12 14:03:22 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-06-12 14:03:22 +0200 |
| commit | ce9f7ae9d70582bb07e1436360b1eab927c81bf0 (patch) | |
| tree | d11551cedfdb7d1b054b1684efd9d84a63f3ad81 /pdf-as-web-db/src/main/java/at/gv | |
| parent | 326c1cd1a7340932b027266927dda1bb60555032 (diff) | |
| download | pdf-as-4-ce9f7ae9d70582bb07e1436360b1eab927c81bf0.tar.gz pdf-as-4-ce9f7ae9d70582bb07e1436360b1eab927c81bf0.tar.bz2 pdf-as-4-ce9f7ae9d70582bb07e1436360b1eab927c81bf0.zip | |
Fix pdf-as-web-db data model (#97)
* also delete packaged release builds when running gradle clean
* fix & test pdf-as-web-db
- rename column for `end`
- fix embeddable data model for statisticevent
- fix storage model to store sign request and statistic event paired
Diffstat (limited to 'pdf-as-web-db/src/main/java/at/gv')
3 files changed, 20 insertions, 97 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 b371026d..fbb6bd70 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 @@ -4,6 +4,7 @@ import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; +import kotlin.Pair; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; @@ -21,7 +22,6 @@ import at.gv.egiz.pdfas.web.config.WebConfiguration; import at.gv.egiz.pdfas.web.stats.StatisticEvent; 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 { @@ -34,7 +34,6 @@ public class DBRequestStore implements IRequestStore { final Configuration cfg = new Configuration(); cfg.addAnnotatedClass(Request.class); cfg.addAnnotatedClass(Response.class); - cfg.addAnnotatedClass(StatisticRequest.class); cfg.setProperties(WebConfiguration.getHibernateProps()); ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings( @@ -77,11 +76,6 @@ public class DBRequestStore implements IRequestStore { query.setParameter("date", calendar.getTime()); query.executeUpdate(); - final MutationQuery queryStat = session.createMutationQuery("delete from StatisticRequest as req" - + " where req.created < :date"); - queryStat.setParameter("date", calendar.getTime()); - queryStat.executeUpdate(); - final MutationQuery queryResponse = session.createMutationQuery("delete from Response as req" + " where req.created < :date"); queryResponse.setParameter("date", calendar.getTime()); @@ -100,14 +94,10 @@ public class DBRequestStore implements IRequestStore { tx = session.beginTransaction(); final Request dbRequest = new Request(); dbRequest.setSignRequest(request); + dbRequest.setStatisticEvent(event); dbRequest.setCreated(Calendar.getInstance().getTime()); session.persist(dbRequest); - final StatisticRequest statisticRequest = new StatisticRequest(); - statisticRequest.setStatisticEvent(event); - statisticRequest.setCreated(Calendar.getInstance().getTime()); - session.persist(statisticRequest); - tx.commit(); return dbRequest.getId(); } catch (final Throwable e) { @@ -118,7 +108,7 @@ public class DBRequestStore implements IRequestStore { } @Override - public PdfasSignRequest fetchStoreEntry(String id) { + public Pair<PdfasSignRequest, StatisticEvent> fetchStoreEntry(String id) { // Clean Old Requests this.cleanOldRequests(); @@ -126,13 +116,14 @@ public class DBRequestStore implements IRequestStore { try (Session session = sessions.openSession()) { tx = session.beginTransaction(); final Request dbRequest = session.get(Request.class, id); + if (dbRequest == null) return null; final PdfasSignRequest request = dbRequest.getSignRequest(); - + final StatisticEvent event = dbRequest.getStatisticEvent(); session.remove(dbRequest); tx.commit(); - return request; + return new Pair<>(request, event); } catch (final Throwable e) { logger.error("Failed to fetch Request", e); if (tx != null) tx.rollback(); @@ -142,30 +133,6 @@ public class DBRequestStore implements IRequestStore { } @Override - public StatisticEvent fetchStatisticEntry(String id) { - // Clean Old Requests - this.cleanOldRequests(); - - Transaction tx = null; - try (Session session = sessions.openSession()) { - tx = session.beginTransaction(); - final StatisticRequest dbRequest = session.get( - StatisticRequest.class, id); - - final StatisticEvent request = dbRequest.getStatisticEvent(); - - session.remove(dbRequest); - - tx.commit(); - return request; - } catch (final Throwable e) { - logger.error("Failed to fetch Request", e); - if (tx != null) tx.rollback(); - return null; - } - } - - @Override public String createNewResponseEntry(PdfasSignResponse response) { // Clean Old Requests this.cleanOldRequests(); 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 978601b1..a78d471e 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 @@ -2,11 +2,8 @@ package at.gv.egiz.pdfas.web.store.db; import java.util.Date; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.Table; +import at.gv.egiz.pdfas.web.stats.StatisticEvent; +import jakarta.persistence.*; import org.hibernate.annotations.GenericGenerator; @@ -19,6 +16,7 @@ public class Request { private String uuid; private Date created; private PdfasSignRequest signRequest; + private StatisticEvent statisticEvent; @Id @GeneratedValue(generator = "uuid") @@ -49,6 +47,15 @@ public class Request { public void setSignRequest(PdfasSignRequest signRequest) { this.signRequest = signRequest; } - - + + @Column(name = "statisticEvent", nullable = false, length = 52428800) + @Embedded + public StatisticEvent getStatisticEvent() { + return this.statisticEvent; + } + + public void setStatisticEvent(StatisticEvent statisticEvent) { + this.statisticEvent = statisticEvent; + } + } diff --git a/pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/store/db/StatisticRequest.java b/pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/store/db/StatisticRequest.java deleted file mode 100644 index 276db6b0..00000000 --- a/pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/store/db/StatisticRequest.java +++ /dev/null @@ -1,51 +0,0 @@ -package at.gv.egiz.pdfas.web.store.db; - -import java.util.Date; - -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.Table; - -import org.hibernate.annotations.GenericGenerator; - -import at.gv.egiz.pdfas.web.stats.StatisticEvent; - -@Entity -@Table(name = "statisticRequest") -public class StatisticRequest { - private String uuid; - private Date created; - private StatisticEvent statisticEvent; - - @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 = "statisticEvent", nullable = false, length = 52428800) - public StatisticEvent getStatisticEvent() { - return this.statisticEvent; - } - - public void setStatisticEvent(StatisticEvent statisticEvent) { - this.statisticEvent = statisticEvent; - } -} |
