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);
}
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;
}
});
}
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);
}
}
}
}
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;
}
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);
}
}
Aggregations