Package org.purl.sword.base

Examples of org.purl.sword.base.SWORDErrorException


        // Set the X-On-Behalf-Of header
                String onBehalfOf = request.getHeader(HttpHeaders.X_ON_BEHALF_OF.toString());
        if ((onBehalfOf != null) && (onBehalfOf.equals("reject"))) {
                    // user name is "reject", so throw a not know error to allow the client to be tested
                    throw new SWORDErrorException(ErrorCodes.TARGET_OWNER_UKNOWN,"unknown user \"reject\"");
                } else {
                    d.setOnBehalfOf(onBehalfOf);
                }

        // Set the X-Packaging header
        d.setPackaging(request.getHeader(HttpHeaders.X_PACKAGING));

        // Set the X-No-Op header
        String noop = request.getHeader(HttpHeaders.X_NO_OP);
                log.error("X_NO_OP value is " + noop);
        if ((noop != null) && (noop.equals("true"))) {
          d.setNoOp(true);
        } else if ((noop != null) && (noop.equals("false"))) {
          d.setNoOp(false);
                }else if (noop == null) {
                    d.setNoOp(false);
        } else {
                    throw new SWORDErrorException(ErrorCodes.ERROR_BAD_REQUEST,"Bad no-op");
                }

        // Set the X-Verbose header
        String verbose = request.getHeader(HttpHeaders.X_VERBOSE);
        if ((verbose != null) && (verbose.equals("true"))) {
          d.setVerbose(true);
        } else if ((verbose != null) && (verbose.equals("false"))) {
          d.setVerbose(false);
                }else if (verbose == null) {
                    d.setVerbose(false);
        } else {
                    throw new SWORDErrorException(ErrorCodes.ERROR_BAD_REQUEST,"Bad verbose");
                }

        // Set the slug
        String slug = request.getHeader(HttpHeaders.SLUG);
        if (slug != null) {
View Full Code Here


        // Set the X-On-Behalf-Of header
                String onBehalfOf = request.getHeader(HttpHeaders.X_ON_BEHALF_OF.toString());
        if ((onBehalfOf != null) && (onBehalfOf.equals("reject"))) {
                    // user name is "reject", so throw a not know error to allow the client to be tested
                    throw new SWORDErrorException(ErrorCodes.TARGET_OWNER_UKNOWN,"unknown user \"reject\"");
                } else {
                    d.setOnBehalfOf(onBehalfOf);
                }

        // Set the X-Packaging header
        d.setPackaging(request.getHeader(HttpHeaders.X_PACKAGING));

        // Set the X-No-Op header
        String noop = request.getHeader(HttpHeaders.X_NO_OP);
                log.error("X_NO_OP value is " + noop);
        if ((noop != null) && (noop.equals("true"))) {
          d.setNoOp(true);
        } else if ((noop != null) && (noop.equals("false"))) {
          d.setNoOp(false);
                }else if (noop == null) {
                    d.setNoOp(false);
        } else {
                    throw new SWORDErrorException(ErrorCodes.ERROR_BAD_REQUEST,"Bad no-op");
                }

        // Set the X-Verbose header
        String verbose = request.getHeader(HttpHeaders.X_VERBOSE);
        if ((verbose != null) && (verbose.equals("true"))) {
          d.setVerbose(true);
        } else if ((verbose != null) && (verbose.equals("false"))) {
          d.setVerbose(false);
                }else if (verbose == null) {
                    d.setVerbose(false);
        } else {
                    throw new SWORDErrorException(ErrorCodes.ERROR_BAD_REQUEST,"Bad verbose");
                }

        // Set the slug
        String slug = request.getHeader(HttpHeaders.SLUG);
        if (slug != null) {
View Full Code Here

    // the throw a 415 (ERROR_CONTENT) until further notice
    //
    // determine if this is an acceptable file format
    if (!swordConfig.isAcceptableContentType(context, deposit.getContentType(), item))
    {
      throw new SWORDErrorException(ErrorCodes.ERROR_CONTENT,
          "Unacceptable content type in deposit request: " + deposit.getContentType());
    }

    // determine if this is an acceptable packaging type for the deposit
    // if not, we throw a 415 HTTP error (Unsupported Media Type, ERROR_CONTENT)
    if (!swordConfig.isSupportedMediaType(deposit.getPackaging(), this.item))
    {
      throw new SWORDErrorException(ErrorCodes.ERROR_CONTENT,
          "Unacceptable packaging type in deposit request: " + deposit.getPackaging());
    }

    // Obtain the relevant ingester from the factory
    SWORDIngester si = SWORDIngesterFactory.getInstance(context, deposit, item);
View Full Code Here

    if (dso instanceof Collection)
    {
      SWORDIngester ingester = (SWORDIngester) PluginManager.getNamedPlugin("sword-server", SWORDIngester.class, deposit.getPackaging());
      if (ingester == null)
      {
        throw new SWORDErrorException(ErrorCodes.ERROR_CONTENT, "No ingester configured for this package type");
      }
      return ingester;
    }
    else if (dso instanceof Item)
    {
View Full Code Here

    try
    {
      String baseUrl = this.getBaseDepositUrl();
      if (baseUrl.length() == location.length())
      {
        throw new SWORDErrorException(DSpaceSWORDErrorCodes.BAD_URL, "The deposit URL is incomplete");
      }
      String handle = location.substring(baseUrl.length());
      if (handle.startsWith("/"))
      {
        handle = handle.substring(1);
      }
      if ("".equals(handle))
      {
        throw new SWORDErrorException(DSpaceSWORDErrorCodes.BAD_URL, "The deposit URL is incomplete");
      }

      DSpaceObject dso = HandleManager.resolveToObject(context, handle);

      if (!(dso instanceof Collection))
      {
        throw new SWORDErrorException(DSpaceSWORDErrorCodes.BAD_URL, "The deposit URL does not resolve to a valid collection");
      }

      return (Collection) dso;
    }
    catch (SQLException e)
View Full Code Here

    try
    {
      String baseUrl = this.getBaseDepositUrl();
      if (baseUrl.length() == location.length())
      {
        throw new SWORDErrorException(DSpaceSWORDErrorCodes.BAD_URL, "The deposit URL is incomplete");
      }
      String handle = location.substring(baseUrl.length());
      if (handle.startsWith("/"))
      {
        handle = handle.substring(1);
      }
      if ("".equals(handle))
      {
        throw new SWORDErrorException(DSpaceSWORDErrorCodes.BAD_URL, "The deposit URL is incomplete");
      }

      DSpaceObject dso = HandleManager.resolveToObject(context, handle);

      if (!(dso instanceof Collection) && !(dso instanceof Item))
      {
        throw new SWORDErrorException(DSpaceSWORDErrorCodes.BAD_URL, "The deposit URL does not resolve to a valid deposit target");
      }

      return dso;
    }
    catch (SQLException e)
View Full Code Here

        {
          return dso;
        }
        else
        {
          throw new SWORDErrorException(DSpaceSWORDErrorCodes.BAD_URL,
              "Service Document request does not refer to a DSpace Collection or Community");
        }
      }
      else if (url.startsWith(mlBase))
      {
        // we are dealing with a bitstream media link

        // find the index of the "/bitstream/" segment of the url
        int bsi = url.indexOf("/bitstream/");

        // subtsring the url from the end of this "/bitstream/" string, to get the bitstream id
        String bsid = url.substring(bsi + 11);

        // strip off extraneous slashes
        if (bsid.endsWith("/"))
        {
          bsid = bsid.substring(0, url.length() - 1);
        }

                return Bitstream.find(context, Integer.parseInt(bsid));
      }
      else
      {
        throw new SWORDErrorException(DSpaceSWORDErrorCodes.BAD_URL,
            "Unable to recognise URL as a valid service document: " + url);
      }
    }
    catch (SQLException e)
    {
View Full Code Here

   
    // Allow users to force the throwing of a SWORD error exception by setting
    // the OBO user to 'error'
    if ((sdr.getOnBehalfOf() != null) && (sdr.getOnBehalfOf().equals("error"))) {
      // Throw the error exception
      throw new SWORDErrorException(ErrorCodes.MEDIATION_NOT_ALLOWED, "Mediated deposits not allowed");
    }
   
    // Create and return a dummy ServiceDocument
    ServiceDocument document = new ServiceDocument();
    Service service = new Service("1.3", true, true);
View Full Code Here

    }
   
    // Check this is a collection that takes obo deposits, else thrown an error
    if (((deposit.getOnBehalfOf() != null) && (!deposit.getOnBehalfOf().equals(""))) &&
          (!deposit.getLocation().contains("deposit?user="))) {
      throw new SWORDErrorException(ErrorCodes.MEDIATION_NOT_ALLOWED,
                                "Mediated deposit not allowed to this collection");
    }
   
    // Get the filenames
    StringBuffer filenames = new StringBuffer("Deposit file contained: ");
View Full Code Here

      // ingest the item from the temp file
      DSpaceObject ingestedObject = pi.ingest(context, collection, depositFile, params, licence);
      if (ingestedObject == null)
      {
        swordService.message("Failed to ingest the package; throwing exception");
        throw new SWORDErrorException(DSpaceSWORDErrorCodes.UNPACKAGE_FAIL, "METS package ingester failed to unpack package");
      }
                       
                        //Verify we have an Item as a result -- SWORD can only ingest Items
                        if (!(ingestedObject instanceof Item))
      {
View Full Code Here

TOP

Related Classes of org.purl.sword.base.SWORDErrorException

Copyright © 2018 www.massapicom. 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.