Skip to content

Commit

Permalink
EPMRPP-88461 Switch to LocalDateTime
Browse files Browse the repository at this point in the history
  • Loading branch information
grabsefx committed Feb 5, 2024
1 parent 458b67a commit 406efa0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ dependencies {
} else {
compile 'com.github.reportportal:commons:07566b8e'
compile 'com.github.reportportal:commons-rules:42d4dd5634'
compile 'com.github.reportportal:commons-model:3072286352'
compile 'com.github.reportportal:commons-model:ac3947f'
}

//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
11 changes: 11 additions & 0 deletions src/main/java/com/epam/ta/reportportal/commons/EntityUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@

import com.google.common.base.Preconditions;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.Date;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;

/**
* Some useful utils for working with entities<br> For example: usernames, project names, tags,
Expand All @@ -38,6 +40,15 @@ public class EntityUtils {
date).map(d -> LocalDateTime.ofInstant(d.toInstant(),
ZoneOffset.UTC
)).orElse(null);

public static final UnaryOperator<LocalDateTime> TO_UTC_LOCAL_DATE_TIME =
localDateTime -> ofNullable(localDateTime)
.map(date -> date
.atZone(ZoneId.systemDefault())
.withZoneSameInstant(ZoneOffset.UTC)
.toLocalDateTime())
.orElse(null);

public static final Function<LocalDateTime, Date> TO_DATE = localDateTime -> ofNullable(
localDateTime).map(l -> Date.from(l.atZone(
ZoneOffset.UTC).toInstant())).orElse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.epam.ta.reportportal.commons;

import static com.epam.ta.reportportal.commons.EntityUtils.TO_LOCAL_DATE_TIME;
import static com.epam.ta.reportportal.commons.EntityUtils.TO_UTC_LOCAL_DATE_TIME;
import static com.epam.ta.reportportal.commons.querygen.constant.LaunchCriteriaConstant.CRITERIA_LAUNCH_MODE;

import com.epam.ta.reportportal.commons.querygen.FilterCondition;
Expand Down Expand Up @@ -62,6 +63,14 @@ public static Predicate<Date> sameTimeOrLater(final LocalDateTime than) {
};
}

public static Predicate<LocalDateTime> sameLocalDateTimeOrLater(final LocalDateTime than) {
com.google.common.base.Preconditions.checkNotNull(than, ErrorType.BAD_REQUEST_ERROR);
return date -> {
LocalDateTime localDateTime = TO_UTC_LOCAL_DATE_TIME.apply(date);
return localDateTime.isAfter(than) || localDateTime.isEqual(than);
};
}

public static Predicate<StatusEnum> statusIn(final StatusEnum... statuses) {
return input -> ArrayUtils.contains(statuses, input);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package com.epam.ta.reportportal.dao.util;

import static com.epam.ta.reportportal.commons.EntityUtils.TO_DATE;
import static com.epam.ta.reportportal.commons.querygen.QueryBuilder.STATISTICS_KEY;
import static com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_END_TIME;
import static com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_LAST_MODIFIED;
Expand Down Expand Up @@ -253,8 +252,7 @@ public static <K, V> void consumeIfNotNull(K key, V value, BiConsumer<K, V> cons
activityResource.setActionType(r.get(ACTIVITY.EVENT_NAME));
activityResource.setObjectType(r.get(ACTIVITY.OBJECT_TYPE));
activityResource.setObjectName(r.get(ACTIVITY.OBJECT_NAME));
activityResource.setLastModified(
TO_DATE.apply(r.get(ACTIVITY.CREATED_AT, LocalDateTime.class)));
activityResource.setLastModified(r.get(ACTIVITY.CREATED_AT, LocalDateTime.class));
activityResource.setLoggedObjectId(r.get(ACTIVITY.OBJECT_ID));
String detailsJson = r.get(ACTIVITY.DETAILS, String.class);
ofNullable(detailsJson).ifPresent(s -> {
Expand Down

0 comments on commit 406efa0

Please sign in to comment.