use of org.apereo.portal.user.IUserInstance in project uPortal by Jasig.
the class PortletEntityRegistryImpl method getOrCreateDefaultPortletEntity.
@Override
public IPortletEntity getOrCreateDefaultPortletEntity(HttpServletRequest request, IPortletDefinitionId portletDefinitionId) {
Validate.notNull(request, "HttpServletRequest cannot be null");
Validate.notNull(portletDefinitionId, "portletDefinitionId cannot be null");
final IPortletDefinition portletDefinition = this.getPortletDefinition(request, portletDefinitionId);
if (portletDefinition == null) {
throw new IllegalArgumentException("No portlet definition found for id '" + portletDefinitionId + "'.");
}
// Determine the appropriate portlet window ID for the definition
final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
// Determine the subscribe ID
final String portletFName = portletDefinition.getFName();
final String layoutNodeId = userLayoutManager.getSubscribeId(portletFName);
if (layoutNodeId == null) {
throw new IllegalArgumentException("No layout node ID found for fname '" + portletFName + "'.");
}
this.logger.trace("Found layout node {} for portlet definition {}", layoutNodeId, portletFName);
final IPerson person = userInstance.getPerson();
final int personId = person.getID();
return this.getOrCreatePortletEntity(request, portletDefinitionId, layoutNodeId, personId);
}
use of org.apereo.portal.user.IUserInstance in project uPortal by Jasig.
the class PortletEntityRegistryImpl method parseConsistentPortletEntityId.
protected IPortletEntityId parseConsistentPortletEntityId(HttpServletRequest request, String consistentEntityIdString) {
Validate.notNull(consistentEntityIdString, "consistentEntityIdString can not be null");
// Check in the cache first
final Element element = this.entityIdParseCache.get(consistentEntityIdString);
if (element != null) {
final Object value = element.getObjectValue();
if (value != null) {
return (IPortletEntityId) value;
}
}
if (!PortletEntityIdStringUtils.hasCorrectNumberOfParts(consistentEntityIdString)) {
throw new IllegalArgumentException("consistentEntityIdString does not have 3 parts and is invalid: " + consistentEntityIdString);
}
// Verify the portlet definition id
final String portletDefinitionIdString = PortletEntityIdStringUtils.parsePortletDefinitionId(consistentEntityIdString);
final IPortletDefinition portletDefinition = this.getPortletDefinition(request, portletDefinitionIdString);
if (portletDefinition == null) {
throw new IllegalArgumentException("No parent IPortletDefinition found for " + portletDefinitionIdString + " from entity id string: " + consistentEntityIdString);
}
final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
// Verify non-delegate layout node id exists and is for a portlet
final String layoutNodeId = PortletEntityIdStringUtils.parseLayoutNodeId(consistentEntityIdString);
if (!PortletEntityIdStringUtils.isDelegateLayoutNode(layoutNodeId)) {
final IUserLayoutNodeDescription node = userLayoutManager.getNode(layoutNodeId);
if (node == null || node.getType() != LayoutNodeType.PORTLET) {
throw new IllegalArgumentException("No portlet layout node found for " + layoutNodeId + " from entity id string: " + consistentEntityIdString);
}
// TODO is this doable for delegation?
// Verify the portlet definition matches
final IUserLayoutChannelDescription portletNode = (IUserLayoutChannelDescription) node;
final String channelPublishId = portletNode.getChannelPublishId();
if (!portletDefinitionId.getStringId().equals(channelPublishId)) {
throw new IllegalArgumentException("The portlet layout node found for " + layoutNodeId + " does not match the IPortletDefinitionId " + portletDefinitionId + " specified in entity id string: " + consistentEntityIdString);
}
}
// TODO when there is a JPA backed user dao actually verify this mapping
// User just conver to an int
final int userId;
final String userIdAsString = PortletEntityIdStringUtils.parseUserIdAsString(consistentEntityIdString);
try {
userId = Integer.parseInt(userIdAsString);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("The user id " + userIdAsString + " is not a valid integer from entity id string: " + consistentEntityIdString, e);
}
final IPortletEntityId portletEntityId = createConsistentPortletEntityId(portletDefinitionId, layoutNodeId, userId);
// Cache the resolution
this.entityIdParseCache.put(new Element(consistentEntityIdString, portletEntityId));
return portletEntityId;
}
use of org.apereo.portal.user.IUserInstance in project uPortal by Jasig.
the class PortletWindowRegistryImpl method storePortletWindow.
@Override
public void storePortletWindow(HttpServletRequest request, IPortletWindow portletWindow) {
if (isDisablePersistentWindowStates(request)) {
return;
}
final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
final IPerson person = userInstance.getPerson();
if (person.isGuest()) {
// Never persist things for the guest user, just rely on in-memory storage
return;
}
final IStylesheetDescriptor themeStylesheetDescriptor = this.getThemeStylesheetDescriptor(request);
final WindowState windowState = portletWindow.getWindowState();
final IPortletEntity portletEntity = portletWindow.getPortletEntity();
final WindowState entityWindowState = portletEntity.getWindowState(themeStylesheetDescriptor);
// If the window and entity states are different
if (windowState != entityWindowState && !windowState.equals(entityWindowState)) {
final WindowState defaultWindowState = this.getDefaultWindowState(themeStylesheetDescriptor);
// If a window state is set and is one of the persistent states set it on the entity
if (!defaultWindowState.equals(windowState) && persistentWindowStates.contains(windowState)) {
portletEntity.setWindowState(themeStylesheetDescriptor, windowState);
} else // If not remove the state from the entity
if (entityWindowState != null) {
portletEntity.setWindowState(themeStylesheetDescriptor, null);
}
// Persist the modified entity
this.portletEntityRegistry.storePortletEntity(request, portletEntity);
}
}
use of org.apereo.portal.user.IUserInstance in project uPortal by Jasig.
the class UserLayoutStoreComponent method getUserLayoutManager.
/**
* Get the {@link IUserLayoutManager} for the user making the request
*/
protected IUserLayoutManager getUserLayoutManager(HttpServletRequest request) {
final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
return preferencesManager.getUserLayoutManager();
}
use of org.apereo.portal.user.IUserInstance in project uPortal by Jasig.
the class ProfileFNamePredicate method test.
@Override
public boolean test(final HttpServletRequest request) {
final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
final String profileFName = userInstance.getPreferencesManager().getUserProfile().getProfileFname();
// used for logging
final String username = userInstance.getPerson().getUserName();
if (profileFNameToMatch.equals(profileFName)) {
logger.debug("User {} does have profile with matching fname {}.", username, profileFName);
return true;
}
logger.debug("Request for user {} presents profile fname {} which does not match configured profile fname {}.", username, profileFName, profileFNameToMatch);
return false;
}
Aggregations