Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Set release version
run: echo ::set-env name=RELEASE_VERSION::$(echo ${GITHUB_REF:11}"-SNAPSHOT")
run: echo "RELEASE_VERSION=${GITHUB_REF:11}-SNAPSHOT" >> $GITHUB_ENV
- name: Build and deploy to Sonatype snapshot
uses: digipost/action-maven-publish@1.1.0
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Check out Git repository
uses: actions/checkout@v1
- name: Set release version
run: echo ::set-env name=RELEASE_VERSION::$(echo ${GITHUB_REF:10})
run: echo "RELEASE_VERSION=${GITHUB_REF:10}" >> $GITHUB_ENV
- name: Release to Central Repository
uses: digipost/action-maven-publish@1.1.0
with:
Expand Down
24 changes: 12 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,29 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<signature.api.version>multiple-documents-SNAPSHOT</signature.api.version>
<slf4j.version>1.7.29</slf4j.version>
<slf4j.version>1.7.30</slf4j.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>5.2.1.RELEASE</version>
<version>5.3.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>2.29.1</version>
<version>2.33</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.6.0-M1</version>
<version>5.7.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -74,7 +74,7 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.10</version>
<version>4.5.13</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
Expand All @@ -85,7 +85,7 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.12</version>
<version>4.4.14</version>
</dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
Expand Down Expand Up @@ -118,13 +118,13 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
<version>2.8.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.13</version>
<version>1.15</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
Expand All @@ -137,12 +137,12 @@
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-xml</artifactId>
<version>3.0.8.RELEASE</version>
<version>3.0.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
<version>3.11</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -182,7 +182,7 @@
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<version>3.1.10</version>
<version>3.5.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -206,7 +206,7 @@
<dependency>
<groupId>no.digipost</groupId>
<artifactId>digg</artifactId>
<version>0.22</version>
<version>0.25</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Object buildXmlManifest(DirectJob job, Sender sender) {
.withSigners(signers)
.withRequiredAuthentication(job.getRequiredAuthentication().map(AuthenticationLevel::getXmlEnumValue).orElse(null))
.withSender(new XMLSender().withOrganizationNumber(sender.getOrganizationNumber()))
.withDocuments(new XMLDirectDocument()
.withDocument(new XMLDirectDocument()
.withTitle(document.getTitle())
.withDescription(document.getMessage())
.withHref(XMLHref.of(document.getFileName()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ Object buildXmlManifest(PortalJob job, Sender sender) {
.withSigners(xmlSigners)
.withRequiredAuthentication(job.getRequiredAuthentication().map(AuthenticationLevel::getXmlEnumValue).orElse(null))
.withSender(new XMLSender().withOrganizationNumber(sender.getOrganizationNumber()))
.withTitle(job.getTitle())
.withNonsensitiveTitle(job.getNonsensitiveTitle().orElse(null))
.withDescription(job.getDescription().orElse(null))
.withDocuments(documents.stream().map(document ->
new XMLPortalDocument()
.withTitle(document.getTitle())
.withNonsensitiveTitle(document.getNonsensitiveTitle())
.withDescription(document.getMessage())
.withHref(XMLHref.of(document.getFileName()))
.withMime(document.getMimeType())
).collect(Collectors.toList())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
public abstract class Document implements ASiCEAttachable {

private String title;
private String message;
private String fileName;
private byte[] document;
private FileType fileType;

protected Document(final String title, final String message, final String fileName, final FileType fileType, final byte[] document) {
protected Document(final String title, final String fileName, final FileType fileType, final byte[] document) {
this.title = title;
this.message = message;
this.fileName = fileName;
this.fileType = fileType;
this.document = document;
Expand All @@ -37,10 +35,6 @@ public String getTitle() {
return title;
}

public String getMessage() {
return message;
}

public enum FileType {
PDF("application/pdf"),
TXT("text/plain");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@
import static no.digipost.signature.client.core.Document.FileType.PDF;

public class DirectDocument extends Document {

private final String message;

private DirectDocument(String title, String message, String fileName, FileType fileType, byte[] document) {
super(title, message, fileName, fileType, document);
super(title, fileName, fileType, document);
this.message = message;
}

public static Builder builder(final String title, final String fileName, final byte[] document) {
return new Builder(title, fileName, document);
}

public String getMessage() {
return message;
}

public static class Builder {

private String title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,8 @@
import static no.digipost.signature.client.core.Document.FileType.PDF;

public class PortalDocument extends Document {
private final String nonsensitiveTitle;

private PortalDocument(String title, String nonsensitiveTitle, String message, String fileName, FileType fileType, byte[] document) {
super(title, message, fileName, fileType, document);
this.nonsensitiveTitle = nonsensitiveTitle;
}

public String getNonsensitiveTitle() {
return nonsensitiveTitle;
private PortalDocument(String title, String fileName, FileType fileType, byte[] document) {
super(title, fileName, fileType, document);
}

public static Builder builder(final String title, final String fileName, final byte[] document) {
Expand All @@ -23,10 +16,8 @@ public static Builder builder(final String title, final String fileName, final b
public static class Builder {

private String title;
private String nonsensitiveTitle;
private String fileName;
private byte[] document;
private String message;
private FileType fileType = PDF;

public Builder(final String title, final String fileName, final byte[] document) {
Expand All @@ -35,23 +26,13 @@ public Builder(final String title, final String fileName, final byte[] document)
this.document = document;
}

public Builder message(String message) {
this.message = message;
return this;
}

public Builder nonsensitiveTitle(String nonsensitiveTitle) {
this.nonsensitiveTitle = nonsensitiveTitle;
return this;
}

public Builder fileType(final FileType fileType) {
this.fileType = fileType;
return this;
}

public PortalDocument build() {
return new PortalDocument(title, nonsensitiveTitle, message, fileName, fileType, document);
return new PortalDocument(title, fileName, fileType, document);
}
}
}
44 changes: 35 additions & 9 deletions src/main/java/no/digipost/signature/client/portal/PortalJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ public class PortalJob implements SignatureJob {

private final List<PortalSigner> signers;
private final List<PortalDocument> documents;
private String title;
private Optional<String> nonsensitiveTitle = Optional.empty();
private Optional<String> description = Optional.empty();
private String reference;
private Optional<Instant> activationTime = Optional.empty();
private Long availableSeconds;
private Optional<Sender> sender = Optional.empty();
private Optional<AuthenticationLevel> requiredAuthentication = Optional.empty();
private Optional<IdentifierInSignedDocuments> identifierInSignedDocuments = Optional.empty();

private PortalJob(List<PortalSigner> signers, List<PortalDocument> documents) {
private PortalJob(String title, List<PortalSigner> signers, List<PortalDocument> documents) {
this.title = title;
this.signers = unmodifiableList(new ArrayList<>(signers));
this.documents = unmodifiableList(new ArrayList<>(documents));
}
Expand Down Expand Up @@ -67,25 +71,37 @@ public Long getAvailableSeconds() {
}


public static Builder builder(PortalDocument document, PortalSigner... signers) {
return builder(Collections.singletonList(document), Arrays.asList(signers));
public static Builder builder(String title, PortalDocument document, PortalSigner... signers) {
return builder(title, Collections.singletonList(document), Arrays.asList(signers));
}

public static Builder builder(PortalDocument document, List<PortalSigner> signers) {
return builder(Collections.singletonList(document), signers);
public static Builder builder(String title, PortalDocument document, List<PortalSigner> signers) {
return builder(title, Collections.singletonList(document), signers);
}

public static Builder builder(List<PortalDocument> documents, List<PortalSigner> signers) {
return new Builder(signers, documents);
public static Builder builder(String title, List<PortalDocument> documents, List<PortalSigner> signers) {
return new Builder(title, signers, documents);
}

public String getTitle() {
return title;
}

public Optional<String> getNonsensitiveTitle() {
return nonsensitiveTitle;
}

public Optional<String> getDescription() {
return description;
}

public static class Builder implements JobCustomizations<Builder> {

private final PortalJob target;
private boolean built = false;

private Builder(List<PortalSigner> signers, List<PortalDocument> documents) {
target = new PortalJob(signers, documents);
private Builder(String title, List<PortalSigner> signers, List<PortalDocument> documents) {
target = new PortalJob(title, signers, documents);
}

@Override
Expand Down Expand Up @@ -127,6 +143,16 @@ public Builder availableFor(long duration, TimeUnit unit) {
return this;
}

public Builder withNonsensitiveTitle(String nonsensitiveTitle) {
target.nonsensitiveTitle = Optional.of(nonsensitiveTitle);
return this;
}

public Builder withDescription(String description) {
target.description = Optional.of(description);
return this;
}

public PortalJob build() {
if (built) throw new IllegalStateException("Can't build twice");
built = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public static void initTempFolder() throws URISyntaxException, IOException {
.build();

private static final PortalDocument PORTAL_DOCUMENT = PortalDocument.builder("Title", "file.txt", "hello".getBytes())
.message("Message")
.fileType(Document.FileType.TXT)
.build();

Expand All @@ -78,8 +77,9 @@ public void create_direct_asice_and_write_to_disk() throws IOException {

@Test
public void create_portal_asice_and_write_to_disk() throws IOException {
PortalJob job = PortalJob.builder(PORTAL_DOCUMENT, PortalSigner.identifiedByPersonalIdentificationNumber("12345678910", NotificationsUsingLookup.EMAIL_ONLY).build())
PortalJob job = PortalJob.builder("Job title", PORTAL_DOCUMENT, PortalSigner.identifiedByPersonalIdentificationNumber("12345678910", NotificationsUsingLookup.EMAIL_ONLY).build())
.withReference("portal job")
.withDescription("Message")
.withActivationTime(clock.instant())
.availableFor(30, DAYS)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ void accept_valid_manifest() {
CreatePortalManifest createManifest = new CreatePortalManifest(clock);

PortalDocument document = PortalDocument.builder("Title", "file.txt", "hello".getBytes())
.message("Message")
.fileType(Document.FileType.TXT)
.build();

PortalJob job = PortalJob.builder(document, Collections.singletonList(PortalSigner.identifiedByPersonalIdentificationNumber("12345678910", NotificationsUsingLookup.EMAIL_ONLY).build()))
PortalJob job = PortalJob.builder("Job title", document, Collections.singletonList(PortalSigner.identifiedByPersonalIdentificationNumber("12345678910", NotificationsUsingLookup.EMAIL_ONLY).build()))
.withActivationTime(clock.instant())
.availableFor(30, DAYS)
.withDescription("Message")
.withIdentifierInSignedDocuments(IdentifierInSignedDocuments.PERSONAL_IDENTIFICATION_NUMBER_AND_NAME)
.build();
assertThat(createManifest, where(__ -> __.createManifest(job, new Sender("123456789")), instanceOf(Manifest.class)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ static void create_and_send_signature_job() {
PortalClient client = new PortalClient(clientConfiguration);

byte[] documentBytes = null; // Loaded document bytes
PortalDocument document = PortalDocument.builder("Subject", "document.pdf", documentBytes).build();
PortalDocument document = PortalDocument.builder("Document title", "document.pdf", documentBytes).build();

PortalJob portalJob = PortalJob.builder(
"Job title",
document,
PortalSigner.identifiedByPersonalIdentificationNumber("12345678910",
NotificationsUsingLookup.EMAIL_ONLY).build(),
Expand Down Expand Up @@ -95,9 +96,10 @@ static void specifying_queues() {
Sender sender = new Sender("000000000", PollingQueue.of("CustomPollingQueue"));

byte[] documentBytes = null; // Loaded document bytes
PortalDocument document = PortalDocument.builder("Subject", "document.pdf", documentBytes).build();
PortalDocument document = PortalDocument.builder("Document title", "document.pdf", documentBytes).build();

PortalJob portalJob = PortalJob.builder(
"Job title",
document,
PortalSigner.identifiedByPersonalIdentificationNumber("12345678910",
NotificationsUsingLookup.EMAIL_ONLY).build(),
Expand Down