Search in sources :

Example 1 with IStylesheetUserPreferences

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

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

the class StylesheetUserPreferencesServiceImpl method populateLayoutAttributes.

@Override
public <P extends Populator<String, String>> P populateLayoutAttributes(HttpServletRequest request, PreferencesScope prefScope, String nodeId, P layoutAttributes) {
    final StylesheetPreferencesKey stylesheetPreferencesKey = this.getStylesheetPreferencesKey(request, prefScope);
    final IStylesheetDescriptor stylesheetDescriptor = stylesheetPreferencesKey.stylesheetDescriptor;
    //Get the scoped sources once
    final IStylesheetUserPreferences stylesheetUserPreferences = this.getStylesheetUserPreferences(request, stylesheetPreferencesKey);
    final Map<String, Map<String, String>> sessionLayoutAttributes;
    final HttpSession session = request.getSession(false);
    if (session == null) {
        sessionLayoutAttributes = null;
    } else {
        sessionLayoutAttributes = getSessionLayoutAttributes(session, stylesheetPreferencesKey);
    }
    final Map<String, Map<String, String>> requestLayoutAttributes = getRequestLayoutAttributes(request, stylesheetPreferencesKey);
    final IStylesheetUserPreferences distributedStylesheetUserPreferences = this.getDistributedStylesheetUserPreferences(request, prefScope);
    if (distributedStylesheetUserPreferences != null) {
        distributedStylesheetUserPreferences.populateLayoutAttributes(nodeId, layoutAttributes);
    }
    //Try getting each layout attribute to populate the Map
    for (final ILayoutAttributeDescriptor layoutAttributeDescriptor : stylesheetDescriptor.getLayoutAttributeDescriptors()) {
        final String name = layoutAttributeDescriptor.getName();
        String value;
        final Scope scope = layoutAttributeDescriptor.getScope();
        switch(scope) {
            case PERSISTENT:
                {
                    if (stylesheetUserPreferences == null) {
                        value = null;
                        break;
                    }
                    value = stylesheetUserPreferences.getLayoutAttribute(nodeId, name);
                    break;
                }
            case SESSION:
                {
                    if (sessionLayoutAttributes == null) {
                        value = null;
                        break;
                    }
                    final Map<String, String> nodeAttributes = sessionLayoutAttributes.get(nodeId);
                    if (nodeAttributes == null) {
                        value = null;
                        break;
                    }
                    value = nodeAttributes.get(name);
                    break;
                }
            case REQUEST:
                {
                    if (requestLayoutAttributes == null) {
                        value = null;
                        break;
                    }
                    final Map<String, String> nodeAttributes = requestLayoutAttributes.get(nodeId);
                    if (nodeAttributes == null) {
                        value = null;
                        break;
                    }
                    value = nodeAttributes.get(name);
                    break;
                }
            default:
                {
                    value = null;
                    break;
                }
        }
        //Don't add unset properties
        if (value == null) {
            continue;
        }
        //If the value is equal to the default value remove the property and return null
        if (this.compareValues(value, layoutAttributeDescriptor.getDefaultValue())) {
            this.removeLayoutAttribute(request, prefScope, nodeId, name);
            continue;
        }
        layoutAttributes.put(name, value);
    }
    return layoutAttributes;
}
Also used : Scope(org.apereo.portal.layout.om.IStylesheetData.Scope) HttpSession(javax.servlet.http.HttpSession) IStylesheetDescriptor(org.apereo.portal.layout.om.IStylesheetDescriptor) IStylesheetUserPreferences(org.apereo.portal.layout.om.IStylesheetUserPreferences) ILayoutAttributeDescriptor(org.apereo.portal.layout.om.ILayoutAttributeDescriptor) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 3 with IStylesheetUserPreferences

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

the class StylesheetUserPreferencesServiceImpl method removeOutputProperty.

@Transactional
@Override
public String removeOutputProperty(HttpServletRequest request, PreferencesScope prefScope, String name) {
    final StylesheetPreferencesKey stylesheetPreferencesKey = this.getStylesheetPreferencesKey(request, prefScope);
    final IStylesheetDescriptor stylesheetDescriptor = stylesheetPreferencesKey.stylesheetDescriptor;
    final IOutputPropertyDescriptor outputPropertyDescriptor = stylesheetDescriptor.getOutputPropertyDescriptor(name);
    if (outputPropertyDescriptor == null) {
        logger.warn("Attempted to remove output property '{}' but no such output property is defined in stylesheet descriptor '{}'. It will be ignored", new Object[] { name, stylesheetDescriptor.getName() });
        return null;
    }
    final Scope scope = this.getWriteScope(request, prefScope, stylesheetPreferencesKey, outputPropertyDescriptor);
    switch(scope) {
        case PERSISTENT:
            {
                final IStylesheetUserPreferences stylesheetUserPreferences = this.getStylesheetUserPreferences(request, stylesheetPreferencesKey);
                if (stylesheetUserPreferences == null) {
                    return null;
                }
                final String oldValue = stylesheetUserPreferences.removeOutputProperty(name);
                this.stylesheetUserPreferencesDao.storeStylesheetUserPreferences(stylesheetUserPreferences);
                this.clearStylesheetUserPreferencesCache(request, stylesheetPreferencesKey);
                return oldValue;
            }
        default:
            {
                return removeDataValue(request, stylesheetPreferencesKey, scope, OUTPUT_PROPERTIES_KEY, name);
            }
    }
}
Also used : IOutputPropertyDescriptor(org.apereo.portal.layout.om.IOutputPropertyDescriptor) 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 4 with IStylesheetUserPreferences

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

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

