@Override public boolean isIn(Item item, Collection collection) throws SQLException { List<Collection> collections = item.getCollections(); return collections != null && collections.contains(collection); }
@Override public List<Community> getCommunities(Context context, Item item) throws SQLException { List<Community> result = new ArrayList<>(); List<Collection> collections = item.getCollections(); for (Collection collection : collections) { result.addAll(communityService.getAllParents(context, collection)); } return result; }
protected void deleteItem(Context c, Item myitem) throws Exception { if (!isTest) { ArrayList<Collection> removeList = new ArrayList<>(); List<Collection> collections = myitem.getCollections(); // Save items to be removed to prevent concurrent modification exception DS-3322 for (Collection collection : collections) { removeList.add(collection); } // Remove item from all the collections it's in for (Collection collection : removeList) { collectionService.removeItem(c, collection, myitem); } } }
/** * Fill out the containers field of the HarvestedItemInfo object * * @param context DSpace context * @param itemInfo HarvestedItemInfo object to fill out * @throws SQLException if database error */ private static void fillCollections(Context context, HarvestedItemInfo itemInfo) throws SQLException { // Get the collection Handles from DB List<Collection> collections = itemInfo.item.getCollections(); itemInfo.collectionHandles = new ArrayList<>(); for (Collection collection : collections) { itemInfo.collectionHandles.add(collection.getHandle()); } }
@Override public ItemMarkingInfo getItemMarkingInfo(Context context, Item item) throws SQLException { if (mapping != null) { for (Collection collection : item.getCollections()) { if (mapping.containsKey(collection.getHandle())) { return mapping.get(collection.getHandle()); } } } return null; }
@Override public List<Community> flatParentCommunities(Context context, Item c) throws SQLException { Queue<Community> queue = new LinkedList<>(); List<Community> result = new ArrayList<>(); for (Collection collection : c.getCollections()) { queue.addAll(communityService.getAllParents(context, collection)); } 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; } }
protected boolean isCitationEnabledThroughCollection(Context context, Bitstream bitstream) throws SQLException { //Reject quickly if no-enabled collections if (citationEnabledCollectionsList.size() == 0) { return false; } DSpaceObject owningDSO = bitstreamService.getParentObject(context, bitstream); if (owningDSO instanceof Item) { Item item = (Item) owningDSO; List<Collection> collections = item.getCollections(); for (Collection collection : collections) { if (citationEnabledCollectionsList.contains(collection.getHandle())) { return true; } } } // If previous logic didn't return true, then we're false return false; }
/** * @param context DSpace context * @param myitem the item for which our locations are to be retrieved * @return a list containing the identifiers of the communities and collections * @throws SQLException sql exception */ protected List<String> getItemLocations(Context context, Item myitem) throws SQLException { List<String> locations = new Vector<String>(); // build list of community ids List<Community> communities = itemService.getCommunities(context, myitem); // build list of collection ids List<Collection> collections = myitem.getCollections(); // now put those into strings int i = 0; for (i = 0; i < communities.size(); i++) { locations.add("m" + communities.get(i).getID()); } for (i = 0; i < collections.size(); i++) { locations.add("l" + collections.get(i).getID()); } return locations; }
@Override public List<Collection> getCollectionsNotLinked(Context context, Item item) throws SQLException { List<Collection> allCollections = collectionService.findAll(context); List<Collection> linkedCollections = item.getCollections(); List<Collection> notLinkedCollections = new ArrayList<>(allCollections.size() - linkedCollections.size()); if ((allCollections.size() - linkedCollections.size()) == 0) { return notLinkedCollections; } for (Collection collection : allCollections) { boolean alreadyLinked = false; for (Collection linkedCommunity : linkedCollections) { if (collection.getID().equals(linkedCommunity.getID())) { alreadyLinked = true; break; } } if (!alreadyLinked) { notLinkedCollections.add(collection); } } return notLinkedCollections; }
/** * Method that retrieves a list of all the configuration objects from the given item * A configuration object can be returned for each parent community/collection * * @param item the DSpace item * @return a list of configuration objects * @throws SQLException An exception that provides information on a database access error or other errors. */ public static List<DiscoveryConfiguration> getAllDiscoveryConfigurations(Item item) throws SQLException { Map<String, DiscoveryConfiguration> result = new HashMap<String, DiscoveryConfiguration>(); List<Collection> collections = item.getCollections(); for (Collection collection : collections) { DiscoveryConfiguration configuration = getDiscoveryConfiguration(collection); if (!result.containsKey(configuration.getId())) { result.put(configuration.getId(), configuration); } } //Also add one for the default DiscoveryConfiguration configuration = getDiscoveryConfiguration(null); if (!result.containsKey(configuration.getId())) { result.put(configuration.getId(), configuration); } return Arrays.asList(result.values().toArray(new DiscoveryConfiguration[result.size()])); }
/** * @param myitem the item for which our locations are to be retrieved * @return a list containing the identifiers of the communities & collections * @throws SQLException sql exception */ private List<String> getItemLocations(Item myitem) throws SQLException { List<String> locations = new Vector<String>(); // build list of community ids Community[] communities = myitem.getCommunities(); // build list of collection ids Collection[] collections = myitem.getCollections(); // now put those into strings int i = 0; for (i = 0; i < communities.length; i++) { locations.add("m" + communities[i].getID()); } for (i = 0; i < collections.length; i++) { locations.add("l" + collections[i].getID()); } return locations; }
/** * Method that retrieves a list of all the configuration objects from the given item * A configuration object can be returned for each parent community/collection * @param item the DSpace item * @return a list of configuration objects */ public static List<DiscoveryConfiguration> getAllDiscoveryConfigurations(Item item) throws SQLException { Map<String, DiscoveryConfiguration> result = new HashMap<String, DiscoveryConfiguration>(); Collection[] collections = item.getCollections(); for (Collection collection : collections) { DiscoveryConfiguration configuration = getDiscoveryConfiguration(collection); if(!result.containsKey(configuration.getId())){ result.put(configuration.getId(), configuration); } } //Also add one for the default DiscoveryConfiguration configuration = getDiscoveryConfiguration(null); if(!result.containsKey(configuration.getId())){ result.put(configuration.getId(), configuration); } return Arrays.asList(result.values().toArray(new DiscoveryConfiguration[result.size()])); }
.append("Item was in collections:\n"); List<Collection> colls = item.getCollections();
List<Collection> colls = item.getCollections();
List<Collection> colls = item.getCollections();
@Override public void addItem(Context context, Collection collection, Item item) throws SQLException, AuthorizeException { // Check authorisation authorizeService.authorizeAction(context, collection, Constants.ADD); log.info(LogManager.getHeader(context, "add_item", "collection_id=" + collection.getID() + ",item_id=" + item.getID())); // Create mapping // We do NOT add the item to the collection template since we would have to load in all our items // Instead we add the collection to an item which works in the same way. if (!item.getCollections().contains(collection)) { item.addCollection(collection); } context.addEvent(new Event(Event.ADD, Constants.COLLECTION, collection.getID(), Constants.ITEM, item.getID(), item.getHandle(), getIdentifiers(context, collection))); }
@Override public void removeItem(Context context, Collection collection, Item item) throws SQLException, AuthorizeException, IOException { // Check authorisation authorizeService.authorizeAction(context, collection, Constants.REMOVE); //Check if we orphaned our poor item if (item.getCollections().size() == 1) { // Orphan; delete it itemService.delete(context, item); } else { //Remove the item from the collection if we have multiple collections item.removeCollection(collection); } context.addEvent(new Event(Event.REMOVE, Constants.COLLECTION, collection.getID(), Constants.ITEM, item.getID(), item.getHandle(), getIdentifiers(context, collection))); }
Collection[] collections = item.getCollections();
List<Collection> collections = i.getCollections(); for (Collection c : collections) {
List<Collection> collections = item.getCollections(); for (Collection collection : collections) { doc1.addField("owningColl", collection.getID());