Пример #1
0
  /**
   * Upload one SIP file from the input folder. First call the DESA API method
   * asyncSubmitPackageStart, then copy the zip file to the mapped DESA target folder and finally
   * call the DESA API method asyncSubmitPackageEnd. Add the corresponding entry into the results
   * file JAXB representation.
   *
   * @param file
   * @param sipType
   * @param writeResults
   */
  private void uploadFile(File file, SipType sipType, boolean writeResults) {
    Holder<String> sipId = new Holder<String>(getSipId(file));
    Holder<String> idSipVersion = new Holder<String>();
    String checksum = getMD5Checksum(file);
    log.info("Transporting file: " + file.getName());

    if (useRest) {
      idSipVersion.value =
          desaClient.submitPackage(
              file, operatorName, producerCode, sipId.value, FileHashAlg.MD_5, checksum, "cs");
      log.info("Received idSipVersion:" + idSipVersion.value);
      if (idSipVersion.value == null || "".equals(idSipVersion.value)) {
        throw new RuntimeException(
            "DESA REST call did not return idSipVersion for file " + file.getName());
      }
    } else {
      try {
        desaPort.asyncSubmitPackageStart(
            0,
            producerCode,
            operatorName,
            sipId,
            (int) file.length(),
            checksum,
            FileHashAlg.MD_5,
            idSipVersion);
      } catch (SIPSubmissionFault sipSubmissionFault) {
        throw new RuntimeException(sipSubmissionFault);
      }
      if (idSipVersion.value == null || "".equals(idSipVersion.value)) {
        throw new RuntimeException(
            "DESA SOAP call did not return idSipVersion for file " + file.getName());
      }
      File target = new File(getDesaFolder(), idSipVersion.value + ".sip");
      try {
        FileUtils.copyFile(file, target);
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
      log.info("Received idSipVersion:" + idSipVersion.value);
      try {
        desaPort.asyncSubmitPackageEnd(0, producerCode, operatorName, idSipVersion.value);
      } catch (SIPSubmissionFault sipSubmissionFault) {
        throw new RuntimeException(sipSubmissionFault);
      }
    }
    if (writeResults) {
      XMLGregorianCalendar currentDate =
          desaClient.getXmlTypes().newXMLGregorianCalendar(new GregorianCalendar());
      PSPSIP.SIP entry = resultsFactory.createPSPSIPSIP();
      entry.setIdentifier(sipId.value);
      entry.setIdSIPVersion(idSipVersion.value);
      entry.setResultTime(currentDate);
      entry.setResultCode(ResultType.PROGRESS);
      entry.setType(sipType);
      results.getSIP().add(entry);
    }
  }
Пример #2
0
 /**
  * Check the status of the SIP of one entry in the results file and update the entry in the JAXB
  * object.
  *
  * @param sip
  * @return
  */
 private boolean checkSIP(PSPSIP.SIP sip) {
   Holder<String> sipId = new Holder<String>(sip.getIdentifier());
   Holder<String> idSipVersion = new Holder<String>(sip.getIdSIPVersion());
   Holder<String> packageStateCode = new Holder<String>();
   Holder<String> packageStateText = new Holder<String>();
   Holder<String> errorCode = new Holder<String>();
   log.info("Checking file: " + sipId.value);
   /*
    * if(config.getBoolean("desa.rest")){ try { URLConnection connection =
    * new
    * URL(config.getString("desa.restapi")+"/packagestatus"+"?userName="******"desa.user")
    * +"&producerCode="+config.getString("desa.producer"
    * )+"&producerSipId="+
    * sipId.value+"&idSIPVersion="+idSipVersion.value).openConnection();
    * packageStateCode
    * .value=connection.getHeaderField("X-DEA-packageStateCode");
    * packageStateText
    * .value=connection.getHeaderField("X-DEA-packageStateText");
    * errorCode.value=connection.getHeaderField("X-DEA-errorCode"); } catch
    * (Exception e) { throw new RuntimeException(e); } }else{
    */
   try {
     desaPort.getPackageStatus(
         0,
         producerCode,
         operatorName,
         idSipVersion,
         sipId,
         packageStateCode,
         packageStateText,
         errorCode);
   } catch (SIPSubmissionFault sipSubmissionFault) {
     throw new RuntimeException(sipSubmissionFault);
   } catch (Exception e1) {
     log.log(Level.SEVERE, "DESA exception", e1);
     throw new IllegalStateException("DESA exception", e1);
   }
   /* } */
   log.info(
       "Status: "
           + packageStateCode.value
           + " ("
           + packageStateText.value
           + ")"
           + (errorCode.value != null ? (", errorCode:" + errorCode.value) : ""));
   XMLGregorianCalendar currentDate =
       desaClient.getXmlTypes().newXMLGregorianCalendar(new GregorianCalendar());
   ;
   boolean retval = false;
   sip.setResultTime(currentDate);
   if ("AI_ACC_OK".equalsIgnoreCase(packageStateCode.value)) {
     sip.setResultCode(ResultType.FINISHED);
     retval = true;
   } else if ("AI_ERROR".equalsIgnoreCase(packageStateCode.value)
       || "AI_INVALID".equalsIgnoreCase(packageStateCode.value)
       || "AI_REJECT".equalsIgnoreCase(packageStateCode.value)
       || "AI_INFECTED".equalsIgnoreCase(packageStateCode.value)
       || "AI_QA_ERR".equalsIgnoreCase(packageStateCode.value)) {
     sip.setResultCode(ResultType.ERROR);
   } else {
     sip.setResultCode(ResultType.PROGRESS);
   }
   return retval;
 }