Search in sources :

Example 6 with ILayoutAttributeDescriptor

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

the class StylesheetUserPreferencesServiceImpl method getLayoutAttribute.

@Override
public String getLayoutAttribute(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 get layout attribute {} for ID=\"{}\" but no such stylesheet parameter is defined in stylesheet descriptor {}. Null will be returned", new Object[] { name, nodeId, stylesheetDescriptor.getName() });
        return null;
    }
    // Load the default value
    String defaultValue = null;
    final IStylesheetUserPreferences distributedStylesheetUserPreferences = this.getDistributedStylesheetUserPreferences(request, prefScope);
    if (distributedStylesheetUserPreferences != null) {
        defaultValue = distributedStylesheetUserPreferences.getLayoutAttribute(nodeId, name);
        // special handling for fragment owner
        if (this.isFragmentOwnerStylesheetPreferencesKey(stylesheetPreferencesKey)) {
            return defaultValue;
        }
        if (this.compareValues(defaultValue, layoutAttributeDescriptor.getDefaultValue())) {
            // DLM attribute value matches the stylesheet descriptor default, remove the DLM
            // value
            distributedStylesheetUserPreferences.removeLayoutAttribute(nodeId, name);
            defaultValue = null;
        }
    }
    final String value;
    final Scope scope = layoutAttributeDescriptor.getScope();
    switch(scope) {
        case PERSISTENT:
            {
                final IStylesheetUserPreferences stylesheetUserPreferences = this.getStylesheetUserPreferences(request, stylesheetPreferencesKey);
                if (stylesheetUserPreferences == null) {
                    value = null;
                    break;
                }
                value = stylesheetUserPreferences.getLayoutAttribute(nodeId, name);
                break;
            }
        default:
            {
                final Map<String, String> nodeAttributes = this.getDataValue(request, stylesheetPreferencesKey, scope, LAYOUT_ATTRIBUTES_KEY, nodeId);
                if (nodeAttributes == null) {
                    value = null;
                    break;
                }
                value = nodeAttributes.get(name);
                break;
            }
    }
    if (value == null) {
        return defaultValue;
    }
    if (!this.isFragmentOwnerStylesheetPreferencesKey(stylesheetPreferencesKey)) {
        if (this.compareValues(value, layoutAttributeDescriptor.getDefaultValue()) || // Value is equal to stylesheet descriptor default
        (defaultValue != null && this.compareValues(value, defaultValue))) {
            // Value is equal to DLM stylesheet
            // preferences default
            // Remove the user's customized value
            this.removeLayoutAttribute(request, prefScope, nodeId, name);
            return null;
        }
    }
    return value;
}
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)

Example 7 with ILayoutAttributeDescriptor

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

the class StylesheetUserPreferencesServiceImpl method setLayoutAttribute.

@Transactional
@Override
public String setLayoutAttribute(HttpServletRequest request, PreferencesScope prefScope, String nodeId, String name, String value) {
    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 set layout attribute {}={} on node with ID=\"{}\" but no such stylesheet parameter is defined in stylesheet descriptor {}. It will be ignored.", new Object[] { name, value, nodeId, stylesheetDescriptor.getName() });
        return null;
    }
    if (this.compareValues(value, layoutAttributeDescriptor.getDefaultValue())) {
        // Value matches the default value, remove the attribute
        return this.removeLayoutAttribute(request, prefScope, nodeId, name);
    }
    final IStylesheetUserPreferences distributedStylesheetUserPreferences = this.getDistributedStylesheetUserPreferences(request, prefScope);
    if (distributedStylesheetUserPreferences != null) {
        final String defaultValue = distributedStylesheetUserPreferences.getLayoutAttribute(nodeId, name);
        if (this.compareValues(value, defaultValue)) {
            // Value matches the DLM preferences value, remove the value
            return this.removeLayoutAttribute(request, prefScope, nodeId, name);
        }
    }
    final Scope scope = this.getWriteScope(request, prefScope, stylesheetPreferencesKey, layoutAttributeDescriptor);
    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.setLayoutAttribute(nodeId, name, value);
                this.stylesheetUserPreferencesDao.storeStylesheetUserPreferences(stylesheetUserPreferences);
                return oldValue;
            }
        default:
            {
                // Determine the mutex to use for accessing the nodeAttributes map
                final Object mutex;
                switch(scope) {
                    case REQUEST:
                        {
                            mutex = PortalWebUtils.getRequestAttributeMutex(request);
                            break;
                        }
                    case SESSION:
                        {
                            final HttpSession session = request.getSession();
                            mutex = WebUtils.getSessionMutex(session);
                            break;
                        }
                    default:
                        {
                            mutex = new Object();
                            break;
                        }
                }
                // Get/Create the nodeAttributes map
                Map<String, String> nodeAttributes;
                synchronized (mutex) {
                    nodeAttributes = this.getDataValue(request, stylesheetPreferencesKey, scope, LAYOUT_ATTRIBUTES_KEY, nodeId);
                    if (nodeAttributes == null) {
                        nodeAttributes = new ConcurrentHashMap<>();
                        this.putDataValue(request, stylesheetPreferencesKey, scope, LAYOUT_ATTRIBUTES_KEY, nodeId, nodeAttributes);
                    }
                }
                return nodeAttributes.put(name, value);
            }
    }
}
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) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) 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)

Example 8 with ILayoutAttributeDescriptor

use of org.apereo.portal.layout.om.ILayoutAttributeDescriptor 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)

Example 9 with ILayoutAttributeDescriptor

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

the class StylesheetAttributeSourceForSpELVariablesTest method layoutAttributeFoundForName.

private void layoutAttributeFoundForName(final String layoutAttributeName, final String defaultValue) {
    final ILayoutAttributeDescriptor layoutAttributeDescriptor = mock(ILayoutAttributeDescriptor.class);
    this.layoutAttributeDescriptorReturnsTargetElementNames(layoutAttributeDescriptor, this.localEventName);
    this.layoutAttributeDescriptors.add(layoutAttributeDescriptor);
    given(layoutAttributeDescriptor.getName()).willReturn(layoutAttributeName);
    given(layoutAttributeDescriptor.getDefaultValue()).willReturn(defaultValue);
}
Also used : ILayoutAttributeDescriptor(org.apereo.portal.layout.om.ILayoutAttributeDescriptor)

Aggregations

ILayoutAttributeDescriptor (org.apereo.portal.layout.om.ILayoutAttributeDescriptor)9 IStylesheetDescriptor (org.apereo.portal.layout.om.IStylesheetDescriptor)7 Scope (org.apereo.portal.layout.om.IStylesheetData.Scope)5 IStylesheetUserPreferences (org.apereo.portal.layout.om.IStylesheetUserPreferences)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 Map (java.util.Map)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 ConcurrentMap (java.util.concurrent.ConcurrentMap)4 IOutputPropertyDescriptor (org.apereo.portal.layout.om.IOutputPropertyDescriptor)3 IStylesheetParameterDescriptor (org.apereo.portal.layout.om.IStylesheetParameterDescriptor)3 Transactional (org.springframework.transaction.annotation.Transactional)3 HttpSession (javax.servlet.http.HttpSession)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 QName (javax.xml.namespace.QName)1 Attribute (javax.xml.stream.events.Attribute)1 IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)1 IUserProfile (org.apereo.portal.IUserProfile)1 PreferencesScope (org.apereo.portal.layout.IStylesheetUserPreferencesService.PreferencesScope)1