@Test public final void testProcessOther() { try { HttpServletRequest aReq = new MockHttpServletRequest(); TargetInstanceManager targetInstanceManager = new MockTargetInstanceManager(testFile); testInstance.setTargetInstanceManager(targetInstanceManager); TargetInstance targetInstance = targetInstanceManager.getTargetInstance(5000L); List<Annotation> list = createAnnotationList(); assertFalse(checkSortedList(list)); targetInstance.setAnnotations(list); aReq.getSession().setAttribute(TargetInstanceCommand.SESSION_TI, targetInstance); HttpServletResponse aResp = new MockHttpServletResponse(); TargetInstanceCommand aCmd = new TargetInstanceCommand(); TabbedController tc = new TabbedTargetInstanceController(); TabConfig tabConfig = new TabConfig(); tabConfig.setViewName("targetInstance"); List<Tab> tabs = getTabList(targetInstanceManager); tabConfig.setTabs(tabs); tc.setTabConfig(tabConfig); tc.setDefaultCommandClass(org.webcurator.ui.target.command.TargetInstanceCommand.class); Tab currentTab = tabs.get(1); aCmd.setCmd(TargetInstanceCommand.ACTION_ADD_NOTE); aCmd.setNote("A note"); BindException aErrors = new BindException(aCmd, aCmd.getCmd()); int numAnnotations = targetInstance.getAnnotations().size(); ModelAndView mav = testInstance.processOther(tc, currentTab, aReq, aResp, aCmd, aErrors); assertTrue(mav != null); assertTrue(mav.getViewName().equals("targetInstance")); assertTrue(((TabStatus)mav.getModel().get("tabStatus")).getCurrentTab().getPageId().equals("ANNOTATIONS")); int noteIndex = 0; assertTrue(targetInstance.getAnnotations().size() == (numAnnotations+1)); assertTrue(targetInstance.getAnnotations().get(noteIndex).getNote().equals("A note")); assertTrue(checkSortedList(((TargetInstance)mav.getModel().get(TargetInstanceCommand.MDL_INSTANCE)).getAnnotations())); currentTab = tabs.get(1); aCmd.setCmd(TargetInstanceCommand.ACTION_MODIFY_NOTE); aCmd.setNote("A new note"); aCmd.setNoteIndex(noteIndex); aErrors = new BindException(aCmd, aCmd.getCmd()); mav = testInstance.processOther(tc, currentTab, aReq, aResp, aCmd, aErrors); assertTrue(mav != null); assertTrue(mav.getViewName().equals("targetInstance")); assertTrue(((TabStatus)mav.getModel().get("tabStatus")).getCurrentTab().getPageId().equals("ANNOTATIONS")); int listSize = targetInstance.getAnnotations().size(); int newNoteIndex = 0; assertTrue(newNoteIndex == noteIndex); assertTrue(targetInstance.getAnnotations().size() == (numAnnotations+1)); assertFalse(targetInstance.getAnnotations().get(noteIndex).getNote().equals("A note")); assertTrue(targetInstance.getAnnotations().get(noteIndex).getNote().equals("A new note")); assertTrue(checkSortedList(((TargetInstance)mav.getModel().get(TargetInstanceCommand.MDL_INSTANCE)).getAnnotations())); currentTab = tabs.get(1); aCmd.setCmd(TargetInstanceCommand.ACTION_DELETE_NOTE); aCmd.setNoteIndex(noteIndex); aErrors = new BindException(aCmd, aCmd.getCmd()); mav = testInstance.processOther(tc, currentTab, aReq, aResp, aCmd, aErrors); assertTrue(mav != null); assertTrue(mav.getViewName().equals("targetInstance")); assertTrue(((TabStatus)mav.getModel().get("tabStatus")).getCurrentTab().getPageId().equals("ANNOTATIONS")); int newListSize = targetInstance.getAnnotations().size(); assertTrue(newListSize == (listSize-1)); assertTrue(targetInstance.getAnnotations().size() == numAnnotations); assertTrue(checkSortedList(((TargetInstance)mav.getModel().get(TargetInstanceCommand.MDL_INSTANCE)).getAnnotations())); } catch(Exception e) { fail(e.getMessage()); } }
public ModelAndView processOther(TabbedController tc, Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { TargetInstanceCommand cmd = (TargetInstanceCommand) comm; if (cmd.getCmd().equals(TargetInstanceCommand.ACTION_ADD_NOTE)) { if (log.isDebugEnabled()) { log.debug("Processing add annotation."); } TargetInstance ti = (TargetInstance) req.getSession().getAttribute(TargetInstanceCommand.SESSION_TI); if (!errors.hasErrors()) { addAnnotation(cmd, ti); } } else if (cmd.getCmd().equals(TargetInstanceCommand.ACTION_MODIFY_NOTE)) { if (log.isDebugEnabled()) { log.debug("Processing modify annotation."); } TargetInstance ti = (TargetInstance) req.getSession().getAttribute(TargetInstanceCommand.SESSION_TI); Annotation annotation = ti.getAnnotation(cmd.getNoteIndex()); if(annotation != null && annotation.getUser().equals(AuthUtil.getRemoteUserObject())) { annotation.setDate(new Date()); annotation.setNote(cmd.getNote()); annotation.setAlertable(cmd.isAlertable()); } } else if (cmd.getCmd().equals(TargetInstanceCommand.ACTION_DELETE_NOTE)) { if (log.isDebugEnabled()) { log.debug("Processing delete annotation."); } TargetInstance ti = (TargetInstance) req.getSession().getAttribute(TargetInstanceCommand.SESSION_TI); Annotation annotation = ti.getAnnotation(cmd.getNoteIndex()); if(annotation != null && annotation.getUser().equals(AuthUtil.getRemoteUserObject())) { ti.deleteAnnotation(cmd.getNoteIndex()); } } TargetInstance ti = (TargetInstance) req.getSession().getAttribute(TargetInstanceCommand.SESSION_TI); ti.sortAnnotations(); Tab tab = tc.getTabConfig().getTabByID("ANNOTATIONS"); TabbedModelAndView tmav = tc.new TabbedModelAndView(); tmav.getTabStatus().setCurrentTab(tab); tmav.getTabStatus().setEnabled(true); cmd.setCmd(TargetInstanceCommand.ACTION_EDIT); tmav.addObject(Constants.GBL_CMD_DATA, cmd); tmav.addObject(TargetInstanceCommand.MDL_INSTANCE, ti); return tmav; }
TargetInstanceAnnotationHandler extends TabHandler { public ModelAndView processOther(TabbedController tc, Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { TargetInstanceCommand cmd = (TargetInstanceCommand) comm; if (cmd.getCmd().equals(TargetInstanceCommand.ACTION_ADD_NOTE)) { if (log.isDebugEnabled()) { log.debug("Processing add annotation."); } TargetInstance ti = (TargetInstance) req.getSession().getAttribute(TargetInstanceCommand.SESSION_TI); if (!errors.hasErrors()) { addAnnotation(cmd, ti); } } else if (cmd.getCmd().equals(TargetInstanceCommand.ACTION_MODIFY_NOTE)) { if (log.isDebugEnabled()) { log.debug("Processing modify annotation."); } TargetInstance ti = (TargetInstance) req.getSession().getAttribute(TargetInstanceCommand.SESSION_TI); Annotation annotation = ti.getAnnotation(cmd.getNoteIndex()); if(annotation != null && annotation.getUser().equals(AuthUtil.getRemoteUserObject())) { annotation.setDate(new Date()); annotation.setNote(cmd.getNote()); annotation.setAlertable(cmd.isAlertable()); } } else if (cmd.getCmd().equals(TargetInstanceCommand.ACTION_DELETE_NOTE)) { if (log.isDebugEnabled()) { log.debug("Processing delete annotation."); } TargetInstance ti = (TargetInstance) req.getSession().getAttribute(TargetInstanceCommand.SESSION_TI); Annotation annotation = ti.getAnnotation(cmd.getNoteIndex()); if(annotation != null && annotation.getUser().equals(AuthUtil.getRemoteUserObject())) { ti.deleteAnnotation(cmd.getNoteIndex()); } } TargetInstance ti = (TargetInstance) req.getSession().getAttribute(TargetInstanceCommand.SESSION_TI); ti.sortAnnotations(); Tab tab = tc.getTabConfig().getTabByID("ANNOTATIONS"); TabbedModelAndView tmav = tc.new TabbedModelAndView(); tmav.getTabStatus().setCurrentTab(tab); tmav.getTabStatus().setEnabled(true); cmd.setCmd(TargetInstanceCommand.ACTION_EDIT); tmav.addObject(Constants.GBL_CMD_DATA, cmd); tmav.addObject(TargetInstanceCommand.MDL_INSTANCE, ti); return tmav; } }
TargetInstanceAnnotationHandler extends TabHandler { public ModelAndView processOther(TabbedController tc, Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { TargetInstanceCommand cmd = (TargetInstanceCommand) comm; if (cmd.getCmd().equals(TargetInstanceCommand.ACTION_ADD_NOTE)) { if (log.isDebugEnabled()) { log.debug("Processing add annotation."); } TargetInstance ti = (TargetInstance) req.getSession().getAttribute(TargetInstanceCommand.SESSION_TI); if (!errors.hasErrors()) { addAnnotation(cmd, ti); } } else if (cmd.getCmd().equals(TargetInstanceCommand.ACTION_MODIFY_NOTE)) { if (log.isDebugEnabled()) { log.debug("Processing modify annotation."); } TargetInstance ti = (TargetInstance) req.getSession().getAttribute(TargetInstanceCommand.SESSION_TI); Annotation annotation = ti.getAnnotation(cmd.getNoteIndex()); if(annotation != null && annotation.getUser().equals(AuthUtil.getRemoteUserObject())) { annotation.setDate(new Date()); annotation.setNote(cmd.getNote()); annotation.setAlertable(cmd.isAlertable()); } } else if (cmd.getCmd().equals(TargetInstanceCommand.ACTION_DELETE_NOTE)) { if (log.isDebugEnabled()) { log.debug("Processing delete annotation."); } TargetInstance ti = (TargetInstance) req.getSession().getAttribute(TargetInstanceCommand.SESSION_TI); Annotation annotation = ti.getAnnotation(cmd.getNoteIndex()); if(annotation != null && annotation.getUser().equals(AuthUtil.getRemoteUserObject())) { ti.deleteAnnotation(cmd.getNoteIndex()); } } TargetInstance ti = (TargetInstance) req.getSession().getAttribute(TargetInstanceCommand.SESSION_TI); ti.sortAnnotations(); Tab tab = tc.getTabConfig().getTabByID("ANNOTATIONS"); TabbedModelAndView tmav = tc.new TabbedModelAndView(); tmav.getTabStatus().setCurrentTab(tab); tmav.getTabStatus().setEnabled(true); cmd.setCmd(TargetInstanceCommand.ACTION_EDIT); tmav.addObject(Constants.GBL_CMD_DATA, cmd); tmav.addObject(TargetInstanceCommand.MDL_INSTANCE, ti); return tmav; }  }
TargetInstanceAnnotationHandler extends TabHandler { public ModelAndView processOther(TabbedController tc, Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { TargetInstanceCommand cmd = (TargetInstanceCommand) comm; if (cmd.getCmd().equals(TargetInstanceCommand.ACTION_ADD_NOTE)) { if (log.isDebugEnabled()) { log.debug("Processing add annotation."); } TargetInstance ti = (TargetInstance) req.getSession().getAttribute(TargetInstanceCommand.SESSION_TI); if (!errors.hasErrors()) { addAnnotation(cmd, ti); } } else if (cmd.getCmd().equals(TargetInstanceCommand.ACTION_MODIFY_NOTE)) { if (log.isDebugEnabled()) { log.debug("Processing modify annotation."); } TargetInstance ti = (TargetInstance) req.getSession().getAttribute(TargetInstanceCommand.SESSION_TI); Annotation annotation = ti.getAnnotation(cmd.getNoteIndex()); if(annotation != null && annotation.getUser().equals(AuthUtil.getRemoteUserObject())) { annotation.setDate(new Date()); annotation.setNote(cmd.getNote()); annotation.setAlertable(cmd.isAlertable()); } } else if (cmd.getCmd().equals(TargetInstanceCommand.ACTION_DELETE_NOTE)) { if (log.isDebugEnabled()) { log.debug("Processing delete annotation."); } TargetInstance ti = (TargetInstance) req.getSession().getAttribute(TargetInstanceCommand.SESSION_TI); Annotation annotation = ti.getAnnotation(cmd.getNoteIndex()); if(annotation != null && annotation.getUser().equals(AuthUtil.getRemoteUserObject())) { ti.deleteAnnotation(cmd.getNoteIndex()); } } TargetInstance ti = (TargetInstance) req.getSession().getAttribute(TargetInstanceCommand.SESSION_TI); ti.sortAnnotations(); Tab tab = tc.getTabConfig().getTabByID("ANNOTATIONS"); TabbedModelAndView tmav = tc.new TabbedModelAndView(); tmav.getTabStatus().setCurrentTab(tab); tmav.getTabStatus().setEnabled(true); cmd.setCmd(TargetInstanceCommand.ACTION_EDIT); tmav.addObject(Constants.GBL_CMD_DATA, cmd); tmav.addObject(TargetInstanceCommand.MDL_INSTANCE, ti); return tmav; }  void initBinder(HttpServletRequest request, ServletRequestDataBinder binder); void processTab(TabbedController tc, Tab currentTab,
            HttpServletRequest req, HttpServletResponse res, Object comm,
            BindException errors); @SuppressWarnings("unchecked") TabbedModelAndView preProcessNextTab(TabbedController tc,
            Tab nextTabID, HttpServletRequest req, HttpServletResponse res,
            Object comm, BindException errors); ModelAndView processOther(TabbedController tc, Tab currentTab,
            HttpServletRequest req, HttpServletResponse res, Object comm,
            BindException errors); void setTargetInstanceManager(TargetInstanceManager targetInstanceManager); }
TargetInstanceAnnotationHandler extends TabHandler { public ModelAndView processOther(TabbedController tc, Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { TargetInstanceCommand cmd = (TargetInstanceCommand) comm; if (cmd.getCmd().equals(TargetInstanceCommand.ACTION_ADD_NOTE)) { if (log.isDebugEnabled()) { log.debug("Processing add annotation."); } TargetInstance ti = (TargetInstance) req.getSession().getAttribute(TargetInstanceCommand.SESSION_TI); if (!errors.hasErrors()) { addAnnotation(cmd, ti); } } else if (cmd.getCmd().equals(TargetInstanceCommand.ACTION_MODIFY_NOTE)) { if (log.isDebugEnabled()) { log.debug("Processing modify annotation."); } TargetInstance ti = (TargetInstance) req.getSession().getAttribute(TargetInstanceCommand.SESSION_TI); Annotation annotation = ti.getAnnotation(cmd.getNoteIndex()); if(annotation != null && annotation.getUser().equals(AuthUtil.getRemoteUserObject())) { annotation.setDate(new Date()); annotation.setNote(cmd.getNote()); annotation.setAlertable(cmd.isAlertable()); } } else if (cmd.getCmd().equals(TargetInstanceCommand.ACTION_DELETE_NOTE)) { if (log.isDebugEnabled()) { log.debug("Processing delete annotation."); } TargetInstance ti = (TargetInstance) req.getSession().getAttribute(TargetInstanceCommand.SESSION_TI); Annotation annotation = ti.getAnnotation(cmd.getNoteIndex()); if(annotation != null && annotation.getUser().equals(AuthUtil.getRemoteUserObject())) { ti.deleteAnnotation(cmd.getNoteIndex()); } } TargetInstance ti = (TargetInstance) req.getSession().getAttribute(TargetInstanceCommand.SESSION_TI); ti.sortAnnotations(); Tab tab = tc.getTabConfig().getTabByID("ANNOTATIONS"); TabbedModelAndView tmav = tc.new TabbedModelAndView(); tmav.getTabStatus().setCurrentTab(tab); tmav.getTabStatus().setEnabled(true); cmd.setCmd(TargetInstanceCommand.ACTION_EDIT); tmav.addObject(Constants.GBL_CMD_DATA, cmd); tmav.addObject(TargetInstanceCommand.MDL_INSTANCE, ti); return tmav; }  void initBinder(HttpServletRequest request, ServletRequestDataBinder binder); void processTab(TabbedController tc, Tab currentTab,
            HttpServletRequest req, HttpServletResponse res, Object comm,
            BindException errors); @SuppressWarnings("unchecked") TabbedModelAndView preProcessNextTab(TabbedController tc,
            Tab nextTabID, HttpServletRequest req, HttpServletResponse res,
            Object comm, BindException errors); ModelAndView processOther(TabbedController tc, Tab currentTab,
            HttpServletRequest req, HttpServletResponse res, Object comm,
            BindException errors); void setTargetInstanceManager(TargetInstanceManager targetInstanceManager);  }