Search in sources :

Example 16 with IStylesheetDescriptor

use of org.apereo.portal.layout.om.IStylesheetDescriptor in project uPortal by Jasig.

the class RDBMDistributedLayoutStore method addStylesheetUserPreferencesAttributes.

private void addStylesheetUserPreferencesAttributes(IPerson person, IUserProfile profile, org.dom4j.Document layoutDoc, int stylesheetId, String attributeType) {
    final IStylesheetDescriptor structureStylesheetDescriptor = this.stylesheetDescriptorDao.getStylesheetDescriptor(stylesheetId);
    final IStylesheetUserPreferences ssup = this.stylesheetUserPreferencesDao.getStylesheetUserPreferences(structureStylesheetDescriptor, person, profile);
    if (ssup != null) {
        final Collection<String> allLayoutAttributeNodeIds = ssup.getAllLayoutAttributeNodeIds();
        for (final String nodeId : allLayoutAttributeNodeIds) {
            final MapPopulator<String, String> layoutAttributesPopulator = new MapPopulator<>();
            ssup.populateLayoutAttributes(nodeId, layoutAttributesPopulator);
            final Map<String, String> layoutAttributes = layoutAttributesPopulator.getMap();
            final org.dom4j.Element element = layoutDoc.elementByID(nodeId);
            if (element == null) {
                logger.warn("No node with id '{}' found in layout for: {}. Stylesheet user preference layout attributes will be ignored: {}", nodeId, person.getUserName(), layoutAttributes);
                continue;
            }
            for (final Entry<String, String> attributeEntry : layoutAttributes.entrySet()) {
                final String name = attributeEntry.getKey();
                final String value = attributeEntry.getValue();
                logger.debug("Adding structure folder attribute:  name={}, value={}", name, value);
                final org.dom4j.Element structAttrElement = this.fac.createElement(attributeType + "-attribute");
                final org.dom4j.Element nameAttribute = structAttrElement.addElement("name");
                nameAttribute.setText(name);
                final org.dom4j.Element valueAttribute = structAttrElement.addElement("value");
                valueAttribute.setText(value);
                element.elements().add(0, structAttrElement);
            }
        }
    } else {
        logger.debug("no StylesheetUserPreferences found for {}, {}", person, profile);
    }
}
Also used : IStylesheetDescriptor(org.apereo.portal.layout.om.IStylesheetDescriptor) IStylesheetUserPreferences(org.apereo.portal.layout.om.IStylesheetUserPreferences) MapPopulator(org.apereo.portal.utils.MapPopulator)

Example 17 with IStylesheetDescriptor

use of org.apereo.portal.layout.om.IStylesheetDescriptor in project uPortal by Jasig.

the class StylesheetUserPreferencesServiceImplTest method testThemeStylesheetUserPreferences.

/**
 * @throws Exception
 */
