Skip to content

Commit

Permalink
fiks implementasjonsbug i konvertering av gyldige xml-datetimes uten …
Browse files Browse the repository at this point in the history
…offset

+ ikke endre tidssone for innsendte data.
+ lag ZonedDateTimes som er XML datetime-identiske i unmarshall, dropp java-sone-greier i eksmepler for å få testene til å funke igjen
  • Loading branch information
Christian Strandenæs committed Mar 25, 2020
1 parent b8c762a commit 4b20f27
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private static ObjectMapper initMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
mapper.setTimeZone(TimeZone.getDefault());
mapper.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CAMEL_CASE);
return mapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import javax.xml.bind.DatatypeConverter;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import java.time.ZoneId;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAccessor;
import java.util.GregorianCalendar;

public class ZonedDateTimeXmlAdapter extends XmlAdapter<String, ZonedDateTime> {
Expand All @@ -21,7 +24,12 @@ public ZonedDateTime unmarshal(final String s) {
if (s == null) {
return null;
}
return ZonedDateTime.from(DateTimeFormatter.ISO_DATE_TIME.parse(s)).withZoneSameInstant(ZoneId.systemDefault());
final TemporalAccessor parsed = DateTimeFormatter.ISO_DATE_TIME.parse(s);
if (parsed.isSupported(ChronoField.OFFSET_SECONDS)) {
return ZonedDateTime.from(parsed);
} else {
return LocalDateTime.from(parsed).atZone(ZoneOffset.UTC);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public Appointment withDefaultsForMissingOptionalValues() {
}

public static Appointment EXAMPLE = new Appointment(
ZonedDateTime.of(2017, 6, 27, 10, 0, 0, 0, ZoneId.systemDefault())
, ZonedDateTime.of(2017, 6, 27, 11, 0, 0, 0, ZoneId.systemDefault())
ZonedDateTime.of(2017, 6, 27, 10, 0, 0, 0, ZoneId.of("+02:00"))
, ZonedDateTime.of(2017, 6, 27, 11, 0, 0, 0, ZoneId.of("+02:00"))
, "Oppmøte senest 15 minutter før timen"
, "Oslo City Røntgen"
, Address.EXAMPLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public Boligdetaljer(Residence residence, List<Hjemmelshaver> hjemmelshavere, In
Residence.EXAMPLE
, Collections.singletonList(new Hjemmelshaver("Gunnar Gunnersen", "[email protected]"))
, 59, 3, 4
, Collections.singletonList(new Omsetningshistorikk(ZonedDateTime.of(2017, 7, 27, 10, 0, 0, 0, ZoneId.systemDefault())
, Collections.singletonList(new Omsetningshistorikk(ZonedDateTime.of(2017, 7, 27, 10, 0, 0, 0, ZoneId.of("+02:00"))
, "Privat salg av sekundærbolig"
, "Bill Isalg"
, "Cooper Coopersen"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public ExternalLink(final URI url) {
String buttonText;

public static ExternalLink EXAMPLE = new ExternalLink(URI.create("https://www.oslo.kommune.no/barnehage/svar-pa-tilbud-om-plass/"),
ZonedDateTime.of(2017, 9, 30, 13, 37, 0, 0, ZoneId.systemDefault()),
ZonedDateTime.of(2017, 9, 30, 13, 37, 0, 0, ZoneId.of("+02:00")),
"Oslo Kommune ber deg akseptere eller avslå tilbudet om barnehageplass.", "Svar på barnehageplass");

public static ExternalLink EXAMPLE_NO_DEADLINE = new ExternalLink(URI.create("https://www.example.com"),
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/api/datatypes/types/Inkasso.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class Inkasso implements DataType {

public static Inkasso EXAMPLE = new Inkasso(
ExternalLink.EXAMPLE_NO_DEADLINE
, ZonedDateTime.of(2019, 12, 10, 0, 0, 0, 0, ZoneId.systemDefault())
, ZonedDateTime.of(2019, 12, 10, 0, 0, 0, 0, ZoneId.of("+01:00"))
, BigDecimal.valueOf(42), "01235424320", "1435025439583420243982723"
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class SignedDocument implements DataType {
public static SignedDocument EXAMPLE = new SignedDocument(
"Bedrift AS",
"Ansettelseskontrakt",
ZonedDateTime.of(2018, 7, 11, 10, 0, 0, 0, ZoneId.systemDefault())
ZonedDateTime.of(2018, 7, 11, 10, 0, 0, 0, ZoneId.of("+02:00"))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class TimeInterval {
ZonedDateTime endTime;

public static TimeInterval EXAMPLE = new TimeInterval(
ZonedDateTime.of(2019, 5, 23, 10, 0, 0, 0, ZoneId.systemDefault())
, ZonedDateTime.of(2019, 5, 23, 16, 0, 0, 0, ZoneId.systemDefault())
ZonedDateTime.of(2019, 5, 23, 10, 0, 0, 0, ZoneId.of("+02:00"))
, ZonedDateTime.of(2019, 5, 23, 16, 0, 0, 0, ZoneId.of("+02:00"))
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public PickupNotice withDefaultsForMissingOptionalValues() {
, "70300492517312675"
, Barcode.EXAMPLE.withBarcodeType("CODE_128")
, "Klimanøytral Servicepakke"
, ZonedDateTime.of(2018, 9, 10, 10, 0, 0, 0, ZoneId.systemDefault())
, ZonedDateTime.of(2018, 9, 24, 10, 0, 0, 0, ZoneId.systemDefault())
, ZonedDateTime.of(2018, 9, 10, 10, 0, 0, 0, ZoneId.of("+02:00"))
, ZonedDateTime.of(2018, 9, 24, 10, 0, 0, 0, ZoneId.of("+02:00"))
, Recipient.EXAMPLE
, Sender.EXAMPLE
, PickupPlace.EXAMPLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ public class PickupNoticeStatus implements DataType {

public static PickupNoticeStatus EXAMPLE = new PickupNoticeStatus(
Status.READY_FOR_PICKUP
, ZonedDateTime.of(2019, 1, 10, 10, 10, 0, 0, ZoneId.systemDefault())
, ZonedDateTime.of(2019, 1, 10, 10, 10, 0, 0, ZoneId.of("+01:00"))
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public class Proof implements DataType {
new Proof(
"Bekkestua Bibliotek",
"#e1e1e1",
ZonedDateTime.of(2019, 5, 23, 10, 0, 0, 0, ZoneId.systemDefault()),
ZonedDateTime.of(2019, 5, 23, 10, 0, 0, 0, ZoneId.of("+02:00")),
ValidPeriod.EXAMPLE,
ProofHolder.EXAMPLE,
"Lånekort",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public class Receipt implements DataType {
public static Receipt EXAMPLE = new Receipt(
"F96B6805-2453-478A-B58B-CCDFA07E21ED"
, "364567"
, ZonedDateTime.of(2018, 5, 27, 10, 0, 0, 0, ZoneId.systemDefault())
, ZonedDateTime.of(2018, 5, 27, 10, 0, 0, 0, ZoneId.of("+02:00"))
, ReceiptLine.EXAMPLE.getTotalPrice()
, ReceiptLine.EXAMPLE.getTotalVat()
, "NOK"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public class TaxiDetails {

public static final TaxiDetails EXAMPLE = new TaxiDetails(
"EK99999", "12341ASDF", "123456789",
ZonedDateTime.of(2018, 6, 5, 10, 0, 0, 0, ZoneId.systemDefault()),
ZonedDateTime.of(2018, 6, 5, 10, 30, 0, 0, ZoneId.systemDefault()),
ZonedDateTime.of(2018, 6, 5, 10, 0, 0, 0, ZoneId.of("+02:00")),
ZonedDateTime.of(2018, 6, 5, 10, 30, 0, 0, ZoneId.of("+02:00")),
new BigDecimal("8.00"), new BigDecimal("438.50"), 2000, 8500,
6500, 320, 1220, 900,
VatDetails.EXAMPLE);
Expand Down

0 comments on commit 4b20f27

Please sign in to comment.