diff --git a/avni-server-api/src/main/java/org/avni/server/domain/User.java b/avni-server-api/src/main/java/org/avni/server/domain/User.java index d6b71b00c..687d82279 100644 --- a/avni-server-api/src/main/java/org/avni/server/domain/User.java +++ b/avni-server-api/src/main/java/org/avni/server/domain/User.java @@ -6,6 +6,7 @@ import jakarta.validation.constraints.NotNull; import org.apache.commons.validator.routines.EmailValidator; import org.avni.server.framework.hibernate.JSONObjectUserType; +import org.avni.server.util.DateTimeUtil; import org.avni.server.util.ObjectMapperSingleton; import org.avni.server.util.ValidationUtil; import org.avni.server.web.request.syncAttribute.UserSyncSettings; @@ -15,8 +16,9 @@ import org.hibernate.annotations.Type; import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.LazyInitializer; +import org.joda.time.DateTime; -import java.time.ZonedDateTime; +import java.time.Instant; import java.util.*; import java.util.stream.Collectors; @@ -63,14 +65,14 @@ public class User { private User createdBy; @Column - private ZonedDateTime createdDateTime; + private Instant createdDateTime; @JsonIgnore @JoinColumn(name = "last_modified_by_id") @ManyToOne(targetEntity = User.class) private User lastModifiedBy; - private ZonedDateTime lastModifiedDateTime; + private Instant lastModifiedDateTime; @Column private boolean isVoided; @@ -265,16 +267,16 @@ public void setCreatedBy(User createdBy) { this.createdBy = createdBy; } - public void setCreatedDateTime(ZonedDateTime createdDateTime) { - this.createdDateTime = createdDateTime; + public void setCreatedDateTime(DateTime createdDateTime) { + this.createdDateTime = DateTimeUtil.toInstant(createdDateTime); } public void setLastModifiedBy(User lastModifiedBy) { this.lastModifiedBy = lastModifiedBy; } - public void setLastModifiedDateTime(ZonedDateTime lastModifiedDateTime) { - this.lastModifiedDateTime = lastModifiedDateTime; + public void setLastModifiedDateTime(DateTime lastModifiedDateTime) { + this.lastModifiedDateTime = DateTimeUtil.toInstant(lastModifiedDateTime); } public User getCreatedBy() { @@ -289,16 +291,16 @@ public String getLastModifiedByUserName() { return this.lastModifiedBy.getName(); } - public ZonedDateTime getCreatedDateTime() { - return createdDateTime; + public DateTime getCreatedDateTime() { + return DateTimeUtil.toJodaDateTime(createdDateTime); } public User getLastModifiedBy() { return lastModifiedBy; } - public ZonedDateTime getLastModifiedDateTime() { - return lastModifiedDateTime; + public DateTime getLastModifiedDateTime() { + return DateTimeUtil.toJodaDateTime(lastModifiedDateTime); } public JsonObject getSyncSettings() { @@ -378,10 +380,10 @@ public void setSettings(JsonObject settings) { public void setAuditInfo(User currentUser) { if (this.getCreatedBy() == null) { this.setCreatedBy(currentUser); - this.setCreatedDateTime(ZonedDateTime.now()); + this.setCreatedDateTime(DateTime.now()); } this.setLastModifiedBy(currentUser); - this.setLastModifiedDateTime(ZonedDateTime.now()); + this.setLastModifiedDateTime(DateTime.now()); } public void assignUUID() { diff --git a/avni-server-api/src/main/java/org/avni/server/service/UserService.java b/avni-server-api/src/main/java/org/avni/server/service/UserService.java index c1ee5e559..d1eaa06f4 100644 --- a/avni-server-api/src/main/java/org/avni/server/service/UserService.java +++ b/avni-server-api/src/main/java/org/avni/server/service/UserService.java @@ -190,7 +190,7 @@ public void ensureSubjectForUser(User user, SubjectType subjectType) { subject.setSubjectType(subjectType); subject.setFirstName(user.getName()); subject.setOrganisationId(subjectType.getOrganisationId()); - subject.setRegistrationDate(DateTimeUtil.toJodaDate(user.getCreatedDateTime())); + subject.setRegistrationDate(user.getCreatedDateTime().toLocalDate()); subject.assignUUID(); userSubject.setSubject(subject); diff --git a/avni-server-api/src/main/java/org/avni/server/web/UserInfoController.java b/avni-server-api/src/main/java/org/avni/server/web/UserInfoController.java index 4470f821e..3c7fe23a2 100644 --- a/avni-server-api/src/main/java/org/avni/server/web/UserInfoController.java +++ b/avni-server-api/src/main/java/org/avni/server/web/UserInfoController.java @@ -138,7 +138,7 @@ public void saveMyProfile(@RequestBody UserInfoContract userInfo) { User user = userService.getCurrentUser(); user.setSettings(userInfo.getSettings()); user.setLastModifiedBy(user); - user.setLastModifiedDateTime(ZonedDateTime.now()); + user.setLastModifiedDateTime(DateTime.now()); userRepository.save(user); } diff --git a/avni-server-api/src/main/java/org/avni/server/web/request/UserContract.java b/avni-server-api/src/main/java/org/avni/server/web/request/UserContract.java index 905cf1962..cfbc7d080 100644 --- a/avni-server-api/src/main/java/org/avni/server/web/request/UserContract.java +++ b/avni-server-api/src/main/java/org/avni/server/web/request/UserContract.java @@ -46,9 +46,9 @@ public static UserContract fromEntity(User user) { userContract.setCatchmentId(user.getCatchmentId().orElse(null)); userContract.setSettings(user.getSettings()); userContract.setCreatedBy(user.getCreatedByUserName()); - userContract.setCreatedDateTime(DateTimeUtil.toJodaDateTime(user.getCreatedDateTime())); + userContract.setCreatedDateTime(user.getCreatedDateTime().toDateTime()); userContract.setLastModifiedBy(user.getLastModifiedByUserName()); - userContract.setLastModifiedDateTime(DateTimeUtil.toJodaDateTime(user.getLastModifiedDateTime())); + userContract.setLastModifiedDateTime(user.getLastModifiedDateTime().toDateTime()); userContract.setGroupIds(user.getUserGroups().stream() .map(userGroup -> userGroup.getGroupId()).collect(Collectors.toList())); userContract.setUserGroupNames(user.getUserGroups().stream() diff --git a/avni-server-api/src/main/java/org/avni/server/web/response/UserInfoWebResponse.java b/avni-server-api/src/main/java/org/avni/server/web/response/UserInfoWebResponse.java index 8c1910764..3d154355d 100644 --- a/avni-server-api/src/main/java/org/avni/server/web/response/UserInfoWebResponse.java +++ b/avni-server-api/src/main/java/org/avni/server/web/response/UserInfoWebResponse.java @@ -27,7 +27,7 @@ public static UserInfoWebResponse createForAdminUser(List