@Test
public void testThemeStylesheetUserPreferences() throws Exception {
    // Setup mocks
    final HttpServletRequest request = new MockHttpServletRequest();
    // initialize the session
    request.getSession();
    final IStylesheetDescriptorDao stylesheetDescriptorDao = mock(IStylesheetDescriptorDao.class);
    final IUserInstanceManager userInstanceManager = mock(IUserInstanceManager.class);
    final IStylesheetUserPreferencesDao stylesheetUserPreferencesDao = mock(IStylesheetUserPreferencesDao.class);
    final IFragmentDefinitionUtils fragmentUtils = mock(IFragmentDefinitionUtils.class);
    final IUserInstance userInstance = mock(IUserInstance.class);
    when(userInstanceManager.getUserInstance(request)).thenReturn(userInstance);
    final IPerson person = mock(IPerson.class);
    when(userInstance.getPerson()).thenReturn(person);
    final IUserPreferencesManager preferencesManager = mock(IUserPreferencesManager.class);
    when(userInstance.getPreferencesManager()).thenReturn(preferencesManager);
    final IUserProfile userProfile = mock(IUserProfile.class);
    when(preferencesManager.getUserProfile()).thenReturn(userProfile);
    final IUserLayoutManager userLayoutManager = mock(IUserLayoutManager.class);
    when(preferencesManager.getUserLayoutManager()).thenReturn(userLayoutManager);
    final IUserLayout userLayout = mock(IUserLayout.class);
    when(userLayoutManager.getUserLayout()).thenReturn(userLayout);
    when(userProfile.getThemeStylesheetId()).thenReturn(1);
    final IStylesheetDescriptor stylesheetDescriptor = mock(IStylesheetDescriptor.class);
    when(stylesheetDescriptorDao.getStylesheetDescriptor(1)).thenReturn(stylesheetDescriptor);
    final ILayoutAttributeDescriptor skinLayoutAttributeDescriptor = mock(ILayoutAttributeDescriptor.class);
    when(stylesheetDescriptor.getLayoutAttributeDescriptor("minimized")).thenReturn(skinLayoutAttributeDescriptor);
    when(skinLayoutAttributeDescriptor.getName()).thenReturn("minimized");
    when(skinLayoutAttributeDescriptor.getScope()).thenReturn(Scope.REQUEST);
    when(skinLayoutAttributeDescriptor.getTargetElementNames()).thenReturn(Collections.singleton("folder"));
    final IOutputPropertyDescriptor mediaOutputPropertyDescriptor = mock(IOutputPropertyDescriptor.class);
    when(stylesheetDescriptor.getOutputPropertyDescriptor("media")).thenReturn(mediaOutputPropertyDescriptor);
    when(mediaOutputPropertyDescriptor.getName()).thenReturn("media");
    when(mediaOutputPropertyDescriptor.getScope()).thenReturn(Scope.SESSION);
    final IStylesheetParameterDescriptor skinStylesheetParameterDescriptor = mock(IStylesheetParameterDescriptor.class);
    when(stylesheetDescriptor.getStylesheetParameterDescriptor("skin")).thenReturn(skinStylesheetParameterDescriptor);
    when(skinStylesheetParameterDescriptor.getName()).thenReturn("media");
    when(skinStylesheetParameterDescriptor.getScope()).thenReturn(Scope.PERSISTENT);
    final IStylesheetUserPreferences persistentStylesheetUserPreferences = mock(IStylesheetUserPreferences.class);
    when(stylesheetUserPreferencesDao.createStylesheetUserPreferences(stylesheetDescriptor, person, userProfile)).thenReturn(persistentStylesheetUserPreferences);
    when(stylesheetUserPreferencesDao.getStylesheetUserPreferences(stylesheetDescriptor, person, userProfile)).thenReturn(persistentStylesheetUserPreferences);
    when(persistentStylesheetUserPreferences.getStylesheetParameter("skin")).thenReturn(null).thenReturn("red");
    // Create and initialize service bean
    final StylesheetUserPreferencesServiceImpl stylesheetUserPreferencesService = new StylesheetUserPreferencesServiceImpl();
    stylesheetUserPreferencesService.setStylesheetDescriptorDao(stylesheetDescriptorDao);
    stylesheetUserPreferencesService.setUserInstanceManager(userInstanceManager);
    stylesheetUserPreferencesService.setStylesheetUserPreferencesDao(stylesheetUserPreferencesDao);
    stylesheetUserPreferencesService.setFragmentDefinitionUtils(fragmentUtils);
    // Run test
    String actual;
    actual = stylesheetUserPreferencesService.getLayoutAttribute(request, PreferencesScope.THEME, "u1l1n1", "minimized");
    assertNull(actual);
    actual = stylesheetUserPreferencesService.setLayoutAttribute(request, PreferencesScope.THEME, "u1l1n1", "minimized", "true");
    assertNull(actual);
    actual = stylesheetUserPreferencesService.getLayoutAttribute(request, PreferencesScope.THEME, "u1l1n1", "minimized");
    assertEquals("true", actual);
    actual = stylesheetUserPreferencesService.getStylesheetParameter(request, PreferencesScope.THEME, "skin");
    assertNull(actual);
    actual = stylesheetUserPreferencesService.setStylesheetParameter(request, PreferencesScope.THEME, "skin", "red");
    verify(persistentStylesheetUserPreferences).setStylesheetParameter("skin", "red");
    assertNull(actual);
    actual = stylesheetUserPreferencesService.getStylesheetParameter(request, PreferencesScope.THEME, "skin");
    assertEquals("red", actual);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) IStylesheetDescriptorDao(org.apereo.portal.layout.dao.IStylesheetDescriptorDao) ILayoutAttributeDescriptor(org.apereo.portal.layout.om.ILayoutAttributeDescriptor) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) IOutputPropertyDescriptor(org.apereo.portal.layout.om.IOutputPropertyDescriptor) IStylesheetParameterDescriptor(org.apereo.portal.layout.om.IStylesheetParameterDescriptor) IStylesheetUserPreferencesDao(org.apereo.portal.layout.dao.IStylesheetUserPreferencesDao) IUserProfile(org.apereo.portal.IUserProfile) IStylesheetDescriptor(org.apereo.portal.layout.om.IStylesheetDescriptor) IStylesheetUserPreferences(org.apereo.portal.layout.om.IStylesheetUserPreferences) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) IUserInstanceManager(org.apereo.portal.user.IUserInstanceManager) IFragmentDefinitionUtils(org.apereo.portal.utils.IFragmentDefinitionUtils) Test(org.junit.Test)

