@Test public final void testBuildSip() { 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", ""); testInstance.buildSip(request, response, 1); } catch(Exception e) { fail(e.getMessage()); } }
protected String buildSip(HttpServletRequest request, HttpServletResponse response, int harvestNumber) throws ServletException, IOException { TargetInstance instance = targetInstanceManager.getTargetInstance(Long.parseLong(request.getParameter("instanceID"))); AbstractTarget target = (AbstractTarget)instance.getTarget(); if(target.getObjectType() == AbstractTarget.TYPE_TARGET && !(target instanceof Target)) { target = targetManager.load(target.getOid()); } else if(target.getObjectType() == AbstractTarget.TYPE_GROUP && !(target instanceof TargetGroup)) { target = targetManager.loadGroup(target.getOid()); } request.setAttribute("now",new Date()); request.setAttribute("instance",instance); request.setAttribute("target",target); request.setAttribute("instanceAnnotations",targetInstanceManager.getAnnotations(instance)); request.setAttribute("targetAnnotations",targetManager.getAnnotations(target)); request.setAttribute("result",instance.getHarvestResults().get(harvestNumber-1)); request.setAttribute("webCuratorUrl",webCuratorUrl); request.setAttribute("heritrixVersion",heritrixVersion); request.setAttribute("user",org.webcurator.core.util.AuthUtil.getRemoteUserObject()); request.setAttribute("groups", targetManager.getActiveParentGroups(instance)); Map<String,String> sipSections = instance.getSipParts(); if(sipSections == null || sipSections.size() == 0) { sipSections = sipBuilder.buildSipSections(instance); } if(sipBuilder.updateTargetReference(target, sipSections)) { instance.setSipParts(sipSections); targetInstanceManager.save(instance); } request.setAttribute("sipSections", sipSections); HarvestResult curResult = instance.getHarvestResults().get(harvestNumber-1); LinkedList<HarvestResult> resultChain = new LinkedList<HarvestResult>(); resultChain.add(curResult); while(curResult.getDerivedFrom() != null) { curResult = instance.getHarvestResults().get(curResult.getDerivedFrom() -1); resultChain.add(curResult); } request.setAttribute("resultChain", resultChain); RequestDispatcher rd = request.getRequestDispatcher("/jsp/createSIPXML.jsp"); rd.include(request,response); return (String)request.getAttribute("xmlData"); }
ArchiveController extends AbstractCommandController { protected String buildSip(HttpServletRequest request, HttpServletResponse response, int harvestNumber) throws ServletException, IOException { TargetInstance instance = targetInstanceManager.getTargetInstance(Long.parseLong(request.getParameter("instanceID"))); AbstractTarget target = (AbstractTarget)instance.getTarget(); if(target.getObjectType() == AbstractTarget.TYPE_TARGET && !(target instanceof Target)) { target = targetManager.load(target.getOid()); } else if(target.getObjectType() == AbstractTarget.TYPE_GROUP && !(target instanceof TargetGroup)) { target = targetManager.loadGroup(target.getOid()); } request.setAttribute("now",new Date()); request.setAttribute("instance",instance); request.setAttribute("target",target); request.setAttribute("instanceAnnotations",targetInstanceManager.getAnnotations(instance)); request.setAttribute("targetAnnotations",targetManager.getAnnotations(target)); request.setAttribute("result",instance.getHarvestResults().get(harvestNumber-1)); request.setAttribute("webCuratorUrl",webCuratorUrl); request.setAttribute("heritrixVersion",heritrixVersion); request.setAttribute("user",org.webcurator.core.util.AuthUtil.getRemoteUserObject()); request.setAttribute("groups", targetManager.getActiveParentGroups(instance)); Map<String,String> sipSections = instance.getSipParts(); if(sipSections == null || sipSections.size() == 0) { sipSections = sipBuilder.buildSipSections(instance); } if(sipBuilder.updateTargetReference(target, sipSections)) { instance.setSipParts(sipSections); targetInstanceManager.save(instance); } request.setAttribute("sipSections", sipSections); HarvestResult curResult = instance.getHarvestResults().get(harvestNumber-1); LinkedList<HarvestResult> resultChain = new LinkedList<HarvestResult>(); resultChain.add(curResult); while(curResult.getDerivedFrom() != null) { curResult = instance.getHarvestResults().get(curResult.getDerivedFrom() -1); resultChain.add(curResult); } request.setAttribute("resultChain", resultChain); RequestDispatcher rd = request.getRequestDispatcher("/jsp/createSIPXML.jsp"); rd.include(request,response); return (String)request.getAttribute("xmlData"); } }
ArchiveController extends AbstractCommandController { protected String buildSip(HttpServletRequest request, HttpServletResponse response, int harvestNumber) throws ServletException, IOException { TargetInstance instance = targetInstanceManager.getTargetInstance(Long.parseLong(request.getParameter("instanceID"))); AbstractTarget target = (AbstractTarget)instance.getTarget(); if(target.getObjectType() == AbstractTarget.TYPE_TARGET && !(target instanceof Target)) { target = targetManager.load(target.getOid()); } else if(target.getObjectType() == AbstractTarget.TYPE_GROUP && !(target instanceof TargetGroup)) { target = targetManager.loadGroup(target.getOid()); } request.setAttribute("now",new Date()); request.setAttribute("instance",instance); request.setAttribute("target",target); request.setAttribute("instanceAnnotations",targetInstanceManager.getAnnotations(instance)); request.setAttribute("targetAnnotations",targetManager.getAnnotations(target)); request.setAttribute("result",instance.getHarvestResults().get(harvestNumber-1)); request.setAttribute("webCuratorUrl",webCuratorUrl); request.setAttribute("heritrixVersion",heritrixVersion); request.setAttribute("user",org.webcurator.core.util.AuthUtil.getRemoteUserObject()); request.setAttribute("groups", targetManager.getActiveParentGroups(instance)); Map<String,String> sipSections = instance.getSipParts(); if(sipSections == null || sipSections.size() == 0) { sipSections = sipBuilder.buildSipSections(instance); } if(sipBuilder.updateTargetReference(target, sipSections)) { instance.setSipParts(sipSections); targetInstanceManager.save(instance); } request.setAttribute("sipSections", sipSections); HarvestResult curResult = instance.getHarvestResults().get(harvestNumber-1); LinkedList<HarvestResult> resultChain = new LinkedList<HarvestResult>(); resultChain.add(curResult); while(curResult.getDerivedFrom() != null) { curResult = instance.getHarvestResults().get(curResult.getDerivedFrom() -1); resultChain.add(curResult); } request.setAttribute("resultChain", resultChain); RequestDispatcher rd = request.getRequestDispatcher("/jsp/createSIPXML.jsp"); rd.include(request,response); return (String)request.getAttribute("xmlData"); } ArchiveController(); }
ArchiveController extends AbstractCommandController { protected String buildSip(HttpServletRequest request, HttpServletResponse response, int harvestNumber) throws ServletException, IOException { TargetInstance instance = targetInstanceManager.getTargetInstance(Long.parseLong(request.getParameter("instanceID"))); AbstractTarget target = (AbstractTarget)instance.getTarget(); if(target.getObjectType() == AbstractTarget.TYPE_TARGET && !(target instanceof Target)) { target = targetManager.load(target.getOid()); } else if(target.getObjectType() == AbstractTarget.TYPE_GROUP && !(target instanceof TargetGroup)) { target = targetManager.loadGroup(target.getOid()); } request.setAttribute("now",new Date()); request.setAttribute("instance",instance); request.setAttribute("target",target); request.setAttribute("instanceAnnotations",targetInstanceManager.getAnnotations(instance)); request.setAttribute("targetAnnotations",targetManager.getAnnotations(target)); request.setAttribute("result",instance.getHarvestResults().get(harvestNumber-1)); request.setAttribute("webCuratorUrl",webCuratorUrl); request.setAttribute("heritrixVersion",heritrixVersion); request.setAttribute("user",org.webcurator.core.util.AuthUtil.getRemoteUserObject()); request.setAttribute("groups", targetManager.getActiveParentGroups(instance)); Map<String,String> sipSections = instance.getSipParts(); if(sipSections == null || sipSections.size() == 0) { sipSections = sipBuilder.buildSipSections(instance); } if(sipBuilder.updateTargetReference(target, sipSections)) { instance.setSipParts(sipSections); targetInstanceManager.save(instance); } request.setAttribute("sipSections", sipSections); HarvestResult curResult = instance.getHarvestResults().get(harvestNumber-1); LinkedList<HarvestResult> resultChain = new LinkedList<HarvestResult>(); resultChain.add(curResult); while(curResult.getDerivedFrom() != null) { curResult = instance.getHarvestResults().get(curResult.getDerivedFrom() -1); resultChain.add(curResult); } request.setAttribute("resultChain", resultChain); RequestDispatcher rd = request.getRequestDispatcher("/jsp/createSIPXML.jsp"); rd.include(request,response); return (String)request.getAttribute("xmlData"); } 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); }
ArchiveController extends AbstractCommandController { protected String buildSip(HttpServletRequest request, HttpServletResponse response, int harvestNumber) throws ServletException, IOException { TargetInstance instance = targetInstanceManager.getTargetInstance(Long.parseLong(request.getParameter("instanceID"))); AbstractTarget target = (AbstractTarget)instance.getTarget(); if(target.getObjectType() == AbstractTarget.TYPE_TARGET && !(target instanceof Target)) { target = targetManager.load(target.getOid()); } else if(target.getObjectType() == AbstractTarget.TYPE_GROUP && !(target instanceof TargetGroup)) { target = targetManager.loadGroup(target.getOid()); } request.setAttribute("now",new Date()); request.setAttribute("instance",instance); request.setAttribute("target",target); request.setAttribute("instanceAnnotations",targetInstanceManager.getAnnotations(instance)); request.setAttribute("targetAnnotations",targetManager.getAnnotations(target)); request.setAttribute("result",instance.getHarvestResults().get(harvestNumber-1)); request.setAttribute("webCuratorUrl",webCuratorUrl); request.setAttribute("heritrixVersion",heritrixVersion); request.setAttribute("user",org.webcurator.core.util.AuthUtil.getRemoteUserObject()); request.setAttribute("groups", targetManager.getActiveParentGroups(instance)); Map<String,String> sipSections = instance.getSipParts(); if(sipSections == null || sipSections.size() == 0) { sipSections = sipBuilder.buildSipSections(instance); } if(sipBuilder.updateTargetReference(target, sipSections)) { instance.setSipParts(sipSections); targetInstanceManager.save(instance); } request.setAttribute("sipSections", sipSections); HarvestResult curResult = instance.getHarvestResults().get(harvestNumber-1); LinkedList<HarvestResult> resultChain = new LinkedList<HarvestResult>(); resultChain.add(curResult); while(curResult.getDerivedFrom() != null) { curResult = instance.getHarvestResults().get(curResult.getDerivedFrom() -1); resultChain.add(curResult); } request.setAttribute("resultChain", resultChain); RequestDispatcher rd = request.getRequestDispatcher("/jsp/createSIPXML.jsp"); rd.include(request,response); return (String)request.getAttribute("xmlData"); } 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);  }