use of org.apereo.portal.layout.StylesheetUserPreferencesImpl in project uPortal by Jasig.
the class RDBMDistributedLayoutStore method loadDistributedStylesheetUserPreferences.
private IStylesheetUserPreferences loadDistributedStylesheetUserPreferences(IPerson person, IUserProfile profile, long stylesheetDescriptorId, Set<String> fragmentNames) {
final boolean isFragmentOwner = this.isFragmentOwner(person);
final Locale locale = profile.getLocaleManager().getLocales()[0];
final IStylesheetDescriptor stylesheetDescriptor = this.stylesheetDescriptorDao.getStylesheetDescriptor(stylesheetDescriptorId);
final IStylesheetUserPreferences stylesheetUserPreferences = this.stylesheetUserPreferencesDao.getStylesheetUserPreferences(stylesheetDescriptor, person, profile);
final IStylesheetUserPreferences distributedStylesheetUserPreferences = new StylesheetUserPreferencesImpl();
for (final String fragName : fragmentNames) {
final FragmentDefinition fragmentDefinition = this.fragmentUtils.getFragmentDefinitionByName(fragName);
//UserView may be missing if the fragment isn't defined correctly
final UserView userView = this.fragmentUtils.getUserView(fragmentDefinition, locale);
if (userView == null) {
logger.warn("No UserView is present for fragment {} it will be skipped when loading distributed stylesheet user preferences", fragmentDefinition.getName());
continue;
}
//IStylesheetUserPreferences only exist if something was actually set
final IStylesheetUserPreferences fragmentStylesheetUserPreferences = this.stylesheetUserPreferencesDao.getStylesheetUserPreferences(stylesheetDescriptor, userView.getUserId(), userView.getProfileId());
if (fragmentStylesheetUserPreferences == null) {
continue;
}
//Get the info needed to DLMify node IDs
final Element root = userView.getLayout().getDocumentElement();
final String labelBase = root.getAttribute(Constants.ATT_ID);
boolean modified = false;
// Copy all of the fragment preferences into the distributed preferences
final Collection<String> allLayoutAttributeNodeIds = fragmentStylesheetUserPreferences.getAllLayoutAttributeNodeIds();
for (final String fragmentNodeId : allLayoutAttributeNodeIds) {
final String userNodeId = (isFragmentOwner || fragmentNodeId.startsWith(Constants.FRAGMENT_ID_USER_PREFIX)) ? fragmentNodeId : labelBase + fragmentNodeId;
final MapPopulator<String, String> layoutAttributesPopulator = new MapPopulator<String, String>();
fragmentStylesheetUserPreferences.populateLayoutAttributes(fragmentNodeId, layoutAttributesPopulator);
final Map<String, String> layoutAttributes = layoutAttributesPopulator.getMap();
for (final Map.Entry<String, String> layoutAttributesEntry : layoutAttributes.entrySet()) {
final String name = layoutAttributesEntry.getKey();
final String value = layoutAttributesEntry.getValue();
// Fragmentize the nodeId here
distributedStylesheetUserPreferences.setLayoutAttribute(userNodeId, name, value);
// are identical and removing layout attributes here would affect the fragment layout.
if (stylesheetUserPreferences != null && !isFragmentOwner) {
final String userValue = stylesheetUserPreferences.getLayoutAttribute(userNodeId, name);
if (userValue != null && userValue.equals(value)) {
stylesheetUserPreferences.removeLayoutAttribute(userNodeId, name);
EditManager.removePreferenceDirective(person, userNodeId, name);
modified = true;
}
}
}
}
if (modified) {
this.stylesheetUserPreferencesDao.storeStylesheetUserPreferences(stylesheetUserPreferences);
}
}
return distributedStylesheetUserPreferences;
}
Aggregations