Example 18 with IStylesheetDescriptor

use of org.apereo.portal.layout.om.IStylesheetDescriptor in project uPortal by Jasig.

the class PortletEntityRegistryImpl method createPersistentEntity.

protected IPortletEntity createPersistentEntity(final IPortletEntity portletEntity, final IPortletEntityId wrapperPortletEntityId) {
    final IPortletDefinitionId portletDefinitionId = portletEntity.getPortletDefinitionId();
    final String layoutNodeId = portletEntity.getLayoutNodeId();
    final int userId = portletEntity.getUserId();
    IPortletEntity persistentEntity = this.portletEntityDao.getPortletEntity(layoutNodeId, userId);
    if (persistentEntity != null) {
        this.logger.warn("A persistent portlet entity already exists: " + persistentEntity + ". The data from the passed in entity will be copied to the persistent entity: " + portletEntity);
    } else {
        persistentEntity = this.portletEntityDao.createPortletEntity(portletDefinitionId, layoutNodeId, userId);
    }
    // Copy over preferences to avoid modifying any part of the interim entity by reference
    final List<IPortletPreference> existingPreferences = portletEntity.getPortletPreferences();
    final List<IPortletPreference> persistentPreferences = persistentEntity.getPortletPreferences();
    // Only do the copy if the List objects are not the same instance
    if (persistentPreferences != existingPreferences) {
        persistentPreferences.clear();
        for (final IPortletPreference preference : existingPreferences) {
            persistentPreferences.add(new PortletPreferenceImpl(preference));
        }
    }
    // Copy over WindowStates
    final Map<Long, WindowState> windowStates = portletEntity.getWindowStates();
    for (Map.Entry<Long, WindowState> windowStateEntry : windowStates.entrySet()) {
        final Long stylesheetDescriptorId = windowStateEntry.getKey();
        final IStylesheetDescriptor stylesheetDescriptor = stylesheetDescriptorDao.getStylesheetDescriptor(stylesheetDescriptorId);
        final WindowState windowState = windowStateEntry.getValue();
        persistentEntity.setWindowState(stylesheetDescriptor, windowState);
    }
    this.portletEntityDao.updatePortletEntity(persistentEntity);
    return persistentEntity;
}
Also used : WindowState(javax.portlet.WindowState) IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) IStylesheetDescriptor(org.apereo.portal.layout.om.IStylesheetDescriptor) Map(java.util.Map) ConcurrentMap(java.util.concurrent.ConcurrentMap) PortletPreferenceImpl(org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl)

Example 19 with IStylesheetDescriptor

use of org.apereo.portal.layout.om.IStylesheetDescriptor in project uPortal by Jasig.

the class PortletWindowRegistryImpl method storePortletWindow.

