@Override public void delete(Context context, Community community) throws SQLException, AuthorizeException, IOException { // Check authorisation // FIXME: If this was a subcommunity, it is first removed from it's // parent. // This means the parentCommunity == null // But since this is also the case for top-level communities, we would // give everyone rights to remove the top-level communities. // The same problem occurs in removing the logo if (!authorizeService.authorizeActionBoolean( context, getParentObject(context, community), Constants.REMOVE)) { authorizeService.authorizeAction(context, community, Constants.DELETE); } ArrayList<String> removedIdentifiers = getIdentifiers(context, community); String removedHandle = community.getHandle(); UUID removedId = community.getID(); // If not a top-level community, have parent remove me; this // will call rawDelete() before removing the linkage Community parent = (Community) getParentObject(context, community); if (parent != null) { // remove the subcommunities first Iterator<Community> subcommunities = community.getSubcommunities().iterator(); while (subcommunities.hasNext()) { Community subCommunity = subcommunities.next(); subcommunities.remove(); delete(context, subCommunity); } // now let the parent remove the community removeSubcommunity(context, parent, community); return; } rawDelete(context, community); context.addEvent( new Event( Event.REMOVE, Constants.SITE, siteService.findSite(context).getID(), Constants.COMMUNITY, removedId, removedHandle, removedIdentifiers)); }
/** * Internal method to remove the community and all its children from the database, and perform any * pre/post-cleanup * * @throws SQLException * @throws AuthorizeException * @throws IOException */ protected void rawDelete(Context context, Community community) throws SQLException, AuthorizeException, IOException { log.info( LogManager.getHeader(context, "delete_community", "community_id=" + community.getID())); context.addEvent( new Event( Event.DELETE, Constants.COMMUNITY, community.getID(), community.getHandle(), getIdentifiers(context, community))); // Remove collections Iterator<Collection> collections = community.getCollections().iterator(); while (collections.hasNext()) { Collection collection = collections.next(); collections.remove(); removeCollection(context, community, collection); } // delete subcommunities Iterator<Community> subCommunities = community.getSubcommunities().iterator(); while (subCommunities.hasNext()) { Community subComm = subCommunities.next(); subCommunities.remove(); delete(context, subComm); } // Remove the logo setLogo(context, community, null); // Remove all authorization policies authorizeService.removeAllPolicies(context, community); // Remove any Handle handleService.unbindHandle(context, community); deleteMetadata(context, community); Group g = community.getAdministrators(); // Delete community row communityDAO.delete(context, community); // Remove administrators group - must happen after deleting community if (g != null) { groupService.delete(context, g); } }