Examples of HarvestingException


Examples of org.dspace.harvest.OAIHarvester.HarvestingException

 
  /* Initialize the harvester with a collection object */
  public OAIHarvester(Context c, DSpaceObject dso, HarvestedCollection hc) throws HarvestingException, SQLException
  {
    if (dso.getType() != Constants.COLLECTION)
            throw new HarvestingException("OAIHarvester can only harvest collections");
   
    ourContext = c;
    targetCollection = (Collection)dso;
   
    harvestRow = hc;
    if (harvestRow == null || !harvestRow.isHarvestable())
      throw new HarvestingException("Provided collection is not set up for harvesting");
   
        // Set the ORE options
    Namespace ORESerializationNamespace = OAIHarvester.getORENamespace();
   
        if (ORESerializationNamespace == null) {
          log.error("No ORE serialization namespace declared; see dspace.cfg option \"harvester.oai.oreSerializationFormat.{ORESeialKey} = {ORESeialNS}\"");
          throw new HarvestingException("No ORE serialization namespace specified");
        } else {
          ORESeialNS = Namespace.getNamespace(ORESerializationNamespace.getURI());
          ORESeialKey = ORESerializationNamespace.getPrefix();
        }
       
        // Set the metadata options
        metadataKey = harvestRow.getHarvestMetadataConfig();
        metadataNS = OAIHarvester.getDMDNamespace(metadataKey);
               
        if (metadataNS == null) {
          log.error("No matching metadata namespace found for \"" + metadataKey + "\", see dspace.cfg option \"harvester.oai.metadataformats.{MetadataKey} = {MetadataNS},{Display Name}\"");
          throw new HarvestingException("Metadata declaration not found");
        }
  }
View Full Code Here

