Search in sources :

Example 6 with IStylesheetParameterDescriptor

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

the class StylesheetUserPreferencesServiceImpl method getStylesheetParameter.

@Override
public String getStylesheetParameter(HttpServletRequest request, PreferencesScope prefScope, String name) {
    final StylesheetPreferencesKey stylesheetPreferencesKey = this.getStylesheetPreferencesKey(request, prefScope);
    final IStylesheetDescriptor stylesheetDescriptor = stylesheetPreferencesKey.stylesheetDescriptor;
    final IStylesheetParameterDescriptor stylesheetParameterDescriptor = stylesheetDescriptor.getStylesheetParameterDescriptor(name);
    if (stylesheetParameterDescriptor == null) {
        logger.warn("Attempted to get stylesheet parameter '{}' but no such stylesheet parameter is defined in stylesheet descriptor '{}'. null will be returned", new Object[] { name, stylesheetDescriptor.getName() });
        return null;
    }
    final String value;
    final Scope scope = stylesheetParameterDescriptor.getScope();
    switch(scope) {
        case PERSISTENT:
            {
                final IStylesheetUserPreferences stylesheetUserPreferences = this.getStylesheetUserPreferences(request, stylesheetPreferencesKey);
                if (stylesheetUserPreferences == null) {
                    return null;
                }
                value = stylesheetUserPreferences.getStylesheetParameter(name);
                break;
            }
        default:
            {
                value = this.getDataValue(request, stylesheetPreferencesKey, scope, STYLESHEET_PARAMETERS_KEY, name);
                break;
            }
    }
    if (value == null) {
        return null;
    }
    //If the value is equal to the default value remove the property and return null
    if (this.compareValues(value, stylesheetParameterDescriptor.getDefaultValue())) {
        this.removeStylesheetParameter(request, prefScope, name);
        return null;
    }
    return value;
}
Also used : IStylesheetParameterDescriptor(org.apereo.portal.layout.om.IStylesheetParameterDescriptor) Scope(org.apereo.portal.layout.om.IStylesheetData.Scope) IStylesheetDescriptor(org.apereo.portal.layout.om.IStylesheetDescriptor) IStylesheetUserPreferences(org.apereo.portal.layout.om.IStylesheetUserPreferences)

Example 7 with IStylesheetParameterDescriptor

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

the class StylesheetUserPreferencesServiceImpl method setStylesheetParameter.

@Transactional
@Override
public String setStylesheetParameter(HttpServletRequest request, PreferencesScope prefScope, String name, String value) {
    logger.trace("Setting stylesheet parameter {} with scope {} to {}.", name, prefScope, value);
    final StylesheetPreferencesKey stylesheetPreferencesKey = this.getStylesheetPreferencesKey(request, prefScope);
    final IStylesheetDescriptor stylesheetDescriptor = stylesheetPreferencesKey.stylesheetDescriptor;
    final IStylesheetParameterDescriptor stylesheetParameterDescriptor = stylesheetDescriptor.getStylesheetParameterDescriptor(name);
    if (stylesheetParameterDescriptor == null) {
        logger.warn("Attempted to set stylesheet parameter {}={} but no such stylesheet parameter is defined in stylesheet descriptor {}. It will be ignored", new Object[] { name, value, stylesheetDescriptor.getName() });
        return null;
    }
    if (this.compareValues(value, stylesheetParameterDescriptor.getDefaultValue())) {
        return this.removeStylesheetParameter(request, prefScope, name);
    }
    final Scope scope = this.getWriteScope(request, prefScope, stylesheetPreferencesKey, stylesheetParameterDescriptor);
    switch(scope) {
        case PERSISTENT:
            {
                IStylesheetUserPreferences stylesheetUserPreferences = this.getStylesheetUserPreferences(request, stylesheetPreferencesKey);
                if (stylesheetUserPreferences == null) {
                    stylesheetUserPreferences = this.stylesheetUserPreferencesDao.createStylesheetUserPreferences(stylesheetDescriptor, stylesheetPreferencesKey.person, stylesheetPreferencesKey.userProfile);
                    this.clearStylesheetUserPreferencesCache(request, stylesheetPreferencesKey);
                }
                final String oldValue = stylesheetUserPreferences.setStylesheetParameter(name, value);
                this.stylesheetUserPreferencesDao.storeStylesheetUserPreferences(stylesheetUserPreferences);
                return oldValue;
            }
        default:
            {
                return this.putDataValue(request, stylesheetPreferencesKey, scope, STYLESHEET_PARAMETERS_KEY, name, value);
            }
    }
}
Also used : IStylesheetParameterDescriptor(org.apereo.portal.layout.om.IStylesheetParameterDescriptor) Scope(org.apereo.portal.layout.om.IStylesheetData.Scope) IStylesheetDescriptor(org.apereo.portal.layout.om.IStylesheetDescriptor) IStylesheetUserPreferences(org.apereo.portal.layout.om.IStylesheetUserPreferences) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with IStylesheetParameterDescriptor

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

