ArchiveController extends AbstractCommandController { @Override protected ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object comm, BindException errors) throws Exception { String[] targetInstanceOids = request.getParameterValues("instanceID"); for (String targetInstanceOid : targetInstanceOids) { TargetInstance instance = targetInstanceManager.getTargetInstance(Long.parseLong(targetInstanceOid)); String harvestNo = request.getParameter("harvestNumber"); int harvestNumber; if (harvestNo != null) { harvestNumber = Integer.parseInt(harvestNo); } else { harvestNumber = 0; } if (harvestNumber == 0) { List<HarvestResult> results = targetInstanceManager.getHarvestResults(instance.getOid()); harvestNumber = extractEndorsedHarvestNumber(results); if ( harvestNumber == 0 ) { ModelAndView mav = new ModelAndView("redirect:/" + Constants.CNTRL_TI_QUEUE + "?" + TargetInstanceCommand.REQ_SHOW_SUBMITTED_MSG + "=n"); return mav; } } String xmlData = buildSip(request, response, harvestNumber); Map customDepositFormElements = getCustomDepositFormElementsAsMap(request); try{ Target target = targetManager.load(instance.getTarget().getOid()); if (target.isAutoDenoteReferenceCrawl()) { target.setReferenceCrawlOid(instance.getOid()); targetManager.save(target); } archiveAdapter.submitToArchive(instance, xmlData, customDepositFormElements, harvestNumber); } catch(Exception e){ e.printStackTrace(); errors.reject("archive.failure", new Object[]{e.getMessage()}, "Failed to submit to archive"); ArchiveCommand command = (ArchiveCommand) comm; ModelAndView mav = new ModelAndView("submit-to-archive2"); mav.addObject("instance", instance); mav.addObject(Constants.GBL_CMD_DATA, command); mav.addObject("hasErrors", errors.hasErrors()); mav.addObject(Constants.GBL_ERRORS, errors); return mav; } } ModelAndView mav = new ModelAndView("redirect:/" + Constants.CNTRL_TI_QUEUE + "?" + TargetInstanceCommand.REQ_SHOW_SUBMITTED_MSG + "=y"); return mav; } ArchiveController(); void setTargetInstanceManager(TargetInstanceManager targetInstanceManager); void setArchiveAdapter(ArchiveAdapter archiveAdapter); void setTargetManager(TargetManager targetManager); void setHeritrixVersion(String heritrixVersion); void setWebCuratorUrl(String webCuratorUrl); void setSipBuilder(SipBuilder sipBuilder);  }
@Test public final void testHandle() { testSetArchiveAdapter(); testSetTargetInstanceManager(); testSetTargetManager(); testSetSipBuilder(); try { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); List<HarvestResult> harvestResults = new ArrayList<HarvestResult>(); HarvestResult hr = new HarvestResult(); hr.setHarvestNumber(1); harvestResults.add(hr); TargetInstance ti = targetInstanceManager.getTargetInstance(5001L); ti.setHarvestResults(harvestResults); request.addParameter("instanceID", "5001"); request.addParameter("harvestNumber", "1"); request.setAttribute("xmlData", ""); ArchiveCommand comm = new ArchiveCommand(); comm.setHarvestResultNumber(1); comm.setTargetInstanceID(5001); BindException errors = new BindException(comm, "ArchiveCommand"); ModelAndView mav = testInstance.handle(request, response, comm, errors); assertNotNull(mav); assertEquals(mav.getViewName(), "redirect:/curator/target/queue.html?showSubmittedMsg=y"); } catch(Exception e) { fail(e.getMessage()); } }