diff --git a/portal/portal-impl/impl/src/java/org/sakaiproject/portal/charon/site/MoreSiteViewImpl.java b/portal/portal-impl/impl/src/java/org/sakaiproject/portal/charon/site/MoreSiteViewImpl.java index 6c24dc1cb316..123e0e876242 100644 --- a/portal/portal-impl/impl/src/java/org/sakaiproject/portal/charon/site/MoreSiteViewImpl.java +++ b/portal/portal-impl/impl/src/java/org/sakaiproject/portal/charon/site/MoreSiteViewImpl.java @@ -41,6 +41,7 @@ import org.sakaiproject.exception.IdUnusedException; import org.sakaiproject.portal.api.Portal; import org.sakaiproject.portal.api.SiteNeighbourhoodService; +import org.sakaiproject.portal.util.PortalUtils; import org.sakaiproject.site.api.Site; import org.sakaiproject.site.api.SiteService; import org.sakaiproject.site.api.ToolConfiguration; @@ -50,9 +51,6 @@ import org.sakaiproject.user.api.PreferencesService; import org.sakaiproject.util.ResourceLoader; -import org.sakaiproject.coursemanagement.api.AcademicSession; -import org.sakaiproject.coursemanagement.api.CourseManagementService; -import org.sakaiproject.component.cover.ComponentManager; import org.sakaiproject.util.Web; import lombok.extern.slf4j.Slf4j; @@ -65,7 +63,6 @@ public class MoreSiteViewImpl extends AbstractSiteViewImpl { /** messages. */ private static ResourceLoader rb = new ResourceLoader("sitenav"); - private CourseManagementService courseManagementService = (CourseManagementService) ComponentManager.get(CourseManagementService.class); /** * @param siteHelper @@ -371,56 +368,8 @@ public int compare(Map first, Map second) } - String[] termOrder = serverConfigurationService - .getStrings("portal.term.order"); - List tabsMoreSortedTermList = new ArrayList(); - - // Order term column headers according to order specified in - // portal.term.order - // Filter out terms for which user is not a member of any sites - - // SAK-19464 - Set tab order - // Property portal.term.order - // Course sites (sorted in order by getAcademicSessions START_DATE ASC) - // Rest of terms in alphabetic order - if (termOrder != null) - { - for (int i = 0; i < termOrder.length; i++) - { - - if (tabsMoreTerms.containsKey(termOrder[i])) - { - - tabsMoreSortedTermList.add(termOrder[i]); - - } - - } - } - - - if (courseManagementService != null) { - Collection sessions = courseManagementService.getAcademicSessions(); - for (AcademicSession s: sessions) { - String title = s.getTitle(); - if (tabsMoreTerms.containsKey(title)) { - if (!tabsMoreSortedTermList.contains(title)) { - tabsMoreSortedTermList.add(title); - } - } - } - } - - Iterator i = tabsMoreTerms.keySet().iterator(); - while (i.hasNext()) - { - String term = (String) i.next(); - if (!tabsMoreSortedTermList.contains(term)) - { - tabsMoreSortedTermList.add(term); - - } - } + //Get a list of sorted terms + List tabsMoreSortedTermList = PortalUtils.getPortalTermOrder(tabsMoreTerms.keySet()); SitePanesArrangement sitesByPane = arrangeSitesIntoPanes(tabsMoreTerms); renderContextMap.put("tabsMoreTermsLeftPane", sitesByPane.sitesInLeftPane); diff --git a/portal/portal-util/util/pom.xml b/portal/portal-util/util/pom.xml index f81006851aeb..04898de39dc2 100644 --- a/portal/portal-util/util/pom.xml +++ b/portal/portal-util/util/pom.xml @@ -20,6 +20,10 @@ jar + + org.sakaiproject.edu-services.course-management + coursemanagement-api + org.sakaiproject.kernel sakai-kernel-api diff --git a/portal/portal-util/util/src/java/org/sakaiproject/portal/util/PortalUtils.java b/portal/portal-util/util/src/java/org/sakaiproject/portal/util/PortalUtils.java index de6c6ea7f596..692191232418 100644 --- a/portal/portal-util/util/src/java/org/sakaiproject/portal/util/PortalUtils.java +++ b/portal/portal-util/util/src/java/org/sakaiproject/portal/util/PortalUtils.java @@ -22,12 +22,22 @@ package org.sakaiproject.portal.util; import java.time.Instant; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import org.sakaiproject.component.cover.ComponentManager; import org.sakaiproject.component.cover.ServerConfigurationService; +import org.sakaiproject.coursemanagement.api.AcademicSession; +import org.sakaiproject.coursemanagement.api.CourseManagementService; public class PortalUtils { + private static CourseManagementService courseManagementService = (CourseManagementService) ComponentManager.get(CourseManagementService.class); + /** * Returns an absolute URL for "/library" servlet with CDN path as necessary */ @@ -143,5 +153,68 @@ public static String includeLatestJQuery(String where) public static String getLatestJQueryPath() { return getWebjarsPath() + "jquery/1.12.4/jquery.min.js"; } + + /* + * getPortalTermOrder - Gets the term order as sorted by the portal. Will take into consideration portal.term.order + * and the values returned by the CM service + * Set tabsMoreTerms, a Set containing all terms to include (optional). + * If provided it will both filter by this list and add anything in this list that isn't found in the CM table. + * + * Returns a sorted term List + */ + public static List getPortalTermOrder(Set tabsMoreTerms) { + String[] termOrder = ServerConfigurationService.getStrings("portal.term.order"); + List tabsMoreSortedTermList = new ArrayList(); + + // Order term column headers according to order specified in + // portal.term.order + // Filter out terms for which user is not a member of any sites + + // SAK-19464 - Set tab order + // Property portal.term.order + // Course sites (sorted in order by getAcademicSessions START_DATE ASC) + // Rest of terms in alphabetic order + if (termOrder != null && tabsMoreTerms != null) + { + for (int i = 0; i < termOrder.length; i++) + { + if (tabsMoreTerms.contains(termOrder[i])) + { + tabsMoreSortedTermList.add(termOrder[i]); + } + } + } + + if (courseManagementService != null) { + Collection sessions = courseManagementService.getAcademicSessions(); + for (AcademicSession s: sessions) { + String title = s.getTitle(); + //Add this if the user doesn't specify to filter terms + if (tabsMoreTerms == null) { + tabsMoreSortedTermList.add(title); + } + else if (tabsMoreTerms.contains(title)) { + if (!tabsMoreSortedTermList.contains(title)) { + tabsMoreSortedTermList.add(title); + } + } + } + } + + if (tabsMoreTerms != null) { + Iterator i = tabsMoreTerms.iterator(); + while (i.hasNext()) + { + String term = (String) i.next(); + if (!tabsMoreSortedTermList.contains(term)) + { + tabsMoreSortedTermList.add(term); + + } + } + } + + return tabsMoreSortedTermList; + } } diff --git a/user/user-tool-prefs/tool/src/java/org/sakaiproject/user/tool/UserPrefsTool.java b/user/user-tool-prefs/tool/src/java/org/sakaiproject/user/tool/UserPrefsTool.java index c6160486668e..91cfaf879a4c 100644 --- a/user/user-tool-prefs/tool/src/java/org/sakaiproject/user/tool/UserPrefsTool.java +++ b/user/user-tool-prefs/tool/src/java/org/sakaiproject/user/tool/UserPrefsTool.java @@ -44,13 +44,14 @@ import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; - +import org.apache.commons.lang3.math.NumberUtils; import org.sakaiproject.component.cover.ComponentManager; import org.sakaiproject.component.cover.ServerConfigurationService; import org.sakaiproject.entity.api.ResourceProperties; import org.sakaiproject.entity.api.ResourcePropertiesEdit; import org.sakaiproject.event.cover.NotificationService; import org.sakaiproject.exception.IdUnusedException; +import org.sakaiproject.portal.util.PortalUtils; import org.sakaiproject.site.api.Site; import org.sakaiproject.site.api.SiteService.SelectionType; import org.sakaiproject.site.api.SiteService.SortType; @@ -2566,11 +2567,12 @@ public int compare(DecoratedNotificationPreference first, DecoratedNotificationP public class TermSites { private List terms; + private List termOrder; public class Term implements Comparable { private String label; private List sites; - + public Term(String label, List sites) { if (sites.isEmpty()) { throw new RuntimeException("List of sites can't be empty"); @@ -2593,10 +2595,14 @@ public String getType() { } public int compareTo(Term other) { + if (termOrder != null && (termOrder.contains(this.label) || termOrder.contains(other.label))) { + return(NumberUtils.compare(termOrder.indexOf(this.label), termOrder.indexOf(other.label))); + } + String myType = this.getType(); String theirType = other.getType(); - // Course sites win out over non-course-sites + // Otherwise if not found in a term course sites win out over non-course-sites if (myType == null) { return 1; } else if (theirType == null) { @@ -2642,6 +2648,8 @@ public TermSites(List sites) { terms.add(new Term(name, termsToSites.get(name))); } + termOrder = PortalUtils.getPortalTermOrder(null); + Collections.sort(terms); }