Skip to content

Commit

Permalink
Merge pull request #13 from reportportal/rc/5.12.3
Browse files Browse the repository at this point in the history
5.12.3 || Fix back compatibility
  • Loading branch information
pbortnik authored Nov 1, 2024
2 parents eccef08 + ab77d83 commit 10b76be
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
env:
GH_USER_NAME: github.actor
SCRIPTS_VERSION: 5.12.0
RELEASE_VERSION: 5.12.2
RELEASE_VERSION: 5.12.3

jobs:
release:
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=5.12.2
version=5.12.3
description=EPAM Report portal. REST Reporting API model
hibernateValidatorVersion=6.1.2.Final
validationApiVersion=2.0.1.Final
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@

package com.epam.ta.reportportal.ws.reporting;

import com.epam.ta.reportportal.ws.reporting.databind.OffsetDateTimeInstantSerializer;
import com.epam.ta.reportportal.ws.reporting.databind.MultiFormatDateDeserializer;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.time.Instant;
import java.util.LinkedHashSet;
import java.util.Map;
Expand Down Expand Up @@ -68,16 +70,18 @@ public class LaunchResource extends OwnedResource {
@NotNull
@JsonProperty(value = "startTime", required = true)
@JsonDeserialize(using = MultiFormatDateDeserializer.class)
@JsonSerialize(using = OffsetDateTimeInstantSerializer.class)
private Instant startTime;

@JsonProperty(value = "endTime")
@JsonDeserialize(using = MultiFormatDateDeserializer.class)
@JsonSerialize(using = OffsetDateTimeInstantSerializer.class)
private Instant endTime;

// Temp removed for back compatibility with old agents
// @JsonProperty(value = "lastModified")
// @JsonDeserialize(using = MultiFormatDateDeserializer.class)
// private Instant lastModified;
@JsonProperty(value = "lastModified")
@JsonDeserialize(using = MultiFormatDateDeserializer.class)
@JsonSerialize(using = OffsetDateTimeInstantSerializer.class)
private Instant lastModified;

@NotNull
@JsonProperty(value = "status", required = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@

package com.epam.ta.reportportal.ws.reporting;

import com.epam.ta.reportportal.ws.reporting.databind.OffsetDateTimeInstantSerializer;
import com.epam.ta.reportportal.ws.reporting.databind.MultiFormatDateDeserializer;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.time.Instant;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -65,10 +67,12 @@ public class TestItemResource {

@JsonProperty(value = "startTime")
@JsonDeserialize(using = MultiFormatDateDeserializer.class)
@JsonSerialize(using = OffsetDateTimeInstantSerializer.class)
private Instant startTime;

@JsonProperty(value = "endTime")
@JsonDeserialize(using = MultiFormatDateDeserializer.class)
@JsonSerialize(using = OffsetDateTimeInstantSerializer.class)
private Instant endTime;

@JsonProperty(value = "status")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public class MultiFormatDateDeserializer extends JsonDeserializer<Instant> {
private static final DateTimeFormatter TIMESTAMP_FORMAT =
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneId.of("UTC"));

private static final DateTimeFormatter ZONE_OFFSET_FORMAT = DateTimeFormatter
.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSSZ")
.withZone(ZoneOffset.UTC);

private static final DateTimeFormatter LOCAL_DATE_TIME_MS_FORMAT =
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS");

Expand All @@ -54,7 +58,8 @@ public class MultiFormatDateDeserializer extends JsonDeserializer<Instant> {
DateTimeFormatter.ISO_LOCAL_DATE_TIME,
TIMESTAMP_FORMAT,
LOCAL_DATE_TIME_MS_FORMAT,
LOCAL_DATE_TIME_MS_FORMAT_DATE
LOCAL_DATE_TIME_MS_FORMAT_DATE,
ZONE_OFFSET_FORMAT
);

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.epam.ta.reportportal.ws.reporting.databind;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;

public class OffsetDateTimeInstantSerializer extends JsonSerializer<Instant> {

private static final DateTimeFormatter formatter = DateTimeFormatter
.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSSZ")
.withZone(ZoneOffset.UTC);

@Override
public void serialize(Instant value, JsonGenerator gen, SerializerProvider provider)
throws IOException {
gen.writeString(formatter.format(value));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class MultiFormatDateDeserializerTest {
"2024-03-01T20:24:09.930+00:00",
"2024-03-01T19:24:09.930-01:00",
"2024-03-01T23:24:09.930+0300",
"2024-03-01T20:24:09.930000+0000",
"1709324649930"
})
void deserializeDates(String strDate) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.epam.ta.reportportal.ws.reporting.serializers;

import com.epam.ta.reportportal.ws.reporting.LaunchResource;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.time.Instant;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class OffsetDateTimeInstantSerializerTest {

private static final String EXPECTED_PARSED_TIME = "2024-11-01T08:39:14.125000+0000";

@Test
void serializeTimeInCompatibleFormat() throws IOException {
LaunchResource launchResource = new LaunchResource();
launchResource.setStartTime(Instant.ofEpochMilli(1730450354125L));
ObjectMapper objectMapper = new ObjectMapper();
String s = objectMapper.writeValueAsString(launchResource);
Assertions.assertTrue(s.contains(EXPECTED_PARSED_TIME));
}

}

0 comments on commit 10b76be

Please sign in to comment.