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 | |
| 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
20 files changed, 186 insertions, 269 deletions
diff --git a/pdf-as-cli/build.gradle b/pdf-as-cli/build.gradle index 7f8d91fd..995a8aca 100644 --- a/pdf-as-cli/build.gradle +++ b/pdf-as-cli/build.gradle @@ -11,7 +11,7 @@ repositories { mavenCentral() } -task releases(type: Copy) { +tasks.register('releases', Copy) { from distZip.outputs from distTar.outputs into rootDir.toString() + "/releases/" + version diff --git a/pdf-as-common/build.gradle b/pdf-as-common/build.gradle index 8ff542b2..d855a0c0 100644 --- a/pdf-as-common/build.gradle +++ b/pdf-as-common/build.gradle @@ -11,9 +11,9 @@ repositories { mavenCentral() } -task releases(type: Copy) { - from jar.outputs - into rootDir.toString() + "/releases/" + version +tasks.register('releases', Copy) { + from jar.outputs + into rootDir.toString() + "/releases/" + version } releases.dependsOn jar diff --git a/pdf-as-lib/build.gradle b/pdf-as-lib/build.gradle index 0688b2ef..ae11a8f5 100644 --- a/pdf-as-lib/build.gradle +++ b/pdf-as-lib/build.gradle @@ -97,7 +97,7 @@ dependencies { testImplementation group: 'org.zeroturnaround', name: 'zt-zip', version: ztZipVersion } -task wsdl2Java() { +tasks.register('wsdl2Java') { if (!wsdlDir.listFiles()) { // do nothing } else { @@ -111,27 +111,31 @@ task wsdl2Java() { classpath configurations.ws main = 'org.apache.cxf.tools.wsdlto.WSDLToJava' args = argsin - systemProperties = ['exitOnFinish':'TRUE'] + systemProperties = ['exitOnFinish': 'TRUE'] } } } } } -task releaseConfig(type: Copy) { +tasks.register('releaseConfig', Copy) { dependsOn createConf from 'src/main/resources/config/config.zip' into rootDir.toString() + "/releases/" + version + "/cfg" rename 'config.zip', 'defaultConfig.zip' } -task releases(type: Copy) { +tasks.register('releases', Copy) { from jar.outputs from distZip.outputs from distTar.outputs into rootDir.toString() + "/releases/" + version } +tasks.named('clean', Delete) { + delete "${rootDir}/releases" +} + releases.dependsOn jar releases.dependsOn sourcesJar releases.dependsOn distZip @@ -139,7 +143,7 @@ releases.dependsOn distTar releases.dependsOn releaseConfig -task apidocs(type: Javadoc) { +tasks.register('apidocs', Javadoc) { classpath = configurations.compileClasspath source = sourceSets.main.allJava destinationDir = new File(rootDir.toString() + "/releases/" + version + "/docs/api") @@ -156,7 +160,7 @@ task apidocs(type: Javadoc) { include('at/gv/egiz/pdfas/lib/api/**') } -task fulldocs(type: Javadoc) { +tasks.register('fulldocs', Javadoc) { classpath = configurations.compileClasspath source = sourceSets.main.allJava destinationDir = new File(rootDir.toString() + "/releases/" + version + "/docs/full") diff --git a/pdf-as-moa/build.gradle b/pdf-as-moa/build.gradle index 8a5d211d..924f0a50 100644 --- a/pdf-as-moa/build.gradle +++ b/pdf-as-moa/build.gradle @@ -93,7 +93,7 @@ task wsdl2Java() { } } -task releases(type: Copy) { +tasks.register('releases', Copy) { from jar.outputs into rootDir.toString() + "/releases/" + version } diff --git a/pdf-as-pdfbox-2/build.gradle b/pdf-as-pdfbox-2/build.gradle index 43dba994..f0bc9203 100644 --- a/pdf-as-pdfbox-2/build.gradle +++ b/pdf-as-pdfbox-2/build.gradle @@ -20,10 +20,10 @@ repositories { mavenCentral() } -task releases(type: Copy) { +tasks.register('releases', Copy) { from jar.outputs into rootDir.toString() + "/releases/" + version - + } releases.dependsOn jar diff --git a/pdf-as-web-db/build.gradle b/pdf-as-web-db/build.gradle index d1633c7a..c3e23701 100644 --- a/pdf-as-web-db/build.gradle +++ b/pdf-as-web-db/build.gradle @@ -22,9 +22,11 @@ dependencies { 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 + + testRuntimeOnly 'com.h2database:h2:2.4.240' } -task releases(type: Copy) { +tasks.register('releases', Copy) { from jar.outputs from distZip.outputs from distTar.outputs 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; - } -} 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)); + } +} diff --git a/pdf-as-web-statistic-api/build.gradle b/pdf-as-web-statistic-api/build.gradle index 75a38b79..464b15c1 100644 --- a/pdf-as-web-statistic-api/build.gradle +++ b/pdf-as-web-statistic-api/build.gradle @@ -25,9 +25,10 @@ sourceSets.test.runtimeClasspath += configurations.providedCompile dependencies { implementation group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion implementation group: 'org.apache.commons', name: 'commons-lang3', version: commonsLang3Version + compileOnly "jakarta.persistence:jakarta.persistence-api:3.2.0" } -task releases(type: Copy) { +tasks.register('releases', Copy) { from jar.outputs from distZip.outputs from distTar.outputs diff --git a/pdf-as-web-statistic-api/src/main/java/at/gv/egiz/pdfas/web/stats/StatisticEvent.java b/pdf-as-web-statistic-api/src/main/java/at/gv/egiz/pdfas/web/stats/StatisticEvent.java index a043be3f..49de183f 100644 --- a/pdf-as-web-statistic-api/src/main/java/at/gv/egiz/pdfas/web/stats/StatisticEvent.java +++ b/pdf-as-web-statistic-api/src/main/java/at/gv/egiz/pdfas/web/stats/StatisticEvent.java @@ -1,6 +1,11 @@ package at.gv.egiz.pdfas.web.stats; +import jakarta.persistence.Column; +import lombok.Getter; +import lombok.Setter; + import java.util.Date; +import jakarta.persistence.Transient; /** @@ -25,183 +30,85 @@ public class StatisticEvent { SIGN("sign"), SIGNBULK("signBulk"), VERIFY("verify"); + + @Getter + private final String name; - private String name; - - private Operation(String name) { + Operation(String name) { this.name = name; } - - public String getName() { - return this.name; - } } public enum Source { WEB("web"), SOAP("soap"), JSON("json"); + + @Getter + private final String name; - private String name; - - private Source(String name) { + Source(String name) { this.name = name; } - - public String getName() { - return this.name; - } } public enum Status { OK("ok"), ERROR("error"); + + @Getter + private final String name; - private String name; - - private Status(String name) { + Status(String name) { this.name = name; } - - public String getName() { - return this.name; - } } - + + @Getter @Setter private long timestamp; + @Getter @Setter private Operation operation; + @Getter @Setter private String device; + @Getter @Setter private String profileId; + @Getter @Setter private long filesize; + @Getter @Setter private String userAgent; + @Getter @Setter private Status status; + @Getter @Setter private Throwable exception; + @Getter @Setter private long errorCode; + @Getter(onMethod_ = @Column(name = "startTime")) @Setter private long start; + @Getter(onMethod_ = @Column(name = "endTime")) @Setter private long end; + @Getter @Setter private Source source; private boolean logged = false; - public StatisticEvent() { - - } - - public long getStart() { - return start; - } - - public void setStart(long start) { - this.start = start; - } + public StatisticEvent() {} public void setStartNow() { this.start = (new Date()).getTime(); } - - public long getEnd() { - return end; - } - - public void setEnd(long end) { - this.end = end; - } - public void setEndNow() { this.end = (new Date()).getTime(); } - - public Source getSource() { - return source; - } - - public void setSource(Source source) { - this.source = source; - } - - public long getTimestamp() { - return timestamp; - } - - public void setTimestamp(long timestamp) { - this.timestamp = timestamp; - } - public void setTimestampNow() { this.timestamp = (new Date()).getTime(); } - - public Operation getOperation() { - return operation; - } - - public void setOperation(Operation operation) { - this.operation = operation; - } - - public String getDevice() { - return device; - } - - public void setDevice(String device) { - this.device = device; - } - - public String getProfileId() { - return profileId; - } - - public void setProfileId(String profileId) { - this.profileId = profileId; - } - - public long getFilesize() { - return filesize; - } - - public void setFilesize(long filesize) { - this.filesize = filesize; - } - - public String getUserAgent() { - return userAgent; - } - - public void setUserAgent(String userAgent) { - this.userAgent = userAgent; - } - - public Status getStatus() { - return status; - } - - public void setStatus(Status status) { - this.status = status; - } - - public Throwable getException() { - return exception; - } - - public void setException(Throwable exception) { - this.exception = exception; - } - - public long getErrorCode() { - return errorCode; - } - - public void setErrorCode(long errorCode) { - this.errorCode = errorCode; - } - + @Transient public long getDuration() { return this.end - this.start; } - + @Transient public boolean isLogged() { return logged; } - public void setLogged(boolean logged) { this.logged = logged; } diff --git a/pdf-as-web-status/build.gradle b/pdf-as-web-status/build.gradle index e6977da8..f198cb6a 100644 --- a/pdf-as-web-status/build.gradle +++ b/pdf-as-web-status/build.gradle @@ -28,7 +28,7 @@ dependencies { compileOnly group: 'jakarta.servlet', name: 'jakarta.servlet-api', version: jakartaServletVersion } -task releases(type: Copy) { +tasks.register('releases', Copy) { from jar.outputs from distZip.outputs from distTar.outputs diff --git a/pdf-as-web/build.gradle b/pdf-as-web/build.gradle index 9a18ad8f..8b40583d 100644 --- a/pdf-as-web/build.gradle +++ b/pdf-as-web/build.gradle @@ -172,3 +172,7 @@ tasks.register('releases', Copy) { from(tasks.named('buildTomcatTar').flatMap { it.archiveFile }) into(releasesDirectory) } + +tasks.named('clean', Delete) { + delete(releasesDirectory) +} diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/UIEntryPointServlet.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/UIEntryPointServlet.java index 9c20e1a1..51cc5573 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/UIEntryPointServlet.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/UIEntryPointServlet.java @@ -42,6 +42,7 @@ import at.gv.egiz.pdfas.web.helper.PdfAsHelper; import at.gv.egiz.pdfas.web.stats.StatisticEvent; import at.gv.egiz.pdfas.web.store.RequestStore; import lombok.extern.slf4j.Slf4j; +import lombok.val; @Slf4j public class UIEntryPointServlet extends HttpServlet { @@ -76,16 +77,16 @@ public class UIEntryPointServlet extends HttpServlet { throw new PdfAsStoreException("Wrong Parameters"); } - PdfasSignRequest pdfAsRequest = RequestStore.getInstance() + val storeEntry = RequestStore.getInstance() .fetchStoreEntry(storeId); - if (pdfAsRequest == null) { + if (storeEntry == null) { throw new PdfAsStoreException("Invalid " + REQUEST_ID_PARAM + " value"); } - StatisticEvent statisticEvent = RequestStore.getInstance() - .fetchStatisticEntry(storeId); + val pdfAsRequest = storeEntry.getFirst(); + val statisticEvent = storeEntry.getSecond(); PdfAsHelper.setStatisticEvent(req, resp, statisticEvent); diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/store/IRequestStore.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/store/IRequestStore.java index 643d3ea0..fdcded6c 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/store/IRequestStore.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/store/IRequestStore.java @@ -26,11 +26,11 @@ package at.gv.egiz.pdfas.web.store; import at.gv.egiz.pdfas.api.processing.PdfasSignRequest; import at.gv.egiz.pdfas.api.processing.PdfasSignResponse; import at.gv.egiz.pdfas.web.stats.StatisticEvent; +import kotlin.Pair; public interface IRequestStore { - public StatisticEvent fetchStatisticEntry(String id); public String createNewStoreEntry(PdfasSignRequest request, StatisticEvent event); - public PdfasSignRequest fetchStoreEntry(String id); + public Pair<PdfasSignRequest, StatisticEvent> fetchStoreEntry(String id); public String createNewResponseEntry(PdfasSignResponse response); public PdfasSignResponse fetchStoreResponse(String id); diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/store/InMemoryRequestStore.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/store/InMemoryRequestStore.java index 6ab58ce0..378714e4 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/store/InMemoryRequestStore.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/store/InMemoryRequestStore.java @@ -26,6 +26,8 @@ package at.gv.egiz.pdfas.web.store; import java.util.Map; import java.util.UUID; +import kotlin.Pair; +import lombok.val; import org.apache.commons.collections4.map.PassiveExpiringMap; import at.gv.egiz.pdfas.api.processing.PdfasSignRequest; @@ -37,40 +39,27 @@ public class InMemoryRequestStore implements IRequestStore { // expires after 10 minutes private static final long DEFAULT_EXPIRATION = 10 * 60 * 1000; - private Map<String, PdfasSignRequest> reqStore = new PassiveExpiringMap<>(DEFAULT_EXPIRATION); + private Map<String, Pair<PdfasSignRequest, StatisticEvent>> reqStore = new PassiveExpiringMap<>(DEFAULT_EXPIRATION); private Map<String, PdfasSignResponse> respStore = new PassiveExpiringMap<>(DEFAULT_EXPIRATION); - private Map<String, StatisticEvent> statEvents = new PassiveExpiringMap<>(DEFAULT_EXPIRATION); public InMemoryRequestStore() { } - + + @Override public String createNewStoreEntry(PdfasSignRequest request, StatisticEvent event) { UUID id = UUID.randomUUID(); String sid = id.toString(); - this.reqStore.put(sid, request); - this.statEvents.put(sid, event); + this.reqStore.put(sid, new Pair<>(request, event)); return sid; - } - public StatisticEvent fetchStatisticEntry(String id) { - if(statEvents.containsKey(id)) { - StatisticEvent event = statEvents.get(id); - statEvents.remove(id); - return event; - - } - - return null; - } - - public PdfasSignRequest fetchStoreEntry(String id) { + @Override + public Pair<PdfasSignRequest, StatisticEvent> fetchStoreEntry(String id) { if(reqStore.containsKey(id)) { - PdfasSignRequest request = reqStore.get(id); + val storeEntry = reqStore.get(id); reqStore.remove(id); - return request; - + return storeEntry; } return null; diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/store/RequestStore.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/store/RequestStore.java index 5ed2bef0..e39e9399 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/store/RequestStore.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/store/RequestStore.java @@ -49,7 +49,7 @@ public class RequestStore { throw new PdfAsStoreException("Failed to instantiate Request Store from " + storeClass); } } catch (Throwable e) { - e.printStackTrace(); + logger.error("Failed to instantiate Request Store", e); throw new PdfAsStoreException("Failed to instantiate Request Store", e); } } diff --git a/signature-standards/sigs-pades/build.gradle b/signature-standards/sigs-pades/build.gradle index 9531330a..af1c27e8 100644 --- a/signature-standards/sigs-pades/build.gradle +++ b/signature-standards/sigs-pades/build.gradle @@ -14,7 +14,7 @@ repositories { mavenCentral() } -task releases(type: Copy) { +tasks.register('releases', Copy) { from jar.outputs into rootDir.toString() + "/releases/" + version } diff --git a/signature-standards/sigs-pkcs7detached/build.gradle b/signature-standards/sigs-pkcs7detached/build.gradle index ac29931d..168027e2 100644 --- a/signature-standards/sigs-pkcs7detached/build.gradle +++ b/signature-standards/sigs-pkcs7detached/build.gradle @@ -14,7 +14,7 @@ repositories { mavenCentral() } -task releases(type: Copy) { +tasks.register('releases', Copy) { from jar.outputs into rootDir.toString() + "/releases/" + version } |
