From 2d13d98291b679a8236b3c87fae9314f2fb063e3 Mon Sep 17 00:00:00 2001 From: siarhei_hrabko Date: Tue, 6 Feb 2024 00:32:15 +0300 Subject: [PATCH] EPMRPP-88461 Switch to LocalDateTime --- .../dao/UserCreationBidRepository.java | 4 +- .../ta/reportportal/entity/Modifiable.java | 6 +- .../reportportal/entity/project/Project.java | 112 +----------------- .../entity/user/RestorePasswordBid.java | 10 +- .../entity/user/UserCreationBid.java | 65 ++-------- .../ta/reportportal/jooq/tables/JApiKeys.java | 2 +- .../jooq/tables/records/JApiKeysRecord.java | 28 ++--- .../util/PersonalProjectService.java | 5 +- .../commons/PreconditionsTest.java | 2 +- .../dao/ActivityRepositoryTest.java | 2 +- .../dao/RestorePasswordBidRepositoryTest.java | 6 +- .../dao/UserCreationBidRepositoryTest.java | 7 +- .../entity/project/ProjectUtilsTest.java | 6 +- 13 files changed, 51 insertions(+), 204 deletions(-) diff --git a/src/main/java/com/epam/ta/reportportal/dao/UserCreationBidRepository.java b/src/main/java/com/epam/ta/reportportal/dao/UserCreationBidRepository.java index 9cff50730..6dc8722f5 100644 --- a/src/main/java/com/epam/ta/reportportal/dao/UserCreationBidRepository.java +++ b/src/main/java/com/epam/ta/reportportal/dao/UserCreationBidRepository.java @@ -17,7 +17,7 @@ package com.epam.ta.reportportal.dao; import com.epam.ta.reportportal.entity.user.UserCreationBid; -import java.util.Date; +import java.time.LocalDateTime; import java.util.Optional; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; @@ -35,7 +35,7 @@ Optional findByUuidAndType(@Param("uuid") String uuid, @Modifying @Query(value = "DELETE FROM UserCreationBid u WHERE u.lastModified < :date") - int expireBidsOlderThan(@Param("date") Date date); + int expireBidsOlderThan(@Param("date") LocalDateTime date); Optional findFirstByEmailOrderByLastModifiedDesc(String email); } diff --git a/src/main/java/com/epam/ta/reportportal/entity/Modifiable.java b/src/main/java/com/epam/ta/reportportal/entity/Modifiable.java index 319b2c8de..c219dcc67 100644 --- a/src/main/java/com/epam/ta/reportportal/entity/Modifiable.java +++ b/src/main/java/com/epam/ta/reportportal/entity/Modifiable.java @@ -16,7 +16,7 @@ package com.epam.ta.reportportal.entity; -import java.util.Date; +import java.time.LocalDateTime; /** * Item may be modified @@ -34,5 +34,5 @@ public interface Modifiable { * * @return */ - Date getLastModified(); -} \ No newline at end of file + LocalDateTime getLastModified(); +} diff --git a/src/main/java/com/epam/ta/reportportal/entity/project/Project.java b/src/main/java/com/epam/ta/reportportal/entity/project/Project.java index 75041070d..f64c35efd 100644 --- a/src/main/java/com/epam/ta/reportportal/entity/project/Project.java +++ b/src/main/java/com/epam/ta/reportportal/entity/project/Project.java @@ -24,7 +24,7 @@ import com.epam.ta.reportportal.entity.user.ProjectUser; import com.google.common.collect.Sets; import java.io.Serializable; -import java.util.Date; +import java.time.LocalDateTime; import java.util.Objects; import java.util.Set; import javax.persistence.CascadeType; @@ -38,6 +38,8 @@ import javax.persistence.OneToMany; import javax.persistence.OrderBy; import javax.persistence.Table; +import lombok.Getter; +import lombok.Setter; import org.hibernate.annotations.Type; import org.hibernate.annotations.TypeDef; @@ -47,6 +49,8 @@ @Entity @TypeDef(name = "json", typeClass = Metadata.class) @Table(name = "project", schema = "public") +@Getter +@Setter public class Project implements Serializable { private static final long serialVersionUID = -263516611; @@ -79,7 +83,7 @@ public class Project implements Serializable { private Set senderCases = Sets.newHashSet(); @Column(name = "creation_date") - private Date creationDate; + private LocalDateTime creationDate; @Type(type = "json") @Column(name = "metadata") @@ -107,110 +111,6 @@ public Project(Long id, String name) { public Project() { } - public Date getCreationDate() { - return creationDate; - } - - public void setCreationDate(Date creationDate) { - this.creationDate = creationDate; - } - - public Long getId() { - return this.id; - } - - public void setId(Long id) { - this.id = id; - } - - public ProjectType getProjectType() { - return projectType; - } - - public void setProjectType(ProjectType projectType) { - this.projectType = projectType; - } - - public Set getUsers() { - return users; - } - - public void setUsers(Set users) { - this.users = users; - } - - public long getAllocatedStorage() { - return allocatedStorage; - } - - public void setAllocatedStorage(long allocatedStorage) { - this.allocatedStorage = allocatedStorage; - } - - public Set getPatternTemplates() { - return patternTemplates; - } - - public void setPatternTemplates(Set patternTemplates) { - this.patternTemplates = patternTemplates; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Set getIntegrations() { - return integrations; - } - - public void setIntegrations(Set integrations) { - this.integrations = integrations; - } - - public Set getProjectAttributes() { - return projectAttributes; - } - - public void setProjectAttributes(Set projectAttributes) { - this.projectAttributes = projectAttributes; - } - - public Set getProjectIssueTypes() { - return projectIssueTypes; - } - - public void setProjectIssueTypes(Set projectIssueTypes) { - this.projectIssueTypes = projectIssueTypes; - } - - public Set getSenderCases() { - return senderCases; - } - - public void setSenderCases(Set senderCases) { - this.senderCases = senderCases; - } - - public String getOrganization() { - return organization; - } - - public void setOrganization(String organization) { - this.organization = organization; - } - - public Metadata getMetadata() { - return metadata; - } - - public void setMetadata(Metadata metadata) { - this.metadata = metadata; - } - @Override public boolean equals(Object o) { if (this == o) { diff --git a/src/main/java/com/epam/ta/reportportal/entity/user/RestorePasswordBid.java b/src/main/java/com/epam/ta/reportportal/entity/user/RestorePasswordBid.java index 453baefc9..c84c5de26 100644 --- a/src/main/java/com/epam/ta/reportportal/entity/user/RestorePasswordBid.java +++ b/src/main/java/com/epam/ta/reportportal/entity/user/RestorePasswordBid.java @@ -18,12 +18,13 @@ import com.epam.ta.reportportal.entity.Modifiable; import java.io.Serializable; -import java.util.Date; +import java.time.LocalDateTime; import java.util.Objects; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; +import lombok.Data; import org.springframework.data.annotation.LastModifiedDate; /** @@ -31,6 +32,7 @@ */ @Entity @Table(name = "restore_password_bid") +@Data public class RestorePasswordBid implements Serializable, Modifiable { /** @@ -43,7 +45,7 @@ public class RestorePasswordBid implements Serializable, Modifiable { @LastModifiedDate @Column(name = LAST_MODIFIED) - private Date lastModifiedDate; + private LocalDateTime lastModifiedDate; @Column(name = "email") private String email; @@ -57,11 +59,11 @@ public void setUuid(String uuid) { } @Override - public Date getLastModified() { + public LocalDateTime getLastModified() { return lastModifiedDate; } - public void setLastModifiedDate(Date lastModifiedDate) { + public void setLastModifiedDate(LocalDateTime lastModifiedDate) { this.lastModifiedDate = lastModifiedDate; } diff --git a/src/main/java/com/epam/ta/reportportal/entity/user/UserCreationBid.java b/src/main/java/com/epam/ta/reportportal/entity/user/UserCreationBid.java index 20ea9c292..4ea1b9f67 100644 --- a/src/main/java/com/epam/ta/reportportal/entity/user/UserCreationBid.java +++ b/src/main/java/com/epam/ta/reportportal/entity/user/UserCreationBid.java @@ -18,10 +18,8 @@ import com.epam.ta.reportportal.entity.Metadata; import com.epam.ta.reportportal.entity.Modifiable; -import org.hibernate.annotations.Type; -import org.hibernate.annotations.TypeDef; import java.io.Serializable; -import java.util.Date; +import java.time.LocalDateTime; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; @@ -30,6 +28,10 @@ import javax.persistence.JoinColumn; import javax.persistence.OneToOne; import javax.persistence.Table; +import lombok.Getter; +import lombok.Setter; +import org.hibernate.annotations.Type; +import org.hibernate.annotations.TypeDef; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -40,6 +42,8 @@ @Table(name = "user_creation_bid") @TypeDef(name = "json", typeClass = Metadata.class) @EntityListeners(AuditingEntityListener.class) +@Getter +@Setter public class UserCreationBid implements Serializable, Modifiable { @Id @@ -48,7 +52,7 @@ public class UserCreationBid implements Serializable, Modifiable { @LastModifiedDate @Column(name = LAST_MODIFIED) - private Date lastModified; + private LocalDateTime lastModified; @Column(name = "email") private String email; @@ -67,60 +71,9 @@ public class UserCreationBid implements Serializable, Modifiable { @Column(name = "metadata") private Metadata metadata; - public String getUuid() { - return uuid; - } - - public void setUuid(String uuid) { - this.uuid = uuid; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - public String getProjectName() { - return projectName; - } - - public void setProjectName(String projectName) { - this.projectName = projectName; - } - - public String getRole() { - return role; - } - - public void setRole(String role) { - this.role = role; - } - @Override - public Date getLastModified() { + public LocalDateTime getLastModified() { return lastModified; } - public void setLastModified(Date lastModified) { - this.lastModified = lastModified; - } - - public Metadata getMetadata() { - return metadata; - } - - public void setMetadata(Metadata metadata) { - this.metadata = metadata; - } - - public User getInvitingUser() { - return invitingUser; - } - - public void setInvitingUser(User invitingUser) { - this.invitingUser = invitingUser; - } } diff --git a/src/main/java/com/epam/ta/reportportal/jooq/tables/JApiKeys.java b/src/main/java/com/epam/ta/reportportal/jooq/tables/JApiKeys.java index f15f4627c..6f94434de 100644 --- a/src/main/java/com/epam/ta/reportportal/jooq/tables/JApiKeys.java +++ b/src/main/java/com/epam/ta/reportportal/jooq/tables/JApiKeys.java @@ -87,7 +87,7 @@ public Class getRecordType() { /** * The column public.api_keys.last_used_at. */ - public final TableField LAST_USED_AT = createField(DSL.name("last_used_at"), org.jooq.impl.SQLDataType.DATE, this, ""); + public final TableField LAST_USED_AT = createField(DSL.name("last_used_at"), org.jooq.impl.SQLDataType.TIMESTAMP, this, ""); /** * Create a public.api_keys table reference diff --git a/src/main/java/com/epam/ta/reportportal/jooq/tables/records/JApiKeysRecord.java b/src/main/java/com/epam/ta/reportportal/jooq/tables/records/JApiKeysRecord.java index 1d1780f8a..1541bbfd4 100644 --- a/src/main/java/com/epam/ta/reportportal/jooq/tables/records/JApiKeysRecord.java +++ b/src/main/java/com/epam/ta/reportportal/jooq/tables/records/JApiKeysRecord.java @@ -5,12 +5,8 @@ import com.epam.ta.reportportal.jooq.tables.JApiKeys; - -import java.sql.Date; import java.sql.Timestamp; - import javax.annotation.processing.Generated; - import org.jooq.Field; import org.jooq.Record1; import org.jooq.Record6; @@ -29,7 +25,7 @@ comments = "This class is generated by jOOQ" ) @SuppressWarnings({ "all", "unchecked", "rawtypes" }) -public class JApiKeysRecord extends UpdatableRecordImpl implements Record6 { +public class JApiKeysRecord extends UpdatableRecordImpl implements Record6 { private static final long serialVersionUID = -24722664; @@ -106,15 +102,15 @@ public Long getUserId() { /** * Setter for public.api_keys.last_used_at. */ - public void setLastUsedAt(Date value) { + public void setLastUsedAt(Timestamp value) { set(5, value); } /** * Getter for public.api_keys.last_used_at. */ - public Date getLastUsedAt() { - return (Date) get(5); + public Timestamp getLastUsedAt() { + return (Timestamp) get(5); } // ------------------------------------------------------------------------- @@ -131,12 +127,12 @@ public Record1 key() { // ------------------------------------------------------------------------- @Override - public Row6 fieldsRow() { + public Row6 fieldsRow() { return (Row6) super.fieldsRow(); } @Override - public Row6 valuesRow() { + public Row6 valuesRow() { return (Row6) super.valuesRow(); } @@ -166,7 +162,7 @@ public Field field5() { } @Override - public Field field6() { + public Field field6() { return JApiKeys.API_KEYS.LAST_USED_AT; } @@ -196,7 +192,7 @@ public Long component5() { } @Override - public Date component6() { + public Timestamp component6() { return getLastUsedAt(); } @@ -226,7 +222,7 @@ public Long value5() { } @Override - public Date value6() { + public Timestamp value6() { return getLastUsedAt(); } @@ -261,13 +257,13 @@ public JApiKeysRecord value5(Long value) { } @Override - public JApiKeysRecord value6(Date value) { + public JApiKeysRecord value6(Timestamp value) { setLastUsedAt(value); return this; } @Override - public JApiKeysRecord values(Long value1, String value2, String value3, Timestamp value4, Long value5, Date value6) { + public JApiKeysRecord values(Long value1, String value2, String value3, Timestamp value4, Long value5, Timestamp value6) { value1(value1); value2(value2); value3(value3); @@ -291,7 +287,7 @@ public JApiKeysRecord() { /** * Create a detached, initialised JApiKeysRecord */ - public JApiKeysRecord(Long id, String name, String hash, Timestamp createdAt, Long userId, Date lastUsedAt) { + public JApiKeysRecord(Long id, String name, String hash, Timestamp createdAt, Long userId, Timestamp lastUsedAt) { super(JApiKeys.API_KEYS); set(0, id); diff --git a/src/main/java/com/epam/ta/reportportal/util/PersonalProjectService.java b/src/main/java/com/epam/ta/reportportal/util/PersonalProjectService.java index f814fb6bb..e4b2ff37b 100644 --- a/src/main/java/com/epam/ta/reportportal/util/PersonalProjectService.java +++ b/src/main/java/com/epam/ta/reportportal/util/PersonalProjectService.java @@ -31,8 +31,7 @@ import com.epam.ta.reportportal.entity.user.User; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Sets; -import java.sql.Date; -import java.time.ZonedDateTime; +import java.time.LocalDateTime; import java.util.Collections; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -87,7 +86,7 @@ private String generatePersonalProjectName(String username) { public Project generatePersonalProject(User user) { Project project = new Project(); project.setName(generatePersonalProjectName(user.getLogin())); - project.setCreationDate(Date.from(ZonedDateTime.now().toInstant())); + project.setCreationDate(LocalDateTime.now()); project.setProjectType(ProjectType.PERSONAL); ProjectUser projectUser = new ProjectUser().withUser(user) diff --git a/src/test/java/com/epam/ta/reportportal/commons/PreconditionsTest.java b/src/test/java/com/epam/ta/reportportal/commons/PreconditionsTest.java index 5111d7b2b..f99a04afb 100644 --- a/src/test/java/com/epam/ta/reportportal/commons/PreconditionsTest.java +++ b/src/test/java/com/epam/ta/reportportal/commons/PreconditionsTest.java @@ -94,4 +94,4 @@ private FilterCondition filterConditionWithMode(Mode mode) { return new FilterCondition(Condition.EQUALS, false, mode.name(), CRITERIA_LAUNCH_MODE); } -} \ No newline at end of file +} diff --git a/src/test/java/com/epam/ta/reportportal/dao/ActivityRepositoryTest.java b/src/test/java/com/epam/ta/reportportal/dao/ActivityRepositoryTest.java index 22f61a7d2..9cb09b6da 100644 --- a/src/test/java/com/epam/ta/reportportal/dao/ActivityRepositoryTest.java +++ b/src/test/java/com/epam/ta/reportportal/dao/ActivityRepositoryTest.java @@ -307,4 +307,4 @@ private Filter filterById(long id) { private Filter defaultFilter() { return new Filter(Activity.class, Condition.LOWER_THAN, false, "100", CRITERIA_ID); } -} \ No newline at end of file +} diff --git a/src/test/java/com/epam/ta/reportportal/dao/RestorePasswordBidRepositoryTest.java b/src/test/java/com/epam/ta/reportportal/dao/RestorePasswordBidRepositoryTest.java index dc8b0eacb..4e9b48c25 100644 --- a/src/test/java/com/epam/ta/reportportal/dao/RestorePasswordBidRepositoryTest.java +++ b/src/test/java/com/epam/ta/reportportal/dao/RestorePasswordBidRepositoryTest.java @@ -21,7 +21,7 @@ import com.epam.ta.reportportal.BaseTest; import com.epam.ta.reportportal.entity.user.RestorePasswordBid; -import java.util.Date; +import java.time.LocalDateTime; import java.util.Optional; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -46,10 +46,10 @@ void findByExistedEmail() { RestorePasswordBid restorePasswordBid = new RestorePasswordBid(); restorePasswordBid.setUuid("uuid"); restorePasswordBid.setEmail("existed@email.com"); - restorePasswordBid.setLastModifiedDate(new Date()); + restorePasswordBid.setLastModifiedDate(LocalDateTime.now()); restorePasswordBidRepository.save(restorePasswordBid); Optional bid = restorePasswordBidRepository.findByEmail( "existed@email.com"); assertTrue(bid.isPresent()); } -} \ No newline at end of file +} diff --git a/src/test/java/com/epam/ta/reportportal/dao/UserCreationBidRepositoryTest.java b/src/test/java/com/epam/ta/reportportal/dao/UserCreationBidRepositoryTest.java index 9abc4686d..8e194b7dd 100644 --- a/src/test/java/com/epam/ta/reportportal/dao/UserCreationBidRepositoryTest.java +++ b/src/test/java/com/epam/ta/reportportal/dao/UserCreationBidRepositoryTest.java @@ -21,9 +21,7 @@ import com.epam.ta.reportportal.BaseTest; import com.epam.ta.reportportal.entity.user.UserCreationBid; -import java.sql.Date; import java.time.LocalDateTime; -import java.time.ZoneId; import java.util.List; import java.util.Optional; import org.junit.jupiter.api.Test; @@ -65,14 +63,13 @@ void shouldNotFindByUuidAndTypeWhenTypeNotMatched() { @Test void expireBidsOlderThan() { - final java.util.Date date = Date.from( - LocalDateTime.now().minusDays(20).atZone(ZoneId.systemDefault()).toInstant()); + var date = LocalDateTime.now().minusDays(20); int deletedCount = repository.expireBidsOlderThan(date); final List bids = repository.findAll(); assertEquals(1, deletedCount); - bids.forEach(it -> assertTrue(it.getLastModified().after(date), "Incorrect date")); + bids.forEach(it -> assertTrue(it.getLastModified().isAfter(date), "Incorrect date")); } @Test diff --git a/src/test/java/com/epam/ta/reportportal/entity/project/ProjectUtilsTest.java b/src/test/java/com/epam/ta/reportportal/entity/project/ProjectUtilsTest.java index 8b0a560fd..c4f9c849a 100644 --- a/src/test/java/com/epam/ta/reportportal/entity/project/ProjectUtilsTest.java +++ b/src/test/java/com/epam/ta/reportportal/entity/project/ProjectUtilsTest.java @@ -32,8 +32,8 @@ import com.epam.ta.reportportal.entity.user.ProjectUser; import com.epam.ta.reportportal.entity.user.User; import com.google.common.collect.Sets; +import java.time.LocalDateTime; import java.util.Arrays; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -90,7 +90,7 @@ private static Project getTestProject() { project.setId(1L); project.setName("test_project"); project.setProjectType(ProjectType.PERSONAL); - project.setCreationDate(new Date()); + project.setCreationDate(LocalDateTime.now()); project.setUsers(Sets.newHashSet(new ProjectUser().withUser(getTestUser()) .withProject(project) .withProjectRole(ProjectRole.PROJECT_MANAGER))); @@ -408,4 +408,4 @@ private Set getEmailSenderCasesWithRecipientsOnly() { return Sets.newHashSet(firstSenderCase, secondSenderCase); } -} \ No newline at end of file +}