Skip to content

Commit

Permalink
more service clean up in handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
ern committed Aug 26, 2024
1 parent 448b30f commit 2490614
Show file tree
Hide file tree
Showing 17 changed files with 277 additions and 639 deletions.
4 changes: 1 addition & 3 deletions portal/portal-impl/impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>3.7.0</version>
<scope>test</scope>
<artifactId>mockito-core</artifactId>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@
import org.sakaiproject.portal.api.PortalService;
import org.sakaiproject.portal.util.PortalUtils;
import org.sakaiproject.site.api.Site;
import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.time.api.TimeService;
import org.sakaiproject.time.api.UserTimeService;
import org.sakaiproject.tool.api.Session;
import org.sakaiproject.util.ResourceLoader;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;


/**
Expand All @@ -54,15 +56,8 @@
*
*/
@Slf4j
public abstract class BasePortalHandler implements PortalHandler
{
public BasePortalHandler()
{
urlFragment = "none";
timeService = ComponentManager.get(TimeService.class);
}

private TimeService timeService;
public abstract class BasePortalHandler implements PortalHandler {
@Autowired UserTimeService timeService;

protected PortalService portalService;

Expand All @@ -72,6 +67,11 @@ public BasePortalHandler()

protected ServletContext servletContext;

public BasePortalHandler() {
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
urlFragment = "none";
}

public abstract int doGet(String[] parts, HttpServletRequest req,
HttpServletResponse res, Session session) throws PortalHandlerException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@
import org.sakaiproject.tool.cover.ActiveToolManager;
import org.sakaiproject.tool.cover.SessionManager;
import org.sakaiproject.util.Web;
import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.component.api.ServerConfigurationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;

/**
* Handler to process directtool urls including storing destination state
Expand All @@ -57,12 +58,12 @@
@Slf4j
public class DirectToolHandler extends BasePortalHandler
{
private static ServerConfigurationService serverConfigurationService = (ServerConfigurationService)ComponentManager.get(ServerConfigurationService.class);
@Autowired private ServerConfigurationService serverConfigurationService;

public static final String URL_FRAGMENT = "directtool";

public DirectToolHandler()
{
public DirectToolHandler() {
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
setUrlFragment(DirectToolHandler.URL_FRAGMENT);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,20 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.sakaiproject.authz.api.AuthzGroupService;
import org.sakaiproject.component.cover.ServerConfigurationService;
import org.sakaiproject.exception.IdUnusedException;
import org.sakaiproject.exception.PermissionException;
import org.sakaiproject.portal.api.Portal;
import org.sakaiproject.portal.api.PortalHandlerException;
import org.sakaiproject.portal.api.PortalRenderContext;
import org.sakaiproject.portal.charon.site.PortalSiteHelperImpl;
import org.sakaiproject.site.api.Site;
import org.sakaiproject.site.cover.SiteService;
import org.sakaiproject.site.api.SiteService;
import org.sakaiproject.tool.api.Session;
import org.sakaiproject.tool.api.ToolException;
import org.sakaiproject.portal.util.URLUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;

/**
* Handler for managing the joining of a user to a site.
Expand All @@ -47,8 +49,11 @@ public class JoinHandler extends BasePortalHandler

private static final String URL_FRAGMENT = "join";

public JoinHandler()
{
@Autowired private AuthzGroupService authzGroupService;
@Autowired private SiteService siteService;

public JoinHandler() {
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
setUrlFragment(URL_FRAGMENT);
}

Expand Down Expand Up @@ -98,7 +103,7 @@ protected void doJoin(String[] parts, HttpServletRequest req,
if (site == null) {
throw new IdUnusedException(siteId);
}
SiteService.getInstance().join(site.getId());
siteService.join(site.getId());
sendToSite(res, site);
} else {
// The user didn't opt to join
Expand Down Expand Up @@ -145,7 +150,7 @@ protected void showJoin(String[] parts, HttpServletRequest req,
throw new IdUnusedException(siteId);
}
// Check that the current user can access the site before we redirect.
if (site.getUserRole(session.getUserId()) != null && SiteService.allowAccessSite(site.getId()))
if (site.getUserRole(session.getUserId()) != null && siteService.allowAccessSite(site.getId()))
{
sendToSite(res, site);
return;
Expand All @@ -156,15 +161,15 @@ protected void showJoin(String[] parts, HttpServletRequest req,
String serviceName = ServerConfigurationService.getString("ui.service", "Sakai");

// SAK-29138
List<String> siteProviders = (List<String>) PortalSiteHelperImpl.getProviderIDsForSite(site);
List<String> siteProviders = (List<String>) authzGroupService.getProviderIds(site.getReference());
String title = serviceName + " : " + portal.getSiteHelper().getUserSpecificSiteTitle(site, true, false, siteProviders);

String skin = site.getSkin();
PortalRenderContext context = portal.startPageContext(siteType, title, skin, req, site);
context.put("currentSite", portal.getSiteHelper().convertSiteToMap(req, site, null, site.getId(), null, false, false, false, false, null, true, siteProviders));
context.put("uiService", serviceName);

boolean restrictedByAccountType = !SiteService.getInstance().isAllowedToJoin(site.getId());
boolean restrictedByAccountType = !siteService.isAllowedToJoin(site.getId());
context.put("restrictedByAccountType", restrictedByAccountType);

portal.sendResponse(context, res, "join", "text/html");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.apache.commons.lang3.StringUtils;

import org.sakaiproject.authz.api.SecurityService;
import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.component.cover.ServerConfigurationService;
import org.sakaiproject.exception.IdUnusedException;
import org.sakaiproject.exception.PermissionException;
Expand All @@ -54,6 +53,8 @@
import org.sakaiproject.tool.api.Session;
import org.sakaiproject.tool.api.ToolException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;

/**
* @author ieb
Expand All @@ -67,11 +68,10 @@ public class PageHandler extends BasePortalHandler

private static final String URL_FRAGMENT = "page";

private SecurityService securityService = null;
@Autowired private SecurityService securityService = null;

public PageHandler()
{
securityService = (SecurityService) ComponentManager.get("org.sakaiproject.authz.api.SecurityService");
public PageHandler() {
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
setUrlFragment(PageHandler.URL_FRAGMENT);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import javax.servlet.http.HttpServletResponse;

import org.sakaiproject.authz.api.SecurityService;
import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.component.cover.ServerConfigurationService;
import org.sakaiproject.event.api.EventTrackingService;
import org.sakaiproject.event.api.NotificationService;
Expand All @@ -31,21 +30,20 @@
import org.sakaiproject.site.api.SiteService;
import org.sakaiproject.tool.api.Session;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;

@Slf4j
public class RoleSwitchOutHandler extends BasePortalHandler
{
private static final String URL_FRAGMENT = "role-switch-out";

final EventTrackingService eventTrackingService;
final SecurityService securityService;
final SiteService siteService;
@Autowired private EventTrackingService eventTrackingService;
@Autowired private SecurityService securityService;
@Autowired private SiteService siteService;

public RoleSwitchOutHandler()
{
eventTrackingService = ComponentManager.get(EventTrackingService.class);
securityService = ComponentManager.get(SecurityService.class);
siteService = ComponentManager.get(SiteService.class);
public RoleSwitchOutHandler() {
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
setUrlFragment(RoleSwitchOutHandler.URL_FRAGMENT);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;
import org.sakaiproject.authz.api.AuthzGroupService;
import org.sakaiproject.authz.api.Role;
import org.sakaiproject.authz.api.SecurityService;
import org.sakaiproject.component.api.ServerConfigurationService;
Expand All @@ -59,7 +59,6 @@
import org.sakaiproject.portal.api.SiteView;
import org.sakaiproject.portal.api.StoredState;
import org.sakaiproject.portal.charon.site.AllSitesViewImpl;
import org.sakaiproject.portal.charon.site.PortalSiteHelperImpl;
import org.sakaiproject.portal.util.ByteArrayServletResponse;
import org.sakaiproject.portal.util.ToolUtils;
import org.sakaiproject.portal.util.URLUtils;
Expand Down Expand Up @@ -135,8 +134,8 @@ public class SiteHandler extends WorksiteHandler {
private static final String SAK_PROP_SHOW_SITE_LABELS = "portal.siteList.siteLabels";
private static final boolean SAK_PROP_SHOW_SITE_LABELS_DFLT = true;

@Autowired private AuthzGroupService authzGroupService;
@Autowired private CourseManagementService courseManagementService;
@Autowired private ActiveToolManager toolManager;
@Autowired private EventTrackingService eventTrackingService;
@Autowired private PreferencesService preferencesService;
@Autowired private PresenceService presenceService;
Expand All @@ -146,9 +145,9 @@ public class SiteHandler extends WorksiteHandler {
@Autowired private SessionManager sessionManager;
@Autowired private SiteService siteService;
@Autowired private ThreadLocalManager threadLocalManager;
@Autowired private ActiveToolManager toolManager;
@Autowired private UserDirectoryService userDirectoryService;
@Resource(name = "org.sakaiproject.time.api.UserTimeService")
private UserTimeService userTimeService;
@Autowired private UserTimeService userTimeService;

// When these strings appear in the URL they will be replaced by a calculated value based on the context.
// This can be replaced by the users myworkspace.
Expand Down Expand Up @@ -424,7 +423,7 @@ public void doSite(HttpServletRequest req, HttpServletResponse res, Session sess
session.removeAttribute(Portal.ATTR_SITE_PAGE + siteId);

// SAK-29138 - form a context sensitive title
List<String> providers = PortalSiteHelperImpl.getProviderIDsForSites(List.of(site)).get(site.getReference());
List<String> providers = new ArrayList<>(authzGroupService.getProviderIds(site.getReference()));
String title = serverConfigurationService.getString("ui.service","Sakai") + " : "
+ portal.getSiteHelper().getUserSpecificSiteTitle(site, false, false, providers);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
import org.sakaiproject.portal.api.PortalRenderContext;
import org.sakaiproject.tool.api.Session;
import org.sakaiproject.component.api.ServerConfigurationService;
import org.sakaiproject.component.cover.ComponentManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;

/**
* This is a portal handler to get the necessary information for the timeout
Expand Down Expand Up @@ -64,15 +65,13 @@ public class TimeoutDialogHandler extends BasePortalHandler
private static final String URL_FRAGMENT = "timeout";
private static final String CONFIG_PART = "config";

private ServerConfigurationService serverConfigService;
@Autowired private ServerConfigurationService serverConfigService;

public TimeoutDialogHandler()
{
public TimeoutDialogHandler() {
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
setUrlFragment(TimeoutDialogHandler.URL_FRAGMENT);
serverConfigService = (ServerConfigurationService)
ComponentManager.get(ServerConfigurationService.class);
}

@Override
public int doGet(String[] parts, HttpServletRequest req,
HttpServletResponse res, Session session)
Expand Down
Loading

0 comments on commit 2490614

Please sign in to comment.