@Test public final void testProcessOther() { try { HttpServletRequest aReq = new MockHttpServletRequest(); TargetManager targetManager = new MockTargetManager(testFile); testInstance.setTargetManager(targetManager); Target target = targetManager.load(4000L); List<Annotation> list = createAnnotationList(); assertFalse(checkSortedList(list)); target.setAnnotations(list); TargetEditorContext ctx = new TargetEditorContext(targetManager, target, true); aReq.getSession().setAttribute(TabbedTargetController.EDITOR_CONTEXT, ctx); HttpServletResponse aResp = new MockHttpServletResponse(); TargetAnnotationCommand aCmd = new TargetAnnotationCommand(); TabbedController tc = new TabbedTargetController(); TabConfig tabConfig = new TabConfig(); tabConfig.setViewName("target"); List<Tab> tabs = getTabList(targetManager); tabConfig.setTabs(tabs); tc.setTabConfig(tabConfig); tc.setDefaultCommandClass(org.webcurator.ui.target.command.TargetDefaultCommand.class); Tab currentTab = tabs.get(1); aCmd.setActionCmd(TargetAnnotationCommand.ACTION_ADD_NOTE); aCmd.setNote("A note"); BindException aErrors = new BindException(aCmd, aCmd.getActionCmd()); int numAnnotations = target.getAnnotations().size(); ModelAndView mav = testInstance.processOther(tc, currentTab, aReq, aResp, aCmd, aErrors); assertTrue(mav != null); assertTrue(mav.getViewName().equals("target")); assertTrue(((TabStatus)mav.getModel().get("tabStatus")).getCurrentTab().getPageId().equals("ANNOTATIONS")); int listSize = ((List<Annotation>)mav.getModel().get("annotations")).size(); assertTrue(listSize > 0); int noteIndex = 0; assertTrue(checkSortedList((List<Annotation>)mav.getModel().get("annotations"))); assertTrue(((List<Annotation>)mav.getModel().get("annotations")).get(noteIndex).getNote().equals("A note")); assertTrue(target.getAnnotations().size() == (numAnnotations+1)); assertTrue(target.getAnnotations().get(noteIndex).getNote().equals("A note")); currentTab = tabs.get(1); aCmd.setActionCmd(TargetAnnotationCommand.ACTION_MODIFY_NOTE); aCmd.setNote("A new note"); aCmd.setNoteIndex(noteIndex); aErrors = new BindException(aCmd, aCmd.getActionCmd()); mav = testInstance.processOther(tc, currentTab, aReq, aResp, aCmd, aErrors); assertTrue(mav != null); assertTrue(mav.getViewName().equals("target")); assertTrue(((TabStatus)mav.getModel().get("tabStatus")).getCurrentTab().getPageId().equals("ANNOTATIONS")); assertTrue(checkSortedList((List<Annotation>)mav.getModel().get("annotations"))); listSize = ((List<Annotation>)mav.getModel().get("annotations")).size(); assertTrue(listSize > 0); int newNoteIndex = 0; assertTrue(newNoteIndex == noteIndex); assertFalse(((List<Annotation>)mav.getModel().get("annotations")).get(noteIndex).getNote().equals("A note")); assertTrue(((List<Annotation>)mav.getModel().get("annotations")).get(noteIndex).getNote().equals("A new note")); assertTrue(target.getAnnotations().size() == (numAnnotations+1)); assertFalse(target.getAnnotations().get(noteIndex).getNote().equals("A note")); assertTrue(target.getAnnotations().get(noteIndex).getNote().equals("A new note")); currentTab = tabs.get(1); aCmd.setActionCmd(TargetAnnotationCommand.ACTION_DELETE_NOTE); aCmd.setNoteIndex(noteIndex); aErrors = new BindException(aCmd, aCmd.getActionCmd()); mav = testInstance.processOther(tc, currentTab, aReq, aResp, aCmd, aErrors); assertTrue(mav != null); assertTrue(mav.getViewName().equals("target")); assertTrue(((TabStatus)mav.getModel().get("tabStatus")).getCurrentTab().getPageId().equals("ANNOTATIONS")); assertTrue(checkSortedList((List<Annotation>)mav.getModel().get("annotations"))); int newListSize = ((List<Annotation>)mav.getModel().get("annotations")).size(); assertTrue(newListSize == (listSize-1)); assertTrue(target.getAnnotations().size() == numAnnotations); } catch(Exception e) { fail(e.getMessage()); } }
public ModelAndView processOther(TabbedController tc, Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { TargetAnnotationCommand cmd = (TargetAnnotationCommand) comm; TargetEditorContext ctx = getEditorContext(req); TabbedModelAndView nextView = null; if(ctx.isEditMode()) { if(errors.hasErrors()) { nextView = preProcessNextTab(tc, currentTab, req, res, cmd, errors); nextView.getTabStatus().setCurrentTab(currentTab); nextView.addObject(Constants.GBL_CMD_DATA, cmd); } else { Target target = ctx.getTarget(); if (cmd.isAction(TargetAnnotationCommand.ACTION_ADD_NOTE)) { addAnnotation(cmd, target); } if (cmd.isAction(TargetAnnotationCommand.ACTION_MODIFY_NOTE)) { if (log.isDebugEnabled()) { log.debug("Processing modify annotation."); } Annotation annotation = target.getAnnotation(cmd.getNoteIndex()); if(annotation != null && annotation.getUser().equals(AuthUtil.getRemoteUserObject())) { annotation.setDate(new Date()); annotation.setNote(cmd.getNote()); annotation.setAlertable(cmd.isAlertable()); target.sortAnnotations(); } } else if (cmd.isAction(TargetAnnotationCommand.ACTION_DELETE_NOTE)) { if (log.isDebugEnabled()) { log.debug("Processing delete annotation."); } Annotation annotation = target.getAnnotation(cmd.getNoteIndex()); if(annotation != null && annotation.getUser().equals(AuthUtil.getRemoteUserObject())) { target.deleteAnnotation(cmd.getNoteIndex()); } } updateModel(cmd, target); nextView = preProcessNextTab(tc, currentTab, req, res, cmd, errors); nextView.getTabStatus().setCurrentTab(currentTab); } } else { nextView = preProcessNextTab(tc, currentTab, req, res, cmd, errors); nextView.getTabStatus().setCurrentTab(currentTab); } return nextView; }
TargetAnnotationHandler extends AbstractTargetTabHandler { public ModelAndView processOther(TabbedController tc, Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { TargetAnnotationCommand cmd = (TargetAnnotationCommand) comm; TargetEditorContext ctx = getEditorContext(req); TabbedModelAndView nextView = null; if(ctx.isEditMode()) { if(errors.hasErrors()) { nextView = preProcessNextTab(tc, currentTab, req, res, cmd, errors); nextView.getTabStatus().setCurrentTab(currentTab); nextView.addObject(Constants.GBL_CMD_DATA, cmd); } else { Target target = ctx.getTarget(); if (cmd.isAction(TargetAnnotationCommand.ACTION_ADD_NOTE)) { addAnnotation(cmd, target); } if (cmd.isAction(TargetAnnotationCommand.ACTION_MODIFY_NOTE)) { if (log.isDebugEnabled()) { log.debug("Processing modify annotation."); } Annotation annotation = target.getAnnotation(cmd.getNoteIndex()); if(annotation != null && annotation.getUser().equals(AuthUtil.getRemoteUserObject())) { annotation.setDate(new Date()); annotation.setNote(cmd.getNote()); annotation.setAlertable(cmd.isAlertable()); target.sortAnnotations(); } } else if (cmd.isAction(TargetAnnotationCommand.ACTION_DELETE_NOTE)) { if (log.isDebugEnabled()) { log.debug("Processing delete annotation."); } Annotation annotation = target.getAnnotation(cmd.getNoteIndex()); if(annotation != null && annotation.getUser().equals(AuthUtil.getRemoteUserObject())) { target.deleteAnnotation(cmd.getNoteIndex()); } } updateModel(cmd, target); nextView = preProcessNextTab(tc, currentTab, req, res, cmd, errors); nextView.getTabStatus().setCurrentTab(currentTab); } } else { nextView = preProcessNextTab(tc, currentTab, req, res, cmd, errors); nextView.getTabStatus().setCurrentTab(currentTab); } return nextView; } }
TargetAnnotationHandler extends AbstractTargetTabHandler { public ModelAndView processOther(TabbedController tc, Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { TargetAnnotationCommand cmd = (TargetAnnotationCommand) comm; TargetEditorContext ctx = getEditorContext(req); TabbedModelAndView nextView = null; if(ctx.isEditMode()) { if(errors.hasErrors()) { nextView = preProcessNextTab(tc, currentTab, req, res, cmd, errors); nextView.getTabStatus().setCurrentTab(currentTab); nextView.addObject(Constants.GBL_CMD_DATA, cmd); } else { Target target = ctx.getTarget(); if (cmd.isAction(TargetAnnotationCommand.ACTION_ADD_NOTE)) { addAnnotation(cmd, target); } if (cmd.isAction(TargetAnnotationCommand.ACTION_MODIFY_NOTE)) { if (log.isDebugEnabled()) { log.debug("Processing modify annotation."); } Annotation annotation = target.getAnnotation(cmd.getNoteIndex()); if(annotation != null && annotation.getUser().equals(AuthUtil.getRemoteUserObject())) { annotation.setDate(new Date()); annotation.setNote(cmd.getNote()); annotation.setAlertable(cmd.isAlertable()); target.sortAnnotations(); } } else if (cmd.isAction(TargetAnnotationCommand.ACTION_DELETE_NOTE)) { if (log.isDebugEnabled()) { log.debug("Processing delete annotation."); } Annotation annotation = target.getAnnotation(cmd.getNoteIndex()); if(annotation != null && annotation.getUser().equals(AuthUtil.getRemoteUserObject())) { target.deleteAnnotation(cmd.getNoteIndex()); } } updateModel(cmd, target); nextView = preProcessNextTab(tc, currentTab, req, res, cmd, errors); nextView.getTabStatus().setCurrentTab(currentTab); } } else { nextView = preProcessNextTab(tc, currentTab, req, res, cmd, errors); nextView.getTabStatus().setCurrentTab(currentTab); } return nextView; }  }
TargetAnnotationHandler extends AbstractTargetTabHandler { public ModelAndView processOther(TabbedController tc, Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { TargetAnnotationCommand cmd = (TargetAnnotationCommand) comm; TargetEditorContext ctx = getEditorContext(req); TabbedModelAndView nextView = null; if(ctx.isEditMode()) { if(errors.hasErrors()) { nextView = preProcessNextTab(tc, currentTab, req, res, cmd, errors); nextView.getTabStatus().setCurrentTab(currentTab); nextView.addObject(Constants.GBL_CMD_DATA, cmd); } else { Target target = ctx.getTarget(); if (cmd.isAction(TargetAnnotationCommand.ACTION_ADD_NOTE)) { addAnnotation(cmd, target); } if (cmd.isAction(TargetAnnotationCommand.ACTION_MODIFY_NOTE)) { if (log.isDebugEnabled()) { log.debug("Processing modify annotation."); } Annotation annotation = target.getAnnotation(cmd.getNoteIndex()); if(annotation != null && annotation.getUser().equals(AuthUtil.getRemoteUserObject())) { annotation.setDate(new Date()); annotation.setNote(cmd.getNote()); annotation.setAlertable(cmd.isAlertable()); target.sortAnnotations(); } } else if (cmd.isAction(TargetAnnotationCommand.ACTION_DELETE_NOTE)) { if (log.isDebugEnabled()) { log.debug("Processing delete annotation."); } Annotation annotation = target.getAnnotation(cmd.getNoteIndex()); if(annotation != null && annotation.getUser().equals(AuthUtil.getRemoteUserObject())) { target.deleteAnnotation(cmd.getNoteIndex()); } } updateModel(cmd, target); nextView = preProcessNextTab(tc, currentTab, req, res, cmd, errors); nextView.getTabStatus().setCurrentTab(currentTab); } } else { nextView = preProcessNextTab(tc, currentTab, req, res, cmd, errors); nextView.getTabStatus().setCurrentTab(currentTab); } return nextView; }  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 setTargetManager(TargetManager targetManager); void setSelectionTypesList(WCTTreeSet selectionTypesList); void setHarvestTypesList(WCTTreeSet harvestTypesList); }
TargetAnnotationHandler extends AbstractTargetTabHandler { public ModelAndView processOther(TabbedController tc, Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { TargetAnnotationCommand cmd = (TargetAnnotationCommand) comm; TargetEditorContext ctx = getEditorContext(req); TabbedModelAndView nextView = null; if(ctx.isEditMode()) { if(errors.hasErrors()) { nextView = preProcessNextTab(tc, currentTab, req, res, cmd, errors); nextView.getTabStatus().setCurrentTab(currentTab); nextView.addObject(Constants.GBL_CMD_DATA, cmd); } else { Target target = ctx.getTarget(); if (cmd.isAction(TargetAnnotationCommand.ACTION_ADD_NOTE)) { addAnnotation(cmd, target); } if (cmd.isAction(TargetAnnotationCommand.ACTION_MODIFY_NOTE)) { if (log.isDebugEnabled()) { log.debug("Processing modify annotation."); } Annotation annotation = target.getAnnotation(cmd.getNoteIndex()); if(annotation != null && annotation.getUser().equals(AuthUtil.getRemoteUserObject())) { annotation.setDate(new Date()); annotation.setNote(cmd.getNote()); annotation.setAlertable(cmd.isAlertable()); target.sortAnnotations(); } } else if (cmd.isAction(TargetAnnotationCommand.ACTION_DELETE_NOTE)) { if (log.isDebugEnabled()) { log.debug("Processing delete annotation."); } Annotation annotation = target.getAnnotation(cmd.getNoteIndex()); if(annotation != null && annotation.getUser().equals(AuthUtil.getRemoteUserObject())) { target.deleteAnnotation(cmd.getNoteIndex()); } } updateModel(cmd, target); nextView = preProcessNextTab(tc, currentTab, req, res, cmd, errors); nextView.getTabStatus().setCurrentTab(currentTab); } } else { nextView = preProcessNextTab(tc, currentTab, req, res, cmd, errors); nextView.getTabStatus().setCurrentTab(currentTab); } return nextView; }  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 setTargetManager(TargetManager targetManager); void setSelectionTypesList(WCTTreeSet selectionTypesList); void setHarvestTypesList(WCTTreeSet harvestTypesList);  }