Examples of SwordError


Examples of org.swordapp.server.SwordError

                Bitstream bitstream = urlManager.getBitstream(ctx, uri);
                if (bitstream == null)
                {
                    // bitstream not found in the database, so 404 the client.
                    // Arguably, we should try to authenticate first, but it's not so important
                    throw new SwordError(404);
                }

                // find out, now we know what we're being asked for, whether this is allowed
                WorkflowManagerFactory.getInstance().retrieveBitstream(ctx, bitstream);

                // we can do this in principle, but now find out whether the bitstream is accessible without credentials
                boolean accessible = this.isAccessible(ctx, bitstream);

                if (!accessible)
                {
                    // try to authenticate, and if successful switch the contexts around
                    sc = this.doAuth(authCredentials);
                    ctx.abort();
                    ctx = sc.getContext();

                    // re-retrieve the bitstream using the new context
                    bitstream = Bitstream.find(ctx, bitstream.getID());

                    // and re-verify its accessibility
                    accessible = this.isAccessible(ctx, bitstream);
                    if (!accessible)
                    {
                        throw new SwordAuthException();
                    }
                }

                // if we get to here we are either allowed to access the bitstream without credentials,
                // or we have been authenticated with acceptable credentials
                MediaResource mr = this.getBitstreamResource(ctx, bitstream);
                if (sc != null)
                {
                    sc.abort();
                }
                if (ctx.isValid())
                {
                    ctx.abort();
                }
                return mr;
            }
            else
            {
                // request for an item
                Item item = urlManager.getItem(ctx, uri);
                if (item == null)
                {
                    // item now found in the database, so 404 the client
                    // Arguably, we should try to authenticate first, but it's not so important
                    throw new SwordError(404);
                }

                // find out, now we know what we're being asked for, whether this is allowed
                WorkflowManagerFactory.getInstance().retrieveContent(ctx, item);
View Full Code Here

Examples of org.swordapp.server.SwordError

      if (urlManager.isActionableBitstreamUrl(context, emUri))
      {
                Bitstream bitstream = urlManager.getBitstream(context, emUri);
                if (bitstream == null)
                {
                    throw new SwordError(404);
                }

                // now we have the deposit target, we can determine whether this operation is allowed
                // at all
                WorkflowManager wfm = WorkflowManagerFactory.getInstance();
                wfm.replaceBitstream(context, bitstream);

                // check that we can submit to ALL the items this bitstream is in
        List<Item> items = new ArrayList<Item>();
        for (Bundle bundle : bitstream.getBundles())
        {
          for (Item item : bundle.getItems())
          {
            this.checkAuth(sc, item);
            items.add(item);
          }
        }

        // make a note of the authentication in the verbose string
        this.verboseDescription.append("Authenticated user: " + sc.getAuthenticated().getEmail());
        if (sc.getOnBehalfOf() != null)
        {
          this.verboseDescription.append("Depositing on behalf of: " + sc.getOnBehalfOf().getEmail());
        }

                DepositResult result = null;
                try
                {
                    result = this.replaceBitstream(sc, items, bitstream, deposit, authCredentials, config);
                }
                catch(DSpaceSwordException e)
                {
                    if (config.isKeepPackageOnFailedIngest())
                    {
                        try
                        {
                            this.storePackageAsFile(deposit, authCredentials, config);
                        }
                        catch(IOException e2)
                        {
                            log.warn("Unable to store SWORD package as file: " + e);
                        }
                    }
                    throw e;
                }
                catch(SwordError e)
                {
                    if (config.isKeepPackageOnFailedIngest())
                    {
                        try
                        {
                            this.storePackageAsFile(deposit, authCredentials, config);
                        }
                        catch(IOException e2)
                        {
                            log.warn("Unable to store SWORD package as file: " + e);
                        }
                    }
                    throw e;
                }
               
                // now we've produced a deposit, we need to decide on its workflow state
                wfm.resolveState(context, deposit, null, this.verboseDescription, false);

                ReceiptGenerator genny = new ReceiptGenerator();
                receipt = genny.createFileReceipt(context, result, config);
      }
            else
            {
                // get the deposit target
                Item item = this.getDSpaceTarget(context, emUri, config);
                if (item == null)
                {
                    throw new SwordError(404);
                }

                // now we have the deposit target, we can determine whether this operation is allowed
                // at all
                WorkflowManager wfm = WorkflowManagerFactory.getInstance();
View Full Code Here

Examples of org.swordapp.server.SwordError

      if (urlManager.isActionableBitstreamUrl(context, emUri))
      {
        Bitstream bitstream = urlManager.getBitstream(context, emUri);
                if (bitstream == null)
                {
                    throw new SwordError(404);
                }

        // now we have the deposit target, we can determine whether this operation is allowed
        // at all
        wfm.deleteBitstream(context, bitstream);

        // check that we can submit to ALL the items this bitstream is in
        List<Item> items = new ArrayList<Item>();
        for (Bundle bundle : bitstream.getBundles())
        {
          for (Item item : bundle.getItems())
          {
            this.checkAuth(sc, item);
            items.add(item);
          }
        }

        // make a note of the authentication in the verbose string
        this.verboseDescription.append("Authenticated user: " + sc.getAuthenticated().getEmail());
        if (sc.getOnBehalfOf() != null)
        {
          this.verboseDescription.append("Depositing on behalf of: " + sc.getOnBehalfOf().getEmail());
        }

        this.removeBitstream(sc, bitstream, items, authCredentials, config);
      }
      else
      {
        Item item = this.getDSpaceTarget(context, emUri, config);
                if (item == null)
                {
                    throw new SwordError(404);
                }

        // now we have the deposit target, we can determine whether this operation is allowed
        // at all
        wfm.deleteMediaResource(context, item);
View Full Code Here

Examples of org.swordapp.server.SwordError

            // get the deposit target
            Item item = this.getDSpaceTarget(context, emUri, config);
            if (item == null)
            {
                throw new SwordError(404);
            }

      // now we have the deposit target, we can determine whether this operation is allowed
      // at all
      WorkflowManager wfm = WorkflowManagerFactory.getInstance();
View Full Code Here

Examples of org.swordapp.server.SwordError

            for (Bundle bundle : bitstream.getBundles())
            {
                // is the bitstream in the ORIGINAL bundle?  If not, it can't be worked on
                if (!"ORIGINAL".equals(bundle.getName()))
                {
                    throw new SwordError(UriRegistry.ERROR_METHOD_NOT_ALLOWED, "The file is not in a bundle which can be modified");
                }

                for (Item item : bundle.getItems())
                {
                    this.deleteMediaResource(context, item);
View Full Code Here

Examples of org.swordapp.server.SwordError

            for (Bundle bundle : bitstream.getBundles())
            {
                // is the bitstream in the ORIGINAL bundle?  If not, it can't be worked on
                if (!"ORIGINAL".equals(bundle.getName()))
                {
                    throw new SwordError(UriRegistry.ERROR_METHOD_NOT_ALLOWED, "The file is not in a bundle which can be modified");
                }

                for (Item item : bundle.getItems())
                {
                    this.replaceResourceContent(context, item);
View Full Code Here

Examples of org.swordapp.server.SwordError

      {
        cBaseUrl = sBaseUrl;
      }
            else
            {
        throw new SwordError(DSpaceUriRegistry.BAD_URL, "The item URL is invalid");
      }

            String iid = location.substring(cBaseUrl.length());
            if (iid.endsWith(".atom"))
            {
View Full Code Here

Examples of org.swordapp.server.SwordError

    try
    {
      String baseUrl = this.getBaseCollectionUrl();
      if (baseUrl.length() == location.length())
      {
        throw new SwordError(DSpaceUriRegistry.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 SwordError(DSpaceUriRegistry.BAD_URL, "The deposit URL is incomplete");
      }

      DSpaceObject dso = HandleManager.resolveToObject(context, handle);
            if (dso == null)
            {
                return null;
            }

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

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

Examples of org.swordapp.server.SwordError

        {
          return dso;
        }
        else
        {
          throw new SwordError(DSpaceUriRegistry.BAD_URL,
              "Service Document request does not refer to a DSpace Collection or Community");
        }
      }
      else
      {
        throw new SwordError(DSpaceUriRegistry.BAD_URL,
            "Unable to recognise URL as a valid service document: " + url);
      }
    }
    catch (SQLException e)
    {
View Full Code Here

Examples of org.swordapp.server.SwordError

    {
      String baseUrl = this.getSwordBaseUrl();
            String emBaseUrl = baseUrl + "/edit-media/bitstream/";
      if (!location.startsWith(emBaseUrl))
      {
        throw new SwordError(DSpaceUriRegistry.BAD_URL, "The bitstream URL is invalid");
      }

            String bitstreamParts = location.substring(emBaseUrl.length());

      // the bitstream id is the part up to the first "/"
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.