@Override public void addCollection(Context context, Community community, Collection collection) throws SQLException, AuthorizeException { // Check authorisation authorizeService.authorizeAction(context, community, Constants.ADD); log.info( LogManager.getHeader( context, "add_collection", "community_id=" + community.getID() + ",collection_id=" + collection.getID())); if (!community.getCollections().contains(collection)) { community.addCollection(collection); collection.addCommunity(community); } context.addEvent( new Event( Event.ADD, Constants.COMMUNITY, community.getID(), Constants.COLLECTION, collection.getID(), community.getHandle(), getIdentifiers(context, community))); }
/** Internal method to process subcommunities recursively */ protected void addCollectionList(Community community, List<Collection> collectionList) throws SQLException { for (Community subcommunity : community.getSubcommunities()) { addCollectionList(subcommunity, collectionList); } for (Collection collection : community.getCollections()) { collectionList.add(collection); } }
/** * 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); } }
@Override public int countItems(Context context, Community community) throws SQLException { int total = 0; // add collection counts List<Collection> cols = community.getCollections(); for (Collection col : cols) { total += itemService.countItems(context, col); } // add sub-community counts List<Community> comms = community.getSubcommunities(); for (int j = 0; j < comms.size(); j++) { total += countItems(context, comms.get(j)); } return total; }
@Override public List<Collection> getAllCollections(Context context, Community community) throws SQLException { List<Collection> collectionList = new ArrayList<Collection>(); List<Community> subCommunities = community.getSubcommunities(); for (Community subCommunity : subCommunities) { addCollectionList(subCommunity, collectionList); } List<Collection> collections = community.getCollections(); for (Collection collection : collections) { collectionList.add(collection); } return collectionList; }
/** * Get a preserved community backup file and respective children from cloud. * * @param context context DSpace * @param ref ID of the community * @param establishConnection true if pretend establish connection to cloud * @return true if file correctly sent to cloud, or false if not */ public Boolean getCommunityAndChilds(Context context, Integer ref, Boolean establishConnection) { // if true make the connection available if (establishConnection == true) { this.makeConnection(); this.filesInCloud.putAll(this.newCloudConnection.getInfoFilesIn(Constants.COMMUNITY)); } // get file community from cloud getCommunity(context, ref, false); Community obj; Community[] subCommunities; Collection[] collections; // get community and the respective sub-communities and childs try { obj = Community.find(context, ref); subCommunities = obj.getSubcommunities(); collections = obj.getCollections(); } catch (Exception ex) { // it means it is the first father in the order, so close connection if (establishConnection == true) this.closeConnection(); Logger.getLogger(ActualContentManagement.class.getName()).log(Level.SEVERE, null, ex); return false; } // get from cloud all the respective files sub-communities and childs if (subCommunities.length != 0) { for (int i = 0; i < subCommunities.length; i++) getCommunityAndChilds(context, subCommunities[i].getID(), false); } // get from cloud all files collections and childs if (collections.length != 0) { for (int i = 0; i < collections.length; i++) getCollectionAndChilds(context, collections[i].getID(), false); } // it means it is the first father in the order if (establishConnection == true) this.closeConnection(); return true; }