Search in sources :

Example 1 with IUserProfile

use of org.apereo.portal.IUserProfile in project uPortal by Jasig.

the class PortletWindowRegistryImpl method getThemeStylesheetDescriptor.

protected IStylesheetDescriptor getThemeStylesheetDescriptor(HttpServletRequest request) {
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
    final IUserProfile userProfile = preferencesManager.getUserProfile();
    final int themeStylesheetId = userProfile.getThemeStylesheetId();
    return stylesheetDescriptorDao.getStylesheetDescriptor(themeStylesheetId);
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IUserProfile(org.apereo.portal.IUserProfile) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager)

Example 2 with IUserProfile

use of org.apereo.portal.IUserProfile in project uPortal by Jasig.

the class JpaStylesheetDescriptorDaoTest method testStylesheetUserPreferencesDao.

@Test
public void testStylesheetUserPreferencesDao() throws Exception {
    final long ssdId = this.execute(new Callable<Long>() {

        @Override
        public Long call() throws Exception {
            final IStylesheetDescriptor stylesheetDescriptor = stylesheetDescriptorDao.createStylesheetDescriptor("columns", "classpath:/layout/struct/columns.xsl");
            final long id = stylesheetDescriptor.getId();
            assertNotSame(-1, id);
            return id;
        }
    });
    final IPerson person = mock(IPerson.class);
    when(person.getID()).thenReturn(1);
    final IUserProfile userProfile = mock(IUserProfile.class);
    when(userProfile.getProfileId()).thenReturn(1);
    final long supId = this.execute(new Callable<Long>() {

        @Override
        public Long call() throws Exception {
            final IStylesheetDescriptor stylesheetDescriptor = stylesheetDescriptorDao.getStylesheetDescriptor(ssdId);
            final IStylesheetUserPreferences stylesheetUserPreferences = stylesheetUserPreferencesDao.createStylesheetUserPreferences(stylesheetDescriptor, person, userProfile);
            assertNotNull(stylesheetUserPreferences);
            stylesheetUserPreferences.setStylesheetParameter("activeTab", "1");
            stylesheetUserPreferences.setLayoutAttribute("u1l1n1", "deletable", "false");
            stylesheetUserPreferencesDao.storeStylesheetUserPreferences(stylesheetUserPreferences);
            return stylesheetUserPreferences.getId();
        }
    });
    this.execute(new Callable<Long>() {

        @Override
        public Long call() throws Exception {
            final IStylesheetUserPreferences stylesheetUserPreferences = stylesheetUserPreferencesDao.getStylesheetUserPreferences(supId);
            assertNotNull(stylesheetUserPreferences);
            assertEquals(Collections.singletonMap("activeTab", "1"), stylesheetUserPreferences.populateStylesheetParameters(new MapPopulator<String, String>()).getMap());
            assertEquals(Collections.singletonMap("deletable", "false"), stylesheetUserPreferences.populateLayoutAttributes("u1l1n1", new MapPopulator<String, String>()).getMap());
            return null;
        }
    });
    this.execute(new Callable<Long>() {

        @Override
        public Long call() throws Exception {
            final IStylesheetDescriptor stylesheetDescriptor = stylesheetDescriptorDao.getStylesheetDescriptor(ssdId);
            final IStylesheetUserPreferences stylesheetUserPreferences = stylesheetUserPreferencesDao.getStylesheetUserPreferences(stylesheetDescriptor, person, userProfile);
            assertNotNull(stylesheetUserPreferences);
            assertEquals(Collections.singletonMap("activeTab", "1"), stylesheetUserPreferences.populateStylesheetParameters(new MapPopulator<String, String>()).getMap());
            assertEquals(Collections.singletonMap("deletable", "false"), stylesheetUserPreferences.populateLayoutAttributes("u1l1n1", new MapPopulator<String, String>()).getMap());
            stylesheetUserPreferencesDao.deleteStylesheetUserPreferences(stylesheetUserPreferences);
            return null;
        }
    });
}
Also used : IPerson(org.apereo.portal.security.IPerson) IUserProfile(org.apereo.portal.IUserProfile) IStylesheetDescriptor(org.apereo.portal.layout.om.IStylesheetDescriptor) IStylesheetUserPreferences(org.apereo.portal.layout.om.IStylesheetUserPreferences) MapPopulator(org.apereo.portal.utils.MapPopulator) Test(org.junit.Test) BasePortalJpaDaoTest(org.apereo.portal.test.BasePortalJpaDaoTest)