the class StylesheetUserPreferencesServiceImpl method removeStylesheetParameter.

@Transactional
@Override
public String removeStylesheetParameter(HttpServletRequest request, PreferencesScope prefScope, String name) {
    final StylesheetPreferencesKey stylesheetPreferencesKey = this.getStylesheetPreferencesKey(request, prefScope);
    final IStylesheetDescriptor stylesheetDescriptor = stylesheetPreferencesKey.stylesheetDescriptor;
    final IStylesheetParameterDescriptor stylesheetParameterDescriptor = stylesheetDescriptor.getStylesheetParameterDescriptor(name);
    if (stylesheetParameterDescriptor == null) {
        logger.warn("Attempted to remove stylesheet parameter {} but no such stylesheet parameter is defined in stylesheet descriptor {}. It will be ignored", new Object[] { name, stylesheetDescriptor.getName() });
        return null;
    }
    final Scope scope = this.getWriteScope(request, prefScope, stylesheetPreferencesKey, stylesheetParameterDescriptor);
    switch(scope) {
        case PERSISTENT:
            {
                final IStylesheetUserPreferences stylesheetUserPreferences = this.getStylesheetUserPreferences(request, stylesheetPreferencesKey);
                if (stylesheetUserPreferences == null) {
                    return null;
                }
                final String oldValue = stylesheetUserPreferences.removeStylesheetParameter(name);
                this.stylesheetUserPreferencesDao.storeStylesheetUserPreferences(stylesheetUserPreferences);
                return oldValue;
            }
        default:
            {
                return removeDataValue(request, stylesheetPreferencesKey, scope, STYLESHEET_PARAMETERS_KEY, name);
            }
    }
}
Also used : IStylesheetParameterDescriptor(org.apereo.portal.layout.om.IStylesheetParameterDescriptor) Scope(org.apereo.portal.layout.om.IStylesheetData.Scope) IStylesheetDescriptor(org.apereo.portal.layout.om.IStylesheetDescriptor) IStylesheetUserPreferences(org.apereo.portal.layout.om.IStylesheetUserPreferences) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with IStylesheetParameterDescriptor

use of org.apereo.portal.layout.om.IStylesheetParameterDescriptor 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 10 with IStylesheetParameterDescriptor

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

the class StylesheetDescriptorImporterExporter method convert.

/**
     * Convert the {@link IStylesheetDescriptor} to an {@link ExternalStylesheetDescriptor}.
     *
     * @param stylesheetDescriptor
     * @return converted object, never null
     */
