aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-web-db
diff options
context:
space:
mode:
Diffstat (limited to 'pdf-as-web-db')
-rw-r--r--pdf-as-web-db/.gitignore4
-rw-r--r--pdf-as-web-db/build.gradle168
-rw-r--r--pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/store/DBRequestStore.java249
-rw-r--r--pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/store/db/Request.java21
-rw-r--r--pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/store/db/Response.java10
-rw-r--r--pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/store/db/StatisticRequest.java51
-rw-r--r--pdf-as-web-db/src/test/java/at/gv/egiz/pdfas/web/store/DBRequestStoreTest.java86
7 files changed, 335 insertions, 254 deletions
diff --git a/pdf-as-web-db/.gitignore b/pdf-as-web-db/.gitignore
index ae3c1726..1626e96d 100644
--- a/pdf-as-web-db/.gitignore
+++ b/pdf-as-web-db/.gitignore
@@ -1 +1,3 @@
-/bin/
+/bin
+/build
+/releases
diff --git a/pdf-as-web-db/build.gradle b/pdf-as-web-db/build.gradle
index c54b9dbb..5ba12625 100644
--- a/pdf-as-web-db/build.gradle
+++ b/pdf-as-web-db/build.gradle
@@ -1,36 +1,148 @@
-apply plugin: 'java'
-apply plugin: 'eclipse'
-apply plugin: 'java-library-distribution'
+plugins {
+ id 'java-library'
+ id 'eclipse'
+ id 'distribution'
+}
+
+configurations {
+ tomcatDist
+}
+
+dependencies {
+ tomcatDist "org.apache.tomcat:tomcat:${tomcatVersion}@zip"
+}
jar {
- manifest {
- attributes 'Implementation-Title': 'PDF-AS-4 Web Extension Library', 'JARMANIFEST': 'PDF-AS-LIB'
- }
+ manifest {
+ attributes 'Implementation-Title': 'PDF-AS-5 Web Extension Library', 'JARMANIFEST': 'PDF-AS-LIB'
+ }
}
repositories {
- mavenLocal()
- mavenCentral()
+ mavenLocal()
+ mavenCentral()
}
dependencies {
- implementation project (':pdf-as-web')
- implementation project (':pdf-as-web-status')
- implementation project (':pdf-as-web-statistic-api')
- api "org.hibernate:hibernate-core:5.6.15.Final"
- api "org.hibernate:hibernate-entitymanager:5.6.15.Final"
- implementation 'ch.qos.logback:logback-classic:1.2.13'
- implementation group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion
-}
-
-task releases(type: Copy) {
- from jar.outputs
- from distZip.outputs
- from distTar.outputs
- into rootDir.toString() + "/releases/" + version
-}
-
-releases.dependsOn jar
-releases.dependsOn sourcesJar
-releases.dependsOn distZip
-releases.dependsOn distTar
+ implementation project (':pdf-as-web')
+ implementation project (':pdf-as-web-status')
+ implementation project (':pdf-as-web-statistic-api')
+ api "org.hibernate:hibernate-core:6.6.44.Final"
+ implementation group: 'ch.qos.logback', name: 'logback-classic', version: logbackVersion
+ implementation group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion
+ runtimeOnly 'org.mariadb.jdbc:mariadb-java-client:3.5.6'
+
+ testRuntimeOnly 'com.h2database:h2:2.4.240'
+}
+
+/*
+ * Release-Bundle analog zu :pdf-as-web, erweitert um die DB-Extension.
+ */
+def tomcatVer = tomcatVersion
+def tomcatDir = layout.buildDirectory.dir("tomcat-bundling")
+def tomcatHome = tomcatDir.map { it.dir("apache-tomcat-${tomcatVer}") }
+def releasesDirectory = layout.projectDirectory.dir("releases/${project.version}")
+def webProject = project(':pdf-as-web')
+def dbExtensionJar = tasks.named('jar', Jar)
+def dbExtensionRuntimeClasspath = configurations.named('runtimeClasspath')
+
+tasks.register('extractTomcat', Sync) {
+ from({
+ zipTree(configurations.tomcatDist.singleFile)
+ })
+ into(tomcatDir)
+}
+
+tasks.register('cleanWebAppsInTomcat', Delete) {
+ dependsOn('extractTomcat')
+ delete(tomcatHome.map { it.dir("webapps") })
+}
+
+tasks.register('putTemplateIntoTomcat', Copy) {
+ dependsOn('cleanWebAppsInTomcat')
+ from(webProject.layout.projectDirectory.dir("src/main/assembly/tomcat"))
+ into(tomcatHome)
+}
+
+tasks.register('putConfigIntoTomcat', Copy) {
+ dependsOn(':pdf-as-lib:processResources', 'putTemplateIntoTomcat')
+ from(zipTree(project(':pdf-as-lib').layout.buildDirectory.file('resources/main/config/config.zip')))
+ into(tomcatHome.map { it.dir("conf/pdf-as") })
+}
+
+tasks.register('putWebConfigIntoTomcat', Copy) {
+ dependsOn('putConfigIntoTomcat')
+ from(webProject.layout.projectDirectory.dir("src/main/configuration"))
+ into(tomcatHome.map { it.dir("conf/pdf-as") })
+}
+
+tasks.register('putDbExtensionIntoWebApp', Zip) {
+ dependsOn(dbExtensionJar, ':pdf-as-web:bootWar')
+ from(zipTree(webProject.tasks.named('bootWar').flatMap { it.archiveFile }))
+ from(dbExtensionJar.flatMap { it.archiveFile }) {
+ into 'WEB-INF/lib'
+ }
+ from(dbExtensionRuntimeClasspath) {
+ into 'WEB-INF/lib'
+ }
+ archiveFileName = "pdf-as-web-db-${project.version}.war"
+ destinationDirectory = layout.buildDirectory.dir('db-enhanced-webapp')
+ duplicatesStrategy = DuplicatesStrategy.EXCLUDE
+}
+
+/*
+ * DB-Extension weiterhin auch separat als Lib-Verzeichnis ablegen.
+ * Das entspricht dem bisherigen Extension-Artefakt: eigenes JAR + Runtime-Dependencies.
+ */
+tasks.register('putDbExtensionLibs', Copy) {
+ dependsOn(dbExtensionJar)
+ from(dbExtensionJar.flatMap { it.archiveFile })
+ from(dbExtensionRuntimeClasspath)
+ into(releasesDirectory.dir("pdf-as-web-db-extension-${project.version}/lib"))
+ duplicatesStrategy = DuplicatesStrategy.EXCLUDE
+}
+
+tasks.register('injectPdfAsWebApp', Copy) {
+ dependsOn('putDbExtensionIntoWebApp', 'extractTomcat')
+ from(tasks.named('putDbExtensionIntoWebApp', Zip).flatMap { it.archiveFile }) {
+ rename { 'pdf-as-web.war' }
+ }
+ into(tomcatHome.map { it.dir("webapps") })
+}
+
+tasks.register('buildTomcatZip', Zip) {
+ dependsOn('injectPdfAsWebApp')
+ from(tomcatDir)
+ archiveFileName = "apache-tomcat-${tomcatVer}-pdf-as-web-db-${project.version}.zip"
+ destinationDirectory = layout.buildDirectory
+}
+
+tasks.register('buildTomcatTar', Tar) {
+ dependsOn('injectPdfAsWebApp')
+ from(tomcatDir)
+ archiveFileName = "apache-tomcat-${tomcatVer}-pdf-as-web-db-${project.version}.tar"
+ destinationDirectory = layout.buildDirectory
+ compression = Compression.NONE
+}
+
+tasks.register('releaseConfig', Copy) {
+ from(webProject.layout.projectDirectory.file('src/main/configuration/pdf-as-web.properties'))
+ into(releasesDirectory.dir("cfg"))
+}
+
+tasks.register('releases', Copy) {
+ dependsOn(dbExtensionJar, 'sourcesJar', 'distZip', 'distTar', 'releaseConfig', 'putDbExtensionLibs', 'buildTomcatZip', 'buildTomcatTar')
+
+ from(dbExtensionJar.flatMap { it.archiveFile })
+ from(tasks.named('sourcesJar').flatMap { it.archiveFile })
+ from(tasks.named('distZip').flatMap { it.archiveFile })
+ from(tasks.named('distTar').flatMap { it.archiveFile })
+ from(tasks.named('putDbExtensionIntoWebApp', Zip).flatMap { it.archiveFile })
+ from(tasks.named('buildTomcatZip').flatMap { it.archiveFile })
+ from(tasks.named('buildTomcatTar').flatMap { it.archiveFile })
+ into(releasesDirectory)
+}
+
+tasks.named('clean', Delete) {
+ delete(releasesDirectory)
+}
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 e5a789d2..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,11 +4,13 @@ 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;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
+import org.hibernate.query.MutationQuery;
import org.hibernate.query.Query;
import org.hibernate.service.ServiceRegistry;
import org.slf4j.Logger;
@@ -20,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 {
@@ -28,17 +29,15 @@ public class DBRequestStore implements IRequestStore {
.getLogger(DBRequestStore.class);
private final SessionFactory sessions;
- private final ServiceRegistry serviceRegistry;
public DBRequestStore() {
final Configuration cfg = new Configuration();
cfg.addAnnotatedClass(Request.class);
cfg.addAnnotatedClass(Response.class);
- cfg.addAnnotatedClass(StatisticRequest.class);
cfg.setProperties(WebConfiguration.getHibernateProps());
- serviceRegistry = new StandardServiceRegistryBuilder().applySettings(
- cfg.getProperties()).build();
+ ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(
+ cfg.getProperties()).build();
sessions = cfg.buildSessionFactory(serviceRegistry);
}
@@ -50,24 +49,18 @@ public class DBRequestStore implements IRequestStore {
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();
- tx.commit();
- } catch (final Throwable e) {
- logger.error("Failed to save Request", e);
- tx.rollback();
- } finally {
- if (session != null) {
- session.close();
+ Transaction tx = null;
+ try (Session session = sessions.openSession()) {
+ tx = session.beginTransaction();
+ final MutationQuery query = session.createMutationQuery("delete from Request as req"
+ + " where req.created < :date");
+ query.setParameter("date", calendar.getTime());
+ query.executeUpdate();
+ tx.commit();
+ } catch (final Throwable e) {
+ logger.error("Failed to save Request", e);
+ if (tx != null) tx.rollback();
}
- }
}
public void cleanOldRequestException() {
@@ -77,29 +70,18 @@ public class DBRequestStore implements IRequestStore {
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();
+ try (Session session = sessions.openSession()) {
+ final MutationQuery query = session.createMutationQuery("delete from Request as req"
+ + " where req.created < :date");
+ query.setParameter("date", calendar.getTime());
+ query.executeUpdate();
+
+ final MutationQuery queryResponse = session.createMutationQuery("delete from Response as req"
+ + " where req.created < :date");
+ queryResponse.setParameter("date", calendar.getTime());
+ queryResponse.executeUpdate();
+
}
- }
}
@Override
@@ -107,119 +89,68 @@ public class DBRequestStore implements IRequestStore {
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();
+ Transaction tx = null;
+ try (Session session = sessions.openSession()) {
+ tx = session.beginTransaction();
+ final Request dbRequest = new Request();
+ dbRequest.setSignRequest(request);
+ dbRequest.setStatisticEvent(event);
+ dbRequest.setCreated(Calendar.getInstance().getTime());
+ session.persist(dbRequest);
+
+ tx.commit();
+ return dbRequest.getId();
+ } catch (final Throwable e) {
+ logger.error("Failed to save Request", e);
+ if (tx != null) tx.rollback();
+ return null;
}
- }
}
@Override
- public PdfasSignRequest fetchStoreEntry(String id) {
+ public Pair<PdfasSignRequest, StatisticEvent> 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();
+ Transaction tx = null;
+ 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 new Pair<>(request, event);
+ } catch (final Throwable e) {
+ logger.error("Failed to fetch Request", e);
+ if (tx != null) tx.rollback();
+ return null;
}
- }
-
- }
-
- @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();
+ Transaction tx = null;
+ try (Session session = sessions.openSession()) {
+ tx = session.beginTransaction();
+ final Response dbRequest = new Response();
+ dbRequest.setSignedResponse(response);
+ dbRequest.setCreated(Calendar.getInstance().getTime());
+ session.persist(dbRequest);
+
+ tx.commit();
+ return dbRequest.getId();
+ } catch (final Throwable e) {
+ logger.error("Failed to save Request", e);
+ if (tx != null) tx.rollback();
+ return null;
}
- }
}
@Override
@@ -227,27 +158,21 @@ public class DBRequestStore implements IRequestStore {
// 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();
+ Transaction tx = null;
+ try (Session session = sessions.openSession()) {
+ tx = session.beginTransaction();
+ final Response dbResponse = session.get(Response.class, id);
+
+ final PdfasSignResponse request = dbResponse.getSignedResponse();
+
+ session.remove(dbResponse);
+
+ tx.commit();
+ return request;
+ } catch (final Throwable e) {
+ logger.error("Failed to fetch Response", e);
+ if (tx != null) tx.rollback();
+ return null;
}
- }
}
}
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 f8a169c3..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 javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.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/Response.java b/pdf-as-web-db/src/main/java/at/gv/egiz/pdfas/web/store/db/Response.java
index a47f532c..2367dcf0 100644
--- 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
@@ -2,11 +2,11 @@ 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 jakarta.persistence.Column;
+import jakarta.persistence.Entity;
+import jakarta.persistence.GeneratedValue;
+import jakarta.persistence.Id;
+import jakarta.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
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 23b2425b..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 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.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;
- }
-}
diff --git a/pdf-as-web-db/src/test/java/at/gv/egiz/pdfas/web/store/DBRequestStoreTest.java b/pdf-as-web-db/src/test/java/at/gv/egiz/pdfas/web/store/DBRequestStoreTest.java
new file mode 100644
index 00000000..a74283fe
--- /dev/null
+++ b/pdf-as-web-db/src/test/java/at/gv/egiz/pdfas/web/store/DBRequestStoreTest.java
@@ -0,0 +1,86 @@
+package at.gv.egiz.pdfas.web.store;
+
+import at.gv.egiz.pdfas.api.processing.PdfasSignRequest;
+import at.gv.egiz.pdfas.web.config.WebConfiguration;
+import at.gv.egiz.pdfas.web.stats.StatisticEvent;
+import io.micrometer.core.instrument.Statistic;
+import lombok.SneakyThrows;
+import lombok.val;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import java.io.ByteArrayInputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.Random;
+
+public class DBRequestStoreTest {
+ @BeforeAll
+ @SneakyThrows
+ public static void configureH2Hibernate() {
+ String config = """
+ pdfas.dir=.
+ request.db.timeout=600
+
+ hibernate.props.hibernate.dialect=org.hibernate.dialect.H2Dialect
+ hibernate.props.hibernate.connection.driver_class=org.h2.Driver
+ hibernate.props.hibernate.connection.url=jdbc:h2:mem:pdfaswebdbtest;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
+ hibernate.props.hibernate.connection.username=sa
+ hibernate.props.hibernate.connection.password=
+ hibernate.props.hibernate.connection.pool_size=1
+ hibernate.props.hibernate.connection.autocommit=false
+ hibernate.props.hibernate.hbm2ddl.auto=create-drop
+ hibernate.props.hibernate.show_sql=false
+ """;
+
+ WebConfiguration.configure(
+ new ByteArrayInputStream(config.getBytes(StandardCharsets.UTF_8)));
+ }
+
+ public static String azstring(int length) {
+ return
+ new Random().ints(97,123).limit(length)
+ .collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append)
+ .toString();
+ }
+
+ @Test
+ void signRequestRoundTrip() {
+ val store = new DBRequestStore();
+
+ val request = new PdfasSignRequest();
+ val requestId = azstring(32);
+ request.setRequestID(requestId);
+
+ val event = new StatisticEvent();
+ val filesize = (new Random().nextInt(42, 123456));
+ event.setSource(StatisticEvent.Source.SOAP);
+ event.setOperation(StatisticEvent.Operation.SIGN);
+ event.setStatus(StatisticEvent.Status.OK);
+ event.setDevice("mobile");
+ event.setProfileId("SIGNATURBLOCK_DE_SMALL");
+ event.setFilesize(filesize);
+ event.setTimestampNow();
+
+ val id = store.createNewStoreEntry(request, event);
+ Assertions.assertNotNull(id);
+
+ val fetchedPair = store.fetchStoreEntry(id);
+ Assertions.assertNotNull(fetchedPair);
+
+ val fetchedSignRequest = fetchedPair.getFirst();
+ Assertions.assertNotNull(fetchedSignRequest);
+ Assertions.assertEquals(requestId, fetchedSignRequest.getRequestID());
+
+ val fetchedEvent = fetchedPair.getSecond();
+ Assertions.assertNotNull(fetchedEvent);
+ Assertions.assertEquals(StatisticEvent.Source.SOAP, fetchedEvent.getSource());
+ Assertions.assertEquals(StatisticEvent.Operation.SIGN, fetchedEvent.getOperation());
+ Assertions.assertEquals(StatisticEvent.Status.OK, fetchedEvent.getStatus());
+ Assertions.assertEquals("mobile", fetchedEvent.getDevice());
+ Assertions.assertEquals("SIGNATURBLOCK_DE_SMALL", fetchedEvent.getProfileId());
+ Assertions.assertEquals(filesize, fetchedEvent.getFilesize());
+
+ Assertions.assertNull(store.fetchStoreEntry(id));
+ }
+}