the class StylesheetUserPreferencesServiceImpl method removeLayoutAttribute.

@Transactional
@Override
public String removeLayoutAttribute(HttpServletRequest request, PreferencesScope prefScope, String nodeId, String name) {
    final StylesheetPreferencesKey stylesheetPreferencesKey = this.getStylesheetPreferencesKey(request, prefScope);
    final IStylesheetDescriptor stylesheetDescriptor = stylesheetPreferencesKey.stylesheetDescriptor;
    final ILayoutAttributeDescriptor layoutAttributeDescriptor = stylesheetDescriptor.getLayoutAttributeDescriptor(name);
    if (layoutAttributeDescriptor == null) {
        logger.warn("Attempted to remove layout attribute {} for ID=\"{}\" but no such stylesheet parameter is defined in stylesheet descriptor {}. It will be ignored.", new Object[] { name, nodeId, stylesheetDescriptor.getName() });
        return null;
    }
    final Scope scope = this.getWriteScope(request, prefScope, stylesheetPreferencesKey, layoutAttributeDescriptor);
    switch(scope) {
        case PERSISTENT:
            {
                final IStylesheetUserPreferences stylesheetUserPreferences = this.getStylesheetUserPreferences(request, stylesheetPreferencesKey);
                if (stylesheetUserPreferences == null) {
                    break;
                }
                final String oldValue = stylesheetUserPreferences.removeLayoutAttribute(nodeId, name);
                if (oldValue != null) {
                    this.stylesheetUserPreferencesDao.storeStylesheetUserPreferences(stylesheetUserPreferences);
                    return oldValue;
                }
            }
        default:
            {
                final Map<String, String> nodeAttributes = this.getDataValue(request, stylesheetPreferencesKey, scope, LAYOUT_ATTRIBUTES_KEY, nodeId);
                if (nodeAttributes == null) {
                    break;
                }
                final String oldValue = nodeAttributes.remove(name);
                if (oldValue != null) {
                    return oldValue;
                }
            }
    }
    final IStylesheetUserPreferences distributedStylesheetUserPreferences = this.getDistributedStylesheetUserPreferences(request, prefScope);
    if (distributedStylesheetUserPreferences != null) {
        return distributedStylesheetUserPreferences.removeLayoutAttribute(nodeId, name);
    }
    return null;
}
Also used : Scope(org.apereo.portal.layout.om.IStylesheetData.Scope) IStylesheetDescriptor(org.apereo.portal.layout.om.IStylesheetDescriptor) IStylesheetUserPreferences(org.apereo.portal.layout.om.IStylesheetUserPreferences) ILayoutAttributeDescriptor(org.apereo.portal.layout.om.ILayoutAttributeDescriptor) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IStylesheetUserPreferences (org.apereo.portal.layout.om.IStylesheetUserPreferences)19 IStylesheetDescriptor (org.apereo.portal.layout.om.IStylesheetDescriptor)15 Scope (org.apereo.portal.layout.om.IStylesheetData.Scope)10 Map (java.util.Map)8 HttpSession (javax.servlet.http.HttpSession)7 ImmutableMap (com.google.common.collect.ImmutableMap)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 ConcurrentMap (java.util.concurrent.ConcurrentMap)6 ILayoutAttributeDescriptor (org.apereo.portal.layout.om.ILayoutAttributeDescriptor)5 IStylesheetParameterDescriptor (org.apereo.portal.layout.om.IStylesheetParameterDescriptor)5 Transactional (org.springframework.transaction.annotation.Transactional)5 MapPopulator (org.apereo.portal.utils.MapPopulator)4 IOutputPropertyDescriptor (org.apereo.portal.layout.om.IOutputPropertyDescriptor)3 HashMap (java.util.HashMap)2 IUserProfile (org.apereo.portal.IUserProfile)2 IPerson (org.apereo.portal.security.IPerson)2 Test (org.junit.Test)2 Element (org.w3c.dom.Element)2 NamedNodeMap (org.w3c.dom.NamedNodeMap)2 LinkedHashSet (java.util.LinkedHashSet)1