Skip to content

Commit

Permalink
SAK-40284 Admin-tool: Time -> Date (sakaiproject#5768)
Browse files Browse the repository at this point in the history
* SAK-40284
 CreatedTime => CreatedDate
 ModifiedTime => ModifiedDate
 Site Admin cover =api

* SAK-40284 Avoid unused local variables

* SAK-40284 UserTimeService.dateFormatLong(Date date, Locale locale)
UserTimeService.dateTimeFormatLong(Date date, Locale locale)

* SAK-40284 calendar test
  • Loading branch information
axxter99 authored and ern committed Jul 31, 2018
1 parent ea5d2fc commit 74cc617
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package org.sakaiproject.archive.tool;


import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand All @@ -30,15 +29,15 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.sakaiproject.authz.api.SecurityService;
import org.sakaiproject.component.api.ComponentManager;
import org.sakaiproject.component.api.ServerConfigurationService;
import org.sakaiproject.tool.api.SessionManager;

import lombok.extern.slf4j.Slf4j;

/**
* Download servlet for archive downloads. Restricted to super user as per normal archive tool
*
Expand Down
109 changes: 60 additions & 49 deletions admin-tools/src/java/org/sakaiproject/site/tool/AdminSitesAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

package org.sakaiproject.site.tool;

import static org.sakaiproject.site.api.SiteService.SITE_TITLE_MAX_LENGTH;

import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
Expand All @@ -31,17 +33,14 @@
import java.util.Set;
import java.util.Vector;

import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang3.StringUtils;

import org.sakaiproject.alias.api.Alias;
import org.sakaiproject.alias.api.AliasService;
import org.sakaiproject.authz.api.AuthzGroup;
import org.sakaiproject.authz.api.AuthzGroupService;
import org.sakaiproject.authz.api.GroupNotDefinedException;
import org.sakaiproject.authz.api.Role;
import org.sakaiproject.authz.cover.SecurityService;
import org.sakaiproject.authz.api.SecurityService;
import org.sakaiproject.cheftool.Context;
import org.sakaiproject.cheftool.JetspeedRunData;
import org.sakaiproject.cheftool.PagedResourceActionII;
Expand All @@ -58,8 +57,8 @@
import org.sakaiproject.courier.api.ObservingCourier;
import org.sakaiproject.entity.api.Entity;
import org.sakaiproject.entity.api.ResourcePropertiesEdit;
import org.sakaiproject.event.api.EventTrackingService;
import org.sakaiproject.event.api.SessionState;
import org.sakaiproject.event.cover.EventTrackingService;
import org.sakaiproject.exception.IdInvalidException;
import org.sakaiproject.exception.IdUnusedException;
import org.sakaiproject.exception.IdUsedException;
Expand All @@ -68,22 +67,22 @@
import org.sakaiproject.site.api.Group;
import org.sakaiproject.site.api.Site;
import org.sakaiproject.site.api.SitePage;
import static org.sakaiproject.site.api.SiteService.SITE_TITLE_MAX_LENGTH;
import org.sakaiproject.site.api.SiteService;
import org.sakaiproject.site.api.SiteService.SiteTitleValidationStatus;
import org.sakaiproject.site.api.ToolConfiguration;
import org.sakaiproject.site.cover.SiteService;
import org.sakaiproject.tool.api.Session;
import org.sakaiproject.time.api.UserTimeService;
import org.sakaiproject.tool.api.SessionManager;
import org.sakaiproject.tool.api.Tool;
import org.sakaiproject.tool.api.ToolSession;
import org.sakaiproject.tool.cover.SessionManager;
import org.sakaiproject.tool.cover.ToolManager;
import org.sakaiproject.tool.api.ToolManager;
import org.sakaiproject.user.api.User;
import org.sakaiproject.user.api.UserDirectoryService;
import org.sakaiproject.user.api.UserNotDefinedException;
import org.sakaiproject.user.cover.UserDirectoryService;
import org.sakaiproject.util.FormattedText;
import org.sakaiproject.util.ResourceLoader;
import org.sakaiproject.util.Validator;

import lombok.extern.slf4j.Slf4j;

/**
* <p>
* SitesAction is the Sakai admin sites editor.
Expand Down Expand Up @@ -119,11 +118,27 @@ public class AdminSitesAction extends PagedResourceActionII

private AliasService aliasService;
private AuthzGroupService authzGroupService;
private UserDirectoryService userDirectoryService;
private ToolManager toolManager;
private SessionManager sessionManager;
private SiteService siteService;
private EventTrackingService eventTrackingService;
private SecurityService securityService;
private UserTimeService userTimeService;

public AdminSitesAction() {
super();
aliasService = ComponentManager.get(AliasService.class);
authzGroupService = ComponentManager.get(AuthzGroupService.class);
userDirectoryService = ComponentManager.get(UserDirectoryService.class);
toolManager = ComponentManager.get(ToolManager.class);
sessionManager = ComponentManager.get(SessionManager.class);
siteService = ComponentManager.get(SiteService.class);
eventTrackingService = ComponentManager.get(EventTrackingService.class);
securityService = ComponentManager.get(SecurityService.class);
userTimeService = ComponentManager.get(UserTimeService.class);


}

/**
Expand All @@ -144,7 +159,7 @@ protected List readResourcesPage(SessionState state, int first, int last)
List rv = new Vector();
try
{
Site site = SiteService.getSite(siteId);
Site site = siteService.getSite(siteId);
rv.add(site);
}
catch (IdUnusedException e)
Expand All @@ -169,14 +184,14 @@ else if (userId != null)
// search for non-user sites, using the criteria
else if (search != null)
{
return SiteService.getSites(org.sakaiproject.site.api.SiteService.SelectionType.NON_USER, null, search, null,
return siteService.getSites(org.sakaiproject.site.api.SiteService.SelectionType.NON_USER, null, search, null,
org.sakaiproject.site.api.SiteService.SortType.TITLE_ASC, new PagingPosition(first, last));
}

// otherwise just show a page of all
else
{
return SiteService.getSites(org.sakaiproject.site.api.SiteService.SelectionType.ANY, null, search, null,
return siteService.getSites(org.sakaiproject.site.api.SiteService.SelectionType.ANY, null, search, null,
org.sakaiproject.site.api.SiteService.SortType.TITLE_ASC, new PagingPosition(first, last));
}
}
Expand All @@ -196,7 +211,7 @@ protected int sizeResources(SessionState state)
{
try
{
Site site = SiteService.getSite(siteId);
siteService.getSite(siteId);
return 1;
}
catch (IdUnusedException e)
Expand All @@ -217,12 +232,12 @@ else if (userId != null)

else if (search != null)
{
return SiteService.countSites(org.sakaiproject.site.api.SiteService.SelectionType.NON_USER, null, search, null);
return siteService.countSites(org.sakaiproject.site.api.SiteService.SelectionType.NON_USER, null, search, null);
}

else
{
return SiteService.countSites(org.sakaiproject.site.api.SiteService.SelectionType.ANY, null, search, null);
return siteService.countSites(org.sakaiproject.site.api.SiteService.SelectionType.ANY, null, search, null);
}
}

Expand Down Expand Up @@ -269,7 +284,7 @@ protected Site findUserSiteByUserIdCriteria(String formSubmittedUserId) {
protected User findUserByPk(String userPk) {

try {
User user = UserDirectoryService.getUser(userPk);
User user = userDirectoryService.getUser(userPk);
return user;
} catch ( UserNotDefinedException e ) {
log.debug("Failed to find a user record by PK [pk = {}]", userPk, e);
Expand All @@ -290,7 +305,7 @@ protected User findUserByPk(String userPk) {
protected User findUserByEid(String eid) {

try {
User user = UserDirectoryService.getUserByEid(eid);
User user = userDirectoryService.getUserByEid(eid);
return user;
} catch ( UserNotDefinedException e ) {
log.debug("Failed to find a user record by EID [eid = {}]", eid, e);
Expand All @@ -309,9 +324,9 @@ protected User findUserByEid(String eid) {
protected Site findUserSite(User knownUser) {
String userDbId = knownUser.getId();
String userEid = knownUser.getEid();
String userMyWorkspaceSiteDbId = SiteService.getUserSiteId(userDbId);
String userMyWorkspaceSiteDbId = siteService.getUserSiteId(userDbId);
try {
Site userSite = SiteService.getSite(userMyWorkspaceSiteDbId); // exceptional if no results
Site userSite = siteService.getSite(userMyWorkspaceSiteDbId); // exceptional if no results
return userSite;
} catch ( IdUnusedException e ) {
log.debug("Failed to locate a workspace for user [user id = {}][user eid = {}][site id = {}]", userDbId, userEid, userMyWorkspaceSiteDbId, e);
Expand Down Expand Up @@ -350,20 +365,14 @@ public String buildMainPanelContext(VelocityPortlet portlet, Context context, Ru
context.put("tlang", rb);

// if not logged in as the super user, we won't do anything
if (!SecurityService.isSuperUser())
if (!securityService.isSuperUser())
{
context.put("tlang",rb);
return (String) getContext(rundata).get("template") + "_noaccess";
}

String template = null;

// get the Sakai session
Session session = SessionManager.getCurrentSession();

// get the Tool session
ToolSession toolSession = SessionManager.getCurrentToolSession();

// check mode and dispatch
String mode = (String) state.getAttribute("mode");
if (mode == null)
Expand Down Expand Up @@ -462,7 +471,8 @@ else if (mode.equals("editTool"))
private String buildListContext(SessionState state, Context context)
{
// put the service in the context (used for allow update calls on each site)
context.put("service", SiteService.getInstance());
context.put("service", siteService);
context.put("userTimeService", userTimeService);

// prepare the paging of realms
List sites = prepPage(state);
Expand All @@ -473,7 +483,7 @@ private String buildListContext(SessionState state, Context context)

// build the menu
Menu bar = new MenuImpl();
if (SiteService.allowAddSite(null))
if (siteService.allowAddSite(null))
{
bar.add(new MenuEntry(rb.getString("sitact.newsit"), "doNew"));
}
Expand Down Expand Up @@ -560,6 +570,7 @@ private String buildEditContext(SessionState state, Context context)
context.put("tlang", rb);
Site site = (Site) state.getAttribute("site");
context.put("site", site);
context.put("userTimeService", userTimeService);

// name the html form for user edit fields
context.put("form-name", "site-form");
Expand All @@ -586,7 +597,7 @@ private String buildEditContext(SessionState state, Context context)
// build the menu
// we need the form fields for the remove...
Menu bar = new MenuImpl();
if (site!= null && SiteService.allowRemoveSite(site.getId()))
if (site!= null && siteService.allowRemoveSite(site.getId()))
{
bar.add(new MenuEntry(rb.getString("sitact.remsit"), null, true, MenuItem.CHECKED_NA, "doRemove", null));
}
Expand Down Expand Up @@ -881,12 +892,12 @@ public int compare(Object tool0, Object tool1) {
}

// get all tools
Set all = ToolManager.findTools(null, null);
Set all = toolManager.findTools(null, null);

// get the helpers
Set categories = new HashSet();
categories.add("sakai.helper");
Set helpers = ToolManager.findTools(categories, null);
Set helpers = toolManager.findTools(categories, null);

// remove the helpers from all
all.removeAll(helpers);
Expand Down Expand Up @@ -954,12 +965,12 @@ public void doEdit(RunData data, Context context)
SessionState state = ((JetspeedRunData) data).getPortletSessionState(((JetspeedRunData) data).getJs_peid());
String id = data.getParameters().getString("id");

if (SiteService.allowUpdateSite(id))
if (siteService.allowUpdateSite(id))
{
// get the site
try
{
Site site = SiteService.getSite(id);
Site site = siteService.getSite(id);
state.setAttribute("site", site);

// RealmEdit realm = authzGroupService.editRealm("/site/" + id); // %%% use a site service call -ggolden
Expand Down Expand Up @@ -1024,14 +1035,14 @@ public void doSave(RunData data, Context context)
if (currentSitePublished && !afterSitePublished)
{
// site unpublished
EventTrackingService.post(EventTrackingService.newEvent(
eventTrackingService.post(eventTrackingService.newEvent(
SiteService.EVENT_SITE_UNPUBLISH,
site.getReference(), true));
}
else if (!currentSitePublished && afterSitePublished)
{
// site published
EventTrackingService.post(EventTrackingService.newEvent(
eventTrackingService.post(eventTrackingService.newEvent(
SiteService.EVENT_SITE_PUBLISH,
site.getReference(), true));
}
Expand Down Expand Up @@ -1131,7 +1142,7 @@ public void doSave_edit(RunData data, Context context)
}
}

SiteService.save(site);
siteService.save(site);
}
catch (PermissionException | IdUnusedException e)
{
Expand Down Expand Up @@ -1192,7 +1203,7 @@ public void doSaveas(RunData data, Context context)
try
{
// make a new site with this id and as a structural copy of site
Site newSite = SiteService.addSite(id, site);
siteService.addSite(id, site);
}
catch (IdUsedException e)
{
Expand Down Expand Up @@ -1264,7 +1275,7 @@ public void doCancel(RunData data, Context context)
// remove the site
try
{
SiteService.removeSite(site);
siteService.removeSite(site);
}
catch (PermissionException e)
{
Expand Down Expand Up @@ -1326,7 +1337,7 @@ public void doRemove_confirmed(RunData data, Context context)
// remove the site
try
{
SiteService.removeSite(site);
siteService.removeSite(site);
}
catch (PermissionException e)
{
Expand Down Expand Up @@ -1390,7 +1401,7 @@ private boolean readSiteForm(RunData data, SessionState state)
// Site title is editable; cannot but null/empty after HTML stripping, and cannot exceed max length
String titleOrig = data.getParameters().getString("title");
String titleStripped = FormattedText.stripHtmlFromText(titleOrig, true, true);
SiteTitleValidationStatus status = SiteService.validateSiteTitle(titleOrig, titleStripped);
SiteTitleValidationStatus status = siteService.validateSiteTitle(titleOrig, titleStripped);

if (SiteTitleValidationStatus.STRIPPED_TO_EMPTY.equals(status)) {
addAlert(state, rb.getString("siteTitle.htmlStrippedToEmpty"));
Expand All @@ -1411,7 +1422,7 @@ private boolean readSiteForm(RunData data, SessionState state)
{
try
{
site = SiteService.addSite(id, type);
site = siteService.addSite(id, type);
// mark the site as new, so on cancel it can be deleted
site.getPropertiesEdit().addProperty("new", "true");

Expand Down Expand Up @@ -2600,8 +2611,8 @@ private boolean readToolFeatureForm(RunData data, SessionState state)
// if the feature has changed, update the default configuration
if ((t == null) || (!feature.equals(t.getId())))
{
tool.setTool(feature, ToolManager.getTool(feature));
tool.setTitle(ToolManager.getTool(feature).getTitle());
tool.setTool(feature, toolManager.getTool(feature));
tool.setTitle(toolManager.getTool(feature).getTitle());
tool.getPlacementConfig().clear();
}

Expand Down Expand Up @@ -2640,7 +2651,7 @@ public boolean displaySiteAlias() {
private List layoutsList()
{
List rv = new Vector();
String[] layoutNames = SiteService.getLayoutNames();
String[] layoutNames = siteService.getLayoutNames();
for (int i = 0; i < layoutNames.length; i++)
{
rv.add(layoutNames[i]);
Expand Down Expand Up @@ -2699,8 +2710,8 @@ else if (StringUtils.trimToNull(alias) != null && StringUtils.trimToNull(siteRef
addAlert(state, rb.getFormattedMessage("sitedipag.alias.isinval", new Object[]{alias}));
log.warn("{}.setSiteAlias: {}", this, rb.getFormattedMessage("sitedipag.alias.isinval", new Object[]{alias}));
} catch (PermissionException ee) {
addAlert(state, rb.getFormattedMessage("sitedipag.alias.nopermission", new Object[]{SessionManager.getCurrentSessionUserId()}));
log.warn("{}.setSiteAlias: {}", this, rb.getFormattedMessage("sitedipag.alias.nopermission", new Object[]{SessionManager.getCurrentSessionUserId()}));
addAlert(state, rb.getFormattedMessage("sitedipag.alias.nopermission", new Object[]{sessionManager.getCurrentSessionUserId()}));
log.warn("{}.setSiteAlias: {}", this, rb.getFormattedMessage("sitedipag.alias.nopermission", new Object[]{sessionManager.getCurrentSessionUserId()}));
}
}
}
Expand Down
Loading

0 comments on commit 74cc617

Please sign in to comment.