Example 3 with IUserProfile

use of org.apereo.portal.IUserProfile in project uPortal by Jasig.

the class UserLocaleHelper method updateUserLocale.

/**
 * Update the current user's locale to match the selected locale. This implementation will
 * update the session locale, and if the user is not a guest, will also update the locale in the
 * user's persisted preferences.
 *
 * @param request
 * @param localeString
 */
public void updateUserLocale(HttpServletRequest request, String localeString) {
    IUserInstance ui = userInstanceManager.getUserInstance(request);
    IUserPreferencesManager upm = ui.getPreferencesManager();
    final IUserProfile userProfile = upm.getUserProfile();
    LocaleManager localeManager = userProfile.getLocaleManager();
    if (localeString != null) {
        // build a new List<Locale> from the specified locale
        Locale userLocale = localeManagerFactory.parseLocale(localeString);
        List<Locale> locales = Collections.singletonList(userLocale);
        // set this locale in the session
        localeManager.setSessionLocales(locales);
        // if the current user is logged in, also update the persisted
        // user locale
        final IPerson person = ui.getPerson();
        if (!person.isGuest()) {
            try {
                localeManager.setUserLocales(Collections.singletonList(userLocale));
                localeStore.updateUserLocales(person, new Locale[] { userLocale });
                // remove person layout framgent from session since it contains some of the data
                // in previous
                // translation and won't be cleared until next logout-login (applies when using
                // RDBMDistributedLayoutStore as user layout store).
                person.setAttribute(Constants.PLF, null);
                upm.getUserLayoutManager().loadUserLayout(true);
            } catch (Exception e) {
                throw new PortalException(e);
            }
        }
    }
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) Locale(java.util.Locale) IPerson(org.apereo.portal.security.IPerson) IUserProfile(org.apereo.portal.IUserProfile) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) LocaleManager(org.apereo.portal.i18n.LocaleManager) PortalException(org.apereo.portal.PortalException) PortalException(org.apereo.portal.PortalException)

Example 4 with IUserProfile

use of org.apereo.portal.IUserProfile in project uPortal by Jasig.

the class LayoutRESTController method getRESTController.

/**
 * A REST call to get a json feed of the current users layout. Intent was to provide a layout
 * document without per-tab information for mobile device rendering.
 *
 * @param request The servlet request. Utilized to get the users instance and eventually there
 *     layout
 * @param tab The tab name of which you would like to filter; optional; if not provided, will
 *     return entire layout.
 * @return json feed of the layout
 * @deprecated Use /api/v4-3/dlm/layout.json. It has much more information about portlets and
 *     includes regions and breakout per tab
 */
@Deprecated
@RequestMapping(value = "/layoutDoc", method = RequestMethod.GET)
public ModelAndView getRESTController(HttpServletRequest request, @RequestParam(value = "tab", required = false) String tab) {
    final IPerson person = personManager.getPerson(request);
    List<LayoutPortlet> portlets = new ArrayList<LayoutPortlet>();
    try {
        final IUserInstance ui = userInstanceManager.getUserInstance(request);
        final IUserPreferencesManager upm = ui.getPreferencesManager();
        final IUserProfile profile = upm.getUserProfile();
        final DistributedUserLayout userLayout = userLayoutStore.getUserLayout(person, profile);
        Document document = userLayout.getLayout();
        NodeList portletNodes = null;
        if (tab != null) {
            NodeList folders = document.getElementsByTagName("folder");
            for (int i = 0; i < folders.getLength(); i++) {
                Node node = folders.item(i);
                if (tab.equalsIgnoreCase(node.getAttributes().getNamedItem("name").getNodeValue())) {
                    TabListOfNodes tabNodes = new TabListOfNodes();
                    tabNodes.addAllChannels(node.getChildNodes());
                    portletNodes = tabNodes;
                    break;
                }
            }
        } else {
            portletNodes = document.getElementsByTagName("channel");
        }
        for (int i = 0; i < portletNodes.getLength(); i++) {
            try {
                NamedNodeMap attributes = portletNodes.item(i).getAttributes();
                IPortletDefinition def = portletDao.getPortletDefinitionByFname(attributes.getNamedItem("fname").getNodeValue());
                LayoutPortlet portlet = new LayoutPortlet(def);
                portlet.setNodeId(attributes.getNamedItem("ID").getNodeValue());
                // get alt max URL
                String alternativeMaximizedLink = def.getAlternativeMaximizedLink();
                if (alternativeMaximizedLink != null) {
                    portlet.setUrl(alternativeMaximizedLink);
                    portlet.setAltMaxUrl(true);
                } else {
                    // get the maximized URL for this portlet
                    final IPortalUrlBuilder portalUrlBuilder = urlProvider.getPortalUrlBuilderByLayoutNode(request, attributes.getNamedItem("ID").getNodeValue(), UrlType.RENDER);
                    final IPortletWindowId targetPortletWindowId = portalUrlBuilder.getTargetPortletWindowId();
                    if (targetPortletWindowId != null) {
                        final IPortletUrlBuilder portletUrlBuilder = portalUrlBuilder.getPortletUrlBuilder(targetPortletWindowId);
                        portletUrlBuilder.setWindowState(WindowState.MAXIMIZED);
                    }
                    portlet.setUrl(portalUrlBuilder.getUrlString());
                    portlet.setAltMaxUrl(false);
                }
                portlets.add(portlet);
            } catch (Exception e) {
                log.warn("Exception construction JSON representation of mobile portlet", e);
            }
        }
        ModelAndView mv = new ModelAndView();
        mv.addObject("layout", portlets);
        mv.setViewName("json");
        return mv;
    } catch (Exception e) {
        log.error("Error retrieving user layout document", e);
    }
    return null;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) IPortletUrlBuilder(org.apereo.portal.url.IPortletUrlBuilder) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) Document(org.w3c.dom.Document) IPortalUrlBuilder(org.apereo.portal.url.IPortalUrlBuilder) IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) TabListOfNodes(org.apereo.portal.rest.layout.TabListOfNodes) IUserProfile(org.apereo.portal.IUserProfile) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) DistributedUserLayout(org.apereo.portal.layout.dlm.DistributedUserLayout) LayoutPortlet(org.apereo.portal.layout.LayoutPortlet) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with IUserProfile

