diff --git a/dspace-api/src/main/java/org/dspace/content/Item.java b/dspace-api/src/main/java/org/dspace/content/Item.java index 49ab4b8caa..3c2f20730b 100644 --- a/dspace-api/src/main/java/org/dspace/content/Item.java +++ b/dspace-api/src/main/java/org/dspace/content/Item.java @@ -271,6 +271,31 @@ public class Item extends DSpaceObject implements DSpaceObjectLegacySupport return bundles; } + /** + * Get the bundles matching a bundle name (name corresponds roughly to type) + * + * @param name + * name of bundle (ORIGINAL/TEXT/THUMBNAIL) + * + * @return the bundles in an unordered array + */ + public List getBundles(String name) + { + List matchingBundles = new ArrayList(); + + // now only keep bundles with matching names + List bunds = getBundles(); + for (Bundle bundle : bunds) + { + if (name.equals(bundle.getName())) + { + matchingBundles.add(bundle); + } + } + + return matchingBundles; + } + /** * Add a bundle to the item, should not be made public since we don't want to skip business logic * @param bundle the bundle to be added @@ -298,35 +323,35 @@ public class Item extends DSpaceObject implements DSpaceObjectLegacySupport * @return true if object passed in represents the same item * as this object */ - @Override - public boolean equals(Object obj) - { - if (obj == null) - { - return false; - } - Class objClass = HibernateProxyHelper.getClassWithoutInitializingProxy(obj); - if (this.getClass() != objClass) - { - return false; - } - final Item otherItem = (Item) obj; - if (!this.getID().equals(otherItem.getID())) - { - return false; - } + @Override + public boolean equals(Object obj) + { + if (obj == null) + { + return false; + } + Class objClass = HibernateProxyHelper.getClassWithoutInitializingProxy(obj); + if (this.getClass() != objClass) + { + return false; + } + final Item otherItem = (Item) obj; + if (!this.getID().equals(otherItem.getID())) + { + return false; + } - return true; - } + return true; + } - @Override - public int hashCode() - { - int hash = 5; - hash += 71 * hash + getType(); - hash += 71 * hash + getID().hashCode(); - return hash; - } + @Override + public int hashCode() + { + int hash = 5; + hash += 71 * hash + getType(); + hash += 71 * hash + getID().hashCode(); + return hash; + } /** * return type found in Constants diff --git a/dspace-swordv2/src/main/java/org/dspace/sword2/SwordAuthenticator.java b/dspace-swordv2/src/main/java/org/dspace/sword2/SwordAuthenticator.java index 11a9904644..819664e571 100644 --- a/dspace-swordv2/src/main/java/org/dspace/sword2/SwordAuthenticator.java +++ b/dspace-swordv2/src/main/java/org/dspace/sword2/SwordAuthenticator.java @@ -67,7 +67,7 @@ public class SwordAuthenticator protected ItemService itemService = ContentServiceFactory.getInstance() .getItemService(); - + protected ConfigurationService configurationService = DSpaceServicesFactory .getInstance().getConfigurationService(); @@ -291,7 +291,7 @@ public class SwordAuthenticator * @throws DSpaceSwordException */ public boolean canSubmit(SwordContext swordContext, DSpaceObject dso, - VerboseDescription msg) + VerboseDescription msg) throws DSpaceSwordException, SwordError { // determine if we can submit @@ -547,7 +547,7 @@ public class SwordAuthenticator * @throws DSpaceSwordException */ public List getCommunities(SwordContext swordContext, - Community community) + Community community) throws DSpaceSwordException { // a community is allowed if the following conditions are met @@ -731,7 +731,7 @@ public class SwordAuthenticator * @throws DSpaceSwordException */ public List getAllowedItems(SwordContext swordContext, - org.dspace.content.Collection collection) + org.dspace.content.Collection collection) throws DSpaceSwordException { // an item is allowed if the following conditions are met @@ -765,7 +765,7 @@ public class SwordAuthenticator } // get the "ORIGINAL" bundle(s) - List bundles = item.getBundles(); + List bundles = item.getBundles(Constants.CONTENT_BUNDLE_NAME); // look up the READ policy on the community. This will include determining if the user is an administrator // so we do not need to check that separately @@ -786,16 +786,12 @@ public class SwordAuthenticator { for (Bundle bundle : bundles) { - if (Constants.CONTENT_BUNDLE_NAME - .equals(bundle.getName())) + add = authorizeService.authorizeActionBoolean( + swordContext.getAuthenticatorContext(), + bundle, Constants.ADD); + if (!add) { - add = authorizeService.authorizeActionBoolean( - swordContext.getAuthenticatorContext(), - bundle, Constants.ADD); - if (!add) - { - break; - } + break; } } } @@ -874,7 +870,7 @@ public class SwordAuthenticator * @throws DSpaceSwordException */ public boolean canSubmitTo(SwordContext swordContext, - org.dspace.content.Collection collection) + org.dspace.content.Collection collection) throws DSpaceSwordException { // a user can submit to a collection in the following conditions: @@ -966,7 +962,7 @@ public class SwordAuthenticator .authorizeActionBoolean(allowContext, item, Constants.WRITE); - List bundles = item.getBundles(); + List bundles = item.getBundles(Constants.CONTENT_BUNDLE_NAME); boolean add = false; if (bundles.isEmpty()) { @@ -978,15 +974,12 @@ public class SwordAuthenticator { for (Bundle bundle : bundles) { - if (Constants.CONTENT_BUNDLE_NAME.equals(bundle.getName())) + add = authorizeService + .authorizeActionBoolean(allowContext, bundle, + Constants.ADD); + if (!add) { - add = authorizeService - .authorizeActionBoolean(allowContext, bundle, - Constants.ADD); - if (!add) - { - break; - } + break; } } }