From: <dcr...@hy...> - 2009-11-04 21:40:41
|
Author: dcrutchf Date: 2009-11-04 13:40:20 -0800 (Wed, 04 Nov 2009) New Revision: 13920 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=13920 Modified: branches/HQ_4_2_1/src/org/hyperic/hq/ui/action/resource/group/inventory/AddGroupResourcesAction.java Log: [HHQ-2989] - Stacktrace On Group Add Resources :: Click Reset then ANY BUTTON Modified: branches/HQ_4_2_1/src/org/hyperic/hq/ui/action/resource/group/inventory/AddGroupResourcesAction.java =================================================================== --- branches/HQ_4_2_1/src/org/hyperic/hq/ui/action/resource/group/inventory/AddGroupResourcesAction.java 2009-11-04 06:13:22 UTC (rev 13919) +++ branches/HQ_4_2_1/src/org/hyperic/hq/ui/action/resource/group/inventory/AddGroupResourcesAction.java 2009-11-04 21:40:20 UTC (rev 13920) @@ -29,6 +29,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; @@ -67,7 +68,8 @@ * @see org.hyperic.hq.ui.action.resource.group.inventory.AddGroupResourcesFormPrepareAction */ public class AddGroupResourcesAction extends BaseAction { - + private static Log log = LogFactory.getLog(AddGroupResourcesAction.class.getName()); + /** * Add roles to the user specified in the given * <code>AddGroupResourcesForm</code>. @@ -76,43 +78,21 @@ ActionForm form, HttpServletRequest request, HttpServletResponse response) - throws Exception { - Log log = LogFactory.getLog(AddGroupResourcesAction.class.getName()); + throws Exception { HttpSession session = request.getSession(); - AddGroupResourcesForm addForm = (AddGroupResourcesForm) form; - AppdefEntityID aeid = new AppdefEntityID(addForm.getType().intValue(), - addForm.getRid()); - - HashMap forwardParams = new HashMap(2); + AppdefEntityID aeid = new AppdefEntityID(addForm.getType().intValue(), addForm.getRid()); + Map<String, String> forwardParams = new HashMap<String, String>(2); + forwardParams.put(Constants.ENTITY_ID_PARAM, aeid.getAppdefKey()); forwardParams.put(Constants.ACCORDION_PARAM, "1"); + forwardParams.put(Constants.RESOURCE_PARAM, addForm.getRid().toString()); + forwardParams.put(Constants.RESOURCE_TYPE_ID_PARAM, addForm.getType().toString()); try { - ActionForward forward = checkSubmit(request, mapping, form, - forwardParams); + ActionForward forward = checkSubmit(request, mapping, form, forwardParams); + if (forward != null) { - BaseValidatorForm spiderForm = (BaseValidatorForm) form; - - if (spiderForm.isCancelClicked() || - spiderForm.isResetClicked()) { - log.trace("removing pending/removed resources list"); - SessionUtils - .removeList(session, - Constants.PENDING_RESOURCES_SES_ATTR); - } else if (spiderForm.isAddClicked()) { - log.trace("adding to pending resources list"); - SessionUtils.addToList(session, - Constants.PENDING_RESOURCES_SES_ATTR, - addForm.getAvailableResources()); - } else if (spiderForm.isRemoveClicked()) { - log.trace( - "removing from pending resources list"); - SessionUtils - .removeFromList(session, - Constants.PENDING_RESOURCES_SES_ATTR, - addForm.getPendingResources()); - } return forward; } @@ -121,27 +101,23 @@ Integer sessionId = RequestUtils.getSessionId(request); log.trace("getting pending resource list"); - List pendingResourceIds = - SessionUtils.getListAsListStr(request.getSession(), - Constants.PENDING_RESOURCES_SES_ATTR); - if (pendingResourceIds.size() == 0) + List<String> pendingResourceIds = SessionUtils.getListAsListStr(request.getSession(), Constants.PENDING_RESOURCES_SES_ATTR); + + if (pendingResourceIds.size() == 0) { return returnSuccess(request, mapping, forwardParams); - + } + log.trace("getting group [" + aeid.getID() + "]"); - AppdefGroupValue agroup = boss.findGroup(sessionId.intValue(), - aeid.getId()); - ResourceGroup group = boss.findGroupById(sessionId.intValue(), - agroup.getId()); - List newIds = new ArrayList(); - ResourceGroupManagerLocal groupMan = - ResourceGroupManagerEJBImpl.getOne(); - ResourceManagerLocal resourceMan = - ResourceManagerEJBImpl.getOne(); - for (Iterator i=pendingResourceIds.iterator(); i.hasNext(); ) { - String id = (String) i.next(); - AppdefEntityID entity = new AppdefEntityID(id); + AppdefGroupValue agroup = boss.findGroup(sessionId.intValue(), aeid.getId()); + ResourceGroup group = boss.findGroupById(sessionId.intValue(), agroup.getId()); + List<AppdefEntityID> newIds = new ArrayList<AppdefEntityID>(); + ResourceGroupManagerLocal groupMan = ResourceGroupManagerEJBImpl.getOne(); + ResourceManagerLocal resourceMan = ResourceManagerEJBImpl.getOne(); + + for (Iterator<String> i = pendingResourceIds.iterator(); i.hasNext(); ) { + AppdefEntityID entity = new AppdefEntityID(i.next()); Resource r = resourceMan.findResource(entity); if (!groupMan.isMember(group, r)) { @@ -154,28 +130,67 @@ boss.addResourcesToGroup(sessionId.intValue(), group, newIds); log.trace("removing pending user list"); - SessionUtils.removeList(session, - Constants.PENDING_RESOURCES_SES_ATTR); - - RequestUtils.setConfirmation(request, - "resource.group.inventory.confirm.AddResources"); + + SessionUtils.removeList(session, Constants.PENDING_RESOURCES_SES_ATTR); + RequestUtils.setConfirmation(request, "resource.group.inventory.confirm.AddResources"); return returnSuccess(request, mapping, forwardParams); + } catch (AppSvcClustDuplicateAssignException e1) { + log.debug("group update failed:", e1); + + RequestUtils.setError(request,Constants.ERR_DUP_CLUSTER_ASSIGNMENT); - } - catch (AppSvcClustDuplicateAssignException e1) { - log.debug("group update failed:", e1); - RequestUtils - .setError(request, - Constants.ERR_DUP_CLUSTER_ASSIGNMENT); return returnFailure(request, mapping); - } - catch (AppdefGroupNotFoundException e) { - RequestUtils - .setError(request, - "resource.common.inventory.error.ResourceNotFound"); + } catch (AppdefGroupNotFoundException e) { + RequestUtils.setError(request, "resource.common.inventory.error.ResourceNotFound"); return returnFailure(request, mapping, forwardParams); } } + + @Override + protected ActionForward checkSubmit(HttpServletRequest request, + ActionMapping mapping, + ActionForm form, + Map params, + boolean doReturnPath) + throws Exception { + HttpSession session = request.getSession(); + BaseValidatorForm spiderForm = (BaseValidatorForm) form; + + if (spiderForm.isCancelClicked()) { + log.trace("removing pending/removed resources list"); + SessionUtils.removeList(session, Constants.PENDING_RESOURCES_SES_ATTR); + + return returnCancelled(request, mapping, params, doReturnPath); + } + + if (spiderForm.isResetClicked()) { + log.trace("removing pending/removed resources list"); + SessionUtils.removeList(session, Constants.PENDING_RESOURCES_SES_ATTR); + spiderForm.reset(mapping, request); + + return returnReset(request, mapping, params); + } + + if (spiderForm.isCreateClicked()) { + return returnNew(request, mapping, params); + } + + if (spiderForm.isAddClicked()) { + log.trace("adding to pending resources list"); + SessionUtils.addToList(session, Constants.PENDING_RESOURCES_SES_ATTR, ((AddGroupResourcesForm) form).getAvailableResources()); + + return returnAdd(request, mapping, params); + } + + if (spiderForm.isRemoveClicked()) { + log.trace("removing from pending resources list"); + SessionUtils.removeFromList(session, Constants.PENDING_RESOURCES_SES_ATTR, ((AddGroupResourcesForm) form).getPendingResources()); + + return returnRemove(request, mapping, params); + } + + return null; + } } |