use of org.apereo.portal.IUserProfile in project uPortal by Jasig.

the class LayoutExporter method exportDataElement.

/* (non-Javadoc)
     * @see org.apereo.portal.io.xml.crn.AbstractDom4jExporter#exportDataElement(java.lang.String)
     */
@Override
protected Element exportDataElement(String userName) {
    final Integer userId = this.userIdentityStore.getPortalUserId(userName);
    if (userId == null) {
        this.logger.warn("No user " + userName + " found, no layout will be exported");
        return null;
    }
    // Setup empty IPerson used to interact with the layout store
    final PersonImpl person = new PersonImpl();
    person.setUserName(userName);
    person.setID(userId);
    person.setSecurityContext(new BrokenSecurityContext());
    try {
        this.userLayoutStore.setProfileImportExportCache(layoutCache);
        this.userLayoutStore.setLayoutImportExportCache(profileCache);
        final IUserProfile userProfile = userLayoutStore.getUserProfileByFname(person, UserProfile.DEFAULT_PROFILE_FNAME);
        final Element layoutElement = userLayoutStore.exportLayout(person, userProfile);
        return layoutElement;
    } finally {
        this.userLayoutStore.setProfileImportExportCache(null);
        this.userLayoutStore.setLayoutImportExportCache(null);
    }
}
Also used : PersonImpl(org.apereo.portal.security.provider.PersonImpl) IUserProfile(org.apereo.portal.IUserProfile) Element(org.dom4j.Element) BrokenSecurityContext(org.apereo.portal.security.provider.BrokenSecurityContext)

Aggregations

IUserProfile (org.apereo.portal.IUserProfile)23 IUserInstance (org.apereo.portal.user.IUserInstance)10 IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)9 IPerson (org.apereo.portal.security.IPerson)8 LocaleManager (org.apereo.portal.i18n.LocaleManager)4 IStylesheetDescriptor (org.apereo.portal.layout.om.IStylesheetDescriptor)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 BrokenSecurityContext (org.apereo.portal.security.provider.BrokenSecurityContext)3 PersonImpl (org.apereo.portal.security.provider.PersonImpl)3 Document (org.w3c.dom.Document)3 ArrayList (java.util.ArrayList)2 Locale (java.util.Locale)2 AuthorizationException (org.apereo.portal.AuthorizationException)2 PortalException (org.apereo.portal.PortalException)2 UserProfile (org.apereo.portal.UserProfile)2 IStylesheetUserPreferences (org.apereo.portal.layout.om.IStylesheetUserPreferences)2 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)2 Test (org.junit.Test)2 Node (org.w3c.dom.Node)2 Connection (java.sql.Connection)1