@Test public final void testProcessSave() { try { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); request.getSession().setAttribute(TargetInstanceCommand.SESSION_MODE, true); request.getSession().setAttribute(Constants.GBL_SESS_EDIT_MODE, true); TargetInstanceCommand comm = new TargetInstanceCommand(); comm.setCmd(TargetInstanceCommand.ACTION_EDIT); comm.setTargetInstanceId(5000L); Tab currTab = testInstance.getTabConfig().getTabs().get(0); assertTrue(currTab != null); BindException aError = new BindException(new TargetDefaultCommand(), null); testInstance.showForm(request, response, comm, aError); ModelAndView mav = testInstance.processSave(currTab, request, response, comm, aError); assertTrue(mav != null); assertTrue(mav.getViewName().equals("TargetInstanceQueue")); assertTrue(mav.getModel().get("page_message") != null); assertTrue(((String)mav.getModel().get("page_message")).startsWith("targetInstance.saved")); } catch (Exception e) { String message = e.getClass().toString() + " - " + e.getMessage(); log.debug(message); fail(message); } }
@Override protected ModelAndView processSave(Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { TargetInstance ti = (TargetInstance) req.getSession().getAttribute(TargetInstanceCommand.SESSION_TI); try { targetInstanceManager.save(ti); if (ti.getState().equals(TargetInstance.STATE_PAUSED)) { harvestCoordinator.updateProfileOverrides(ti); } } catch (HibernateOptimisticLockingFailureException e) { if (log.isErrorEnabled()) { log.error("Failed to save target instance. " + e.getMessage(), e); } throw new WCTRuntimeException("The target instance " + ti.getJobName() + " could not be saved as it has been modified by another user or the system."); } finally { unbindContext(req); } try { ModelAndView mav = queueController.showForm(req ,res, errors); mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("targetInstance.saved", new Object[] { ti.getTarget().getName() + " ("+ ti.getOid().toString() + ")" }, Locale.getDefault())); return mav; } catch(Exception ex) { throw new WCTRuntimeException("Failed to load queue controller", ex); } }
TabbedTargetInstanceController extends TabbedController { @Override protected ModelAndView processSave(Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { TargetInstance ti = (TargetInstance) req.getSession().getAttribute(TargetInstanceCommand.SESSION_TI); try { targetInstanceManager.save(ti); if (ti.getState().equals(TargetInstance.STATE_PAUSED)) { harvestCoordinator.updateProfileOverrides(ti); } } catch (HibernateOptimisticLockingFailureException e) { if (log.isErrorEnabled()) { log.error("Failed to save target instance. " + e.getMessage(), e); } throw new WCTRuntimeException("The target instance " + ti.getJobName() + " could not be saved as it has been modified by another user or the system."); } finally { unbindContext(req); } try { ModelAndView mav = queueController.showForm(req ,res, errors); mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("targetInstance.saved", new Object[] { ti.getTarget().getName() + " ("+ ti.getOid().toString() + ")" }, Locale.getDefault())); return mav; } catch(Exception ex) { throw new WCTRuntimeException("Failed to load queue controller", ex); } } }
TabbedTargetInstanceController extends TabbedController { @Override protected ModelAndView processSave(Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { TargetInstance ti = (TargetInstance) req.getSession().getAttribute(TargetInstanceCommand.SESSION_TI); try { targetInstanceManager.save(ti); if (ti.getState().equals(TargetInstance.STATE_PAUSED)) { harvestCoordinator.updateProfileOverrides(ti); } } catch (HibernateOptimisticLockingFailureException e) { if (log.isErrorEnabled()) { log.error("Failed to save target instance. " + e.getMessage(), e); } throw new WCTRuntimeException("The target instance " + ti.getJobName() + " could not be saved as it has been modified by another user or the system."); } finally { unbindContext(req); } try { ModelAndView mav = queueController.showForm(req ,res, errors); mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("targetInstance.saved", new Object[] { ti.getTarget().getName() + " ("+ ti.getOid().toString() + ")" }, Locale.getDefault())); return mav; } catch(Exception ex) { throw new WCTRuntimeException("Failed to load queue controller", ex); } }  }
TabbedTargetInstanceController extends TabbedController { @Override protected ModelAndView processSave(Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { TargetInstance ti = (TargetInstance) req.getSession().getAttribute(TargetInstanceCommand.SESSION_TI); try { targetInstanceManager.save(ti); if (ti.getState().equals(TargetInstance.STATE_PAUSED)) { harvestCoordinator.updateProfileOverrides(ti); } } catch (HibernateOptimisticLockingFailureException e) { if (log.isErrorEnabled()) { log.error("Failed to save target instance. " + e.getMessage(), e); } throw new WCTRuntimeException("The target instance " + ti.getJobName() + " could not be saved as it has been modified by another user or the system."); } finally { unbindContext(req); } try { ModelAndView mav = queueController.showForm(req ,res, errors); mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("targetInstance.saved", new Object[] { ti.getTarget().getName() + " ("+ ti.getOid().toString() + ")" }, Locale.getDefault())); return mav; } catch(Exception ex) { throw new WCTRuntimeException("Failed to load queue controller", ex); } }  void setTargetInstanceManager(TargetInstanceManager targetInstanceManager); void setHarvestCoordinator(HarvestCoordinator harvestCoordinator); void setAuthorityManager(AuthorityManager authorityManager); void setQueueController(QueueController queueController); void setMessageSource(MessageSource messageSource); }
TabbedTargetInstanceController extends TabbedController { @Override protected ModelAndView processSave(Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { TargetInstance ti = (TargetInstance) req.getSession().getAttribute(TargetInstanceCommand.SESSION_TI); try { targetInstanceManager.save(ti); if (ti.getState().equals(TargetInstance.STATE_PAUSED)) { harvestCoordinator.updateProfileOverrides(ti); } } catch (HibernateOptimisticLockingFailureException e) { if (log.isErrorEnabled()) { log.error("Failed to save target instance. " + e.getMessage(), e); } throw new WCTRuntimeException("The target instance " + ti.getJobName() + " could not be saved as it has been modified by another user or the system."); } finally { unbindContext(req); } try { ModelAndView mav = queueController.showForm(req ,res, errors); mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("targetInstance.saved", new Object[] { ti.getTarget().getName() + " ("+ ti.getOid().toString() + ")" }, Locale.getDefault())); return mav; } catch(Exception ex) { throw new WCTRuntimeException("Failed to load queue controller", ex); } }  void setTargetInstanceManager(TargetInstanceManager targetInstanceManager); void setHarvestCoordinator(HarvestCoordinator harvestCoordinator); void setAuthorityManager(AuthorityManager authorityManager); void setQueueController(QueueController queueController); void setMessageSource(MessageSource messageSource);  }