Search in sources :

Example 1 with Scope

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

the class StylesheetDescriptorImporterExporter method importData.

/* (non-Javadoc)
     * @see org.apereo.portal.io.xml.IDataImporterExporter#importData(java.lang.Object)
     */
@Transactional
@Override
public void importData(ExternalStylesheetDescriptor data) {
    final String stylesheetName = data.getName();
    final String uri = data.getUri();
    IStylesheetDescriptor stylesheetDescriptor = this.stylesheetDescriptorDao.getStylesheetDescriptorByName(stylesheetName);
    if (stylesheetDescriptor == null) {
        stylesheetDescriptor = this.stylesheetDescriptorDao.createStylesheetDescriptor(stylesheetName, uri);
    } else {
        stylesheetDescriptor.setStylesheetResource(uri);
    }
    stylesheetDescriptor.setUrlNodeSyntaxHelperName(data.getUrlSyntaxHelper());
    stylesheetDescriptor.setDescription(data.getDescription());
    final List<ExternalOutputPropertyDescriptor> extOutputProperties = data.getOutputProperties();
    final List<IOutputPropertyDescriptor> outputPropertyDescriptors = new ArrayList<IOutputPropertyDescriptor>(extOutputProperties.size());
    for (final ExternalOutputPropertyDescriptor extOutputProperty : extOutputProperties) {
        final String name = extOutputProperty.getName();
        final Scope scope = Scope.valueOf(extOutputProperty.getScope().name());
        final OutputPropertyDescriptorImpl outputPropertyDescriptor = new OutputPropertyDescriptorImpl(name, scope);
        outputPropertyDescriptor.setDefaultValue(extOutputProperty.getDefaultValue());
        outputPropertyDescriptor.setDescription(extOutputProperty.getDescription());
        outputPropertyDescriptors.add(outputPropertyDescriptor);
    }
    stylesheetDescriptor.setOutputPropertyDescriptors(outputPropertyDescriptors);
    final List<ExternalStylesheetParameterDescriptor> extStylesheetParameters = data.getStylesheetParameters();
    final List<IStylesheetParameterDescriptor> stylesheetParameterDescriptors = new ArrayList<IStylesheetParameterDescriptor>(extOutputProperties.size());
    for (final ExternalStylesheetParameterDescriptor extStylesheetParameter : extStylesheetParameters) {
        final String name = extStylesheetParameter.getName();
        final Scope scope = Scope.valueOf(extStylesheetParameter.getScope().name());
        final StylesheetParameterDescriptorImpl stylesheetParameterDescriptor = new StylesheetParameterDescriptorImpl(name, scope);
        stylesheetParameterDescriptor.setDefaultValue(extStylesheetParameter.getDefaultValue());
        stylesheetParameterDescriptor.setDescription(extStylesheetParameter.getDescription());
        stylesheetParameterDescriptors.add(stylesheetParameterDescriptor);
    }
    stylesheetDescriptor.setStylesheetParameterDescriptors(stylesheetParameterDescriptors);
    final List<ExternalLayoutAttributeDescriptor> extLayoutAttributes = data.getLayoutAttributes();
    final List<ILayoutAttributeDescriptor> layoutAttributeDescriptors = new ArrayList<ILayoutAttributeDescriptor>(extOutputProperties.size());
    for (final ExternalLayoutAttributeDescriptor extLayoutAttribute : extLayoutAttributes) {
        final String name = extLayoutAttribute.getName();
        final Scope scope = Scope.valueOf(extLayoutAttribute.getScope().name());
        final LayoutAttributeDescriptorImpl layoutAttributeDescriptor = new LayoutAttributeDescriptorImpl(name, scope);
        layoutAttributeDescriptor.setDefaultValue(extLayoutAttribute.getDefaultValue());
        layoutAttributeDescriptor.setDescription(extLayoutAttribute.getDescription());
        layoutAttributeDescriptor.setTargetElementNames(new LinkedHashSet<String>(extLayoutAttribute.getTargetElements()));
        layoutAttributeDescriptors.add(layoutAttributeDescriptor);
    }
    stylesheetDescriptor.setLayoutAttributeDescriptors(layoutAttributeDescriptors);
    this.stylesheetDescriptorDao.updateStylesheetDescriptor(stylesheetDescriptor);
}
Also used : LayoutAttributeDescriptorImpl(org.apereo.portal.layout.dao.jpa.LayoutAttributeDescriptorImpl) OutputPropertyDescriptorImpl(org.apereo.portal.layout.dao.jpa.OutputPropertyDescriptorImpl) ArrayList(java.util.ArrayList) StylesheetParameterDescriptorImpl(org.apereo.portal.layout.dao.jpa.StylesheetParameterDescriptorImpl) ILayoutAttributeDescriptor(org.apereo.portal.layout.om.ILayoutAttributeDescriptor) IOutputPropertyDescriptor(org.apereo.portal.layout.om.IOutputPropertyDescriptor) IStylesheetParameterDescriptor(org.apereo.portal.layout.om.IStylesheetParameterDescriptor) Scope(org.apereo.portal.layout.om.IStylesheetData.Scope) IStylesheetDescriptor(org.apereo.portal.layout.om.IStylesheetDescriptor) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with Scope

use of org.apereo.portal.layout.om.IStylesheetData.Scope 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 3 with Scope

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

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

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

Aggregations

Scope (org.apereo.portal.layout.om.IStylesheetData.Scope)12 IStylesheetDescriptor (org.apereo.portal.layout.om.IStylesheetDescriptor)11 IStylesheetUserPreferences (org.apereo.portal.layout.om.IStylesheetUserPreferences)10 Transactional (org.springframework.transaction.annotation.Transactional)6 ILayoutAttributeDescriptor (org.apereo.portal.layout.om.ILayoutAttributeDescriptor)5 IStylesheetParameterDescriptor (org.apereo.portal.layout.om.IStylesheetParameterDescriptor)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 HttpSession (javax.servlet.http.HttpSession)4 IOutputPropertyDescriptor (org.apereo.portal.layout.om.IOutputPropertyDescriptor)3 ArrayList (java.util.ArrayList)1 LayoutAttributeDescriptorImpl (org.apereo.portal.layout.dao.jpa.LayoutAttributeDescriptorImpl)1 OutputPropertyDescriptorImpl (org.apereo.portal.layout.dao.jpa.OutputPropertyDescriptorImpl)1 StylesheetParameterDescriptorImpl (org.apereo.portal.layout.dao.jpa.StylesheetParameterDescriptorImpl)1