Skip to content

Commit

Permalink
Merge pull request #150 from digipost/print-if-not-registered
Browse files Browse the repository at this point in the history
Add support for "print-if-not-registered"
  • Loading branch information
draperunner authored Mar 13, 2023
2 parents 135c379 + da4b8ad commit a903e84
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 13 deletions.
23 changes: 17 additions & 6 deletions src/main/java/no/digipost/api/client/representations/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"primaryDocument",
"attachments",
"printIfUnread",
"printIfNotRegistered",
"batch"})
@XmlRootElement(name = "message")
public class Message implements MayHaveSender {
Expand Down Expand Up @@ -89,11 +90,13 @@ public static MessageBuilder newMessage(String messageId, Document primaryDocume
public final List<Document> attachments;
@XmlElement(name = "print-if-unread")
public final PrintIfUnread printIfUnread;
@XmlElement(name = "print-if-not-registered")
public final PrintIfNotRegistered printIfNotRegistered;
@XmlElement(name="batch")
public final Batch batch;

Message() {
this(null, null, null, null, null, null, null, null, null, null);
this(null, null, null, null, null, null, null, null, null, null, null);
}

public static class MessageBuilder {
Expand All @@ -106,6 +109,7 @@ public static class MessageBuilder {
private final List<Document> attachments = new ArrayList<>();
private String invoiceReference;
private PrintIfUnread printIfUnread;
private PrintIfNotRegistered printIfNotRegistered;
private Batch batch;

private MessageBuilder(String messageId, Document primaryDocument) {
Expand Down Expand Up @@ -181,6 +185,11 @@ public MessageBuilder printIfUnread(PrintIfUnread printIfUnread) {
return this;
}

public MessageBuilder printIfNotRegistered(PrintIfNotRegistered printIfNotRegistered) {
this.printIfNotRegistered = printIfNotRegistered;
return this;
}

public MessageBuilder attachments(Document ... attachments) {
return attachments(asList(attachments));
}
Expand All @@ -202,14 +211,14 @@ public Message build() {
if (senderId != null && senderOrganization != null) {
throw new IllegalStateException("You can't set both senderId *and* senderOrganization.");
}
return new Message(messageId, senderId, senderOrganization, recipient, primaryDocument, attachments, deliveryTime, invoiceReference, printIfUnread, batch);
return new Message(messageId, senderId, senderOrganization, recipient, primaryDocument, attachments, deliveryTime, invoiceReference, printIfUnread, printIfNotRegistered, batch);
}

}

private Message(String messageId, Long senderId, SenderOrganization senderOrganization, MessageRecipient recipient,
Document primaryDocument, Iterable<? extends Document> attachments, ZonedDateTime deliveryTime,
String invoiceReference, PrintIfUnread printIfUnread, Batch batch) {
String invoiceReference, PrintIfUnread printIfUnread, PrintIfNotRegistered printIfNotRegistered, Batch batch) {
this.messageId = messageId;
this.senderId = senderId;
this.senderOrganization = senderOrganization;
Expand All @@ -222,6 +231,7 @@ private Message(String messageId, Long senderId, SenderOrganization senderOrgani
this.attachments.add(attachment);
}
this.printIfUnread = printIfUnread;
this.printIfNotRegistered = printIfNotRegistered;
this.batch = batch;
}

Expand All @@ -234,7 +244,7 @@ public static Message copyMessageWithOnlyPrintDetails(Message messageToCopy){
return new Message(messageToCopy.messageId, messageToCopy.senderId, messageToCopy.senderOrganization,
null, null, null, null, messageToCopy.deliveryTime, messageToCopy.invoiceReference,
messageToCopy.primaryDocument.copyDocumentAndSetDigipostFileTypeToPdf(), tmpAttachments, messageToCopy.recipient.getPrintDetails(),
null, null, null, null, messageToCopy.batch);
null, null, null, null, null, messageToCopy.batch);
}

public static Message copyMessageWithOnlyDigipostDetails(Message messageToCopy){
Expand All @@ -243,15 +253,15 @@ public static Message copyMessageWithOnlyDigipostDetails(Message messageToCopy){
messageToCopy.recipient.personalIdentificationNumber, messageToCopy.recipient.organisationNumber,
messageToCopy.deliveryTime, messageToCopy.invoiceReference, messageToCopy.primaryDocument,
messageToCopy.attachments, null, messageToCopy.recipient.bankAccountNumber,
messageToCopy.printIfUnread, messageToCopy.recipient.peppolAddresses, messageToCopy.recipient.emailDetails,
messageToCopy.printIfUnread, messageToCopy.printIfNotRegistered, messageToCopy.recipient.peppolAddresses, messageToCopy.recipient.emailDetails,
messageToCopy.batch);
}

private Message(final String messageId, final Long senderId, final SenderOrganization senderOrganization,
final NameAndAddress nameAndAddress, final String digipostAddress, String personalIdentificationNumber,
final String organisationNumber, final ZonedDateTime deliveryTime, final String invoiceReference,
final Document primaryDocument, final List<Document> attachments, final PrintDetails printDetails, final String bankAccountNumber,
final PrintIfUnread printIfUnread, final PeppolAddresses peppolAddresses, final EmailDetails emailDetails,
final PrintIfUnread printIfUnread, final PrintIfNotRegistered printIfNotRegistered, final PeppolAddresses peppolAddresses, final EmailDetails emailDetails,
final Batch batch
){
this.messageId = messageId;
Expand All @@ -265,6 +275,7 @@ private Message(final String messageId, final Long senderId, final SenderOrganiz
this.primaryDocument = primaryDocument;
this.attachments = attachments;
this.printIfUnread = printIfUnread;
this.printIfNotRegistered = printIfNotRegistered;
this.batch = batch;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Copyright (C) Posten Norge AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package no.digipost.api.client.representations;

import java.time.ZonedDateTime;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import no.digipost.api.client.representations.accounts.EmailAddress;
import no.digipost.api.client.representations.accounts.NationalIdentityNumber;
import no.digipost.api.client.representations.accounts.PhoneNumber;
import no.digipost.api.client.representations.xml.DateTimeXmlAdapter;


@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "print-if-not-registered", propOrder = {
"printIfUnreadAfter",
"phoneNumber",
"emailAddress",
"printDetails"
})
public class PrintIfNotRegistered {

@XmlElement(name = "print-if-not-registered-after", type = String.class)
@XmlJavaTypeAdapter(DateTimeXmlAdapter.class)
@XmlSchemaType(name = "dateTime")
protected ZonedDateTime printIfUnreadAfter;
@XmlElement(name = "phone-number")
protected PhoneNumber phoneNumber;
@XmlElement(name = "email-address")
protected EmailAddress emailAddress;
@XmlElement(name = "print-details", required = true)
protected PrintDetails printDetails;

PrintIfNotRegistered() {}

public PrintIfNotRegistered(ZonedDateTime printIfUnreadAfter, PhoneNumber phoneNumber, EmailAddress emailAddress, PrintDetails printDetails) {
this.printIfUnreadAfter = printIfUnreadAfter;
this.phoneNumber = phoneNumber;
this.emailAddress = emailAddress;
this.printDetails = printDetails;
}
}
10 changes: 10 additions & 0 deletions src/main/resources/xsd/api_v8.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@
<xsd:element name="primary-document" type="document" minOccurs="1" maxOccurs="1" nillable="false"/>
<xsd:element name="attachment" type="document" minOccurs="0" maxOccurs="201" nillable="false"/>
<xsd:element name="print-if-unread" type="print-if-unread" minOccurs="0"/>
<xsd:element name="print-if-not-registered" type="print-if-not-registered" minOccurs="0"/>
<xsd:element name="batch" type="batch" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
Expand Down Expand Up @@ -1213,6 +1214,15 @@
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="print-if-not-registered">
<xsd:sequence>
<xsd:element name="print-if-not-registered-after" type="xsd:dateTime"/>
<xsd:element name="phone-number" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="email-address" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="print-details" type="print-details"/>
</xsd:sequence>
</xsd:complexType>

<xsd:element name="archives" type="archives" />

<xsd:complexType name="archives">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,22 @@ public void shouldBeDirectPrintWhenMessageContainsOnlyPrintDetails() {
@Test
public void assertThatClassesHaveNotBeenChangedWithoutChangingMessageCopyMethod() {
Field[] messageFields = Message.class.getDeclaredFields();
assertThat(messageFields.length, is(10));
assertThat(messageFields.length, is(11));

String[] allFieldsThatAreUsedForCopyInMessage = new String[]{"messageId", "senderId", "senderOrganization",
"recipient", "deliveryTime", "invoiceReference", "primaryDocument", "attachments", "printIfUnread", "batch"};
String[] allFieldsThatAreUsedForCopyInMessage = new String[]{
"messageId", "senderId", "senderOrganization", "recipient", "deliveryTime", "invoiceReference",
"primaryDocument", "attachments", "printIfUnread", "printIfNotRegistered", "batch"
};

for(int i = 0; i < messageFields.length; i++){
for(int n = 0; n < allFieldsThatAreUsedForCopyInMessage.length; n++){
if(messageFields[i].getName().equals(allFieldsThatAreUsedForCopyInMessage[n])){
for (Field messageField : messageFields) {
for (int n = 0; n < allFieldsThatAreUsedForCopyInMessage.length; n++) {
if (messageField.getName().equals(allFieldsThatAreUsedForCopyInMessage[n])) {
allFieldsThatAreUsedForCopyInMessage[n] = "";
}
}
}

for(String shouldBeEmpty : allFieldsThatAreUsedForCopyInMessage){
for (String shouldBeEmpty : allFieldsThatAreUsedForCopyInMessage){
assertThat(shouldBeEmpty, is(""));
}

Expand Down

0 comments on commit a903e84

Please sign in to comment.