Log log = LogFactory.getLog(AddResourcesPrepareAction.class);
AddResourcesForm addForm = (AddResourcesForm) form;
HttpSession session = request.getSession();
WebUser user = RequestUtils.getWebUser(request);
Subject subject = user.getSubject();
ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
PageControl pcAvail = WebUtility.getPageControl(request, "a");
PageControl pcPending = WebUtility.getPageControl(request, "p");
log.trace("available page control: " + pcAvail);
log.trace("pending page control: " + pcPending);
// first, get the pending resources (those that have been added to the RHS
// pending resources are those on the right side of the "add to list" widget that are awaiting association with the group when the form's "ok" button is clicked. */
log.debug("check session if there are pending resources");
List<String> pendingResourceList = new ArrayList<String>();
if (session.getAttribute(Constants.PENDING_RESOURCES_SES_ATTR) == null) {
// if hitting the page for the first time, load resources already associated with user via preferences
log.debug("get pending resources from user preferences");
WebUserPreferences preferences = user.getWebPreferences();
pendingResourceList = preferences.getPreferenceAsList(addForm.getKey(), DashboardUtils.DASHBOARD_DELIMITER);
if (pendingResourceList != null) {
// otherwise, we've been here for a while but the user paged, performed changed LHS<->RHS, etc
log.debug("put entire list of pending resources in session");
session.setAttribute(Constants.PENDING_RESOURCES_SES_ATTR, pendingResourceList);
}
} else {
pendingResourceList = SessionUtils.getListAsList(session, Constants.PENDING_RESOURCES_SES_ATTR);
}
// get the resources, so we can display name & description in the UI
log.debug("get page of pending resources selected by user");
int[] pendingResourceArray = StringUtility.getIntArray(pendingResourceList);
PageList<Resource> pendingResources = resourceManager.findResourceByIds(subject, pendingResourceArray, false,
pcPending);
PageList<DisambiguationReport<Resource>> disambiguatedPendingResources =
DisambiguatedResourceListUtil.disambiguate(resourceManager, pendingResources, RESOURCE_ID_EXTRACTOR);
// give 'em to the jsp page
log.debug("put selected page of pending resources in request");
request.setAttribute(Constants.PENDING_RESOURCES_ATTR, disambiguatedPendingResources);
request.setAttribute(Constants.NUM_PENDING_RESOURCES_ATTR, disambiguatedPendingResources.getTotalSize());
// available resources are all resources in the system that are not associated with the user and are not pending
log.debug("determine if user wants to filter available resources");
Integer typeIdFilter = ((addForm.getType() == null) || (addForm.getType() == DEFAULT_RESOURCE_TYPE)) ? null
: addForm.getType();
ResourceCategory categoryFilter = (addForm.getCategory() != null) ? ResourceCategory.valueOf(addForm
.getCategory().toUpperCase()) : ResourceCategory.PLATFORM;
int[] excludeIds = StringUtility.getIntArray(pendingResourceList);
PageList<Resource> availableResources = null;
availableResources = resourceManager.findAvailableResourcesForDashboardPortlet(subject, typeIdFilter,
categoryFilter, excludeIds, pcAvail);
PageList<DisambiguationReport<Resource>> disambiguatedAvailableResources =
DisambiguatedResourceListUtil.disambiguate(resourceManager, availableResources, RESOURCE_ID_EXTRACTOR);