Examples of org.dspace.harvest.OAIHarvester.HarvestingException

          descMDPrefix = OAIResolveNamespaceToPrefix(oaiSource, metadataNS.getURI());
          OREPrefix = OAIResolveNamespaceToPrefix(oaiSource, ORESeialNS.getURI());
        }
        catch (FileNotFoundException fe) {
          log.error("The OAI server did not respond.");
          throw new HarvestingException("The OAI server did not respond.");
        }
        catch (ConnectException fe) {
          log.error("The OAI server did not respond.");
          throw new HarvestingException("The OAI server did not respond.");
        }       
      if (descMDPrefix == null) {
        log.error("The OAI server does not support this metadata format");
        throw new HarvestingException("The OAI server does not support this metadata format: " + metadataNS.getURI());
      }
      if (OREPrefix == null && harvestRow.getHarvestType() != HarvestedCollection.TYPE_DMD) {
        throw new HarvestingException("The OAI server does not support ORE dissemination in the configured serialization format: " + ORESeialNS.getURI());
      }
     
      Document oaiResponse = null;
      Element root = null;     
      String resumptionToken;
 
      // set the status indicating the collection is currently being processed
      harvestRow.setHarvestStatus(HarvestedCollection.STATUS_BUSY);
      harvestRow.setHarvestMessage("Collection is currently being harvested");
      harvestRow.setHarvestStartTime(startTime);
      harvestRow.update();
      ourContext.commit();
     
      // expiration timer starts
      int expirationInterval = ConfigurationManager.getIntProperty("harvester.threadTimeout");
        if (expirationInterval == 0) expirationInterval = 24;
     
      Calendar calendar = Calendar.getInstance();
      calendar.setTime(startTime);
      calendar.add(Calendar.HOUR, expirationInterval);
      expirationTime = calendar.getTime();
     
      // main loop to keep requesting more objects until we're done
      List<Element> records;
      Set<String> errorSet = new HashSet<String>();
   
      ListRecords listRecords = new ListRecords(oaiSource, fromDate, toDate, oaiSetId, descMDPrefix);
      log.debug("Harvesting request parameters: listRecords " + oaiSource + " " + fromDate + " " + toDate + " " + oaiSetId + " " + descMDPrefix);
      if (listRecords != null)
        log.info("HTTP Request: " + listRecords.getRequestURL());
      while (listRecords != null)
      {
        records = new ArrayList<Element>();
        oaiResponse = db.build(listRecords.getDocument());

        if (listRecords.getErrors() != null && listRecords.getErrors().getLength() > 0)
        {
          for (int i=0; i<listRecords.getErrors().getLength(); i++)
          {
            String errorCode = listRecords.getErrors().item(i).getAttributes().getNamedItem("code").getTextContent();
            errorSet.add(errorCode);
          }
          if (errorSet.contains("noRecordsMatch"))
          {
            log.info("noRecordsMatch: OAI server did not contain any updates");
            harvestRow.setHarvestResult(new Date(), "OAI server did not contain any updates");
            harvestRow.setHarvestStatus(HarvestedCollection.STATUS_READY);
            harvestRow.update();
            return;
          } else {
            throw new HarvestingException(errorSet.toString());
          }
        }
        else
        {
          root = oaiResponse.getRootElement();
          records.addAll(root.getChild("ListRecords", OAI_NS).getChildren("record", OAI_NS));
        }

        // Process the obtained records
        if (records != null && records.size()>0)
        {
          log.info("Found " + records.size() + " records to process");
          for (Element record : records) {
            // check for STOP interrupt from the scheduler
            if (HarvestScheduler.interrupt == HarvestScheduler.HARVESTER_INTERRUPT_STOP)
              throw new HarvestingException("Harvest process for " + targetCollection.getID() + " interrupted by stopping the scheduler.");
            // check for timeout
            if (expirationTime.before(new Date()))
              throw new HarvestingException("runHarvest method timed out for collection " + targetCollection.getID());
           
            processRecord(record,OREPrefix);
            ourContext.commit();
          }
        }
View Full Code Here

Examples of org.dspace.harvest.OAIHarvester.HarvestingException

       
        if (handle != null)
        {
          DSpaceObject dso = HandleManager.resolveToObject(ourContext, handle);
          if (dso != null)
            throw new HarvestingException("Handle collision: attempted to re-assign handle '" + handle + "' to an incoming harvested item '" + hi.getOaiID() + "'.");                   
        }
       
        try {
          item = InstallItem.installItem(ourContext, wi, handle);
          //item = InstallItem.installItem(ourContext, wi);
View Full Code Here

Examples of org.dspace.harvest.OAIHarvester.HarvestingException

            item.clearMetadata(value.schema, Item.ANY, Item.ANY, Item.ANY);
            continue;
          }
          // otherwise, go ahead and generate the error
          else {
            throw new HarvestingException("The '" + value.schema + "' schema has not been defined in this DSpace instance. ");
          }
        }
       
        // Verify that the element exists; this part is reachable only if the metadata schema is valid
        MetadataField mdField = MetadataField.findByElement(ourContext, mdSchema.getSchemaID(), value.element, value.qualifier);
        if (mdField == null) {
          if (fieldChoice.equals("add")) {
            mdField = new MetadataField(mdSchema, value.element, value.qualifier, null);
            try {
            mdField.create(ourContext);
            mdField.update(ourContext);
          } catch (NonUniqueMetadataException e) {
            // This case should also not be possible
            e.printStackTrace();
          }
          }
          else if (fieldChoice.equals("ignore")) {
            item.clearMetadata(value.schema, value.element, value.qualifier, Item.ANY);
          }
          else {
            throw new HarvestingException("The '" + value.element + "." + value.qualifier + "' element has not been defined in this DSpace instance. ");
          }
        }
      }
     
      return;     
View Full Code Here

Examples of org.dspace.harvest.OAIHarvester.HarvestingException

    if (getRecord != null && getRecord.getErrors() != null && getRecord.getErrors().getLength() > 0) {
      for (int i=0; i<getRecord.getErrors().getLength(); i++) {
        String errorCode = getRecord.getErrors().item(i).getAttributes().getNamedItem("code").getTextContent();
        errorSet.add(errorCode);
      }
      throw new HarvestingException("OAI server returned the following errors during getDescMD execution: " + errorSet.toString());
    }

    Document record = db.build(getRecord.getDocument());
    Element root = record.getRootElement();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.