Exemplo n.º 1
0
 /* (non-Javadoc)
  * @see org.dspace.app.dav.DAVResource#deleteInternal()
  */
 @Override
 protected int deleteInternal()
     throws DAVStatusException, SQLException, AuthorizeException, IOException {
   Community[] ca = this.collection.getCommunities();
   if (ca != null)
     for (Community element : ca) {
       element.removeCollection(this.collection);
     }
   // collection.delete();
   return HttpServletResponse.SC_OK; // HTTP OK
 }
Exemplo n.º 2
0
  /**
   * Delete collection itself
   *
   * @param context The current DSpace context.
   * @param collectionID The collection id.
   * @return A process result's object.
   */
  public static FlowResult processDeleteCollection(Context context, int collectionID)
      throws SQLException, AuthorizeException, IOException {
    FlowResult result = new FlowResult();

    Collection collection = Collection.find(context, collectionID);

    Community[] parents = collection.getCommunities();

    for (Community parent : parents) {
      parent.removeCollection(collection);
      parent.update();
    }

    context.commit();

    result.setContinue(true);
    result.setOutcome(true);
    result.setMessage(new Message("default", "The collection was successfully deleted."));

    return result;
  }
Exemplo n.º 3
0
  /**
   * Delete collection.
   *
   * @param collectionId Id of collection which will be deleted.
   * @param headers If you want to access to collection under logged user into context. In headers
   *     must be set header "rest-dspace-token" with passed token from login method.
   * @return Return response code OK(200) if was everything all right. Otherwise return
   *     NOT_FOUND(404) if was id of community or collection incorrect. Or (UNAUTHORIZED)401 if was
   *     problem with permission to community or collection.
   * @throws WebApplicationException It is throw when was problem with creating context or problem
   *     with database reading or writing. Or problem with deleting collection caused by IOException
   *     or authorization.
   */
  @DELETE
  @Path("/{collection_id}")
  @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
  public Response deleteCollection(
      @PathParam("collection_id") Integer collectionId,
      @QueryParam("userIP") String user_ip,
      @QueryParam("userAgent") String user_agent,
      @QueryParam("xforwarderfor") String xforwarderfor,
      @Context HttpHeaders headers,
      @Context HttpServletRequest request)
      throws WebApplicationException {

    log.info("Delete collection(id=" + collectionId + ").");
    org.dspace.core.Context context = null;

    try {
      context = createContext(getUser(headers));
      org.dspace.content.Collection dspaceCollection =
          findCollection(context, collectionId, org.dspace.core.Constants.DELETE);

      writeStats(
          dspaceCollection,
          UsageEvent.Action.REMOVE,
          user_ip,
          user_agent,
          xforwarderfor,
          headers,
          request,
          context);

      org.dspace.content.Community community =
          (org.dspace.content.Community) dspaceCollection.getParentObject();
      community.removeCollection(dspaceCollection);

      context.complete();

    } catch (ContextException e) {
      processException(
          "Could not delete collection(id="
              + collectionId
              + "), ContextExcpetion. Message: "
              + e.getMessage(),
          context);
    } catch (SQLException e) {
      processException(
          "Could not delete collection(id=" + collectionId + "), SQLException. Message: " + e,
          context);
    } catch (AuthorizeException e) {
      processException(
          "Could not delete collection(id=" + collectionId + "), AuthorizeException. Message: " + e,
          context);
    } catch (IOException e) {
      processException(
          "Could not delete collection(id=" + collectionId + "), IOException. Message: " + e,
          context);
    } finally {
      processFinally(context);
    }

    log.info("Collection(id=" + collectionId + ") was successfully deleted.");
    return Response.ok().build();
  }