use of org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl in project uPortal by Jasig.
the class PortletDefinitionPreferencesImpl method loadBasePortletPreferences.
@Override
protected void loadBasePortletPreferences(IPortletDefinition portletDefinition, Map<String, IPortletPreference> basePortletPreferences) {
//Add descriptor prefs to base Map
final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId);
final Preferences descriptorPreferences = portletDescriptor.getPortletPreferences();
for (final Preference preference : descriptorPreferences.getPortletPreferences()) {
final IPortletPreference preferenceWrapper = new PortletPreferenceImpl(preference);
basePortletPreferences.put(preferenceWrapper.getName(), preferenceWrapper);
}
}
use of org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl in project uPortal by Jasig.
the class PortletEntityPreferencesImpl method loadBasePortletPreferences.
@Override
protected void loadBasePortletPreferences(IPortletEntity portletEntity, Map<String, IPortletPreference> basePortletPreferences) {
final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
//Add descriptor prefs to base Map
final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId);
final Preferences descriptorPreferences = portletDescriptor.getPortletPreferences();
for (final Preference preference : descriptorPreferences.getPortletPreferences()) {
final IPortletPreference preferenceWrapper = new PortletPreferenceImpl(preference);
basePortletPreferences.put(preferenceWrapper.getName(), preferenceWrapper);
}
//Add definition prefs to base Map
final List<IPortletPreference> definitionPreferences = portletDefinition.getPortletPreferences();
for (final IPortletPreference preference : definitionPreferences) {
basePortletPreferences.put(preference.getName(), preference);
}
}
use of org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl in project uPortal by Jasig.
the class PortletEntityRegistryImpl method createPersistentEntity.
protected IPortletEntity createPersistentEntity(final IPortletEntity portletEntity, final IPortletEntityId wrapperPortletEntityId) {
final IPortletDefinitionId portletDefinitionId = portletEntity.getPortletDefinitionId();
final String layoutNodeId = portletEntity.getLayoutNodeId();
final int userId = portletEntity.getUserId();
IPortletEntity persistentEntity = this.portletEntityDao.getPortletEntity(layoutNodeId, userId);
if (persistentEntity != null) {
this.logger.warn("A persistent portlet entity already exists: " + persistentEntity + ". The data from the passed in entity will be copied to the persistent entity: " + portletEntity);
} else {
persistentEntity = this.portletEntityDao.createPortletEntity(portletDefinitionId, layoutNodeId, userId);
}
//Copy over preferences to avoid modifying any part of the interim entity by reference
final List<IPortletPreference> existingPreferences = portletEntity.getPortletPreferences();
final List<IPortletPreference> persistentPreferences = persistentEntity.getPortletPreferences();
//Only do the copy if the List objects are not the same instance
if (persistentPreferences != existingPreferences) {
persistentPreferences.clear();
for (final IPortletPreference preference : existingPreferences) {
persistentPreferences.add(new PortletPreferenceImpl(preference));
}
}
//Copy over WindowStates
final Map<Long, WindowState> windowStates = portletEntity.getWindowStates();
for (Map.Entry<Long, WindowState> windowStateEntry : windowStates.entrySet()) {
final Long stylesheetDescriptorId = windowStateEntry.getKey();
final IStylesheetDescriptor stylesheetDescriptor = stylesheetDescriptorDao.getStylesheetDescriptor(stylesheetDescriptorId);
final WindowState windowState = windowStateEntry.getValue();
persistentEntity.setWindowState(stylesheetDescriptor, windowState);
}
this.portletEntityDao.updatePortletEntity(persistentEntity);
return persistentEntity;
}
use of org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl in project uPortal by Jasig.
the class RDBMDistributedLayoutStore method importLayout.
@Override
@SuppressWarnings("unchecked")
@Transactional
public void importLayout(org.dom4j.Element layout) {
if (layout.getNamespaceForPrefix("dlm") == null) {
layout.add(new Namespace("dlm", Constants.NS_URI));
}
//Remove comments from the DOM they break import
final List<org.dom4j.Node> comments = layout.selectNodes("//comment()");
for (final org.dom4j.Node comment : comments) {
comment.detach();
}
//Get a ref to the prefs element and then remove it from the layout
final org.dom4j.Node preferencesElement = layout.selectSingleNode("preferences");
if (preferencesElement != null) {
preferencesElement.getParent().remove(preferencesElement);
}
final String ownerUsername = layout.valueOf("@username");
//Get a ref to the profile element and then remove it from the layout
final org.dom4j.Node profileElement = layout.selectSingleNode("profile");
if (profileElement != null) {
profileElement.getParent().remove(profileElement);
final org.dom4j.Document profileDocument = new org.dom4j.DocumentFactory().createDocument();
profileDocument.setRootElement((org.dom4j.Element) profileElement);
profileDocument.setName(ownerUsername + ".profile");
final DocumentSource profileSource = new DocumentSource(profileElement);
this.portalDataHandlerService.importData(profileSource);
}
final IPerson person = new PersonImpl();
person.setUserName(ownerUsername);
int ownerId;
try {
//Can't just pass true for create here, if the user actually exists the create flag also updates the user data
ownerId = this.userIdentityStore.getPortalUID(person);
} catch (final AuthorizationException t) {
if (this.errorOnMissingUser) {
throw new RuntimeException("Unrecognized user " + person.getUserName() + "; you must import users before their layouts or set org.apereo.portal.io.layout.errorOnMissingUser to false.", t);
}
//Create the missing user
ownerId = this.userIdentityStore.getPortalUID(person, true);
}
if (ownerId == -1) {
throw new RuntimeException("Unrecognized user " + person.getUserName() + "; you must import users before their layouts or set org.apereo.portal.io.layout.errorOnMissingUser to false.");
}
person.setID(ownerId);
IUserProfile profile = null;
try {
person.setSecurityContext(new BrokenSecurityContext());
profile = this.getUserProfileByFname(person, "default");
} catch (final Throwable t) {
throw new RuntimeException("Failed to load profile for " + person.getUserName() + "; This user must have a profile for import to continue.", t);
}
// (6) Add database Ids & (5) Add dlm:plfID ...
int nextId = 1;
for (final Iterator<org.dom4j.Element> it = (Iterator<org.dom4j.Element>) layout.selectNodes("folder | dlm:* | channel").iterator(); it.hasNext(); ) {
nextId = this.addIdAttributesIfNecessary(it.next(), nextId);
}
// Now update UP_USER...
this.jdbcOperations.update("UPDATE up_user SET next_struct_id = ? WHERE user_id = ?", nextId, person.getID());
// (4) Convert external DLM pathrefs to internal form (noderefs)...
for (final Iterator<org.dom4j.Attribute> itr = (Iterator<org.dom4j.Attribute>) layout.selectNodes("//@dlm:origin").iterator(); itr.hasNext(); ) {
final org.dom4j.Attribute a = itr.next();
final Noderef dlmNoderef = nodeReferenceFactory.getNoderefFromPathref(ownerUsername, a.getValue(), null, true, layout);
if (dlmNoderef != null) {
// Change the value only if we have a valid pathref...
a.setValue(dlmNoderef.toString());
// For dlm:origin only, also use the noderef as the ID attribute...
a.getParent().addAttribute("ID", dlmNoderef.toString());
} else {
// At least insure the value is between 1 and 35 characters
a.setValue(BAD_PATHREF_MESSAGE);
}
}
for (final Iterator<org.dom4j.Attribute> itr = (Iterator<org.dom4j.Attribute>) layout.selectNodes("//@dlm:target").iterator(); itr.hasNext(); ) {
final org.dom4j.Attribute a = itr.next();
final Noderef dlmNoderef = nodeReferenceFactory.getNoderefFromPathref(ownerUsername, a.getValue(), null, true, layout);
// Put in the correct value, or at least insure the value is between 1 and 35 characters
a.setValue(dlmNoderef != null ? dlmNoderef.toString() : BAD_PATHREF_MESSAGE);
}
for (final Iterator<org.dom4j.Attribute> names = (Iterator<org.dom4j.Attribute>) layout.selectNodes("//dlm:*/@name").iterator(); names.hasNext(); ) {
final org.dom4j.Attribute a = names.next();
final String value = a.getValue().trim();
if (!VALID_PATHREF_PATTERN.matcher(value).matches()) {
/* Don't send it to getDlmNoderef if we know in advance it's not
* going to work; saves annoying/misleading log messages and
* possibly some processing. NOTE this is _only_ a problem with
* the name attribute of some dlm:* elements, which seems to go
* unused intentionally in some circumstances
*/
continue;
}
final org.dom4j.Attribute fname = a.getParent().attribute("fname");
Noderef dlmNoderef = null;
if (fname != null) {
dlmNoderef = nodeReferenceFactory.getNoderefFromPathref(ownerUsername, value, fname.getValue(), false, layout);
// Remove the fname attribute now that we're done w/ it...
fname.getParent().remove(fname);
} else {
dlmNoderef = nodeReferenceFactory.getNoderefFromPathref(ownerUsername, value, null, true, layout);
}
// Put in the correct value, or at least insure the value is between 1 and 35 characters
a.setValue(dlmNoderef != null ? dlmNoderef.toString() : BAD_PATHREF_MESSAGE);
}
// (3) Restore chanID attributes on <channel> elements...
for (final Iterator<org.dom4j.Element> it = (Iterator<org.dom4j.Element>) layout.selectNodes("//channel").iterator(); it.hasNext(); ) {
final org.dom4j.Element c = it.next();
final String fname = c.valueOf("@fname");
final IPortletDefinition cd = this.portletDefinitionRegistry.getPortletDefinitionByFname(fname);
if (cd == null) {
final String msg = "No portlet with fname=" + fname + " exists referenced by node " + c.valueOf("@ID") + " from layout for " + ownerUsername;
if (errorOnMissingPortlet) {
throw new IllegalArgumentException(msg);
} else {
logger.warn(msg);
//Remove the bad channel node
c.getParent().remove(c);
}
} else {
c.addAttribute("chanID", String.valueOf(cd.getPortletDefinitionId().getStringId()));
}
}
// (2) Restore locale info...
// (This step doesn't appear to be needed for imports)
// (1) Process structure & theme attributes...
Document layoutDom = null;
try {
final int structureStylesheetId = profile.getStructureStylesheetId();
this.loadStylesheetUserPreferencesAttributes(person, profile, layout, structureStylesheetId, "structure");
final int themeStylesheetId = profile.getThemeStylesheetId();
this.loadStylesheetUserPreferencesAttributes(person, profile, layout, themeStylesheetId, "theme");
// From this point forward we need the user's PLF set as DLM expects it...
for (final Iterator<org.dom4j.Text> it = (Iterator<org.dom4j.Text>) layout.selectNodes("descendant::text()").iterator(); it.hasNext(); ) {
// How many years have we used Java & XML, and this still isn't easy?
final org.dom4j.Text txt = it.next();
if (txt.getText().trim().length() == 0) {
txt.getParent().remove(txt);
}
}
final org.dom4j.Element copy = layout.createCopy();
final org.dom4j.Document doc = this.fac.createDocument(copy);
doc.normalize();
layoutDom = this.writer.get().write(doc);
person.setAttribute(Constants.PLF, layoutDom);
} catch (final Throwable t) {
throw new RuntimeException("Unable to set UserPreferences for user: " + person.getUserName(), t);
}
// Finally store the layout...
try {
this.setUserLayout(person, profile, layoutDom, true, true);
} catch (final Throwable t) {
final String msg = "Unable to persist layout for user: " + ownerUsername;
throw new RuntimeException(msg, t);
}
if (preferencesElement != null) {
final int ownerUserId = this.userIdentityStore.getPortalUserId(ownerUsername);
//TODO this assumes a single layout, when multi-layout support exists portlet entities will need to be re-worked to allow for a layout id to be associated with the entity
//track which entities from the user's pre-existing set are touched (all non-touched entities will be removed)
final Set<IPortletEntity> oldPortletEntities = new LinkedHashSet<IPortletEntity>(this.portletEntityDao.getPortletEntitiesForUser(ownerUserId));
final List<org.dom4j.Element> entries = preferencesElement.selectNodes("entry");
for (final org.dom4j.Element entry : entries) {
final String dlmPathRef = entry.attributeValue("entity");
final String fname = entry.attributeValue("channel");
final String prefName = entry.attributeValue("name");
final Noderef dlmNoderef = nodeReferenceFactory.getNoderefFromPathref(person.getUserName(), dlmPathRef, fname, false, layout);
if (dlmNoderef != null && fname != null) {
final IPortletEntity portletEntity = this.getPortletEntity(fname, dlmNoderef.toString(), ownerUserId);
oldPortletEntities.remove(portletEntity);
final List<IPortletPreference> portletPreferences = portletEntity.getPortletPreferences();
final List<org.dom4j.Element> valueElements = entry.selectNodes("value");
final List<String> values = new ArrayList<String>(valueElements.size());
for (final org.dom4j.Element valueElement : valueElements) {
values.add(valueElement.getText());
}
portletPreferences.add(new PortletPreferenceImpl(prefName, false, values.toArray(new String[values.size()])));
this.portletEntityDao.updatePortletEntity(portletEntity);
}
}
//Delete all portlet preferences for entities that were not imported
for (final IPortletEntity portletEntity : oldPortletEntities) {
portletEntity.setPortletPreferences(null);
if (portletEntityRegistry.shouldBePersisted(portletEntity)) {
this.portletEntityDao.updatePortletEntity(portletEntity);
} else {
this.portletEntityDao.deletePortletEntity(portletEntity);
}
}
}
}
use of org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl in project uPortal by Jasig.
the class PortletDefinitionImporterExporter method importData.
@Transactional
@Override
public void importData(ExternalPortletDefinition portletRep) {
final PortletDescriptor portletDescriptor = portletRep.getPortletDescriptor();
final Boolean isFramework = portletDescriptor.isIsFramework();
if (isFramework != null && isFramework && "UPGRADED_CHANNEL_IS_NOT_A_PORTLET".equals(portletDescriptor.getPortletName())) {
if (errorOnChannel) {
throw new IllegalArgumentException(portletRep.getFname() + " is not a portlet. It was likely an IChannel from a previous version of uPortal and cannot be imported.");
}
logger.warn(portletRep.getFname() + " is not a portlet. It was likely an IChannel from a previous version of uPortal and will not be imported.");
return;
}
// get the portlet type
final IPortletType portletType = portletTypeRegistry.getPortletType(portletRep.getType());
if (portletType == null) {
throw new IllegalArgumentException("No portlet type registered for: " + portletRep.getType());
}
final List<PortletCategory> categories = new ArrayList<PortletCategory>();
for (String categoryName : portletRep.getCategories()) {
EntityIdentifier[] cats = GroupService.searchForGroups(categoryName, IGroupConstants.IS, IPortletDefinition.class);
PortletCategory category = null;
if (cats != null && cats.length > 0) {
category = portletCategoryRegistry.getPortletCategory(cats[0].getKey());
} else {
category = portletCategoryRegistry.getPortletCategory(categoryName);
}
if (category == null) {
throw new IllegalArgumentException("No category '" + categoryName + "' found when importing portlet: " + portletRep.getFname());
}
categories.add(category);
}
final String fname = portletRep.getFname();
final Map<ExternalPermissionDefinition, Set<IGroupMember>> permissions = new HashMap<>();
final Set<IGroupMember> subscribeMembers = toGroupMembers(portletRep.getGroups(), fname);
permissions.put(ExternalPermissionDefinition.SUBSCRIBE, subscribeMembers);
if (portletRep.getPermissions() != null && portletRep.getPermissions().getPermissions() != null) {
for (ExternalPermissionMemberList perm : portletRep.getPermissions().getPermissions()) {
Set<IGroupMember> members = toGroupMembers(perm.getGroups(), fname);
ExternalPermissionDefinition permDef = toExternalPermissionDefinition(perm.getSystem(), perm.getActivity());
if (permissions.containsKey(permDef)) {
permissions.get(permDef).addAll(members);
} else {
permissions.put(permDef, members);
}
}
}
IPortletDefinition def = portletDefinitionDao.getPortletDefinitionByFname(fname);
if (def == null) {
def = new PortletDefinitionImpl(portletType, fname, portletRep.getName(), portletRep.getTitle(), portletDescriptor.getWebAppName(), portletDescriptor.getPortletName(), isFramework != null ? isFramework : false);
} else {
final IPortletDescriptorKey portletDescriptorKey = def.getPortletDescriptorKey();
portletDescriptorKey.setPortletName(portletDescriptor.getPortletName());
if (isFramework != null && isFramework) {
portletDescriptorKey.setFrameworkPortlet(true);
portletDescriptorKey.setWebAppName(null);
} else {
portletDescriptorKey.setFrameworkPortlet(false);
portletDescriptorKey.setWebAppName(portletDescriptor.getWebAppName());
}
def.setName(portletRep.getName());
def.setTitle(portletRep.getTitle());
def.setType(portletType);
}
def.setDescription(portletRep.getDesc());
final BigInteger timeout = portletRep.getTimeout();
if (timeout != null) {
def.setTimeout(timeout.intValue());
}
final BigInteger actionTimeout = portletRep.getActionTimeout();
if (actionTimeout != null) {
def.setActionTimeout(actionTimeout.intValue());
}
final BigInteger eventTimeout = portletRep.getEventTimeout();
if (eventTimeout != null) {
def.setEventTimeout(eventTimeout.intValue());
}
final BigInteger renderTimeout = portletRep.getRenderTimeout();
if (renderTimeout != null) {
def.setRenderTimeout(renderTimeout.intValue());
}
final BigInteger resourceTimeout = portletRep.getResourceTimeout();
if (resourceTimeout != null) {
def.setResourceTimeout(resourceTimeout.intValue());
}
handleLifecycleApproval(def, portletRep.getLifecycle());
handleLifecyclePublished(def, portletRep.getLifecycle());
handleLifecycleExpired(def, portletRep.getLifecycle());
final Set<IPortletDefinitionParameter> parameters = new LinkedHashSet<IPortletDefinitionParameter>();
for (ExternalPortletParameter param : portletRep.getParameters()) {
parameters.add(new PortletDefinitionParameterImpl(param.getName(), param.getValue()));
}
def.setParameters(parameters);
final ArrayList<IPortletPreference> preferenceList = new ArrayList<IPortletPreference>();
for (ExternalPortletPreference pref : portletRep.getPortletPreferences()) {
final List<String> valueList = pref.getValues();
final String[] values = valueList.toArray(new String[valueList.size()]);
final Boolean readOnly = pref.isReadOnly();
preferenceList.add(new PortletPreferenceImpl(pref.getName(), readOnly != null ? readOnly : false, values));
}
def.setPortletPreferences(preferenceList);
savePortletDefinition(def, systemUser, categories, permissions);
}
Aggregations