From d7f9bec7ae85b65eafe0f0ebafc0191124b16c03 Mon Sep 17 00:00:00 2001 From: Siarhei Hrabko <45555481+grabsefx@users.noreply.github.com> Date: Mon, 15 Apr 2024 09:06:44 +0300 Subject: [PATCH] EPMRPP-88602 Instant time (#20) * EPMRPP-88602 Instant time * EPMRPP-88602 LDT serialization fix for analyzer --- .../databind/LocalDateTimeSerializer.java | 47 ++++++++ .../reportportal/model/ActivityResource.java | 106 ++---------------- .../model/analyzer/IndexLaunch.java | 3 + .../reportportal/model/analyzer/IndexLog.java | 3 + .../model/analyzer/IndexTestItem.java | 3 + 5 files changed, 66 insertions(+), 96 deletions(-) create mode 100644 src/main/java/com/epam/reportportal/databind/LocalDateTimeSerializer.java diff --git a/src/main/java/com/epam/reportportal/databind/LocalDateTimeSerializer.java b/src/main/java/com/epam/reportportal/databind/LocalDateTimeSerializer.java new file mode 100644 index 0000000..9995140 --- /dev/null +++ b/src/main/java/com/epam/reportportal/databind/LocalDateTimeSerializer.java @@ -0,0 +1,47 @@ +/* + * Copyright 2024 EPAM Systems + * + * 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 com.epam.reportportal.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.LocalDateTime; + +/** + * Serialization class for converting dates into array of integers. + * Required for compatibility with analyzer. + * + * @author Siarhei Hrabko + */ +public class LocalDateTimeSerializer extends JsonSerializer { + + @Override + public void serialize(LocalDateTime localDateTime, JsonGenerator jsonGenerator, + SerializerProvider serializerProvider) throws IOException { + int[] time = { + localDateTime.getYear(), + localDateTime.getMonthValue(), + localDateTime.getDayOfMonth(), + localDateTime.getHour(), + localDateTime.getMinute(), + localDateTime.getSecond(), + localDateTime.getNano() + }; + jsonGenerator.writeArray(time, 0, 7); + } +} diff --git a/src/main/java/com/epam/reportportal/model/ActivityResource.java b/src/main/java/com/epam/reportportal/model/ActivityResource.java index a7e6181..92bc0cd 100644 --- a/src/main/java/com/epam/reportportal/model/ActivityResource.java +++ b/src/main/java/com/epam/reportportal/model/ActivityResource.java @@ -21,8 +21,12 @@ import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema.RequiredMode; -import java.util.Date; +import java.time.Instant; import javax.validation.constraints.NotNull; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; /** * JSON Representation of Report Portal's Activity domain object. @@ -30,6 +34,10 @@ * @see HATEOAS Description */ @JsonInclude(Include.NON_NULL) +@Getter +@Setter +@ToString +@NoArgsConstructor public class ActivityResource { @NotNull @@ -50,7 +58,7 @@ public class ActivityResource { @NotNull @JsonProperty(value = "lastModified", required = true) @Schema(requiredMode = RequiredMode.REQUIRED) - private Date lastModified; + private Instant lastModified; @NotNull @JsonProperty(value = "actionType", required = true) @@ -76,98 +84,4 @@ public class ActivityResource { @JsonProperty(value = "objectName") private String objectName; - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getUser() { - return user; - } - - public void setUser(String user) { - this.user = user; - } - - public Long getLoggedObjectId() { - return loggedObjectId; - } - - public void setLoggedObjectId(Long loggedObjectId) { - this.loggedObjectId = loggedObjectId; - } - - public Date getLastModified() { - return lastModified; - } - - public void setLastModified(Date lastModified) { - this.lastModified = lastModified; - } - - public String getActionType() { - return actionType; - } - - public void setActionType(String actionType) { - this.actionType = actionType; - } - - public String getObjectType() { - return objectType; - } - - public void setObjectType(String objectType) { - this.objectType = objectType; - } - - public Long getProjectId() { - return projectId; - } - - public void setProjectId(Long projectId) { - this.projectId = projectId; - } - - public String getProjectName() { - return projectName; - } - - public void setProjectName(String projectName) { - this.projectName = projectName; - } - - public Object getDetails() { - return details; - } - - public void setDetails(Object details) { - this.details = details; - } - - public String getObjectName() { - return objectName; - } - - public void setObjectName(String objectName) { - this.objectName = objectName; - } - - @Override - public String toString() { - return "ActivityResource{" + "id=" + id - + ", user='" + user + '\'' - + ", loggedObjectId='" + loggedObjectId + '\'' - + ", lastModified=" + lastModified - + ", actionType='" + actionType + '\'' - + ", objectType='" + objectType + '\'' - + ", projectId=" + projectId - + ", projectName='" + projectName + '\'' - + ", objectName='" + objectName + '\'' - + ", details=" + details - + '}'; - } } diff --git a/src/main/java/com/epam/reportportal/model/analyzer/IndexLaunch.java b/src/main/java/com/epam/reportportal/model/analyzer/IndexLaunch.java index dfae8f9..ae42517 100644 --- a/src/main/java/com/epam/reportportal/model/analyzer/IndexLaunch.java +++ b/src/main/java/com/epam/reportportal/model/analyzer/IndexLaunch.java @@ -16,9 +16,11 @@ package com.epam.reportportal.model.analyzer; +import com.epam.reportportal.databind.LocalDateTimeSerializer; import com.epam.reportportal.model.project.AnalyzerConfig; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import java.time.LocalDateTime; import java.util.List; import java.util.Map; @@ -38,6 +40,7 @@ public class IndexLaunch { private String launchName; @JsonProperty("launchStartTime") + @JsonSerialize(using = LocalDateTimeSerializer.class) private LocalDateTime launchStartTime; @JsonProperty("project") diff --git a/src/main/java/com/epam/reportportal/model/analyzer/IndexLog.java b/src/main/java/com/epam/reportportal/model/analyzer/IndexLog.java index 57f1934..7ac77fc 100644 --- a/src/main/java/com/epam/reportportal/model/analyzer/IndexLog.java +++ b/src/main/java/com/epam/reportportal/model/analyzer/IndexLog.java @@ -16,8 +16,10 @@ package com.epam.reportportal.model.analyzer; +import com.epam.reportportal.databind.LocalDateTimeSerializer; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import java.time.LocalDateTime; import java.util.Objects; @@ -36,6 +38,7 @@ public class IndexLog { private int logLevel; @JsonProperty("logTime") + @JsonSerialize(using = LocalDateTimeSerializer.class) private LocalDateTime logTime; @JsonProperty("message") diff --git a/src/main/java/com/epam/reportportal/model/analyzer/IndexTestItem.java b/src/main/java/com/epam/reportportal/model/analyzer/IndexTestItem.java index e814881..b6b62b2 100644 --- a/src/main/java/com/epam/reportportal/model/analyzer/IndexTestItem.java +++ b/src/main/java/com/epam/reportportal/model/analyzer/IndexTestItem.java @@ -16,7 +16,9 @@ package com.epam.reportportal.model.analyzer; +import com.epam.reportportal.databind.LocalDateTimeSerializer; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import java.time.LocalDateTime; import java.util.Objects; import java.util.Set; @@ -37,6 +39,7 @@ public class IndexTestItem { @JsonProperty("issueType") private String issueTypeLocator; + @JsonSerialize(using = LocalDateTimeSerializer.class) private LocalDateTime startTime; @JsonProperty("logs")