Skip to content

Commit

Permalink
KNL-1581 Remove deprecated methods User.java - > getCreatedTime, getM…
Browse files Browse the repository at this point in the history
…odifiedTime (sakaiproject#5222)

* KNL-1581 User delete: Time getModifiedTime(), Time getCreatedTime()

* KNL-1581
  • Loading branch information
axxter99 authored and jonespm committed Mar 13, 2018
1 parent 9d81f9d commit 4ef7b55
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ public TempUser(String eid, String email, String firstName, String lastName, Str
@Override public User getCreatedBy() { return null; }
@Override public Date getCreatedDate() { return null; }
@Override public Date getModifiedDate() { return null; }
@Override public Time getCreatedTime() { return null; }
@Override public Time getModifiedTime() { return null; }
@Override public int compareTo(Object o) { return 0; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.sakaiproject.entitybroker.entityprovider.annotations.EntityLastModified;
import org.sakaiproject.entitybroker.entityprovider.annotations.EntityOwner;
import org.sakaiproject.entitybroker.entityprovider.annotations.EntityTitle;
import org.sakaiproject.time.api.Time;
import org.sakaiproject.user.api.User;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
Expand Down Expand Up @@ -84,7 +83,7 @@ public EntityUser(User user) {
this.displayName = user.getDisplayName();
this.displayId = user.getDisplayId();
this.owner = user.getCreatedBy() == null ? null : "/user/" + user.getCreatedBy().getId();
this.lastModified = user.getModifiedTime() == null ? System.currentTimeMillis() : user.getModifiedTime().getTime();
this.lastModified = user.getModifiedDate() == null ? System.currentTimeMillis() : user.getModifiedDate().getTime();
this.type = user.getType();
ResourceProperties rp = user.getProperties();
for (Iterator<String> iterator = rp.getPropertyNames(); iterator.hasNext();) {
Expand Down Expand Up @@ -224,13 +223,6 @@ public User getCreatedBy() {
throw new UnsupportedOperationException();
}

public Time getCreatedTime() {
if (user != null) {
return user.getCreatedTime();
}
throw new UnsupportedOperationException();
}

public Date getCreatedDate() {
if (user != null) {
return user.getCreatedDate();
Expand All @@ -249,12 +241,6 @@ public User getModifiedBy() {
throw new UnsupportedOperationException();
}

public Time getModifiedTime() {
if (user != null) {
return user.getModifiedTime();
}
throw new UnsupportedOperationException();
}

public Date getModifiedDate() {
if (user != null) {
Expand Down
12 changes: 1 addition & 11 deletions kernel/api/src/main/java/org/sakaiproject/user/api/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,13 @@ public interface User extends Entity, Comparable
*/
User getModifiedBy();

/**
* @return the time created.
* @deprecated see {@link #getCreatedDate()}
*
*/
Time getCreatedTime();


/**
* @return the time created.
*/
Date getCreatedDate();

/**
* @return the time last modified.
* @deprecated see {@link #getModifiedDate()}
*/
Time getModifiedTime();

/**
* @return the time last modified.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,79 @@

package org.sakaiproject.user.impl;

import java.util.*;

import lombok.extern.slf4j.Slf4j;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Observable;
import java.util.Observer;
import java.util.Set;
import java.util.Stack;
import java.util.TreeSet;
import java.util.Vector;

import org.apache.commons.lang3.StringUtils;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import org.sakaiproject.authz.api.*;
import org.sakaiproject.authz.api.AuthzGroupService;
import org.sakaiproject.authz.api.AuthzPermissionException;
import org.sakaiproject.authz.api.FunctionManager;
import org.sakaiproject.authz.api.GroupNotDefinedException;
import org.sakaiproject.authz.api.SecurityService;
import org.sakaiproject.component.api.ServerConfigurationService;
import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.entity.api.*;
import org.sakaiproject.entity.api.Entity;
import org.sakaiproject.entity.api.EntityManager;
import org.sakaiproject.entity.api.HttpAccess;
import org.sakaiproject.entity.api.Reference;
import org.sakaiproject.entity.api.ResourceProperties;
import org.sakaiproject.entity.api.ResourcePropertiesEdit;
import org.sakaiproject.event.api.Event;
import org.sakaiproject.event.api.EventTrackingService;
import org.sakaiproject.id.api.IdManager;
import org.sakaiproject.memory.api.Cache;
import org.sakaiproject.memory.api.MemoryService;
import org.sakaiproject.time.api.Time;
import org.sakaiproject.time.api.TimeService;
import org.sakaiproject.tool.api.SessionBindingEvent;
import org.sakaiproject.tool.api.SessionBindingListener;
import org.sakaiproject.tool.api.SessionManager;
import org.sakaiproject.user.api.*;
import org.sakaiproject.user.api.AuthenticatedUserProvider;
import org.sakaiproject.user.api.AuthenticationIdUDP;
import org.sakaiproject.user.api.AuthenticationManager;
import org.sakaiproject.user.api.ContextualUserDisplayService;
import org.sakaiproject.user.api.DisplayAdvisorUDP;
import org.sakaiproject.user.api.DisplaySortAdvisorUPD;
import org.sakaiproject.user.api.ExternalUserSearchUDP;
import org.sakaiproject.user.api.PasswordPolicyProvider;
import org.sakaiproject.user.api.User;
import org.sakaiproject.user.api.UserAlreadyDefinedException;
import org.sakaiproject.user.api.UserDirectoryProvider;
import org.sakaiproject.user.api.UserDirectoryService;
import org.sakaiproject.user.api.UserEdit;
import org.sakaiproject.user.api.UserFactory;
import org.sakaiproject.user.api.UserIdInvalidException;
import org.sakaiproject.user.api.UserLockedException;
import org.sakaiproject.user.api.UserNotDefinedException;
import org.sakaiproject.user.api.UserPermissionException;
import org.sakaiproject.user.api.UsersShareEmailUDP;
import org.sakaiproject.util.BaseResourceProperties;
import org.sakaiproject.util.BaseResourcePropertiesEdit;
import org.sakaiproject.util.StringUtil;
import org.sakaiproject.util.Validator;
import org.sakaiproject.util.api.FormattedText;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import lombok.extern.slf4j.Slf4j;

/**
* <p>
Expand Down Expand Up @@ -1712,9 +1754,8 @@ protected void addLiveProperties(BaseUserEdit edit)
edit.m_createdUserId = current;
edit.m_lastModifiedUserId = current;

Time now = timeService().newTime();
edit.m_createdTime = now;
edit.m_lastModifiedTime = (Time) now.clone();
edit.m_createdInstant = Instant.now();
edit.m_lastModifiedInstant = Instant.now();
}

/**
Expand All @@ -1725,7 +1766,7 @@ protected void addLiveUpdateProperties(BaseUserEdit edit)
String current = sessionManager().getCurrentSessionUserId();

edit.m_lastModifiedUserId = current;
edit.m_lastModifiedTime = timeService().newTime();
edit.m_lastModifiedInstant = Instant.now();
}

/**
Expand Down Expand Up @@ -2089,10 +2130,10 @@ public class BaseUserEdit implements UserEdit, SessionBindingListener
protected String m_lastModifiedUserId = null;

/** The time created. */
protected Time m_createdTime = null;
protected Instant m_createdInstant = null;

/** The time last modified. */
protected Time m_lastModifiedTime = null;
protected Instant m_lastModifiedInstant = null;

/** If editing the first name is restricted **/
protected boolean m_restrictedFirstName = false;
Expand Down Expand Up @@ -2185,13 +2226,13 @@ public BaseUserEdit(Element el)
String time = StringUtils.trimToNull(el.getAttribute("created-time"));
if (time != null)
{
m_createdTime = timeService().newTimeGmt(time);
m_createdInstant = Instant.ofEpochMilli(timeService().newTimeGmt(time).getTime());
}

time = StringUtils.trimToNull(el.getAttribute("modified-time"));
if (time != null)
{
m_lastModifiedTime = timeService().newTimeGmt(time);
m_lastModifiedInstant = Instant.ofEpochMilli(timeService().newTimeGmt(time).getTime());
}

// the children (roles, properties)
Expand All @@ -2218,21 +2259,21 @@ public BaseUserEdit(Element el)
{
m_lastModifiedUserId = m_properties.getProperty("CHEF:modifiedby");
}
if (m_createdTime == null)
if (m_createdInstant == null)
{
try
{
m_createdTime = m_properties.getTimeProperty("DAV:creationdate");
m_createdInstant = m_properties.getInstantProperty("DAV:creationdate");
}
catch (Exception ignore)
{
}
}
if (m_lastModifiedTime == null)
if (m_lastModifiedInstant == null)
{
try
{
m_lastModifiedTime = m_properties.getTimeProperty("DAV:getlastmodified");
m_lastModifiedInstant = m_properties.getInstantProperty("DAV:getlastmodified");
}
catch (Exception ignore)
{
Expand Down Expand Up @@ -2273,7 +2314,7 @@ public BaseUserEdit(Element el)
* The modified on property.
*/
public BaseUserEdit(String id, String eid, String email, String firstName, String lastName, String type, String pw,
String createdBy, Time createdOn, String modifiedBy, Time modifiedOn)
String createdBy, Instant createdOn, String modifiedBy, Instant modifiedOn)
{
m_id = id;
m_eid = eid;
Expand All @@ -2284,8 +2325,8 @@ public BaseUserEdit(String id, String eid, String email, String firstName, Strin
m_pw = pw;
m_createdUserId = createdBy;
m_lastModifiedUserId = modifiedBy;
m_createdTime = createdOn;
m_lastModifiedTime = modifiedOn;
if (createdOn != null) m_createdInstant = createdOn;
if (modifiedBy != null) m_lastModifiedInstant = modifiedOn;

// setup for properties, but mark them lazy since we have not yet established them from data
BaseResourcePropertiesEdit props = new BaseResourcePropertiesEdit();
Expand All @@ -2310,9 +2351,9 @@ protected void setAll(User user)
m_pw = ((BaseUserEdit) user).m_pw;
m_createdUserId = ((BaseUserEdit) user).m_createdUserId;
m_lastModifiedUserId = ((BaseUserEdit) user).m_lastModifiedUserId;
if (((BaseUserEdit) user).m_createdTime != null) m_createdTime = (Time) ((BaseUserEdit) user).m_createdTime.clone();
if (((BaseUserEdit) user).m_lastModifiedTime != null)
m_lastModifiedTime = (Time) ((BaseUserEdit) user).m_lastModifiedTime.clone();
if (((BaseUserEdit) user).m_createdInstant != null) m_createdInstant = (Instant) ((BaseUserEdit) user).m_createdInstant;
if (((BaseUserEdit) user).m_lastModifiedInstant != null)
m_lastModifiedInstant = (Instant) ((BaseUserEdit) user).m_lastModifiedInstant;

m_properties = new BaseResourcePropertiesEdit();
m_properties.addAll(user.getProperties());
Expand Down Expand Up @@ -2345,15 +2386,18 @@ public Element toXml(Document doc, Stack<Element> stack)
user.setAttribute("email", getEmail());
user.setAttribute("created-id", m_createdUserId);
user.setAttribute("modified-id", m_lastModifiedUserId);
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");

if (m_createdTime != null)
if (m_createdInstant != null)
{
user.setAttribute("created-time", m_createdTime.toString());
LocalDateTime localDateTime = LocalDateTime.ofInstant(m_createdInstant, ZoneId.of("UTC"));
user.setAttribute("created-time", localDateTime.format(dtf));
}

if (m_lastModifiedTime != null)
if (m_lastModifiedInstant != null)
{
user.setAttribute("modified-time", m_lastModifiedTime.toString());
LocalDateTime localDateTime = LocalDateTime.ofInstant(m_lastModifiedInstant, ZoneId.of("UTC"));
user.setAttribute("modified-time", localDateTime.format(dtf));
}

// properties
Expand Down Expand Up @@ -2457,42 +2501,27 @@ public User getModifiedBy()
}
}

/**
* @inheritDoc
*/
public Time getCreatedTime()
{
return m_createdTime;
}

/**
* @inheritDoc
*/
public Date getCreatedDate()
{
Date date = null;
if (m_createdTime != null)
if (m_createdInstant != null)
{
date = new Date(m_createdTime.getTime());
date = new Date(m_createdInstant.toEpochMilli());
}
return date;
}
/**
* @inheritDoc
*/
public Time getModifiedTime()
{
return m_lastModifiedTime;
}

/**
* @inheritDoc
*/
public Date getModifiedDate()
{
Date date = null;
if (m_lastModifiedTime != null) {
date = new Date(m_lastModifiedTime.getTime());
if (m_lastModifiedInstant != null) {
date = new Date(m_lastModifiedInstant.getEpochSecond());
}
return date;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.Instant;
import java.util.*;

import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -416,8 +417,8 @@ protected Object[] fields(String id, UserEdit edit, boolean idAgain)
rv[8] = rv[0];
}

rv[9] = edit.getCreatedTime();
rv[10] = edit.getModifiedTime();
rv[9] = edit.getCreatedDate();
rv[10] = edit.getModifiedDate();
}

return rv;
Expand All @@ -443,8 +444,8 @@ public Object readSqlResultRecord(ResultSet result)
String pw = result.getString(7);
String createdBy = result.getString(8);
String modifiedBy = result.getString(9);
Time createdOn = timeService().newTime(result.getTimestamp(10, sqlService().getCal()).getTime());
Time modifiedOn = timeService().newTime(result.getTimestamp(11, sqlService().getCal()).getTime());
Instant createdOn = Instant.ofEpochMilli(result.getTimestamp(10, sqlService().getCal()).getTime());
Instant modifiedOn = Instant.ofEpochMilli(result.getTimestamp(11, sqlService().getCal()).getTime());

// find the eid from the mapping
String eid = checkMapForEid(id);
Expand Down Expand Up @@ -846,8 +847,8 @@ public Object readSqlResultRecord(ResultSet result) throws SqlReaderFinishedExce
String pw = result.getString(8);
String createdBy = result.getString(9);
String modifiedBy = result.getString(10);
Time createdOn = (result.getObject(11) != null) ? timeService().newTime(result.getTimestamp(11, sqlService().getCal()).getTime()) : null;
Time modifiedOn = (result.getObject(12) != null) ? timeService().newTime(result.getTimestamp(12, sqlService().getCal()).getTime()) : null;
Instant createdOn = (result.getObject(11) != null) ? Instant.ofEpochMilli(result.getTimestamp(11, sqlService().getCal()).getTime()) : null;
Instant modifiedOn = (result.getObject(12) != null) ? Instant.ofEpochMilli(result.getTimestamp(12, sqlService().getCal()).getTime()) : null;

// create the Resource from these fields
userEdit = new BaseUserEdit(idFromMap, eidFromMap, email, firstName, lastName, type, pw, createdBy, createdOn, modifiedBy, modifiedOn);
Expand Down

0 comments on commit 4ef7b55

Please sign in to comment.