Skip to content

Commit

Permalink
#813 - removed zoned date time and using instant
Browse files Browse the repository at this point in the history
  • Loading branch information
petmongrels committed Nov 6, 2024
1 parent c6985a9 commit 49cc333
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 21 deletions.
28 changes: 15 additions & 13 deletions avni-server-api/src/main/java/org/avni/server/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static UserInfoWebResponse createForAdminUser(List<UserPrivilegeWebRespon
response.isAdmin = true;
response.setName(user.getName());
response.setUsername(user.getUsername());
response.setLastModifiedDateTime(DateTimeUtil.toJodaDateTime(user.getLastModifiedDateTime()));
response.setLastModifiedDateTime(user.getLastModifiedDateTime().toDateTime());
if (contextOrganisation != null) {
response.setOrganisationId(contextOrganisation.getId());
response.setOrganisationName(contextOrganisation.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.avni.server.web.request.syncAttribute.UserSyncSettings;
import org.joda.time.DateTime;

import java.time.ZonedDateTime;
import java.util.UUID;

public class UserBuilder {
Expand Down Expand Up @@ -55,8 +54,8 @@ public UserBuilder withOperatingIndividualScope(OperatingIndividualScope operati

public UserBuilder withDefaultValuesForNewEntity() {
String placeholder = UUID.randomUUID().toString();
user.setCreatedDateTime(ZonedDateTime.now());
user.setLastModifiedDateTime(ZonedDateTime.now());
user.setCreatedDateTime(DateTime.now());
user.setLastModifiedDateTime(DateTime.now());
user.setName(placeholder);
return userName(placeholder).phoneNumber(placeholder.substring(0, 10)).withUuid(placeholder).withOperatingIndividualScope(OperatingIndividualScope.None);
}
Expand Down

0 comments on commit 49cc333

Please sign in to comment.