use of org.apereo.portal.PortalException in project uPortal by Jasig.
the class UpdatePreferencesServlet method moveElementInternal.
/**
* Moves the source element.
*
* <p>- If the destination is a tab, the new element automatically goes to the end of the first
* column or in a new column. - If the destination is a folder, the element is added to the end
* of the folder. - Otherwise, the element is inserted before the destination (the destination
* can't be a tab or folder so it must be a portlet).
*
* @return true if the element was moved and saved.
*/
private boolean moveElementInternal(HttpServletRequest request, String sourceId, String destinationId, String method) {
logger.debug("moveElementInternal invoked for sourceId={}, destinationId={}, method={}", sourceId, destinationId, method);
if (StringUtils.isEmpty(destinationId)) {
//shortcut for beginning and end
return true;
}
IUserInstance ui = userInstanceManager.getUserInstance(request);
UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
IUserLayoutManager ulm = upm.getUserLayoutManager();
boolean success = false;
if (isTab(ulm, destinationId)) {
// If the target is a tab type node, move the element to the end of the first column.
// TODO Try to insert it into the first available column if multiple columns
Enumeration<String> columns = ulm.getChildIds(destinationId);
if (columns.hasMoreElements()) {
success = attemptNodeMove(ulm, sourceId, columns.nextElement(), null);
} else {
// Attempt to create a new column
IUserLayoutFolderDescription newColumn = new UserLayoutFolderDescription();
newColumn.setName("Column");
newColumn.setId("tbd");
newColumn.setFolderType(IUserLayoutFolderDescription.REGULAR_TYPE);
newColumn.setHidden(false);
newColumn.setUnremovable(false);
newColumn.setImmutable(false);
// add the column to our layout
IUserLayoutNodeDescription col = ulm.addNode(newColumn, destinationId, null);
// If column was created (might not if the tab had addChild=false), move the channel.
if (col != null) {
success = attemptNodeMove(ulm, sourceId, col.getId(), null);
} else {
logger.info("Unable to move item into existing columns on tab {} and unable to create new column", destinationId);
}
}
} else {
// If destination is a column, attempt to move into end of column
if (isFolder(ulm, destinationId)) {
success = attemptNodeMove(ulm, sourceId, destinationId, null);
} else {
// If insertBefore move to prior to node else to end of folder containing node
success = attemptNodeMove(ulm, sourceId, ulm.getParentId(destinationId), "insertBefore".equals(method) ? destinationId : null);
}
}
try {
if (success) {
ulm.saveUserLayout();
}
} catch (PortalException e) {
logger.warn("Error saving layout", e);
return false;
}
return success;
}
use of org.apereo.portal.PortalException in project uPortal by Jasig.
the class UpdatePreferencesServlet method removeByFName.
/**
* Remove the first element with the provided fname from the layout.
*
* @param request HttpServletRequest
* @param response HttpServletResponse
* @param fname fname of the portlet to remove from the layout
* @return json response
* @throws IOException if the person cannot be retrieved
*/
@RequestMapping(method = RequestMethod.POST, params = "action=removeByFName")
public ModelAndView removeByFName(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "fname", required = true) String fname) throws IOException {
IUserInstance ui = userInstanceManager.getUserInstance(request);
IPerson per = getPerson(ui, response);
UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
IUserLayoutManager ulm = upm.getUserLayoutManager();
try {
String elementId = ulm.getUserLayout().findNodeId(new PortletSubscribeIdResolver(fname));
if (elementId != null && elementId.startsWith(Constants.FRAGMENT_ID_USER_PREFIX) && ulm.getNode(elementId) instanceof org.apereo.portal.layout.node.UserLayoutFolderDescription) {
removeSubscription(per, elementId, ulm);
} else if (elementId != null) {
// all node types, so we can just have a generic action.
if (!ulm.deleteNode(elementId)) {
logger.info("Failed to remove element ID {} from layout root folder ID {}, delete node returned false", elementId, ulm.getRootFolderId());
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
return new ModelAndView("jsonView", Collections.singletonMap("error", getMessage("error.element.update", "Unable to update element", RequestContextUtils.getLocale(request))));
}
} else {
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return null;
}
ulm.saveUserLayout();
return new ModelAndView("jsonView", Collections.EMPTY_MAP);
} catch (PortalException e) {
return handlePersistError(request, response, e);
}
}
use of org.apereo.portal.PortalException in project uPortal by Jasig.
the class UserLayoutHelperImpl method resetUserLayout.
/**
* @param personAttributes
* @see
* org.apereo.portal.layout.IUserLayoutHelper#resetUserLayout(org.jasig.services.persondir.IPersonAttributes)
*/
public void resetUserLayout(final IPersonAttributes personAttributes) {
// Create an empty RestrictedPerson object
RestrictedPerson person = PersonFactory.createRestrictedPerson();
// populate the person with the supplied attributes
person.setAttributes(personAttributes.getAttributes());
// get the integer uid into the person object without creating any new person data
int uid = userIdentityStore.getPortalUID(person, false);
person.setID(uid);
try {
// determine user profile
IUserProfile userProfile = userLayoutStore.getUserProfileByFname(person, DEFAULT_LAYOUT_FNAME);
// Finally set the layout id to 0. This orphans the existing layout but it will be replaced by the default
// when the user logs in
userProfile.setLayoutId(0);
// persist the change
userLayoutStore.updateUserProfile(person, userProfile);
logger.info("resetUserLayout complete for " + person);
} catch (Exception e) {
final String msg = "Exception caught during resetUserLayout for " + person;
logger.error(msg, e);
throw new PortalException(msg, e);
}
}
use of org.apereo.portal.PortalException in project uPortal by Jasig.
the class UserLayoutHelperImpl method resetUserLayoutAllProfiles.
/**
* Resets a users layout for all the users profiles
*
* @param personAttributes
*/
public void resetUserLayoutAllProfiles(final IPersonAttributes personAttributes) {
RestrictedPerson person = PersonFactory.createRestrictedPerson();
person.setAttributes(personAttributes.getAttributes());
// get the integer uid into the person object without creating any new person data
int uid = userIdentityStore.getPortalUID(person, false);
person.setID(uid);
try {
Hashtable<Integer, UserProfile> userProfileList = userLayoutStore.getUserProfileList(person);
for (Integer key : userProfileList.keySet()) {
UserProfile userProfile = userProfileList.get(key);
userProfile.setLayoutId(0);
userLayoutStore.updateUserProfile(person, userProfile);
logger.info("resetUserLayout complete for " + person + "for profile " + userProfile);
}
} catch (Exception e) {
final String msg = "Exception caught during resetUserLayout for " + person;
logger.error(msg, e);
throw new PortalException(msg, e);
}
return;
}
use of org.apereo.portal.PortalException in project uPortal by Jasig.
the class DeleteManager method getDeleteSet.
/**
* Get the delete set if any stored in the root of the document or create it is passed in create
* flag is true.
*/
private static Element getDeleteSet(Document plf, IPerson person, boolean create) throws PortalException {
Node root = plf.getDocumentElement();
Node child = root.getFirstChild();
while (child != null) {
if (child.getNodeName().equals(Constants.ELM_DELETE_SET))
return (Element) child;
child = child.getNextSibling();
}
if (create == false)
return null;
String ID = null;
try {
ID = getDLS().getNextStructDirectiveId(person);
} catch (Exception e) {
throw new PortalException("Exception encountered while " + "generating new delete set node " + "Id for userId=" + person.getID(), e);
}
Element delSet = plf.createElement(Constants.ELM_DELETE_SET);
delSet.setAttribute(Constants.ATT_TYPE, Constants.ELM_DELETE_SET);
delSet.setAttribute(Constants.ATT_ID, ID);
root.appendChild(delSet);
return delSet;
}
Aggregations