Skip to content

Commit 56a23ab

Browse files
author
Christian Strandenæs
authored
Merge pull request #30 from digipost/fetch-messages-2
Fetch messages
2 parents 3310be2 + 8cd9e13 commit 56a23ab

File tree

7 files changed

+121
-5
lines changed

7 files changed

+121
-5
lines changed

docs/_v2_x/4_fetch_messages.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ if (agreementResult.isSuccess()) {
5252
final SenderId senderId = SenderId.of(1234L);
5353
final UserId userId = UserId.of("01017012345");
5454

55-
final List<Document> unpaidInvoice = client.getDocuments(senderId, AgreementType.FETCH_MESSAGES, userId,
56-
GetDocumentsQuery.empty());
55+
final List<Document> previouslyDeliveredDocs = client.getDocuments(senderId, AgreementType.FETCH_MESSAGES,
56+
userId, GetDocumentsQuery.empty());
5757

5858
final ZoneId OSLO_ZONE = ZoneId.of("Europe/Oslo");
59-
final List<Document> allOptions = client.getDocuments(senderId, AgreementType.FETCH_MESSAGES, userId,
59+
final List<Document> withinTimeWindow = client.getDocuments(senderId, AgreementType.FETCH_MESSAGES, userId,
6060
GetDocumentsQuery.builder()
6161
.deliveryTimeFrom(ZonedDateTime.of(2020, 1, 1, 0, 0, 0, 0, OSLO_ZONE))
6262
.deliveryTimeTo(ZonedDateTime.now(OSLO_ZONE))

src/main/java/no/digipost/api/useragreements/client/AgreementType.java

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public final class AgreementType {
1919

2020
public static final AgreementType INVOICE_BANK = new AgreementType("invoice-bank");
2121
public static final AgreementType BANK_ACCOUNT_NUMBER_FOR_RECEIPTS = new AgreementType("account-num-for-receipts");
22+
public static final AgreementType FETCH_MESSAGES = new AgreementType("fetch-messages");
2223

2324
public static final String QUERY_PARAM_NAME = "agreement-type";
2425

src/main/java/no/digipost/api/useragreements/client/ApiService.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,11 @@ public StreamingRateLimitedResponse<UserId> getAgreementOwners(final SenderId se
181181
}
182182

183183
private static String userAgreementsPath(final SenderId senderId) {
184-
return senderId.serialize() + "/" + USER_AGREEMENTS_PATH;
184+
return "/" + senderId.serialize() + "/" + USER_AGREEMENTS_PATH;
185185
}
186186

187187
private static String userDocumentsPath(final SenderId senderId) {
188-
return senderId.serialize() + "/" + USER_DOCUMENTS_PATH;
188+
return "/" + senderId.serialize() + "/" + USER_DOCUMENTS_PATH;
189189
}
190190

191191
private <T> T executeHttpRequest(final HttpRequestBase request, final ResponseHandler<T> handler) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Copyright (C) Posten Norge AS
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package no.digipost.api.useragreements.client;
17+
18+
import java.util.Arrays;
19+
20+
public enum AuthenticationLevel {
21+
IDPORTEN_4("Id-Porten Two-Factor"),
22+
IDPORTEN_3("Id-Porten MinId", IDPORTEN_4),
23+
TWO_FACTOR("Two-Factor", IDPORTEN_4),
24+
PASSWORD("Password", TWO_FACTOR, IDPORTEN_3, IDPORTEN_4);
25+
26+
final String description;
27+
final AuthenticationLevel[] acceptable;
28+
29+
AuthenticationLevel(String description, AuthenticationLevel... acceptable) {
30+
this.description = description;
31+
this.acceptable = acceptable;
32+
}
33+
34+
boolean isAccessibleAtLevel(AuthenticationLevel other) {
35+
return Arrays.asList(this, acceptable).contains(other);
36+
}
37+
}

src/main/java/no/digipost/api/useragreements/client/Document.java

+34
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import javax.xml.bind.annotation.XmlAccessorType;
2020
import javax.xml.bind.annotation.XmlElement;
2121
import javax.xml.bind.annotation.XmlRootElement;
22+
import java.net.URI;
23+
import java.time.ZonedDateTime;
2224

2325
@XmlAccessorType(XmlAccessType.FIELD)
2426
@XmlRootElement(name = "user-document")
@@ -30,6 +32,16 @@ public class Document {
3032
private String senderName;
3133
@XmlElement
3234
private Invoice invoice;
35+
@XmlElement
36+
private String subject;
37+
@XmlElement(name = "delivery-time")
38+
private ZonedDateTime deliveryTime;
39+
@XmlElement(name = "read")
40+
private Boolean read;
41+
@XmlElement(name = "authentication-level")
42+
private String authenticationLevel;
43+
@XmlElement(name = "digipost-uri")
44+
private String digipostUri;
3345

3446
private Document() {}
3547

@@ -50,12 +62,34 @@ public long getId() {
5062
return id;
5163
}
5264

65+
public String getSubject() {
66+
return subject;
67+
}
68+
69+
public ZonedDateTime getDeliveryTime() {
70+
return deliveryTime;
71+
}
72+
73+
public boolean isRead() {
74+
return read != null && read;
75+
}
76+
77+
public AuthenticationLevel getAuthenticationLevel() {
78+
return AuthenticationLevel.valueOf(authenticationLevel);
79+
}
80+
81+
public URI getDigipostUri() {
82+
return URI.create(digipostUri);
83+
}
84+
5385
@Override
5486
public String toString() {
5587
final StringBuilder sb = new StringBuilder("Document{");
5688
sb.append("id=").append(id);
5789
sb.append(", senderName='").append(senderName).append('\'');
5890
sb.append(", invoice=").append(invoice);
91+
sb.append(", authenticationLevel=").append(authenticationLevel);
92+
sb.append(", deliveryTime=").append(deliveryTime);
5993
sb.append('}');
6094
return sb.toString();
6195
}

src/main/java/no/digipost/api/useragreements/client/package-info.java

+3
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,22 @@
1717
@XmlJavaTypeAdapters({
1818
@XmlJavaTypeAdapter(type = Instant.class, value = InstantXmlAdapter.class),
1919
@XmlJavaTypeAdapter(type = LocalDate.class, value = DateXmlAdapter.class),
20+
@XmlJavaTypeAdapter(type = ZonedDateTime.class, value = ZonedDateTImeXmlAdapter.class),
2021
@XmlJavaTypeAdapter(type = UserId.class, value = UserIdXmlAdapter.class)
2122
})
2223
package no.digipost.api.useragreements.client;
2324

2425
import no.digipost.api.useragreements.client.xml.DateXmlAdapter;
2526
import no.digipost.api.useragreements.client.xml.InstantXmlAdapter;
2627
import no.digipost.api.useragreements.client.xml.UserIdXmlAdapter;
28+
import no.digipost.api.useragreements.client.xml.ZonedDateTImeXmlAdapter;
2729

2830
import javax.xml.bind.annotation.XmlSchema;
2931
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
3032
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters;
3133

3234
import java.time.Instant;
3335
import java.time.LocalDate;
36+
import java.time.ZonedDateTime;
3437

3538
import static javax.xml.bind.annotation.XmlNsForm.QUALIFIED;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright (C) Posten Norge AS
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package no.digipost.api.useragreements.client.xml;
17+
18+
import javax.xml.bind.annotation.adapters.XmlAdapter;
19+
import java.time.ZonedDateTime;
20+
21+
import static java.time.format.DateTimeFormatter.ISO_ZONED_DATE_TIME;
22+
23+
public class ZonedDateTImeXmlAdapter extends XmlAdapter<String, ZonedDateTime> {
24+
25+
@Override
26+
public ZonedDateTime unmarshal(String value) {
27+
if (value == null) {
28+
return null;
29+
}
30+
return ZonedDateTime.from(ISO_ZONED_DATE_TIME.parse(value));
31+
32+
}
33+
34+
@Override
35+
public String marshal(ZonedDateTime dateTime) {
36+
if (dateTime == null) {
37+
return null;
38+
}
39+
return ISO_ZONED_DATE_TIME.format(dateTime);
40+
}
41+
}

0 commit comments

Comments
 (0)