@Test public final void testHandelSave() { try { testHandelAction(); aCmd = new TreeToolCommand(); aCmd.setActionCmd(TreeToolCommand.ACTION_SAVE); aCmd.setProvenanceNote("Test Provenance Note"); aCmd.setHrOid(((long) 111000)); ModelAndView mav = testInstance.handle(aReq, aResp, aCmd, aErrors); assertTrue(mav != null); assertTrue(mav.getViewName().startsWith( "redirect:/curator/target/target-instance.html")); } catch (Exception e) { fail(e.getClass().getName() + " - " + e.getMessage()); } }
@SuppressWarnings("unchecked") @Override protected ModelAndView handle(HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) throws Exception { TreeToolCommand command = (TreeToolCommand) comm; TargetInstance ti = (TargetInstance) req.getSession().getAttribute("sessionTargetInstance"); if(command.getLoadTree() != null) { log.info("Generating Tree"); HarvestResourceNodeTreeBuilder treeBuilder = qualityReviewFacade.getHarvestResultTree(command.getLoadTree()); WCTNodeTree tree = treeBuilder.getTree(); req.getSession().setAttribute("tree", tree); command.setHrOid(command.getLoadTree()); log.info("Tree complete"); if(autoQAUrl != null && autoQAUrl.length() > 0) { List<AQAElement> candidateElements = new ArrayList<AQAElement>(); File xmlFile; try { xmlFile = harvestLogManager.getLogfile(ti, command.getLogFileName()); } catch (Exception e) { xmlFile = null; log.info("Missing AQA report file: " + command.getLogFileName()); } if (xmlFile != null) { Document aqaResult = readXMLDocument(xmlFile); NodeList parentElementsNode = aqaResult.getElementsByTagName("missingElements"); if (parentElementsNode.getLength() > 0) { NodeList elementNodes = ((Element)parentElementsNode.item(0)).getElementsByTagName("element"); for(int i = 0; i < elementNodes.getLength(); i++) { Element element = (Element)elementNodes.item(i); if (element.getAttribute("statuscode").equals("200")) { candidateElements.add(new AQAElement(element.getAttribute("url"), element.getAttribute("contentfile"), element.getAttribute("contentType"), Long.parseLong(element.getAttribute("contentLength")))); } } } req.getSession().setAttribute("aqaImports", candidateElements); } } } WCTNodeTree tree = (WCTNodeTree) req.getSession().getAttribute("tree"); List<AQAElement> imports = (List<AQAElement>) req.getSession().getAttribute("aqaImports"); if(errors.hasErrors()) { ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "command", command); mav.addObject( "aqaImports", imports); mav.addObject( Constants.GBL_ERRORS, errors); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } else if( command.isAction(TreeToolCommand.ACTION_TREE_ACTION)){ if( command.getToggleId() != null) { tree.toggle(command.getToggleId()); } if( command.getMarkForDelete() != null) { tree.markForDelete(command.getMarkForDelete(), command.getPropagateDelete()); } if( command.getTargetURL() != null) { HarvestResourceNodeTreeBuilder tb = new HarvestResourceNodeTreeBuilder(); try { URL parentUrl = tb.getParent(new URL(command.getTargetURL())); } catch (MalformedURLException me) { errors.reject("tools.errors.invalidtargeturl"); ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "command", command); mav.addObject( "aqaImports", imports); mav.addObject( Constants.GBL_ERRORS, errors); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } if( command.getImportType().equals(TreeToolCommand.IMPORT_FILE)) { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) req; CommonsMultipartFile uploadedFile = (CommonsMultipartFile) multipartRequest.getFile("sourceFile"); String tempFileName = UUID.randomUUID().toString(); File xfrFile = new File(uploadedFilesDir+tempFileName); StringBuffer buf = new StringBuffer(); buf.append("HTTP/1.1 200 OK\n"); buf.append("Content-Type: "); buf.append(uploadedFile.getContentType()+"\n"); buf.append("Content-Length: "); buf.append(uploadedFile.getSize()+"\n"); buf.append("Connection: close\n\n"); FileOutputStream fos = new FileOutputStream(xfrFile); fos.write(buf.toString().getBytes()); fos.write(uploadedFile.getBytes()); fos.close(); tree.insert(command.getTargetURL(),xfrFile.length(), tempFileName, uploadedFile.getContentType()); } if( command.getImportType().equals(TreeToolCommand.IMPORT_URL)) { String tempFileName = UUID.randomUUID().toString(); File xfrFile = new File(uploadedFilesDir+tempFileName); FileOutputStream fos = new FileOutputStream(xfrFile); String outStrings[] = new String[1]; try { fos.write(fetchHTTPResponse(command.getSourceURL(), outStrings)); } catch (HTTPGetException ge) { errors.reject("tools.errors.httpgeterror", new Object[] {command.getSourceURL(), ge.getMessage()} ,""); ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "aqaImports", imports); mav.addObject( "command", command); mav.addObject( Constants.GBL_ERRORS, errors); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } finally { fos.close(); } tree.insert(command.getTargetURL(),xfrFile.length(), tempFileName, outStrings[0]); } } ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "aqaImports", imports); mav.addObject( "command", command); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } else if(command.isAction(TreeToolCommand.ACTION_VIEW)) { HarvestResource resource = tree.getNodeCache().get(command.getSelectedRow()).getSubject(); Long resultOid = resource.getResult().getOid(); String url = resource.getName(); if (enableAccessTool && harvestResourceUrlMapper != null) { return new ModelAndView("redirect:" + harvestResourceUrlMapper.generateUrl(resource.getResult(), resource.buildDTO())); } else { return new ModelAndView("redirect:/curator/tools/browse/" + resultOid + "/" +url); } } else if(command.isAction(TreeToolCommand.ACTION_SHOW_HOP_PATH)) { TargetInstance tinst = (TargetInstance) req.getSession().getAttribute("sessionTargetInstance"); Long instanceOid = tinst.getOid(); String url = command.getSelectedUrl(); return new ModelAndView("redirect:/curator/target/show-hop-path.html?targetInstanceOid=" + instanceOid + "&logFileName=sortedcrawl.log&url=" +url); } else if(command.isAction(TreeToolCommand.IMPORT_AQA_FILE)) { if (command.getAqaImports() != null) { List<AQAElement> removeElements = new ArrayList<AQAElement>(); String[] aqaImportUrls = command.getAqaImports(); for(int i=0;i<aqaImportUrls.length;i++) { String aqaUrl = aqaImportUrls[i]; for (Iterator iter = imports.iterator(); iter.hasNext();) { AQAElement elem = (AQAElement) iter.next(); if (elem.getUrl().equals(aqaUrl)) { File aqaFile = null; try { aqaFile = harvestLogManager.getLogfile(ti, elem.getContentFile()); String tempFileName = UUID.randomUUID().toString(); File xfrFile = new File(uploadedFilesDir+tempFileName); StringBuffer buf = new StringBuffer(); buf.append("HTTP/1.1 200 OK\n"); buf.append("Content-Type: "); buf.append(elem.getContentType()+"\n"); buf.append("Content-Length: "); buf.append(elem.getContentLength()+"\n"); buf.append("Connection: close\n\n"); FileOutputStream fos = new FileOutputStream(xfrFile); fos.write(buf.toString().getBytes()); FileInputStream fin = new FileInputStream(aqaFile); byte[] bytes = new byte[8192]; int len = 0; while ((len = fin.read(bytes)) >= 0) { fos.write(bytes, 0, len); } fos.close(); fin.close(); tree.insert(aqaUrl, xfrFile.length(), tempFileName, elem.getContentType()); removeElements.add(elem); } catch (Exception e) { log.info("Missing AQA import file: " + elem.getContentFile()); } } } }; for (Iterator remit = removeElements.iterator(); remit.hasNext();) { AQAElement rem = (AQAElement) remit.next(); imports.remove(rem); } }; ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "aqaImports", imports); mav.addObject( "command", command); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } else if(command.isAction(TreeToolCommand.ACTION_SAVE)) { List<String> uris = new LinkedList<String>(); for(WCTNode node: tree.getPrunedNodes()) { if(node.getSubject() != null) { uris.add( node.getSubject().getName()); } } List<HarvestResourceDTO> hrs = new LinkedList<HarvestResourceDTO>(); for(HarvestResourceDTO dto: tree.getImportedNodes()) { hrs.add(dto); } HarvestResult result = qualityReviewFacade.copyAndPrune(command.getHrOid(), uris, hrs, command.getProvenanceNote(), tree.getModificationNotes()); removeTree(req); removeAQAImports(req); return new ModelAndView("redirect:/" + Constants.CNTRL_TI + "?targetInstanceId=" + result.getTargetInstance().getOid()+"&cmd=edit&init_tab=RESULTS"); } else if(command.isAction(TreeToolCommand.ACTION_CANCEL)) { removeTree(req); removeAQAImports(req); TargetInstance tinst = (TargetInstance) req.getSession().getAttribute("sessionTargetInstance"); return new ModelAndView("redirect:/curator/target/quality-review-toc.html?targetInstanceOid=" + tinst.getOid() + "&harvestResultId=" + command.getHrOid()); } else { ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "command", command); mav.addObject( "aqaImports", imports); mav.addObject( Constants.GBL_ERRORS, errors); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } }
TreeToolController extends AbstractCommandController { @SuppressWarnings("unchecked") @Override protected ModelAndView handle(HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) throws Exception { TreeToolCommand command = (TreeToolCommand) comm; TargetInstance ti = (TargetInstance) req.getSession().getAttribute("sessionTargetInstance"); if(command.getLoadTree() != null) { log.info("Generating Tree"); HarvestResourceNodeTreeBuilder treeBuilder = qualityReviewFacade.getHarvestResultTree(command.getLoadTree()); WCTNodeTree tree = treeBuilder.getTree(); req.getSession().setAttribute("tree", tree); command.setHrOid(command.getLoadTree()); log.info("Tree complete"); if(autoQAUrl != null && autoQAUrl.length() > 0) { List<AQAElement> candidateElements = new ArrayList<AQAElement>(); File xmlFile; try { xmlFile = harvestLogManager.getLogfile(ti, command.getLogFileName()); } catch (Exception e) { xmlFile = null; log.info("Missing AQA report file: " + command.getLogFileName()); } if (xmlFile != null) { Document aqaResult = readXMLDocument(xmlFile); NodeList parentElementsNode = aqaResult.getElementsByTagName("missingElements"); if (parentElementsNode.getLength() > 0) { NodeList elementNodes = ((Element)parentElementsNode.item(0)).getElementsByTagName("element"); for(int i = 0; i < elementNodes.getLength(); i++) { Element element = (Element)elementNodes.item(i); if (element.getAttribute("statuscode").equals("200")) { candidateElements.add(new AQAElement(element.getAttribute("url"), element.getAttribute("contentfile"), element.getAttribute("contentType"), Long.parseLong(element.getAttribute("contentLength")))); } } } req.getSession().setAttribute("aqaImports", candidateElements); } } } WCTNodeTree tree = (WCTNodeTree) req.getSession().getAttribute("tree"); List<AQAElement> imports = (List<AQAElement>) req.getSession().getAttribute("aqaImports"); if(errors.hasErrors()) { ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "command", command); mav.addObject( "aqaImports", imports); mav.addObject( Constants.GBL_ERRORS, errors); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } else if( command.isAction(TreeToolCommand.ACTION_TREE_ACTION)){ if( command.getToggleId() != null) { tree.toggle(command.getToggleId()); } if( command.getMarkForDelete() != null) { tree.markForDelete(command.getMarkForDelete(), command.getPropagateDelete()); } if( command.getTargetURL() != null) { HarvestResourceNodeTreeBuilder tb = new HarvestResourceNodeTreeBuilder(); try { URL parentUrl = tb.getParent(new URL(command.getTargetURL())); } catch (MalformedURLException me) { errors.reject("tools.errors.invalidtargeturl"); ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "command", command); mav.addObject( "aqaImports", imports); mav.addObject( Constants.GBL_ERRORS, errors); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } if( command.getImportType().equals(TreeToolCommand.IMPORT_FILE)) { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) req; CommonsMultipartFile uploadedFile = (CommonsMultipartFile) multipartRequest.getFile("sourceFile"); String tempFileName = UUID.randomUUID().toString(); File xfrFile = new File(uploadedFilesDir+tempFileName); StringBuffer buf = new StringBuffer(); buf.append("HTTP/1.1 200 OK\n"); buf.append("Content-Type: "); buf.append(uploadedFile.getContentType()+"\n"); buf.append("Content-Length: "); buf.append(uploadedFile.getSize()+"\n"); buf.append("Connection: close\n\n"); FileOutputStream fos = new FileOutputStream(xfrFile); fos.write(buf.toString().getBytes()); fos.write(uploadedFile.getBytes()); fos.close(); tree.insert(command.getTargetURL(),xfrFile.length(), tempFileName, uploadedFile.getContentType()); } if( command.getImportType().equals(TreeToolCommand.IMPORT_URL)) { String tempFileName = UUID.randomUUID().toString(); File xfrFile = new File(uploadedFilesDir+tempFileName); FileOutputStream fos = new FileOutputStream(xfrFile); String outStrings[] = new String[1]; try { fos.write(fetchHTTPResponse(command.getSourceURL(), outStrings)); } catch (HTTPGetException ge) { errors.reject("tools.errors.httpgeterror", new Object[] {command.getSourceURL(), ge.getMessage()} ,""); ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "aqaImports", imports); mav.addObject( "command", command); mav.addObject( Constants.GBL_ERRORS, errors); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } finally { fos.close(); } tree.insert(command.getTargetURL(),xfrFile.length(), tempFileName, outStrings[0]); } } ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "aqaImports", imports); mav.addObject( "command", command); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } else if(command.isAction(TreeToolCommand.ACTION_VIEW)) { HarvestResource resource = tree.getNodeCache().get(command.getSelectedRow()).getSubject(); Long resultOid = resource.getResult().getOid(); String url = resource.getName(); if (enableAccessTool && harvestResourceUrlMapper != null) { return new ModelAndView("redirect:" + harvestResourceUrlMapper.generateUrl(resource.getResult(), resource.buildDTO())); } else { return new ModelAndView("redirect:/curator/tools/browse/" + resultOid + "/" +url); } } else if(command.isAction(TreeToolCommand.ACTION_SHOW_HOP_PATH)) { TargetInstance tinst = (TargetInstance) req.getSession().getAttribute("sessionTargetInstance"); Long instanceOid = tinst.getOid(); String url = command.getSelectedUrl(); return new ModelAndView("redirect:/curator/target/show-hop-path.html?targetInstanceOid=" + instanceOid + "&logFileName=sortedcrawl.log&url=" +url); } else if(command.isAction(TreeToolCommand.IMPORT_AQA_FILE)) { if (command.getAqaImports() != null) { List<AQAElement> removeElements = new ArrayList<AQAElement>(); String[] aqaImportUrls = command.getAqaImports(); for(int i=0;i<aqaImportUrls.length;i++) { String aqaUrl = aqaImportUrls[i]; for (Iterator iter = imports.iterator(); iter.hasNext();) { AQAElement elem = (AQAElement) iter.next(); if (elem.getUrl().equals(aqaUrl)) { File aqaFile = null; try { aqaFile = harvestLogManager.getLogfile(ti, elem.getContentFile()); String tempFileName = UUID.randomUUID().toString(); File xfrFile = new File(uploadedFilesDir+tempFileName); StringBuffer buf = new StringBuffer(); buf.append("HTTP/1.1 200 OK\n"); buf.append("Content-Type: "); buf.append(elem.getContentType()+"\n"); buf.append("Content-Length: "); buf.append(elem.getContentLength()+"\n"); buf.append("Connection: close\n\n"); FileOutputStream fos = new FileOutputStream(xfrFile); fos.write(buf.toString().getBytes()); FileInputStream fin = new FileInputStream(aqaFile); byte[] bytes = new byte[8192]; int len = 0; while ((len = fin.read(bytes)) >= 0) { fos.write(bytes, 0, len); } fos.close(); fin.close(); tree.insert(aqaUrl, xfrFile.length(), tempFileName, elem.getContentType()); removeElements.add(elem); } catch (Exception e) { log.info("Missing AQA import file: " + elem.getContentFile()); } } } }; for (Iterator remit = removeElements.iterator(); remit.hasNext();) { AQAElement rem = (AQAElement) remit.next(); imports.remove(rem); } }; ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "aqaImports", imports); mav.addObject( "command", command); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } else if(command.isAction(TreeToolCommand.ACTION_SAVE)) { List<String> uris = new LinkedList<String>(); for(WCTNode node: tree.getPrunedNodes()) { if(node.getSubject() != null) { uris.add( node.getSubject().getName()); } } List<HarvestResourceDTO> hrs = new LinkedList<HarvestResourceDTO>(); for(HarvestResourceDTO dto: tree.getImportedNodes()) { hrs.add(dto); } HarvestResult result = qualityReviewFacade.copyAndPrune(command.getHrOid(), uris, hrs, command.getProvenanceNote(), tree.getModificationNotes()); removeTree(req); removeAQAImports(req); return new ModelAndView("redirect:/" + Constants.CNTRL_TI + "?targetInstanceId=" + result.getTargetInstance().getOid()+"&cmd=edit&init_tab=RESULTS"); } else if(command.isAction(TreeToolCommand.ACTION_CANCEL)) { removeTree(req); removeAQAImports(req); TargetInstance tinst = (TargetInstance) req.getSession().getAttribute("sessionTargetInstance"); return new ModelAndView("redirect:/curator/target/quality-review-toc.html?targetInstanceOid=" + tinst.getOid() + "&harvestResultId=" + command.getHrOid()); } else { ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "command", command); mav.addObject( "aqaImports", imports); mav.addObject( Constants.GBL_ERRORS, errors); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } } }
TreeToolController extends AbstractCommandController { @SuppressWarnings("unchecked") @Override protected ModelAndView handle(HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) throws Exception { TreeToolCommand command = (TreeToolCommand) comm; TargetInstance ti = (TargetInstance) req.getSession().getAttribute("sessionTargetInstance"); if(command.getLoadTree() != null) { log.info("Generating Tree"); HarvestResourceNodeTreeBuilder treeBuilder = qualityReviewFacade.getHarvestResultTree(command.getLoadTree()); WCTNodeTree tree = treeBuilder.getTree(); req.getSession().setAttribute("tree", tree); command.setHrOid(command.getLoadTree()); log.info("Tree complete"); if(autoQAUrl != null && autoQAUrl.length() > 0) { List<AQAElement> candidateElements = new ArrayList<AQAElement>(); File xmlFile; try { xmlFile = harvestLogManager.getLogfile(ti, command.getLogFileName()); } catch (Exception e) { xmlFile = null; log.info("Missing AQA report file: " + command.getLogFileName()); } if (xmlFile != null) { Document aqaResult = readXMLDocument(xmlFile); NodeList parentElementsNode = aqaResult.getElementsByTagName("missingElements"); if (parentElementsNode.getLength() > 0) { NodeList elementNodes = ((Element)parentElementsNode.item(0)).getElementsByTagName("element"); for(int i = 0; i < elementNodes.getLength(); i++) { Element element = (Element)elementNodes.item(i); if (element.getAttribute("statuscode").equals("200")) { candidateElements.add(new AQAElement(element.getAttribute("url"), element.getAttribute("contentfile"), element.getAttribute("contentType"), Long.parseLong(element.getAttribute("contentLength")))); } } } req.getSession().setAttribute("aqaImports", candidateElements); } } } WCTNodeTree tree = (WCTNodeTree) req.getSession().getAttribute("tree"); List<AQAElement> imports = (List<AQAElement>) req.getSession().getAttribute("aqaImports"); if(errors.hasErrors()) { ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "command", command); mav.addObject( "aqaImports", imports); mav.addObject( Constants.GBL_ERRORS, errors); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } else if( command.isAction(TreeToolCommand.ACTION_TREE_ACTION)){ if( command.getToggleId() != null) { tree.toggle(command.getToggleId()); } if( command.getMarkForDelete() != null) { tree.markForDelete(command.getMarkForDelete(), command.getPropagateDelete()); } if( command.getTargetURL() != null) { HarvestResourceNodeTreeBuilder tb = new HarvestResourceNodeTreeBuilder(); try { URL parentUrl = tb.getParent(new URL(command.getTargetURL())); } catch (MalformedURLException me) { errors.reject("tools.errors.invalidtargeturl"); ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "command", command); mav.addObject( "aqaImports", imports); mav.addObject( Constants.GBL_ERRORS, errors); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } if( command.getImportType().equals(TreeToolCommand.IMPORT_FILE)) { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) req; CommonsMultipartFile uploadedFile = (CommonsMultipartFile) multipartRequest.getFile("sourceFile"); String tempFileName = UUID.randomUUID().toString(); File xfrFile = new File(uploadedFilesDir+tempFileName); StringBuffer buf = new StringBuffer(); buf.append("HTTP/1.1 200 OK\n"); buf.append("Content-Type: "); buf.append(uploadedFile.getContentType()+"\n"); buf.append("Content-Length: "); buf.append(uploadedFile.getSize()+"\n"); buf.append("Connection: close\n\n"); FileOutputStream fos = new FileOutputStream(xfrFile); fos.write(buf.toString().getBytes()); fos.write(uploadedFile.getBytes()); fos.close(); tree.insert(command.getTargetURL(),xfrFile.length(), tempFileName, uploadedFile.getContentType()); } if( command.getImportType().equals(TreeToolCommand.IMPORT_URL)) { String tempFileName = UUID.randomUUID().toString(); File xfrFile = new File(uploadedFilesDir+tempFileName); FileOutputStream fos = new FileOutputStream(xfrFile); String outStrings[] = new String[1]; try { fos.write(fetchHTTPResponse(command.getSourceURL(), outStrings)); } catch (HTTPGetException ge) { errors.reject("tools.errors.httpgeterror", new Object[] {command.getSourceURL(), ge.getMessage()} ,""); ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "aqaImports", imports); mav.addObject( "command", command); mav.addObject( Constants.GBL_ERRORS, errors); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } finally { fos.close(); } tree.insert(command.getTargetURL(),xfrFile.length(), tempFileName, outStrings[0]); } } ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "aqaImports", imports); mav.addObject( "command", command); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } else if(command.isAction(TreeToolCommand.ACTION_VIEW)) { HarvestResource resource = tree.getNodeCache().get(command.getSelectedRow()).getSubject(); Long resultOid = resource.getResult().getOid(); String url = resource.getName(); if (enableAccessTool && harvestResourceUrlMapper != null) { return new ModelAndView("redirect:" + harvestResourceUrlMapper.generateUrl(resource.getResult(), resource.buildDTO())); } else { return new ModelAndView("redirect:/curator/tools/browse/" + resultOid + "/" +url); } } else if(command.isAction(TreeToolCommand.ACTION_SHOW_HOP_PATH)) { TargetInstance tinst = (TargetInstance) req.getSession().getAttribute("sessionTargetInstance"); Long instanceOid = tinst.getOid(); String url = command.getSelectedUrl(); return new ModelAndView("redirect:/curator/target/show-hop-path.html?targetInstanceOid=" + instanceOid + "&logFileName=sortedcrawl.log&url=" +url); } else if(command.isAction(TreeToolCommand.IMPORT_AQA_FILE)) { if (command.getAqaImports() != null) { List<AQAElement> removeElements = new ArrayList<AQAElement>(); String[] aqaImportUrls = command.getAqaImports(); for(int i=0;i<aqaImportUrls.length;i++) { String aqaUrl = aqaImportUrls[i]; for (Iterator iter = imports.iterator(); iter.hasNext();) { AQAElement elem = (AQAElement) iter.next(); if (elem.getUrl().equals(aqaUrl)) { File aqaFile = null; try { aqaFile = harvestLogManager.getLogfile(ti, elem.getContentFile()); String tempFileName = UUID.randomUUID().toString(); File xfrFile = new File(uploadedFilesDir+tempFileName); StringBuffer buf = new StringBuffer(); buf.append("HTTP/1.1 200 OK\n"); buf.append("Content-Type: "); buf.append(elem.getContentType()+"\n"); buf.append("Content-Length: "); buf.append(elem.getContentLength()+"\n"); buf.append("Connection: close\n\n"); FileOutputStream fos = new FileOutputStream(xfrFile); fos.write(buf.toString().getBytes()); FileInputStream fin = new FileInputStream(aqaFile); byte[] bytes = new byte[8192]; int len = 0; while ((len = fin.read(bytes)) >= 0) { fos.write(bytes, 0, len); } fos.close(); fin.close(); tree.insert(aqaUrl, xfrFile.length(), tempFileName, elem.getContentType()); removeElements.add(elem); } catch (Exception e) { log.info("Missing AQA import file: " + elem.getContentFile()); } } } }; for (Iterator remit = removeElements.iterator(); remit.hasNext();) { AQAElement rem = (AQAElement) remit.next(); imports.remove(rem); } }; ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "aqaImports", imports); mav.addObject( "command", command); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } else if(command.isAction(TreeToolCommand.ACTION_SAVE)) { List<String> uris = new LinkedList<String>(); for(WCTNode node: tree.getPrunedNodes()) { if(node.getSubject() != null) { uris.add( node.getSubject().getName()); } } List<HarvestResourceDTO> hrs = new LinkedList<HarvestResourceDTO>(); for(HarvestResourceDTO dto: tree.getImportedNodes()) { hrs.add(dto); } HarvestResult result = qualityReviewFacade.copyAndPrune(command.getHrOid(), uris, hrs, command.getProvenanceNote(), tree.getModificationNotes()); removeTree(req); removeAQAImports(req); return new ModelAndView("redirect:/" + Constants.CNTRL_TI + "?targetInstanceId=" + result.getTargetInstance().getOid()+"&cmd=edit&init_tab=RESULTS"); } else if(command.isAction(TreeToolCommand.ACTION_CANCEL)) { removeTree(req); removeAQAImports(req); TargetInstance tinst = (TargetInstance) req.getSession().getAttribute("sessionTargetInstance"); return new ModelAndView("redirect:/curator/target/quality-review-toc.html?targetInstanceOid=" + tinst.getOid() + "&harvestResultId=" + command.getHrOid()); } else { ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "command", command); mav.addObject( "aqaImports", imports); mav.addObject( Constants.GBL_ERRORS, errors); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } } TreeToolController(); }
TreeToolController extends AbstractCommandController { @SuppressWarnings("unchecked") @Override protected ModelAndView handle(HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) throws Exception { TreeToolCommand command = (TreeToolCommand) comm; TargetInstance ti = (TargetInstance) req.getSession().getAttribute("sessionTargetInstance"); if(command.getLoadTree() != null) { log.info("Generating Tree"); HarvestResourceNodeTreeBuilder treeBuilder = qualityReviewFacade.getHarvestResultTree(command.getLoadTree()); WCTNodeTree tree = treeBuilder.getTree(); req.getSession().setAttribute("tree", tree); command.setHrOid(command.getLoadTree()); log.info("Tree complete"); if(autoQAUrl != null && autoQAUrl.length() > 0) { List<AQAElement> candidateElements = new ArrayList<AQAElement>(); File xmlFile; try { xmlFile = harvestLogManager.getLogfile(ti, command.getLogFileName()); } catch (Exception e) { xmlFile = null; log.info("Missing AQA report file: " + command.getLogFileName()); } if (xmlFile != null) { Document aqaResult = readXMLDocument(xmlFile); NodeList parentElementsNode = aqaResult.getElementsByTagName("missingElements"); if (parentElementsNode.getLength() > 0) { NodeList elementNodes = ((Element)parentElementsNode.item(0)).getElementsByTagName("element"); for(int i = 0; i < elementNodes.getLength(); i++) { Element element = (Element)elementNodes.item(i); if (element.getAttribute("statuscode").equals("200")) { candidateElements.add(new AQAElement(element.getAttribute("url"), element.getAttribute("contentfile"), element.getAttribute("contentType"), Long.parseLong(element.getAttribute("contentLength")))); } } } req.getSession().setAttribute("aqaImports", candidateElements); } } } WCTNodeTree tree = (WCTNodeTree) req.getSession().getAttribute("tree"); List<AQAElement> imports = (List<AQAElement>) req.getSession().getAttribute("aqaImports"); if(errors.hasErrors()) { ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "command", command); mav.addObject( "aqaImports", imports); mav.addObject( Constants.GBL_ERRORS, errors); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } else if( command.isAction(TreeToolCommand.ACTION_TREE_ACTION)){ if( command.getToggleId() != null) { tree.toggle(command.getToggleId()); } if( command.getMarkForDelete() != null) { tree.markForDelete(command.getMarkForDelete(), command.getPropagateDelete()); } if( command.getTargetURL() != null) { HarvestResourceNodeTreeBuilder tb = new HarvestResourceNodeTreeBuilder(); try { URL parentUrl = tb.getParent(new URL(command.getTargetURL())); } catch (MalformedURLException me) { errors.reject("tools.errors.invalidtargeturl"); ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "command", command); mav.addObject( "aqaImports", imports); mav.addObject( Constants.GBL_ERRORS, errors); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } if( command.getImportType().equals(TreeToolCommand.IMPORT_FILE)) { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) req; CommonsMultipartFile uploadedFile = (CommonsMultipartFile) multipartRequest.getFile("sourceFile"); String tempFileName = UUID.randomUUID().toString(); File xfrFile = new File(uploadedFilesDir+tempFileName); StringBuffer buf = new StringBuffer(); buf.append("HTTP/1.1 200 OK\n"); buf.append("Content-Type: "); buf.append(uploadedFile.getContentType()+"\n"); buf.append("Content-Length: "); buf.append(uploadedFile.getSize()+"\n"); buf.append("Connection: close\n\n"); FileOutputStream fos = new FileOutputStream(xfrFile); fos.write(buf.toString().getBytes()); fos.write(uploadedFile.getBytes()); fos.close(); tree.insert(command.getTargetURL(),xfrFile.length(), tempFileName, uploadedFile.getContentType()); } if( command.getImportType().equals(TreeToolCommand.IMPORT_URL)) { String tempFileName = UUID.randomUUID().toString(); File xfrFile = new File(uploadedFilesDir+tempFileName); FileOutputStream fos = new FileOutputStream(xfrFile); String outStrings[] = new String[1]; try { fos.write(fetchHTTPResponse(command.getSourceURL(), outStrings)); } catch (HTTPGetException ge) { errors.reject("tools.errors.httpgeterror", new Object[] {command.getSourceURL(), ge.getMessage()} ,""); ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "aqaImports", imports); mav.addObject( "command", command); mav.addObject( Constants.GBL_ERRORS, errors); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } finally { fos.close(); } tree.insert(command.getTargetURL(),xfrFile.length(), tempFileName, outStrings[0]); } } ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "aqaImports", imports); mav.addObject( "command", command); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } else if(command.isAction(TreeToolCommand.ACTION_VIEW)) { HarvestResource resource = tree.getNodeCache().get(command.getSelectedRow()).getSubject(); Long resultOid = resource.getResult().getOid(); String url = resource.getName(); if (enableAccessTool && harvestResourceUrlMapper != null) { return new ModelAndView("redirect:" + harvestResourceUrlMapper.generateUrl(resource.getResult(), resource.buildDTO())); } else { return new ModelAndView("redirect:/curator/tools/browse/" + resultOid + "/" +url); } } else if(command.isAction(TreeToolCommand.ACTION_SHOW_HOP_PATH)) { TargetInstance tinst = (TargetInstance) req.getSession().getAttribute("sessionTargetInstance"); Long instanceOid = tinst.getOid(); String url = command.getSelectedUrl(); return new ModelAndView("redirect:/curator/target/show-hop-path.html?targetInstanceOid=" + instanceOid + "&logFileName=sortedcrawl.log&url=" +url); } else if(command.isAction(TreeToolCommand.IMPORT_AQA_FILE)) { if (command.getAqaImports() != null) { List<AQAElement> removeElements = new ArrayList<AQAElement>(); String[] aqaImportUrls = command.getAqaImports(); for(int i=0;i<aqaImportUrls.length;i++) { String aqaUrl = aqaImportUrls[i]; for (Iterator iter = imports.iterator(); iter.hasNext();) { AQAElement elem = (AQAElement) iter.next(); if (elem.getUrl().equals(aqaUrl)) { File aqaFile = null; try { aqaFile = harvestLogManager.getLogfile(ti, elem.getContentFile()); String tempFileName = UUID.randomUUID().toString(); File xfrFile = new File(uploadedFilesDir+tempFileName); StringBuffer buf = new StringBuffer(); buf.append("HTTP/1.1 200 OK\n"); buf.append("Content-Type: "); buf.append(elem.getContentType()+"\n"); buf.append("Content-Length: "); buf.append(elem.getContentLength()+"\n"); buf.append("Connection: close\n\n"); FileOutputStream fos = new FileOutputStream(xfrFile); fos.write(buf.toString().getBytes()); FileInputStream fin = new FileInputStream(aqaFile); byte[] bytes = new byte[8192]; int len = 0; while ((len = fin.read(bytes)) >= 0) { fos.write(bytes, 0, len); } fos.close(); fin.close(); tree.insert(aqaUrl, xfrFile.length(), tempFileName, elem.getContentType()); removeElements.add(elem); } catch (Exception e) { log.info("Missing AQA import file: " + elem.getContentFile()); } } } }; for (Iterator remit = removeElements.iterator(); remit.hasNext();) { AQAElement rem = (AQAElement) remit.next(); imports.remove(rem); } }; ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "aqaImports", imports); mav.addObject( "command", command); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } else if(command.isAction(TreeToolCommand.ACTION_SAVE)) { List<String> uris = new LinkedList<String>(); for(WCTNode node: tree.getPrunedNodes()) { if(node.getSubject() != null) { uris.add( node.getSubject().getName()); } } List<HarvestResourceDTO> hrs = new LinkedList<HarvestResourceDTO>(); for(HarvestResourceDTO dto: tree.getImportedNodes()) { hrs.add(dto); } HarvestResult result = qualityReviewFacade.copyAndPrune(command.getHrOid(), uris, hrs, command.getProvenanceNote(), tree.getModificationNotes()); removeTree(req); removeAQAImports(req); return new ModelAndView("redirect:/" + Constants.CNTRL_TI + "?targetInstanceId=" + result.getTargetInstance().getOid()+"&cmd=edit&init_tab=RESULTS"); } else if(command.isAction(TreeToolCommand.ACTION_CANCEL)) { removeTree(req); removeAQAImports(req); TargetInstance tinst = (TargetInstance) req.getSession().getAttribute("sessionTargetInstance"); return new ModelAndView("redirect:/curator/target/quality-review-toc.html?targetInstanceOid=" + tinst.getOid() + "&harvestResultId=" + command.getHrOid()); } else { ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "command", command); mav.addObject( "aqaImports", imports); mav.addObject( Constants.GBL_ERRORS, errors); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } } TreeToolController(); @Override void initBinder(HttpServletRequest request, ServletRequestDataBinder binder); void setQualityReviewFacade(QualityReviewFacade qrf); String getSuccessView(); void setSuccessView(String successView); HarvestResourceUrlMapper getHarvestResourceUrlMapper(); void setHarvestResourceUrlMapper(
			HarvestResourceUrlMapper harvestResourceUrlMapper); void setEnableAccessTool(boolean enableAccessTool); boolean isEnableAccessTool(); String getUploadedFilesDir(); void setUploadedFilesDir(String uploadedFilesDir); void setAutoQAUrl(String autoQAUrl); String getAutoQAUrl(); void setHarvestLogManager(HarvestLogManager harvestLogManager); void setTargetInstanceManager(TargetInstanceManager targetInstanceManager); }
