Search in sources :

Example 51 with IUserInstance

use of org.apereo.portal.user.IUserInstance in project uPortal by Jasig.

the class UpdatePreferencesServlet method changeColumns.

/**
 * Change the number of columns on a specified tab. In the event that the user is decreasing the
 * number of columns, extra columns will be stripped from the right-hand side. Any channels in
 * these columns will be moved to the bottom of the last preserved column.
 *
 * @param widths array of column widths
 * @param deleted array of deleted column IDs
 * @param acceptor not sure what this is
 * @param request HttpRequest
 * @param response HttpResponse
 * @throws IOException
 * @throws PortalException
 */
@RequestMapping(method = RequestMethod.POST, params = "action=changeColumns")
public ModelAndView changeColumns(HttpServletRequest request, HttpServletResponse response, @RequestParam("tabId") String tabId, @RequestParam("widths[]") String[] widths, @RequestParam(value = "deleted[]", required = false) String[] deleted, @RequestParam(value = "acceptor", required = false) String acceptor) throws IOException, PortalException {
    final IUserInstance ui = userInstanceManager.getUserInstance(request);
    final IPerson person = getPerson(ui, response);
    final UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
    final IUserLayoutManager ulm = upm.getUserLayoutManager();
    final int newColumnCount = widths.length;
    // build a list of the current columns for this tab
    final Enumeration<String> columns = ulm.getChildIds(tabId);
    final List<String> columnList = new ArrayList<>();
    while (columns.hasMoreElements()) {
        columnList.add(columns.nextElement());
    }
    final int oldColumnCount = columnList.size();
    final Map<String, Object> model = new HashMap<>();
    // if the new layout has more columns
    if (newColumnCount > oldColumnCount) {
        final List<String> newColumnIds = new ArrayList<>();
        for (int i = columnList.size(); i < newColumnCount; i++) {
            // create new column element
            final IUserLayoutFolderDescription newColumn = new UserLayoutFolderDescription();
            newColumn.setName("Column");
            newColumn.setId("tbd");
            newColumn.setFolderType(IUserLayoutFolderDescription.REGULAR_TYPE);
            newColumn.setHidden(false);
            newColumn.setUnremovable(false);
            newColumn.setImmutable(false);
            // add the column to our layout
            final IUserLayoutNodeDescription node = ulm.addNode(newColumn, tabId, null);
            newColumnIds.add(node.getId());
            model.put("newColumnIds", newColumnIds);
            columnList.add(node.getId());
        }
    } else // if the new layout has fewer columns
    if (deleted != null && deleted.length > 0) {
        for (String columnId : deleted) {
            // move all channels in the current column to the last valid column
            final Enumeration channels = ulm.getChildIds(columnId);
            while (channels.hasMoreElements()) {
                ulm.addNode(ulm.getNode((String) channels.nextElement()), acceptor, null);
            }
            // delete the column from the user's layout
            ulm.deleteNode(columnId);
            columnList.remove(columnId);
        }
    }
    /*
         * Now that the number of columns is established, the appearance and behavior of the columns
         * on the page is determined by Structure Stylesheet User Preferences.  "Classic" uPortal
         * columns use a 'width' attribute, while the new(er) columns based on CSS Flex use a
         * 'flexColumns' attribute.
         */
    resetColumnStylesheetUserPreferences(request, person, ulm, // Clear previous selections
    columnList);
    // Choose a column layout strategy...
    // default is "classic"
    boolean useFlexStrategy = false;
    if (columnList.size() == 1) {
        int firstColumnWidthAsInt = Integer.parseInt(widths[0]);
        if (firstColumnWidthAsInt > 100) {
            // A single column with a width parameter creater than 100(%)
            // signals that we want the flexColumns strategy.
            useFlexStrategy = true;
        }
    }
    // Update Structure Stylesheet User Preferences based on the selected strategy
    if (useFlexStrategy) {
        updateColumnStylesheetUserPreferencesFlex(request, person, ulm, columnList, widths);
    } else {
        updateColumnStylesheetUserPreferencesClassic(request, person, ulm, columnList, widths);
    }
    try {
        ulm.saveUserLayout();
    } catch (PortalException e) {
        logger.warn("Error saving layout", e);
    }
    return new ModelAndView("jsonView", model);
}
Also used : IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) Enumeration(java.util.Enumeration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) IUserLayoutFolderDescription(org.apereo.portal.layout.node.IUserLayoutFolderDescription) UserLayoutFolderDescription(org.apereo.portal.layout.node.UserLayoutFolderDescription) UserPreferencesManager(org.apereo.portal.UserPreferencesManager) IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) PortalException(org.apereo.portal.PortalException) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) IUserLayoutFolderDescription(org.apereo.portal.layout.node.IUserLayoutFolderDescription) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 52 with IUserInstance

