From e3f17718f72d7df63791bb05954a66460027a211 Mon Sep 17 00:00:00 2001 From: siarhei_hrabko Date: Mon, 13 Nov 2023 13:00:46 +0300 Subject: [PATCH 1/3] EPMRPP-87271 fixed datetime parser --- build.gradle | 6 + gradle.properties | 1 + .../commons/querygen/CriteriaHolder.java | 6 +- .../entity/activity/Activity.java | 143 +----------------- .../ta/reportportal/util/DateTimeUtils.java | 66 ++++++++ 5 files changed, 82 insertions(+), 140 deletions(-) create mode 100644 src/main/java/com/epam/ta/reportportal/util/DateTimeUtils.java diff --git a/build.gradle b/build.gradle index 198c0d586..7c264e0d1 100644 --- a/build.gradle +++ b/build.gradle @@ -99,6 +99,12 @@ dependencies { compile 'org.apache.jclouds.provider:aws-s3:2.5.0' implementation 'org.apache.jclouds.api:filesystem:2.5.0' + // add lombok support + compileOnly "org.projectlombok:lombok:${lombokVersion}" + annotationProcessor "org.projectlombok:lombok:${lombokVersion}" + testCompileOnly "org.projectlombok:lombok:${lombokVersion}" + testAnnotationProcessor "org.projectlombok:lombok:${lombokVersion}" + testCompile 'org.springframework.boot:spring-boot-starter-test' testCompile 'org.flywaydb.flyway-test-extensions:flyway-spring-test:6.1.0' diff --git a/gradle.properties b/gradle.properties index 24cce7a9a..4b30a6367 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1,2 @@ version=5.10.0 +lombokVersion=1.18.30 diff --git a/src/main/java/com/epam/ta/reportportal/commons/querygen/CriteriaHolder.java b/src/main/java/com/epam/ta/reportportal/commons/querygen/CriteriaHolder.java index 995026760..244d04424 100644 --- a/src/main/java/com/epam/ta/reportportal/commons/querygen/CriteriaHolder.java +++ b/src/main/java/com/epam/ta/reportportal/commons/querygen/CriteriaHolder.java @@ -30,6 +30,7 @@ import com.epam.ta.reportportal.jooq.enums.JLaunchModeEnum; import com.epam.ta.reportportal.jooq.enums.JStatusEnum; import com.epam.ta.reportportal.jooq.enums.JTestItemTypeEnum; +import com.epam.ta.reportportal.util.DateTimeUtils; import com.epam.ta.reportportal.ws.model.ErrorType; import com.google.common.base.Preconditions; import com.google.common.collect.Lists; @@ -165,8 +166,7 @@ public Object castValue(String oneValue, ErrorType errorType) { } else { try { - Instant instant = Instant.parse(oneValue); - castedValue = LocalDateTime.ofInstant(instant, ZoneId.systemDefault()); + castedValue = DateTimeUtils.parseDateTimeWithOffset(oneValue); } catch (DateTimeParseException e) { throw new ReportPortalException(errorType, Suppliers.formattedSupplier("Cannot convert '{}' to valid date", oneValue).get() @@ -245,4 +245,4 @@ private Long parseLong(String value, ErrorType errorType) { } } -} \ No newline at end of file +} diff --git a/src/main/java/com/epam/ta/reportportal/entity/activity/Activity.java b/src/main/java/com/epam/ta/reportportal/entity/activity/Activity.java index 537d94658..2750da580 100644 --- a/src/main/java/com/epam/ta/reportportal/entity/activity/Activity.java +++ b/src/main/java/com/epam/ta/reportportal/entity/activity/Activity.java @@ -28,14 +28,9 @@ import javax.persistence.Id; import javax.persistence.Table; import javax.persistence.Transient; -import org.hibernate.annotations.Type; -import org.hibernate.annotations.TypeDef; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; import org.hibernate.annotations.Type; import org.hibernate.annotations.TypeDef; @@ -47,6 +42,9 @@ @Entity @Table(name = "activity", schema = "public") @TypeDef(name = "activityDetails", typeClass = ActivityDetails.class) +@Getter +@Setter +@ToString public class Activity implements Serializable { @Id @@ -108,125 +106,6 @@ public Activity() { this.isSavedEvent = true; } - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public LocalDateTime getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(LocalDateTime createdAt) { - this.createdAt = createdAt; - } - - public EventAction getAction() { - return action; - } - - public void setAction(EventAction action) { - this.action = action; - } - - public String getEventName() { - return eventName; - } - - public void setEventName(String eventName) { - this.eventName = eventName; - } - - public EventPriority getPriority() { - return priority; - } - - public void setPriority(EventPriority priority) { - this.priority = priority; - } - - public Long getObjectId() { - return objectId; - } - - public void setObjectId(Long objectId) { - this.objectId = objectId; - } - - public String getObjectName() { - return objectName; - } - - public void setObjectName(String objectName) { - this.objectName = objectName; - } - - public EventObject getObjectType() { - return objectType; - } - - public void setObjectType(EventObject 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 ActivityDetails getDetails() { - return details; - } - - public void setDetails(ActivityDetails details) { - this.details = details; - } - - public Long getSubjectId() { - return subjectId; - } - - public void setSubjectId(Long subjectId) { - this.subjectId = subjectId; - } - - public String getSubjectName() { - return subjectName; - } - - public void setSubjectName(String subjectName) { - this.subjectName = subjectName; - } - - public EventSubject getSubjectType() { - return subjectType; - } - - public void setSubjectType(EventSubject subjectType) { - this.subjectType = subjectType; - } - - public boolean isSavedEvent() { - return isSavedEvent; - } - - public void setSavedEvent(boolean savedEvent) { - isSavedEvent = savedEvent; - } @Override public boolean equals(Object o) { @@ -245,14 +124,4 @@ public int hashCode() { return Objects.hash(id); } - @Override - public String toString() { - return "Activity{" + "createdAt=" + createdAt - + ", action=" + action + ", eventName='" + eventName + '\'' - + ", priority=" + priority + ", objectId=" + objectId - + ", objectName='" + objectName + '\'' + ", objectType=" - + objectType + ", projectId=" + projectId + ", details=" - + details + ", subjectId=" + subjectId + ", subjectName='" - + subjectName + '\'' + ", subjectType=" + subjectType + '}'; - } } diff --git a/src/main/java/com/epam/ta/reportportal/util/DateTimeUtils.java b/src/main/java/com/epam/ta/reportportal/util/DateTimeUtils.java new file mode 100644 index 000000000..ce1be3e94 --- /dev/null +++ b/src/main/java/com/epam/ta/reportportal/util/DateTimeUtils.java @@ -0,0 +1,66 @@ +/* + * Copyright 2023 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.ta.reportportal.util; + +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.temporal.TemporalAccessor; +import java.time.temporal.TemporalQueries; + +/** + * Utility class for date and time handling. + * + * @author Siarhei Hrabko + */ +public final class DateTimeUtils { + + private DateTimeUtils() { + } + + /** + * Parses datetime string to LocalDateTime. + * + * @param timestamp timestamp in different formats for parsing + * @return localDateTime + */ + public static LocalDateTime parseDateTimeWithOffset(String timestamp) { + DateTimeFormatter formatter = new DateTimeFormatterBuilder() + .appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ")) + .appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ")) + .appendOptional(DateTimeFormatter.RFC_1123_DATE_TIME) + .appendOptional(DateTimeFormatter.ISO_OFFSET_DATE_TIME) + .appendOptional(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + .toFormatter(); + + TemporalAccessor temporalAccessor = formatter.parse(timestamp); + if (isParsedTimeStampHasOffset(temporalAccessor)) { + return ZonedDateTime.from(temporalAccessor) + .withZoneSameInstant(ZoneId.systemDefault()) + .toLocalDateTime(); + } else { + return LocalDateTime.from(temporalAccessor); + } + } + + private static boolean isParsedTimeStampHasOffset(TemporalAccessor temporalAccessor) { + return temporalAccessor.query(TemporalQueries.offset()) != null; + } + +} From 5f1bec38a9c38157e115c9def477cd25238cebf2 Mon Sep 17 00:00:00 2001 From: siarhei_hrabko Date: Mon, 13 Nov 2023 14:59:51 +0300 Subject: [PATCH 2/3] EPMRPP-87271 update commons-model --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 7c264e0d1..c3d1a09b3 100644 --- a/build.gradle +++ b/build.gradle @@ -63,7 +63,7 @@ dependencies { } else { compile 'com.github.reportportal:commons:ce2166b5' compile 'com.github.reportportal:commons-rules:e859db2' - compile 'com.github.reportportal:commons-model:bf40974' + compile 'com.github.reportportal:commons-model:6ee9287' } //https://nvd.nist.gov/vuln/detail/CVE-2020-10683 (dom4j 2.1.3 version dependency) AND https://nvd.nist.gov/vuln/detail/CVE-2019-14900 From 2f5112000fdd05d1a85c7b0f99d9ff1c73596a5e Mon Sep 17 00:00:00 2001 From: siarhei_hrabko Date: Mon, 13 Nov 2023 15:20:27 +0300 Subject: [PATCH 3/3] EPMRPP-87271 update commons-model --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index c3d1a09b3..bfb22a8ff 100644 --- a/build.gradle +++ b/build.gradle @@ -63,7 +63,7 @@ dependencies { } else { compile 'com.github.reportportal:commons:ce2166b5' compile 'com.github.reportportal:commons-rules:e859db2' - compile 'com.github.reportportal:commons-model:6ee9287' + compile 'com.github.reportportal:commons-model:508b9ef' } //https://nvd.nist.gov/vuln/detail/CVE-2020-10683 (dom4j 2.1.3 version dependency) AND https://nvd.nist.gov/vuln/detail/CVE-2019-14900