TreeToolController extends AbstractCommandController { @SuppressWarnings("unchecked") @Override protected ModelAndView handle(HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) throws Exception { TreeToolCommand command = (TreeToolCommand) comm; TargetInstance ti = (TargetInstance) req.getSession().getAttribute("sessionTargetInstance"); if(command.getLoadTree() != null) { log.info("Generating Tree"); HarvestResourceNodeTreeBuilder treeBuilder = qualityReviewFacade.getHarvestResultTree(command.getLoadTree()); WCTNodeTree tree = treeBuilder.getTree(); req.getSession().setAttribute("tree", tree); command.setHrOid(command.getLoadTree()); log.info("Tree complete"); if(autoQAUrl != null && autoQAUrl.length() > 0) { List<AQAElement> candidateElements = new ArrayList<AQAElement>(); File xmlFile; try { xmlFile = harvestLogManager.getLogfile(ti, command.getLogFileName()); } catch (Exception e) { xmlFile = null; log.info("Missing AQA report file: " + command.getLogFileName()); } if (xmlFile != null) { Document aqaResult = readXMLDocument(xmlFile); NodeList parentElementsNode = aqaResult.getElementsByTagName("missingElements"); if (parentElementsNode.getLength() > 0) { NodeList elementNodes = ((Element)parentElementsNode.item(0)).getElementsByTagName("element"); for(int i = 0; i < elementNodes.getLength(); i++) { Element element = (Element)elementNodes.item(i); if (element.getAttribute("statuscode").equals("200")) { candidateElements.add(new AQAElement(element.getAttribute("url"), element.getAttribute("contentfile"), element.getAttribute("contentType"), Long.parseLong(element.getAttribute("contentLength")))); } } } req.getSession().setAttribute("aqaImports", candidateElements); } } } WCTNodeTree tree = (WCTNodeTree) req.getSession().getAttribute("tree"); List<AQAElement> imports = (List<AQAElement>) req.getSession().getAttribute("aqaImports"); if(errors.hasErrors()) { ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "command", command); mav.addObject( "aqaImports", imports); mav.addObject( Constants.GBL_ERRORS, errors); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } else if( command.isAction(TreeToolCommand.ACTION_TREE_ACTION)){ if( command.getToggleId() != null) { tree.toggle(command.getToggleId()); } if( command.getMarkForDelete() != null) { tree.markForDelete(command.getMarkForDelete(), command.getPropagateDelete()); } if( command.getTargetURL() != null) { HarvestResourceNodeTreeBuilder tb = new HarvestResourceNodeTreeBuilder(); try { URL parentUrl = tb.getParent(new URL(command.getTargetURL())); } catch (MalformedURLException me) { errors.reject("tools.errors.invalidtargeturl"); ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "command", command); mav.addObject( "aqaImports", imports); mav.addObject( Constants.GBL_ERRORS, errors); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } if( command.getImportType().equals(TreeToolCommand.IMPORT_FILE)) { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) req; CommonsMultipartFile uploadedFile = (CommonsMultipartFile) multipartRequest.getFile("sourceFile"); String tempFileName = UUID.randomUUID().toString(); File xfrFile = new File(uploadedFilesDir+tempFileName); StringBuffer buf = new StringBuffer(); buf.append("HTTP/1.1 200 OK\n"); buf.append("Content-Type: "); buf.append(uploadedFile.getContentType()+"\n"); buf.append("Content-Length: "); buf.append(uploadedFile.getSize()+"\n"); buf.append("Connection: close\n\n"); FileOutputStream fos = new FileOutputStream(xfrFile); fos.write(buf.toString().getBytes()); fos.write(uploadedFile.getBytes()); fos.close(); tree.insert(command.getTargetURL(),xfrFile.length(), tempFileName, uploadedFile.getContentType()); } if( command.getImportType().equals(TreeToolCommand.IMPORT_URL)) { String tempFileName = UUID.randomUUID().toString(); File xfrFile = new File(uploadedFilesDir+tempFileName); FileOutputStream fos = new FileOutputStream(xfrFile); String outStrings[] = new String[1]; try { fos.write(fetchHTTPResponse(command.getSourceURL(), outStrings)); } catch (HTTPGetException ge) { errors.reject("tools.errors.httpgeterror", new Object[] {command.getSourceURL(), ge.getMessage()} ,""); ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "aqaImports", imports); mav.addObject( "command", command); mav.addObject( Constants.GBL_ERRORS, errors); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } finally { fos.close(); } tree.insert(command.getTargetURL(),xfrFile.length(), tempFileName, outStrings[0]); } } ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "aqaImports", imports); mav.addObject( "command", command); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } else if(command.isAction(TreeToolCommand.ACTION_VIEW)) { HarvestResource resource = tree.getNodeCache().get(command.getSelectedRow()).getSubject(); Long resultOid = resource.getResult().getOid(); String url = resource.getName(); if (enableAccessTool && harvestResourceUrlMapper != null) { return new ModelAndView("redirect:" + harvestResourceUrlMapper.generateUrl(resource.getResult(), resource.buildDTO())); } else { return new ModelAndView("redirect:/curator/tools/browse/" + resultOid + "/" +url); } } else if(command.isAction(TreeToolCommand.ACTION_SHOW_HOP_PATH)) { TargetInstance tinst = (TargetInstance) req.getSession().getAttribute("sessionTargetInstance"); Long instanceOid = tinst.getOid(); String url = command.getSelectedUrl(); return new ModelAndView("redirect:/curator/target/show-hop-path.html?targetInstanceOid=" + instanceOid + "&logFileName=sortedcrawl.log&url=" +url); } else if(command.isAction(TreeToolCommand.IMPORT_AQA_FILE)) { if (command.getAqaImports() != null) { List<AQAElement> removeElements = new ArrayList<AQAElement>(); String[] aqaImportUrls = command.getAqaImports(); for(int i=0;i<aqaImportUrls.length;i++) { String aqaUrl = aqaImportUrls[i]; for (Iterator iter = imports.iterator(); iter.hasNext();) { AQAElement elem = (AQAElement) iter.next(); if (elem.getUrl().equals(aqaUrl)) { File aqaFile = null; try { aqaFile = harvestLogManager.getLogfile(ti, elem.getContentFile()); String tempFileName = UUID.randomUUID().toString(); File xfrFile = new File(uploadedFilesDir+tempFileName); StringBuffer buf = new StringBuffer(); buf.append("HTTP/1.1 200 OK\n"); buf.append("Content-Type: "); buf.append(elem.getContentType()+"\n"); buf.append("Content-Length: "); buf.append(elem.getContentLength()+"\n"); buf.append("Connection: close\n\n"); FileOutputStream fos = new FileOutputStream(xfrFile); fos.write(buf.toString().getBytes()); FileInputStream fin = new FileInputStream(aqaFile); byte[] bytes = new byte[8192]; int len = 0; while ((len = fin.read(bytes)) >= 0) { fos.write(bytes, 0, len); } fos.close(); fin.close(); tree.insert(aqaUrl, xfrFile.length(), tempFileName, elem.getContentType()); removeElements.add(elem); } catch (Exception e) { log.info("Missing AQA import file: " + elem.getContentFile()); } } } }; for (Iterator remit = removeElements.iterator(); remit.hasNext();) { AQAElement rem = (AQAElement) remit.next(); imports.remove(rem); } }; ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "aqaImports", imports); mav.addObject( "command", command); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } else if(command.isAction(TreeToolCommand.ACTION_SAVE)) { List<String> uris = new LinkedList<String>(); for(WCTNode node: tree.getPrunedNodes()) { if(node.getSubject() != null) { uris.add( node.getSubject().getName()); } } List<HarvestResourceDTO> hrs = new LinkedList<HarvestResourceDTO>(); for(HarvestResourceDTO dto: tree.getImportedNodes()) { hrs.add(dto); } HarvestResult result = qualityReviewFacade.copyAndPrune(command.getHrOid(), uris, hrs, command.getProvenanceNote(), tree.getModificationNotes()); removeTree(req); removeAQAImports(req); return new ModelAndView("redirect:/" + Constants.CNTRL_TI + "?targetInstanceId=" + result.getTargetInstance().getOid()+"&cmd=edit&init_tab=RESULTS"); } else if(command.isAction(TreeToolCommand.ACTION_CANCEL)) { removeTree(req); removeAQAImports(req); TargetInstance tinst = (TargetInstance) req.getSession().getAttribute("sessionTargetInstance"); return new ModelAndView("redirect:/curator/target/quality-review-toc.html?targetInstanceOid=" + tinst.getOid() + "&harvestResultId=" + command.getHrOid()); } else { ModelAndView mav = new ModelAndView(getSuccessView()); mav.addObject( "tree", tree); mav.addObject( "command", command); mav.addObject( "aqaImports", imports); mav.addObject( Constants.GBL_ERRORS, errors); if(autoQAUrl != null && autoQAUrl.length() > 0) { mav.addObject("showAQAOption", 1); } else { mav.addObject("showAQAOption", 0); } return mav; } } TreeToolController(); @Override void initBinder(HttpServletRequest request, ServletRequestDataBinder binder); void setQualityReviewFacade(QualityReviewFacade qrf); String getSuccessView(); void setSuccessView(String successView); HarvestResourceUrlMapper getHarvestResourceUrlMapper(); void setHarvestResourceUrlMapper(
			HarvestResourceUrlMapper harvestResourceUrlMapper); void setEnableAccessTool(boolean enableAccessTool); boolean isEnableAccessTool(); String getUploadedFilesDir(); void setUploadedFilesDir(String uploadedFilesDir); void setAutoQAUrl(String autoQAUrl); String getAutoQAUrl(); void setHarvestLogManager(HarvestLogManager harvestLogManager); void setTargetInstanceManager(TargetInstanceManager targetInstanceManager); static final String DIR_CONTENT; }