@Override public DSpaceObject getParentObject(Context context, Collection collection) throws SQLException { List<Community> communities = collection.getCommunities(); if (CollectionUtils.isNotEmpty(communities)) { return communities.get(0); } else { return null; } }
@Override public List<Community> getAllParents(Context context, Collection collection) throws SQLException { List<Community> result = new ArrayList<>(); List<Community> communities = collection.getCommunities(); result.addAll(communities); for (Community community : communities) { result.addAll(getAllParents(context, community)); } return result; }
private List<Object> findOwningCommunities(Context context, UUID collId) throws SQLException { Collection coll = collectionService.find(context, collId); List<Object> owningComms = new ArrayList<Object>(); for (int i = 0; i < coll.getCommunities().size(); i++) { Community community = coll.getCommunities().get(i); findComms(community, owningComms); } return owningComms; }
private List<Object> findOwningCommunities(Context context, int collId) throws SQLException { Collection coll = Collection.find(context, collId); List<Object> owningComms = new ArrayList<Object>(); for (int i = 0; i < coll.getCommunities().length; i++) { Community community = coll.getCommunities()[i]; findComms(community, owningComms); } return owningComms; }
private List<String> getCollectionLocations(Collection target) throws SQLException { List<String> locations = new Vector<String>(); // build list of community ids Community[] communities = target.getCommunities(); // now put those into strings for (Community community : communities) { locations.add("m" + community.getID()); } return locations; }
@Override public List<Community> flatParentCommunities(Collection c) throws SQLException { Queue<Community> queue = new LinkedList<>(); List<Community> result = new ArrayList<>(); for (Community com : c.getCommunities()) { queue.add(com); } while (!queue.isEmpty()) { Community p = queue.poll(); List<Community> par = p.getParentCommunities(); if (par != null) { queue.addAll(par); } if (!result.contains(p)) { result.add(p); } } return result; }
/** * Can the current user remove the admins group of the collection? * please note that the create/edit actions need separate check * * @param context the DSpace Context Object * @param collection the collection * @throws AuthorizeException if authorization error * if the current user is not allowed to remove the * collection's admins group * @throws SQLException if database error * if a db error occur * @see #authorizeManageAdminGroup(Context, Collection) */ public static void authorizeRemoveAdminGroup(Context context, Collection collection) throws AuthorizeException, SQLException { List<Community> parentCommunities = collection.getCommunities(); if (AuthorizeConfiguration .canCommunityAdminManageCollectionAdminGroup() && parentCommunities != null && parentCommunities.size() > 0) { authorizeService.authorizeAction(context, collection .getCommunities().get(0), Constants.ADMIN); } else if (!authorizeService.isAdmin(context)) { throw new AuthorizeException( "Only system admin can remove the admin group of a collection"); } }
@Override public DSpaceObject getAdminObject(Context context, Collection collection, int action) throws SQLException { DSpaceObject adminObject = null; Community community = null; List<Community> communities = collection.getCommunities(); if (CollectionUtils.isNotEmpty(communities)) { community = communities.get(0); } switch (action) { case Constants.REMOVE: if (AuthorizeConfiguration.canCollectionAdminPerformItemDeletion()) { adminObject = collection; } else if (AuthorizeConfiguration.canCommunityAdminPerformItemDeletion()) { adminObject = community; } break; case Constants.DELETE: if (AuthorizeConfiguration.canCommunityAdminPerformSubelementDeletion()) { adminObject = community; } break; default: adminObject = collection; break; } return adminObject; }
/** * Can the current user manage (create, remove, edit) the submitters group of * the collection? * * @param context the DSpace Context Object * @param collection the collection * @throws AuthorizeException if authorization error * if the current user is not allowed to manage the collection's * submitters group * @throws SQLException if database error * if a db error occur */ public static void authorizeManageSubmittersGroup(Context context, Collection collection) throws AuthorizeException, SQLException { if (AuthorizeConfiguration.canCollectionAdminManageSubmitters()) { authorizeService.authorizeAction(context, collection, Constants.ADMIN); } else if (AuthorizeConfiguration .canCommunityAdminManageCollectionSubmitters()) { authorizeService.authorizeAction(context, collection .getCommunities().get(0), Constants.ADMIN); } else if (!authorizeService.isAdmin(context)) { throw new AuthorizeException( "Only system admin are allowed to manage collection submitters"); } }
/** * Is allowed manage (create, remove, edit) collection's policies in the * current context? * * @param context the DSpace Context Object * @param collection the collection that the policy refer to * @throws AuthorizeException if authorization error * if the current context (current user) is not allowed to * manage the collection's policies * @throws SQLException if database error * if a db error occur */ public static void authorizeManageCollectionPolicy(Context context, Collection collection) throws AuthorizeException, SQLException { if (AuthorizeConfiguration.canCollectionAdminManagePolicies()) { authorizeService.authorizeAction(context, collection, Constants.ADMIN); } else if (AuthorizeConfiguration .canCommunityAdminManageCollectionPolicies()) { authorizeService.authorizeAction(context, collection .getCommunities().get(0), Constants.ADMIN); } else if (!authorizeService.isAdmin(context)) { throw new AuthorizeException( "Only system admin are allowed to manage collection policies"); } }
/** * Can the current user manage (create, remove, edit) the workflow groups of * the collection? * * @param context the DSpace Context Object * @param collection the collection * @throws AuthorizeException if authorization error * if the current user is not allowed to manage the collection's * workflow groups * @throws SQLException if database error * if a db error occur */ public static void authorizeManageWorkflowsGroup(Context context, Collection collection) throws AuthorizeException, SQLException { if (AuthorizeConfiguration.canCollectionAdminManageWorkflows()) { authorizeService.authorizeAction(context, collection, Constants.ADMIN); } else if (AuthorizeConfiguration .canCommunityAdminManageCollectionWorkflows()) { authorizeService.authorizeAction(context, collection .getCommunities().get(0), Constants.ADMIN); } else if (!authorizeService.isAdmin(context)) { throw new AuthorizeException( "Only system admin are allowed to manage collection workflow"); } }
&& AuthorizeConfiguration .canCommunityAdminManageCollectionTemplateItem()) { List<Community> communities = collection.getCommunities(); Community parent = communities != null && communities.size() > 0 ? communities.get(0) : null;
/** * Can the current user create/edit the admins group of the collection? * please note that the remove action need a separate check * * @param context the DSpace Context Object * @param collection the collection * @throws AuthorizeException if authorization error * if the current user is not allowed to create/edit the * collection's admins group * @throws SQLException if database error * if a db error occur * @see #authorizeRemoveAdminGroup(Context, Collection) */ public static void authorizeManageAdminGroup(Context context, Collection collection) throws AuthorizeException, SQLException { if (AuthorizeConfiguration.canCollectionAdminManageAdminGroup()) { authorizeService.authorizeAction(context, collection, Constants.ADMIN); } else if (AuthorizeConfiguration .canCommunityAdminManageCollectionAdminGroup()) { authorizeService.authorizeAction(context, collection .getCommunities().get(0), Constants.ADMIN); } else if (!authorizeService.isAdmin(context)) { throw new AuthorizeException( "Only system admin are allowed to manage collection admin"); } }
.canCommunityAdminPerformItemReinstatiate() && authorizeService.authorizeActionBoolean(context, coll.getCommunities().get(0), Constants.ADMIN)) {
@Override public void removeCollection(Context context, Community community, Collection collection) throws SQLException, AuthorizeException, IOException { // Check authorisation authorizeService.authorizeAction(context, community, Constants.REMOVE); ArrayList<String> removedIdentifiers = collectionService.getIdentifiers(context, collection); String removedHandle = collection.getHandle(); UUID removedId = collection.getID(); if (collection.getCommunities().size() == 1) { collectionService.delete(context, collection); } else { community.removeCollection(collection); collection.removeCommunity(community); } log.info(LogManager.getHeader(context, "remove_collection", "community_id=" + community.getID() + ",collection_id=" + collection.getID())); // Remove any mappings context.addEvent(new Event(Event.REMOVE, Constants.COMMUNITY, community.getID(), Constants.COLLECTION, removedId, removedHandle, removedIdentifiers)); }
collection = item.getOwningCollection(); if (collection != null) { community = collection.getCommunities().get(0);
authorized = authorizeService .authorizeActionBoolean(context, item.getOwningCollection() .getCommunities().get(0), Constants.ADMIN);
/** * Is allowed manage (create, remove, edit) item's policies in the * current context? * * @param context the DSpace Context Object * @param item the item that the policy refer to * @throws AuthorizeException if authorization error * if the current context (current user) is not allowed to * manage the item's policies * @throws SQLException if database error * if a db error occur */ public static void authorizeManageItemPolicy(Context context, Item item) throws AuthorizeException, SQLException { if (AuthorizeConfiguration.canItemAdminManagePolicies()) { authorizeService.authorizeAction(context, item, Constants.ADMIN); } else if (AuthorizeConfiguration.canCollectionAdminManageItemPolicies()) { authorizeService.authorizeAction(context, item .getOwningCollection(), Constants.ADMIN); } else if (AuthorizeConfiguration.canCommunityAdminManageItemPolicies()) { authorizeService .authorizeAction(context, item.getOwningCollection() .getCommunities().get(0), Constants.ADMIN); } else if (!authorizeService.isAdmin(context)) { throw new AuthorizeException( "Only system admin are allowed to manage item policies"); } }
/** * 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; }
List<Community> communities = coll.getCommunities(); for (Community community : communities) { doc1.addField("owningComm", community.getID());