Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EPMRPP-87271 fixed datetime parser #950

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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: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
Expand Down Expand Up @@ -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'

Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
version=5.10.0
lombokVersion=1.18.30
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -245,4 +245,4 @@ private Long parseLong(String value, ErrorType errorType) {
}
}

}
}
143 changes: 6 additions & 137 deletions src/main/java/com/epam/ta/reportportal/entity/activity/Activity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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 + '}';
}
}
66 changes: 66 additions & 0 deletions src/main/java/com/epam/ta/reportportal/util/DateTimeUtils.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
Loading