/** * Do the work of "copy" method; this code is shared with e.g. DAVInProgressSubmission. * * @param context the context * @param item the item * @param destination the destination * @param overwrite the overwrite * @return HTTP status code. * @throws DAVStatusException the DAV status exception * @throws SQLException the SQL exception * @throws AuthorizeException the authorize exception * @throws IOException Signals that an I/O exception has occurred. */ protected static int addItemToCollection( Context context, Item item, DAVResource destination, boolean overwrite) throws DAVStatusException, SQLException, AuthorizeException, IOException { // sanity checks if (!(destination instanceof DAVCollection)) { throw new DAVStatusException( HttpServletResponse.SC_METHOD_NOT_ALLOWED, "COPY of Item is only allowed when destination is a DSpace Collection."); } // access check AuthorizeManager.authorizeAction(context, item, Constants.READ); // make sure item doesn't belong to this collection Collection destColl = ((DAVCollection) destination).getCollection(); log.debug( "COPY from=" + item.toString() + " (" + item.getHandle() + "), to=" + destColl.toString() + " (" + destColl.getHandle() + ")"); // check if it's already a member Collection refs[] = item.getCollections(); for (Collection element : refs) { if (destColl.equals(element)) { log.debug( "COPY - item @ " + item.getHandle() + " is already a member of collection @ " + destColl.getHandle()); if (overwrite) { return DAV.SC_NO_CONTENT; } else { throw new DAVStatusException( DAV.SC_CONFLICT, "This Item is already a member of collection handle=" + destColl.getHandle()); } } } destColl.addItem(item); return DAV.SC_NO_CONTENT; }