use of org.apereo.portal.user.IUserInstance in project uPortal by Jasig.

the class UpdatePreferencesServlet method removeElement.

/**
 * Remove an element from the layout.
 *
 * @param request
 * @param response
 * @return
 * @throws IOException
 */
@RequestMapping(method = RequestMethod.POST, params = "action=removeElement")
public ModelAndView removeElement(HttpServletRequest request, HttpServletResponse response) throws IOException {
    IUserInstance ui = userInstanceManager.getUserInstance(request);
    IPerson per = getPerson(ui, response);
    UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
    IUserLayoutManager ulm = upm.getUserLayoutManager();
    try {
        // Delete the requested element node.  This code is the same for
        // all node types, so we can just have a generic action.
        String elementId = request.getParameter("elementID");
        if (!ulm.deleteNode(elementId)) {
            logger.info("Failed to remove element ID {} from layout root folder ID {}, delete node returned false", elementId, ulm.getRootFolderId());
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
            return new ModelAndView("jsonView", Collections.singletonMap("error", getMessage("error.element.update", "Unable to update element", RequestContextUtils.getLocale(request))));
        }
        ulm.saveUserLayout();
        return new ModelAndView("jsonView", Collections.emptyMap());
    } catch (PortalException e) {
        return handlePersistError(request, response, e);
    }
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) ModelAndView(org.springframework.web.servlet.ModelAndView) PortalException(org.apereo.portal.PortalException) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) UserPreferencesManager(org.apereo.portal.UserPreferencesManager) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 53 with IUserInstance

use of org.apereo.portal.user.IUserInstance in project uPortal by Jasig.

the class UpdatePreferencesServletTest method testRemoveByFName.

@Test(expected = NullPointerException.class)
public void testRemoveByFName() throws IOException {
    IPerson person = new PersonImpl();
    person.setUserName("jDoe");
    person.setFullName("john doe");
    IUserInstance userInstace = new UserInstance(person, null, null);
    Mockito.when(userInstanceManager.getUserInstance(req)).thenReturn(userInstace);
    ModelAndView modelAndView = updatePreferencesServlet.removeByFName(req, res, "fname");
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) PersonImpl(org.apereo.portal.security.provider.PersonImpl) ModelAndView(org.springframework.web.servlet.ModelAndView) IUserInstance(org.apereo.portal.user.IUserInstance) UserInstance(org.apereo.portal.UserInstance) Test(org.junit.Test)

Example 54 with IUserInstance

use of org.apereo.portal.user.IUserInstance in project uPortal by Jasig.

the class LocaleManagerLocaleResolver method setLocale.

@Override
public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final LocaleManager localeManager = userInstance.getLocaleManager();
    localeManager.setSessionLocales(Collections.singletonList(locale));
    // if the current user is logged in, also update the persisted user locale
    final IUserInstance ui = userInstanceManager.getUserInstance(request);
    final IPerson person = ui.getPerson();
    if (!person.isGuest()) {
        try {
            localeManager.setUserLocales(Collections.singletonList(locale));
            localeStore.updateUserLocales(person, new Locale[] { locale });
            final IUserPreferencesManager upm = ui.getPreferencesManager();
            upm.getUserLayoutManager().loadUserLayout();
        } catch (Exception e) {
            throw new PortalException(e);
        }
    }
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) PortalException(org.apereo.portal.PortalException) PortalException(org.apereo.portal.PortalException)

Example 55 with IUserInstance

use of org.apereo.portal.user.IUserInstance in project uPortal by Jasig.

the class LocaleManagerLocaleResolver method resolveLocale.

@Override
public Locale resolveLocale(HttpServletRequest request) {
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final LocaleManager localeManager = userInstance.getLocaleManager();
    List<Locale> locales = localeManager.getLocales();
    if (locales != null && locales.size() > 0) {
        return locales.get(0);
    }
    // specified by "accept-locale" HTTP header
    return request.getLocale();
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) Locale(java.util.Locale)

Aggregations

IUserInstance (org.apereo.portal.user.IUserInstance)65 IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)28 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)28 IPerson (org.apereo.portal.security.IPerson)25 UserPreferencesManager (org.apereo.portal.UserPreferencesManager)15 PortalException (org.apereo.portal.PortalException)14 IUserLayoutNodeDescription (org.apereo.portal.layout.node.IUserLayoutNodeDescription)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 ModelAndView (org.springframework.web.servlet.ModelAndView)13 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)12 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)12 HttpServletRequest (javax.servlet.http.HttpServletRequest)10 IUserProfile (org.apereo.portal.IUserProfile)10 Locale (java.util.Locale)9 IUserLayout (org.apereo.portal.layout.IUserLayout)7 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)7 HashMap (java.util.HashMap)6 IPortletEntityId (org.apereo.portal.portlet.om.IPortletEntityId)6 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)6 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)5