protected ExternalStylesheetDescriptor convert(IStylesheetDescriptor stylesheetDescriptor) {
    final ExternalStylesheetDescriptor externalStylesheetDescriptor = new ExternalStylesheetDescriptor();
    externalStylesheetDescriptor.setName(stylesheetDescriptor.getName());
    externalStylesheetDescriptor.setUrlSyntaxHelper(stylesheetDescriptor.getUrlNodeSyntaxHelperName());
    externalStylesheetDescriptor.setDescription(stylesheetDescriptor.getDescription());
    externalStylesheetDescriptor.setUri(stylesheetDescriptor.getStylesheetResource());
    final Collection<IOutputPropertyDescriptor> outputPropertyDescriptors = stylesheetDescriptor.getOutputPropertyDescriptors();
    final List<ExternalOutputPropertyDescriptor> extOutputPropertyDescriptors = externalStylesheetDescriptor.getOutputProperties();
    for (final IOutputPropertyDescriptor outputPropertyDescriptor : outputPropertyDescriptors) {
        final ExternalOutputPropertyDescriptor extOutputPropertyDescriptor = new ExternalOutputPropertyDescriptor();
        copyProperties(outputPropertyDescriptor, extOutputPropertyDescriptor);
        extOutputPropertyDescriptors.add(extOutputPropertyDescriptor);
    }
    Collections.sort(extOutputPropertyDescriptors, ExternalStylesheetDataNameComparator.INSTANCE);
    final Collection<IStylesheetParameterDescriptor> stylesheetParameterDescriptors = stylesheetDescriptor.getStylesheetParameterDescriptors();
    final List<ExternalStylesheetParameterDescriptor> extStylesheetParameterDescriptors = externalStylesheetDescriptor.getStylesheetParameters();
    for (final IStylesheetParameterDescriptor stylesheetParameterDescriptor : stylesheetParameterDescriptors) {
        final ExternalStylesheetParameterDescriptor extStylesheetParameterDescriptor = new ExternalStylesheetParameterDescriptor();
        copyProperties(stylesheetParameterDescriptor, extStylesheetParameterDescriptor);
        extStylesheetParameterDescriptors.add(extStylesheetParameterDescriptor);
    }
    Collections.sort(extStylesheetParameterDescriptors, ExternalStylesheetDataNameComparator.INSTANCE);
    final Collection<ILayoutAttributeDescriptor> layoutAttributeDescriptors = stylesheetDescriptor.getLayoutAttributeDescriptors();
    final List<ExternalLayoutAttributeDescriptor> extLayoutAttributeDescriptors = externalStylesheetDescriptor.getLayoutAttributes();
    for (final ILayoutAttributeDescriptor layoutAttributeDescriptor : layoutAttributeDescriptors) {
        final ExternalLayoutAttributeDescriptor extLayoutAttributeDescriptor = new ExternalLayoutAttributeDescriptor();
        copyProperties(layoutAttributeDescriptor, extLayoutAttributeDescriptor);
        extLayoutAttributeDescriptor.getTargetElements().addAll(layoutAttributeDescriptor.getTargetElementNames());
        extLayoutAttributeDescriptors.add(extLayoutAttributeDescriptor);
    }
    Collections.sort(extLayoutAttributeDescriptors, ExternalStylesheetDataNameComparator.INSTANCE);
    return externalStylesheetDescriptor;
}
Also used : ILayoutAttributeDescriptor(org.apereo.portal.layout.om.ILayoutAttributeDescriptor) IOutputPropertyDescriptor(org.apereo.portal.layout.om.IOutputPropertyDescriptor) IStylesheetParameterDescriptor(org.apereo.portal.layout.om.IStylesheetParameterDescriptor)

Aggregations

IStylesheetParameterDescriptor (org.apereo.portal.layout.om.IStylesheetParameterDescriptor)11 IStylesheetDescriptor (org.apereo.portal.layout.om.IStylesheetDescriptor)10 Scope (org.apereo.portal.layout.om.IStylesheetData.Scope)5 IStylesheetUserPreferences (org.apereo.portal.layout.om.IStylesheetUserPreferences)5 ILayoutAttributeDescriptor (org.apereo.portal.layout.om.ILayoutAttributeDescriptor)3 IOutputPropertyDescriptor (org.apereo.portal.layout.om.IOutputPropertyDescriptor)3 Transactional (org.springframework.transaction.annotation.Transactional)3 PreferencesScope (org.apereo.portal.layout.IStylesheetUserPreferencesService.PreferencesScope)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 WindowState (javax.portlet.WindowState)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpSession (javax.servlet.http.HttpSession)1 XMLEventReader (javax.xml.stream.XMLEventReader)1 XMLEvent (javax.xml.stream.events.XMLEvent)1 IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)1 IUserProfile (org.apereo.portal.IUserProfile)1 IStylesheetDescriptorDao (org.apereo.portal.layout.dao.IStylesheetDescriptorDao)1 IStylesheetUserPreferencesDao (org.apereo.portal.layout.dao.IStylesheetUserPreferencesDao)1 LayoutAttributeDescriptorImpl (org.apereo.portal.layout.dao.jpa.LayoutAttributeDescriptorImpl)1