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;
}
});
}
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;
}
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);
}
}
}
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;
}
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;
}
Aggregations