@Override
public void storePortletWindow(HttpServletRequest request, IPortletWindow portletWindow) {
    if (isDisablePersistentWindowStates(request)) {
        return;
    }
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IPerson person = userInstance.getPerson();
    if (person.isGuest()) {
        // Never persist things for the guest user, just rely on in-memory storage
        return;
    }
    final IStylesheetDescriptor themeStylesheetDescriptor = this.getThemeStylesheetDescriptor(request);
    final WindowState windowState = portletWindow.getWindowState();
    final IPortletEntity portletEntity = portletWindow.getPortletEntity();
    final WindowState entityWindowState = portletEntity.getWindowState(themeStylesheetDescriptor);
    // If the window and entity states are different
    if (windowState != entityWindowState && !windowState.equals(entityWindowState)) {
        final WindowState defaultWindowState = this.getDefaultWindowState(themeStylesheetDescriptor);
        // If a window state is set and is one of the persistent states set it on the entity
        if (!defaultWindowState.equals(windowState) && persistentWindowStates.contains(windowState)) {
            portletEntity.setWindowState(themeStylesheetDescriptor, windowState);
        } else // If not remove the state from the entity
        if (entityWindowState != null) {
            portletEntity.setWindowState(themeStylesheetDescriptor, null);
        }
        // Persist the modified entity
        this.portletEntityRegistry.storePortletEntity(request, portletEntity);
    }
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) WindowState(javax.portlet.WindowState) IPerson(org.apereo.portal.security.IPerson) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) IStylesheetDescriptor(org.apereo.portal.layout.om.IStylesheetDescriptor)

Example 20 with IStylesheetDescriptor

use of org.apereo.portal.layout.om.IStylesheetDescriptor in project uPortal by Jasig.

the class StylesheetDescriptorTransformerConfigurationSource method getCacheKey.

@Override
public final CacheKey getCacheKey(HttpServletRequest request, HttpServletResponse response) {
    final CacheKeyBuilder cacheKeyBuilder = CacheKey.builder(this.getName());
    final PreferencesScope preferencesScope = this.getStylesheetPreferencesScope(request);
    final IStylesheetDescriptor stylesheetDescriptor = this.stylesheetUserPreferencesService.getStylesheetDescriptor(request, preferencesScope);
    // Build key from stylesheet descriptor parameters
    for (final IStylesheetParameterDescriptor stylesheetParameterDescriptor : stylesheetDescriptor.getStylesheetParameterDescriptors()) {
        final String defaultValue = stylesheetParameterDescriptor.getDefaultValue();
        if (defaultValue != null) {
            final String name = stylesheetParameterDescriptor.getName();
            cacheKeyBuilder.put(name, defaultValue);
        }
    }
    return cacheKeyBuilder.build();
}
Also used : IStylesheetParameterDescriptor(org.apereo.portal.layout.om.IStylesheetParameterDescriptor) CacheKeyBuilder(org.apereo.portal.utils.cache.CacheKey.CacheKeyBuilder) IStylesheetDescriptor(org.apereo.portal.layout.om.IStylesheetDescriptor) PreferencesScope(org.apereo.portal.layout.IStylesheetUserPreferencesService.PreferencesScope)

Aggregations

IStylesheetDescriptor (org.apereo.portal.layout.om.IStylesheetDescriptor)32 IStylesheetUserPreferences (org.apereo.portal.layout.om.IStylesheetUserPreferences)16 Scope (org.apereo.portal.layout.om.IStylesheetData.Scope)11 IStylesheetParameterDescriptor (org.apereo.portal.layout.om.IStylesheetParameterDescriptor)10 Map (java.util.Map)7 ILayoutAttributeDescriptor (org.apereo.portal.layout.om.ILayoutAttributeDescriptor)7 Transactional (org.springframework.transaction.annotation.Transactional)6 ConcurrentMap (java.util.concurrent.ConcurrentMap)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 WindowState (javax.portlet.WindowState)4 HttpSession (javax.servlet.http.HttpSession)4 IUserProfile (org.apereo.portal.IUserProfile)4 IOutputPropertyDescriptor (org.apereo.portal.layout.om.IOutputPropertyDescriptor)4 IPerson (org.apereo.portal.security.IPerson)4 IUserInstance (org.apereo.portal.user.IUserInstance)4 MapPopulator (org.apereo.portal.utils.MapPopulator)4 IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)3 PreferencesScope (org.apereo.portal.layout.IStylesheetUserPreferencesService.PreferencesScope)3 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)3