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
10 changes: 2 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<version>LOCAL-SNAPSHOT</version>
<name>Digipost API Client</name>
<description>Java library for interacting with the Digipost REST API</description>

<organization>
<name>Posten Bring AS</name>
<url>https://www.posten.no/</url>
Expand All @@ -29,7 +29,7 @@
</comments>
</license>
</licenses>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
Expand Down Expand Up @@ -69,12 +69,6 @@
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.5.1</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.core5</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import no.digipost.api.client.errorhandling.ErrorCode;
import no.digipost.api.client.representations.ErrorMessage;
import no.digipost.api.client.representations.ErrorType;
import org.apache.commons.lang3.StringUtils;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.HttpEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void process(HttpResponse response, EntityDetails entityDetails, HttpCont
X_Content_SHA256, response.getCode())));
byte[] entityBytes = EntityUtils.toByteArray(entity);
validerBytesMotHashHeader(hashHeaderValue, entityBytes);
classicHttpResponse.setEntity(new ByteArrayEntity(entityBytes, ContentType.create(entityDetails.getContentType())));
classicHttpResponse.setEntity(new ByteArrayEntity(entityBytes, ContentType.parse(entityDetails.getContentType())));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import static no.digipost.api.client.representations.Channel.PRINT;
import static org.apache.commons.lang3.ArrayUtils.INDEX_NOT_FOUND;
import static org.apache.commons.lang3.ArrayUtils.indexOf;
import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
import static org.apache.commons.lang3.ObjectUtils.getIfNull;
import static org.apache.commons.lang3.StringUtils.join;

@XmlAccessorType(XmlAccessType.FIELD)
Expand All @@ -55,7 +55,7 @@
"invoiceReference",
"primaryDocument",
"attachments",
"printIfUnread",
"printIfUnread",
"requestForRegistration",
"batch"})
@XmlRootElement(name = "message")
Expand Down Expand Up @@ -195,15 +195,15 @@ public MessageBuilder attachments(Document ... attachments) {
}

public MessageBuilder attachments(Iterable<? extends Document> attachments) {
defaultIfNull(attachments, Collections.<Document>emptyList()).forEach(this.attachments::add);
getIfNull(attachments, Collections.<Document>emptyList()).forEach(this.attachments::add);
return this;
}

public MessageBuilder batch(UUID batchUUID) {
this.batch = new Batch(batchUUID.toString());
return this;
}

public Message build() {
if (recipient == null) {
throw new IllegalStateException("You must specify a recipient.");
Expand All @@ -227,7 +227,7 @@ private Message(String messageId, Long senderId, SenderOrganization senderOrgani
this.invoiceReference = invoiceReference;
this.deliveryTime = deliveryTime;
this.attachments = new ArrayList<>();
for (Document attachment : defaultIfNull(attachments, Collections.<Document>emptyList())) {
for (Document attachment : getIfNull(attachments, Collections.<Document>emptyList())) {
this.attachments.add(attachment);
}
this.printIfUnread = printIfUnread;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

import static java.util.Arrays.asList;
import static no.digipost.api.client.representations.Relation.NEXT_DOCUMENTS;
import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
import static org.apache.commons.lang3.ObjectUtils.getIfNull;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "archive", propOrder = {
Expand Down Expand Up @@ -134,7 +134,7 @@ public Optional<URI> getNextDocumentsWithAttributes(Map<String, String> attribut

public Optional<URI> getNextDocumentsWithAttributesByDate(Map<String, String> attributes, OffsetDateTime from, OffsetDateTime to) {
final String attributesCommaSeparated = attributes.entrySet().stream().flatMap(en -> Stream.of(en.getKey(), en.getValue())).collect(Collectors.joining(","));

return Optional.ofNullable(getLinkByRelationName(NEXT_DOCUMENTS)).map(Link::getUri)
.map(uri -> {
try {
Expand All @@ -150,7 +150,7 @@ public Optional<URI> getNextDocumentsWithAttributesByDate(Map<String, String> at
}

public Optional<URI> getNextDocumentsByDate(OffsetDateTime from, OffsetDateTime to) {

return Optional.ofNullable(getLinkByRelationName(NEXT_DOCUMENTS)).map(Link::getUri)
.map(uri -> {
try {
Expand Down Expand Up @@ -202,7 +202,7 @@ public ArchiveBuilder documents(ArchiveDocument... documents) {
}

public ArchiveBuilder documents(Iterable<ArchiveDocument> documents) {
defaultIfNull(documents, Collections.<ArchiveDocument>emptyList()).forEach(this.documents::add);
getIfNull(documents, Collections.<ArchiveDocument>emptyList()).forEach(this.documents::add);
return this;
}

Expand All @@ -218,5 +218,5 @@ public Archive build() {
private static String base64(String param){
return Base64.getEncoder().encodeToString(param.getBytes(StandardCharsets.UTF_8));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,13 @@ void setMapAndMessageToPrintClonesMessage(String description, Message message) {

private static Stream<Arguments> provideMessages() {
Document primaryDoc = new Document(
UUID.randomUUID(), RandomStringUtils.randomAlphanumeric(1, 128), FileType.PDF
UUID.randomUUID(), RandomStringUtils.insecure().nextAlphanumeric(1, 128), FileType.PDF
);
PrintRecipient printRecipient = new PrintRecipient();
PrintDetails printDetails = new PrintDetails(printRecipient, printRecipient);
MessageRecipient directPrintRecipient = new MessageRecipient(printDetails);
MessageRecipient fallbackPrintRecipient = new MessageRecipient(
new PersonalIdentificationNumber(RandomStringUtils.randomNumeric(11)), printDetails
new PersonalIdentificationNumber(RandomStringUtils.insecure().nextNumeric(11)), printDetails
);
return Stream.of(
Arguments.of("direct print message", Message.newMessage(UUID.randomUUID(), primaryDoc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void setHeader(String name, Object value) {
}

@Override
public void setHeaders(Header[] headers) {
public void setHeaders(Header ... headers) {
throw new UnsupportedOperationException("This is a mock");
}

Expand Down Expand Up @@ -245,6 +245,11 @@ public HttpEntity getEntity() {
return entity;
}

@Override
public int getCode() {
return status;
}

@Override
public void close() throws IOException {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public void isOpenedWhenTrueIsPassed() {
}

@Test
@SuppressWarnings("deprecation")
public void isOpenedWhenTrueBuiltWithDeprecatedConstructorsIsPassed() {
Document boolConstructorTrueDoc = new Document(null, null, null, null, null, null, null, null, new Boolean(true), null, "");
assertThat(boolConstructorTrueDoc.opened, is(true));
Expand Down