From f3efe500b1404e5819434bb355559e28c9bf22b7 Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Tue, 29 Oct 2019 10:12:20 +0100 Subject: [PATCH 01/10] [Task 65902] implemented functionality to create an archived item from the urilist call to the items endpoint with an ExternalSourceEntry in the uriList --- .../external/service/ExternalDataService.java | 17 +++ .../service/impl/ExternalDataServiceImpl.java | 39 ++++++ .../rest/repository/ItemRestRepository.java | 28 +++- .../ExternalSourceEntryUriListHandler.java | 132 ++++++++++++++++++ .../repository/handler/UriListHandler.java | 50 +++++++ .../service/UriListHandlerService.java | 60 ++++++++ 6 files changed, 321 insertions(+), 5 deletions(-) create mode 100644 dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/ExternalSourceEntryUriListHandler.java create mode 100644 dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/UriListHandler.java create mode 100644 dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/service/UriListHandlerService.java diff --git a/dspace-api/src/main/java/org/dspace/external/service/ExternalDataService.java b/dspace-api/src/main/java/org/dspace/external/service/ExternalDataService.java index 2e639dcd56..953b780633 100644 --- a/dspace-api/src/main/java/org/dspace/external/service/ExternalDataService.java +++ b/dspace-api/src/main/java/org/dspace/external/service/ExternalDataService.java @@ -7,9 +7,14 @@ */ package org.dspace.external.service; +import java.sql.SQLException; import java.util.List; import java.util.Optional; +import org.dspace.authorize.AuthorizeException; +import org.dspace.content.Collection; +import org.dspace.content.Item; +import org.dspace.core.Context; import org.dspace.external.model.ExternalDataObject; import org.dspace.external.provider.ExternalDataProvider; @@ -59,4 +64,16 @@ public interface ExternalDataService { * @return The total amount of results that can be returned for this query in the given source */ public int getNumberOfResults(String source, String query); + + /** + * This method will create an Item in the given Collection based on the given ExternalDataObject + * @param context The relevant DSpace context + * @param externalDataObject The relevant ExternalDataObject to be used + * @param collection The Collection in which the item will be present + * @return The created Item + * @throws AuthorizeException If something goes wrong + * @throws SQLException If something goes wrong + */ + Item createItemFromExternalDataObject(Context context, ExternalDataObject externalDataObject, Collection collection) + throws AuthorizeException, SQLException; } diff --git a/dspace-api/src/main/java/org/dspace/external/service/impl/ExternalDataServiceImpl.java b/dspace-api/src/main/java/org/dspace/external/service/impl/ExternalDataServiceImpl.java index 8a10b8ec93..eed376a42a 100644 --- a/dspace-api/src/main/java/org/dspace/external/service/impl/ExternalDataServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/external/service/impl/ExternalDataServiceImpl.java @@ -7,12 +7,23 @@ */ package org.dspace.external.service.impl; +import java.sql.SQLException; import java.util.List; import java.util.Optional; +import org.apache.log4j.Logger; +import org.dspace.authorize.AuthorizeException; +import org.dspace.content.Collection; +import org.dspace.content.Item; +import org.dspace.content.WorkspaceItem; +import org.dspace.content.service.InstallItemService; +import org.dspace.content.service.ItemService; +import org.dspace.content.service.WorkspaceItemService; +import org.dspace.core.Context; import org.dspace.external.model.ExternalDataObject; import org.dspace.external.provider.ExternalDataProvider; import org.dspace.external.service.ExternalDataService; +import org.dspace.mock.MockMetadataValue; import org.springframework.beans.factory.annotation.Autowired; /** @@ -20,9 +31,20 @@ import org.springframework.beans.factory.annotation.Autowired; */ public class ExternalDataServiceImpl implements ExternalDataService { + private static final Logger log = Logger.getLogger(ExternalDataServiceImpl.class); + @Autowired private List externalDataProviders; + @Autowired + private ItemService itemService; + + @Autowired + private WorkspaceItemService workspaceItemService; + + @Autowired + private InstallItemService installItemService; + @Override public Optional getExternalDataObject(String source, String id) { ExternalDataProvider provider = getExternalDataProvider(source); @@ -65,4 +87,21 @@ public class ExternalDataServiceImpl implements ExternalDataService { } return provider.getNumberOfResults(query); } + + + @Override + public Item createItemFromExternalDataObject(Context context, ExternalDataObject externalDataObject, + Collection collection) + throws AuthorizeException, SQLException { + WorkspaceItem workspaceItem = workspaceItemService.create(context, collection, false); + Item item = workspaceItem.getItem(); + for (MockMetadataValue mockMetadataValue : externalDataObject.getMetadata()) { + itemService.addMetadata(context, item, mockMetadataValue.getSchema(), mockMetadataValue.getElement(), + mockMetadataValue.getQualifier(), mockMetadataValue.getLanguage(), + mockMetadataValue.getValue(), mockMetadataValue.getAuthority(), + mockMetadataValue.getConfidence()); + } + + return installItemService.installItem(context, workspaceItem); + } } diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ItemRestRepository.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ItemRestRepository.java index a0b67fd5ba..5af7726145 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ItemRestRepository.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ItemRestRepository.java @@ -28,6 +28,7 @@ import org.dspace.app.rest.exception.UnprocessableEntityException; import org.dspace.app.rest.model.ItemRest; import org.dspace.app.rest.model.hateoas.ItemResource; import org.dspace.app.rest.model.patch.Patch; +import org.dspace.app.rest.repository.handler.service.UriListHandlerService; import org.dspace.app.rest.repository.patch.ItemPatch; import org.dspace.authorize.AuthorizeException; import org.dspace.content.Collection; @@ -38,6 +39,7 @@ import org.dspace.content.service.InstallItemService; import org.dspace.content.service.ItemService; import org.dspace.content.service.WorkspaceItemService; import org.dspace.core.Context; +import org.dspace.external.service.ExternalDataService; import org.dspace.util.UUIDUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; @@ -78,6 +80,12 @@ public class ItemRestRepository extends DSpaceObjectRestRepository stringList) + throws AuthorizeException, SQLException, RepositoryMethodNotImplementedException { + + HttpServletRequest req = getRequestService().getCurrentRequest().getHttpServletRequest(); + Item item = uriListHandlerService.handle(context, req, stringList, Item.class); + return dsoConverter.fromModel(item); + } } \ No newline at end of file diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/ExternalSourceEntryUriListHandler.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/ExternalSourceEntryUriListHandler.java new file mode 100644 index 0000000000..3f0ef1ca91 --- /dev/null +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/ExternalSourceEntryUriListHandler.java @@ -0,0 +1,132 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE and NOTICE files at the root of the source + * tree and available online at + * + * http://www.dspace.org/license/ + */ +package org.dspace.app.rest.repository.handler; + +import java.sql.SQLException; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; +import java.util.UUID; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.Logger; +import org.dspace.authorize.AuthorizeException; +import org.dspace.authorize.service.AuthorizeService; +import org.dspace.content.Collection; +import org.dspace.content.Item; +import org.dspace.content.service.CollectionService; +import org.dspace.core.Context; +import org.dspace.external.model.ExternalDataObject; +import org.dspace.external.service.ExternalDataService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.rest.webmvc.ResourceNotFoundException; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.RequestMethod; + +/** + * This class will handle ExternalSourceEntryUriList and it'll create Item objects based on them + */ +@Component +public class ExternalSourceEntryUriListHandler implements UriListHandler { + + private List allowedRequestMethods = new LinkedList<>(Arrays.asList(RequestMethod.POST)); + + @Autowired + private AuthorizeService authorizeService; + + @Autowired + private ExternalDataService externalDataService; + + @Autowired + private CollectionService collectionService; + + private static final Logger log = org.apache.logging.log4j.LogManager + .getLogger(ExternalSourceEntryUriListHandler.class); + + + @Override + public boolean supports(List uriList, String method) { + if (!allowedRequestMethods.contains(RequestMethod.valueOf(method))) { + return false; + } + for (String string : uriList) { + if (!(StringUtils.contains(string, "api/integration/externalsources") && + StringUtils.contains(string, "entryValues"))) { + return false; + } + } + return true; + } + + @Override + public boolean validate(Context context, HttpServletRequest request, List uriList, + Class clazz) { + if (uriList.size() > 1) { + return false; + } + if (clazz != Item.class) { + return false; + } + if (!request.getParameterMap().containsKey("owningCollection")) { + return false; + } + try { + if (!authorizeService.isAdmin(context)) { + return false; + } + } catch (SQLException e) { + log.error(e.getMessage(), e); + return false; + } + return true; + } + + @Override + public Item handle(Context context, HttpServletRequest request, List uriList) { + ExternalDataObject dataObject = getExternalDataObjectFromUriList(uriList); + + String owningCollectionUuid = request.getParameter("owningCollection"); + Collection collection = null; + Item item = null; + try { + collection = collectionService.find(context, UUID.fromString(owningCollectionUuid)); + item = externalDataService.createItemFromExternalDataObject(context, dataObject, collection); + } catch (AuthorizeException | SQLException e) { + log.error(e.getMessage(), e); + } + return item; + } + + /** + * This method will take the first (and only, verified in the validate method) uriList string from the list + * and it'll perform regex logic to get the AuthorityName and ID parameters from it to then retrieve + * an ExternalDataObject from the service + * @param uriList The list of UriList strings to be parsed + * @return The appropriate ExternalDataObject + */ + private ExternalDataObject getExternalDataObjectFromUriList(List uriList) { + String inputString = uriList.get(0); + Pattern pattern = Pattern.compile("api\\/integration\\/externalsources\\/(.*)\\/entryValues\\/(.*)}"); + Matcher matcher = pattern.matcher(inputString); + + matcher.find(); + String externalSourceIdentifer = matcher.group(1); + String id = matcher.group(2); + + Optional externalDataObject = externalDataService + .getExternalDataObject(externalSourceIdentifer, id); + return externalDataObject.orElseThrow(() -> new ResourceNotFoundException( + "Couldn't find an ExternalSource for source: " + externalSourceIdentifer + " and ID: " + id)); + } + + +} diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/UriListHandler.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/UriListHandler.java new file mode 100644 index 0000000000..2259d20269 --- /dev/null +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/UriListHandler.java @@ -0,0 +1,50 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE and NOTICE files at the root of the source + * tree and available online at + * + * http://www.dspace.org/license/ + */ +package org.dspace.app.rest.repository.handler; + +import java.util.List; +import javax.servlet.http.HttpServletRequest; + +import org.dspace.core.Context; + +/** + * This is an interface to be implemented by classes that want to handle a UriList call + * @param the class of the object that's returned by the handle method + */ +public interface UriListHandler { + + /** + * This method will take the UriList and method as input and verify whether the implementing UriListHandler + * can handle this input or not + * @param uriList The list of UriList Strings to be checked if they're supported + * @param method The request method to be checked if it's supported + * @return A boolean indicating whether the implementing UriListHandler can handle this input + */ + boolean supports(List uriList, String method); + + /** + * This method will take all the required input and validate them to see if there are any issues before + * calling the handle method + * @param context The relevant DSpace context + * @param request The current request + * @param uriList The list of UriList Strings + * @param clazz The class to be returned by the handle method + * @return A boolean indicating whether all this input is valid for the implementing UriListHandler + */ + boolean validate(Context context, HttpServletRequest request, List uriList, Class clazz); + + /** + * This method will perform the actual handle logic + * @param context The relevant DSpace context + * @param request The current request + * @param uriList The list of UriList Strings + * @return The object of class T that was handled + */ + T handle(Context context, HttpServletRequest request, List uriList); + +} diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/service/UriListHandlerService.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/service/UriListHandlerService.java new file mode 100644 index 0000000000..7f5eec1558 --- /dev/null +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/service/UriListHandlerService.java @@ -0,0 +1,60 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE and NOTICE files at the root of the source + * tree and available online at + * + * http://www.dspace.org/license/ + */ +package org.dspace.app.rest.repository.handler.service; + +import java.util.List; +import javax.servlet.http.HttpServletRequest; + +import org.dspace.app.rest.exception.DSpaceBadRequestException; +import org.dspace.app.rest.repository.handler.UriListHandler; +import org.dspace.core.Context; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * This class is a wrapper Service class for the {@link UriListHandler} objects. It will find the right one and try to + * execute it for the given arguments + */ +@Component +public class UriListHandlerService { + + @Autowired + private List uriListHandlers; + + /** + * This method will take the UriList, the request, relevant DSpace context and the class of the object to be handled + * It'll then loop over all the UriListHandlers defined within the codebase and first check if it supports the given + * method and the urilist. If the handler supports this, it'll then validate the input and only if it's valid, it'll + * execute the handle method and perform the logic + * + * @param context The relevant DSpace context + * @param request The current active Request + * @param uriList The list of Strings representing the UriList to be handled + * @param clazz The class to be hadled + * @param The class to be returned, same as the class parameter above + * @return The object that was handled through this method + */ + public T handle(Context context, HttpServletRequest request, List uriList, Class clazz) { + + // Loop all the uriListHandlers + for (UriListHandler uriListHandler : uriListHandlers) { + // Does the class support the given uri list and the request method + if (uriListHandler.supports(uriList, request.getMethod())) { + // Can the class handle the given uri list and can the given class, params and authorization be handled + if (uriListHandler.validate(context, request, uriList, clazz)) { + // If all these things succeed, call handle + return (T) uriListHandler.handle(context, request, uriList); + } else { + throw new DSpaceBadRequestException("The input given to the UriListHandler was invalid"); + } + } + } + + throw new DSpaceBadRequestException("No UriListHandler was found that supports the inputs given"); + } +} From a1ed84d072c70a9cb78258b2efde4941d12e9dc5 Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Wed, 30 Oct 2019 09:17:18 +0100 Subject: [PATCH 02/10] Applied feedback to the external sources entity post feature in ExternalDataService and ExternalSourceEntryUriListHandler --- .../org/dspace/external/service/ExternalDataService.java | 3 ++- .../external/service/impl/ExternalDataServiceImpl.java | 9 ++++++++- .../handler/ExternalSourceEntryUriListHandler.java | 8 +++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/dspace-api/src/main/java/org/dspace/external/service/ExternalDataService.java b/dspace-api/src/main/java/org/dspace/external/service/ExternalDataService.java index 953b780633..bfcfeb6407 100644 --- a/dspace-api/src/main/java/org/dspace/external/service/ExternalDataService.java +++ b/dspace-api/src/main/java/org/dspace/external/service/ExternalDataService.java @@ -66,7 +66,8 @@ public interface ExternalDataService { public int getNumberOfResults(String source, String query); /** - * This method will create an Item in the given Collection based on the given ExternalDataObject + * This method will create an Item in the given Collection based on the given ExternalDataObject. + * Note that this Item will be Archived * @param context The relevant DSpace context * @param externalDataObject The relevant ExternalDataObject to be used * @param collection The Collection in which the item will be present diff --git a/dspace-api/src/main/java/org/dspace/external/service/impl/ExternalDataServiceImpl.java b/dspace-api/src/main/java/org/dspace/external/service/impl/ExternalDataServiceImpl.java index eed376a42a..21cf9d30fb 100644 --- a/dspace-api/src/main/java/org/dspace/external/service/impl/ExternalDataServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/external/service/impl/ExternalDataServiceImpl.java @@ -13,6 +13,7 @@ import java.util.Optional; import org.apache.log4j.Logger; import org.dspace.authorize.AuthorizeException; +import org.dspace.authorize.service.AuthorizeService; import org.dspace.content.Collection; import org.dspace.content.Item; import org.dspace.content.WorkspaceItem; @@ -45,6 +46,9 @@ public class ExternalDataServiceImpl implements ExternalDataService { @Autowired private InstallItemService installItemService; + @Autowired + private AuthorizeService authorizeService; + @Override public Optional getExternalDataObject(String source, String id) { ExternalDataProvider provider = getExternalDataProvider(source); @@ -93,7 +97,10 @@ public class ExternalDataServiceImpl implements ExternalDataService { public Item createItemFromExternalDataObject(Context context, ExternalDataObject externalDataObject, Collection collection) throws AuthorizeException, SQLException { - WorkspaceItem workspaceItem = workspaceItemService.create(context, collection, false); + if (!authorizeService.isAdmin(context)) { + throw new AuthorizeException("You have to be an admin to create an Item from an ExternalDataObject"); + } + WorkspaceItem workspaceItem = workspaceItemService.create(context, collection, true); Item item = workspaceItem.getItem(); for (MockMetadataValue mockMetadataValue : externalDataObject.getMetadata()) { itemService.addMetadata(context, item, mockMetadataValue.getSchema(), mockMetadataValue.getElement(), diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/ExternalSourceEntryUriListHandler.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/ExternalSourceEntryUriListHandler.java index 3f0ef1ca91..4d74e607df 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/ExternalSourceEntryUriListHandler.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/ExternalSourceEntryUriListHandler.java @@ -76,10 +76,15 @@ public class ExternalSourceEntryUriListHandler implements UriListHandler { if (clazz != Item.class) { return false; } - if (!request.getParameterMap().containsKey("owningCollection")) { + String owningCollectionString = request.getParameter("owningCollection"); + if (StringUtils.isBlank(owningCollectionString)) { return false; } try { + Collection collection = collectionService.find(context, UUID.fromString(owningCollectionString)); + if (collection == null) { + return false; + } if (!authorizeService.isAdmin(context)) { return false; } @@ -102,6 +107,7 @@ public class ExternalSourceEntryUriListHandler implements UriListHandler { item = externalDataService.createItemFromExternalDataObject(context, dataObject, collection); } catch (AuthorizeException | SQLException e) { log.error(e.getMessage(), e); + throw new RuntimeException(e); } return item; } From 196894e46e2b53e50c328927cfed39e16b840ece Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Tue, 26 Nov 2019 13:20:36 +0100 Subject: [PATCH 03/10] Refactored Mockmetadata to MetadataValueDTO and fixed checkstyle --- .../service/impl/ExternalDataServiceImpl.java | 12 ++++++------ .../app/rest/repository/ItemRestRepository.java | 3 +-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/dspace-api/src/main/java/org/dspace/external/service/impl/ExternalDataServiceImpl.java b/dspace-api/src/main/java/org/dspace/external/service/impl/ExternalDataServiceImpl.java index 21cf9d30fb..611d24e9f0 100644 --- a/dspace-api/src/main/java/org/dspace/external/service/impl/ExternalDataServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/external/service/impl/ExternalDataServiceImpl.java @@ -16,6 +16,7 @@ import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.service.AuthorizeService; import org.dspace.content.Collection; import org.dspace.content.Item; +import org.dspace.content.MetadataValueDTO; import org.dspace.content.WorkspaceItem; import org.dspace.content.service.InstallItemService; import org.dspace.content.service.ItemService; @@ -24,7 +25,6 @@ import org.dspace.core.Context; import org.dspace.external.model.ExternalDataObject; import org.dspace.external.provider.ExternalDataProvider; import org.dspace.external.service.ExternalDataService; -import org.dspace.mock.MockMetadataValue; import org.springframework.beans.factory.annotation.Autowired; /** @@ -102,11 +102,11 @@ public class ExternalDataServiceImpl implements ExternalDataService { } WorkspaceItem workspaceItem = workspaceItemService.create(context, collection, true); Item item = workspaceItem.getItem(); - for (MockMetadataValue mockMetadataValue : externalDataObject.getMetadata()) { - itemService.addMetadata(context, item, mockMetadataValue.getSchema(), mockMetadataValue.getElement(), - mockMetadataValue.getQualifier(), mockMetadataValue.getLanguage(), - mockMetadataValue.getValue(), mockMetadataValue.getAuthority(), - mockMetadataValue.getConfidence()); + for (MetadataValueDTO metadataValueDTO : externalDataObject.getMetadata()) { + itemService.addMetadata(context, item, metadataValueDTO.getSchema(), metadataValueDTO.getElement(), + metadataValueDTO.getQualifier(), metadataValueDTO.getLanguage(), + metadataValueDTO.getValue(), metadataValueDTO.getAuthority(), + metadataValueDTO.getConfidence()); } return installItemService.installItem(context, workspaceItem); diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ItemRestRepository.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ItemRestRepository.java index ac0f833d41..b9204eb280 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ItemRestRepository.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ItemRestRepository.java @@ -27,8 +27,8 @@ import org.dspace.app.rest.exception.UnprocessableEntityException; import org.dspace.app.rest.model.BundleRest; import org.dspace.app.rest.model.ItemRest; import org.dspace.app.rest.model.patch.Patch; -import org.dspace.app.rest.repository.handler.service.UriListHandlerService; import org.dspace.app.rest.projection.Projection; +import org.dspace.app.rest.repository.handler.service.UriListHandlerService; import org.dspace.app.rest.repository.patch.ItemPatch; import org.dspace.authorize.AuthorizeException; import org.dspace.content.Bundle; @@ -41,7 +41,6 @@ import org.dspace.content.service.InstallItemService; import org.dspace.content.service.ItemService; import org.dspace.content.service.WorkspaceItemService; import org.dspace.core.Context; -import org.dspace.external.service.ExternalDataService; import org.dspace.util.UUIDUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; From 967b598b9923c5582c55dde45866d5ee021c7d3d Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Tue, 26 Nov 2019 13:53:35 +0100 Subject: [PATCH 04/10] Fixed import in ExternalDataServiceImpl --- .../dspace/external/service/impl/ExternalDataServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dspace-api/src/main/java/org/dspace/external/service/impl/ExternalDataServiceImpl.java b/dspace-api/src/main/java/org/dspace/external/service/impl/ExternalDataServiceImpl.java index 611d24e9f0..8f4d8b198a 100644 --- a/dspace-api/src/main/java/org/dspace/external/service/impl/ExternalDataServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/external/service/impl/ExternalDataServiceImpl.java @@ -16,8 +16,8 @@ import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.service.AuthorizeService; import org.dspace.content.Collection; import org.dspace.content.Item; -import org.dspace.content.MetadataValueDTO; import org.dspace.content.WorkspaceItem; +import org.dspace.content.dto.MetadataValueDTO; import org.dspace.content.service.InstallItemService; import org.dspace.content.service.ItemService; import org.dspace.content.service.WorkspaceItemService; From 34714980183012bf18255e685e2479dc550823de Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Tue, 26 Nov 2019 14:03:28 +0100 Subject: [PATCH 05/10] Small improvements to the external sources feature --- .../external/service/impl/ExternalDataServiceImpl.java | 4 ++++ .../handler/ExternalSourceEntryUriListHandler.java | 5 +++-- .../dspace/app/rest/repository/handler/UriListHandler.java | 4 +++- .../repository/handler/service/UriListHandlerService.java | 5 ++++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/dspace-api/src/main/java/org/dspace/external/service/impl/ExternalDataServiceImpl.java b/dspace-api/src/main/java/org/dspace/external/service/impl/ExternalDataServiceImpl.java index 8f4d8b198a..587fe5cd0e 100644 --- a/dspace-api/src/main/java/org/dspace/external/service/impl/ExternalDataServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/external/service/impl/ExternalDataServiceImpl.java @@ -22,6 +22,7 @@ import org.dspace.content.service.InstallItemService; import org.dspace.content.service.ItemService; import org.dspace.content.service.WorkspaceItemService; import org.dspace.core.Context; +import org.dspace.core.LogManager; import org.dspace.external.model.ExternalDataObject; import org.dspace.external.provider.ExternalDataProvider; import org.dspace.external.service.ExternalDataService; @@ -109,6 +110,9 @@ public class ExternalDataServiceImpl implements ExternalDataService { metadataValueDTO.getConfidence()); } + log.info(LogManager.getHeader(context, "create_item_from_externalDataObject", "Created item" + + "with id: " + item.getID() + " from source: " + externalDataObject.getSource() + " with identifier: " + + externalDataObject.getId())); return installItemService.installItem(context, workspaceItem); } } diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/ExternalSourceEntryUriListHandler.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/ExternalSourceEntryUriListHandler.java index 4d74e607df..7c194105e1 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/ExternalSourceEntryUriListHandler.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/ExternalSourceEntryUriListHandler.java @@ -96,7 +96,8 @@ public class ExternalSourceEntryUriListHandler implements UriListHandler { } @Override - public Item handle(Context context, HttpServletRequest request, List uriList) { + public Item handle(Context context, HttpServletRequest request, List uriList) + throws SQLException, AuthorizeException { ExternalDataObject dataObject = getExternalDataObjectFromUriList(uriList); String owningCollectionUuid = request.getParameter("owningCollection"); @@ -107,7 +108,7 @@ public class ExternalSourceEntryUriListHandler implements UriListHandler { item = externalDataService.createItemFromExternalDataObject(context, dataObject, collection); } catch (AuthorizeException | SQLException e) { log.error(e.getMessage(), e); - throw new RuntimeException(e); + throw e; } return item; } diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/UriListHandler.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/UriListHandler.java index 2259d20269..449f4e3acb 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/UriListHandler.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/UriListHandler.java @@ -7,9 +7,11 @@ */ package org.dspace.app.rest.repository.handler; +import java.sql.SQLException; import java.util.List; import javax.servlet.http.HttpServletRequest; +import org.dspace.authorize.AuthorizeException; import org.dspace.core.Context; /** @@ -45,6 +47,6 @@ public interface UriListHandler { * @param uriList The list of UriList Strings * @return The object of class T that was handled */ - T handle(Context context, HttpServletRequest request, List uriList); + T handle(Context context, HttpServletRequest request, List uriList) throws SQLException, AuthorizeException; } diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/service/UriListHandlerService.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/service/UriListHandlerService.java index 7f5eec1558..38139d31b7 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/service/UriListHandlerService.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/service/UriListHandlerService.java @@ -7,11 +7,13 @@ */ package org.dspace.app.rest.repository.handler.service; +import java.sql.SQLException; import java.util.List; import javax.servlet.http.HttpServletRequest; import org.dspace.app.rest.exception.DSpaceBadRequestException; import org.dspace.app.rest.repository.handler.UriListHandler; +import org.dspace.authorize.AuthorizeException; import org.dspace.core.Context; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -39,7 +41,8 @@ public class UriListHandlerService { * @param The class to be returned, same as the class parameter above * @return The object that was handled through this method */ - public T handle(Context context, HttpServletRequest request, List uriList, Class clazz) { + public T handle(Context context, HttpServletRequest request, List uriList, Class clazz) + throws SQLException, AuthorizeException { // Loop all the uriListHandlers for (UriListHandler uriListHandler : uriListHandlers) { From 5133266cadb11db76123529d42c9853a430ba0e1 Mon Sep 17 00:00:00 2001 From: Kevin Van de Velde Date: Wed, 27 Nov 2019 12:45:34 +0100 Subject: [PATCH 06/10] Fixing a merge issue --- .../org/dspace/app/rest/repository/ItemRestRepository.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ItemRestRepository.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ItemRestRepository.java index dcb5fe7bd6..ea44514fa3 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ItemRestRepository.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ItemRestRepository.java @@ -366,8 +366,6 @@ public class ItemRestRepository extends DSpaceObjectRestRepository stringList) throws AuthorizeException, SQLException, RepositoryMethodNotImplementedException { From 664c970da96ddcbe1dc22e2821ca001dbf9ae971 Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Mon, 2 Dec 2019 11:27:12 +0100 Subject: [PATCH 07/10] Fixed minor bug in the UriList parsing and added IT tests --- .../ExternalSourceEntryUriListHandler.java | 2 +- .../dspace/app/rest/ItemRestRepositoryIT.java | 135 ++++++++++++++++++ 2 files changed, 136 insertions(+), 1 deletion(-) diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/ExternalSourceEntryUriListHandler.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/ExternalSourceEntryUriListHandler.java index 7c194105e1..88765f277c 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/ExternalSourceEntryUriListHandler.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/ExternalSourceEntryUriListHandler.java @@ -122,7 +122,7 @@ public class ExternalSourceEntryUriListHandler implements UriListHandler { */ private ExternalDataObject getExternalDataObjectFromUriList(List uriList) { String inputString = uriList.get(0); - Pattern pattern = Pattern.compile("api\\/integration\\/externalsources\\/(.*)\\/entryValues\\/(.*)}"); + Pattern pattern = Pattern.compile("api\\/integration\\/externalsources\\/(.*)\\/entryValues\\/(.*)"); Matcher matcher = pattern.matcher(inputString); matcher.find(); diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/ItemRestRepositoryIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/ItemRestRepositoryIT.java index 717a9e5b9e..76559b6dba 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/ItemRestRepositoryIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/ItemRestRepositoryIT.java @@ -1906,5 +1906,140 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest { .andExpect(status().isForbidden()); } + @Test + public void createItemFromExternalSources() throws Exception { + //We turn off the authorization system in order to create the structure as defined below + context.turnOffAuthorisationSystem(); + //** GIVEN ** + //1. A community-collection structure with one parent community with sub-community and two collections. + parentCommunity = CommunityBuilder.createCommunity(context) + .withName("Parent Community") + .build(); + Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity) + .withName("Sub Community") + .build(); + Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build(); + context.restoreAuthSystemState(); + + ObjectMapper mapper = new ObjectMapper(); + String token = getAuthToken(admin.getEmail(), password); + MvcResult mvcResult = getClient(token).perform(post("/api/core/items?owningCollection=" + + col1.getID().toString()) + .contentType(org.springframework.http.MediaType.parseMediaType( + org.springframework.data.rest.webmvc.RestMediaTypes.TEXT_URI_LIST_VALUE)) + .content("https://localhost:8080/server/api/integration/externalsources/" + + "mock/entryValues/one")).andExpect(status().isCreated()).andReturn(); + + String content = mvcResult.getResponse().getContentAsString(); + Map map = mapper.readValue(content, Map.class); + String itemUuidString = String.valueOf(map.get("uuid")); + String itemHandleString = String.valueOf(map.get("handle")); + + getClient(token).perform(get("/api/core/items/" + itemUuidString)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$", Matchers.allOf( + hasJsonPath("$.id", is(itemUuidString)), + hasJsonPath("$.uuid", is(itemUuidString)), + hasJsonPath("$.handle", is(itemHandleString)), + hasJsonPath("$.type", is("item")), + hasJsonPath("$.metadata", Matchers.allOf( + MetadataMatcher.matchMetadata("dc.contributor.author", "Donald, Smith") + ))))); + } + + @Test + public void createItemFromExternalSourcesNoOwningCollectionUuidBadRequest() throws Exception { + String token = getAuthToken(admin.getEmail(), password); + getClient(token).perform(post("/api/core/items") + .contentType(org.springframework.http.MediaType.parseMediaType( + org.springframework.data.rest.webmvc.RestMediaTypes.TEXT_URI_LIST_VALUE)) + .content("https://localhost:8080/server/api/integration/externalsources/" + + "mock/entryValues/one")).andExpect(status().isBadRequest()).andReturn(); + } + + @Test + public void createItemFromExternalSourcesRandomOwningCollectionUuidBadRequest() throws Exception { + String token = getAuthToken(admin.getEmail(), password); + getClient(token).perform(post("/api/core/items?owningCollection=" + UUID.randomUUID()) + .contentType(org.springframework.http.MediaType.parseMediaType( + org.springframework.data.rest.webmvc.RestMediaTypes.TEXT_URI_LIST_VALUE)) + .content("https://localhost:8080/server/api/integration/externalsources/" + + "mock/entryValues/one")).andExpect(status().isBadRequest()).andReturn(); + } + + @Test + public void createItemFromExternalSourcesWrongUriList() throws Exception { + //We turn off the authorization system in order to create the structure as defined below + context.turnOffAuthorisationSystem(); + //** GIVEN ** + //1. A community-collection structure with one parent community with sub-community and two collections. + parentCommunity = CommunityBuilder.createCommunity(context) + .withName("Parent Community") + .build(); + Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity) + .withName("Sub Community") + .build(); + Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build(); + + context.restoreAuthSystemState(); + + ObjectMapper mapper = new ObjectMapper(); + String token = getAuthToken(admin.getEmail(), password); + getClient(token).perform(post("/api/core/items?owningCollection=" + col1.getID().toString()) + .contentType(org.springframework.http.MediaType.parseMediaType( + org.springframework.data.rest.webmvc.RestMediaTypes.TEXT_URI_LIST_VALUE)) + .content("https://localhost:8080/server/mock/mock/mock/" + + "mock/entryValues/one")).andExpect(status().isBadRequest()); + } + + @Test + public void createItemFromExternalSourcesWrongSourceBadRequest() throws Exception { + //We turn off the authorization system in order to create the structure as defined below + context.turnOffAuthorisationSystem(); + //** GIVEN ** + //1. A community-collection structure with one parent community with sub-community and two collections. + parentCommunity = CommunityBuilder.createCommunity(context) + .withName("Parent Community") + .build(); + Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity) + .withName("Sub Community") + .build(); + Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build(); + + context.restoreAuthSystemState(); + + String token = getAuthToken(admin.getEmail(), password); + getClient(token).perform(post("/api/core/items?owningCollection=" + col1.getID().toString()) + .contentType(org.springframework.http.MediaType.parseMediaType( + org.springframework.data.rest.webmvc.RestMediaTypes.TEXT_URI_LIST_VALUE)) + .content("https://localhost:8080/server/api/integration/externalsources/" + + "mockWrongSource/entryValues/one")).andExpect(status().isBadRequest()); + + } + + @Test + public void createItemFromExternalSourcesWrongIdResourceNotFound() throws Exception { + //We turn off the authorization system in order to create the structure as defined below + context.turnOffAuthorisationSystem(); + //** GIVEN ** + //1. A community-collection structure with one parent community with sub-community and two collections. + parentCommunity = CommunityBuilder.createCommunity(context) + .withName("Parent Community") + .build(); + Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity) + .withName("Sub Community") + .build(); + Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build(); + + context.restoreAuthSystemState(); + + String token = getAuthToken(admin.getEmail(), password); + getClient(token).perform(post("/api/core/items?owningCollection=" + col1.getID().toString()) + .contentType(org.springframework.http.MediaType.parseMediaType( + org.springframework.data.rest.webmvc.RestMediaTypes.TEXT_URI_LIST_VALUE)) + .content("https://localhost:8080/server/api/integration/externalsources/" + + "mock/entryValues/azeazezaezeaz")).andExpect(status().is(404)); + + } } \ No newline at end of file From daeab7481583fd2e10c267053adece78de8a7be8 Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Mon, 2 Dec 2019 12:07:49 +0100 Subject: [PATCH 08/10] Added proper authorization handling for the ExternalSources item create endpoint --- .../ExternalSourceEntryUriListHandler.java | 4 +- .../repository/handler/UriListHandler.java | 3 +- .../dspace/app/rest/ItemRestRepositoryIT.java | 47 +++++++++++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/ExternalSourceEntryUriListHandler.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/ExternalSourceEntryUriListHandler.java index 88765f277c..d40a72044c 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/ExternalSourceEntryUriListHandler.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/ExternalSourceEntryUriListHandler.java @@ -69,7 +69,7 @@ public class ExternalSourceEntryUriListHandler implements UriListHandler { @Override public boolean validate(Context context, HttpServletRequest request, List uriList, - Class clazz) { + Class clazz) throws AuthorizeException { if (uriList.size() > 1) { return false; } @@ -86,7 +86,7 @@ public class ExternalSourceEntryUriListHandler implements UriListHandler { return false; } if (!authorizeService.isAdmin(context)) { - return false; + throw new AuthorizeException("Only admins are allowed to create items using external data"); } } catch (SQLException e) { log.error(e.getMessage(), e); diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/UriListHandler.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/UriListHandler.java index 449f4e3acb..f3702f45ac 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/UriListHandler.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/UriListHandler.java @@ -38,7 +38,8 @@ public interface UriListHandler { * @param clazz The class to be returned by the handle method * @return A boolean indicating whether all this input is valid for the implementing UriListHandler */ - boolean validate(Context context, HttpServletRequest request, List uriList, Class clazz); + boolean validate(Context context, HttpServletRequest request, List uriList, Class clazz) + throws AuthorizeException; /** * This method will perform the actual handle logic diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/ItemRestRepositoryIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/ItemRestRepositoryIT.java index 76559b6dba..6cfa2c48e2 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/ItemRestRepositoryIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/ItemRestRepositoryIT.java @@ -2042,4 +2042,51 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest { "mock/entryValues/azeazezaezeaz")).andExpect(status().is(404)); } + + @Test + public void createItemFromExternalSourcesForbidden() throws Exception { + //We turn off the authorization system in order to create the structure as defined below + context.turnOffAuthorisationSystem(); + //** GIVEN ** + //1. A community-collection structure with one parent community with sub-community and two collections. + parentCommunity = CommunityBuilder.createCommunity(context) + .withName("Parent Community") + .build(); + Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity) + .withName("Sub Community") + .build(); + Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build(); + + context.restoreAuthSystemState(); + + String token = getAuthToken(eperson.getEmail(), password); + getClient(token).perform(post("/api/core/items?owningCollection=" + col1.getID().toString()) + .contentType(org.springframework.http.MediaType.parseMediaType( + org.springframework.data.rest.webmvc.RestMediaTypes.TEXT_URI_LIST_VALUE)) + .content("https://localhost:8080/server/api/integration/externalsources/" + + "mock/entryValues/one")).andExpect(status().isForbidden()); + } + + @Test + public void createItemFromExternalSourcesUnauthorized() throws Exception { + //We turn off the authorization system in order to create the structure as defined below + context.turnOffAuthorisationSystem(); + //** GIVEN ** + //1. A community-collection structure with one parent community with sub-community and two collections. + parentCommunity = CommunityBuilder.createCommunity(context) + .withName("Parent Community") + .build(); + Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity) + .withName("Sub Community") + .build(); + Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build(); + + context.restoreAuthSystemState(); + + getClient().perform(post("/api/core/items?owningCollection=" + col1.getID().toString()) + .contentType(org.springframework.http.MediaType.parseMediaType( + org.springframework.data.rest.webmvc.RestMediaTypes.TEXT_URI_LIST_VALUE)) + .content("https://localhost:8080/server/api/integration/externalsources/" + + "mock/entryValues/one")).andExpect(status().isUnauthorized()); + } } \ No newline at end of file From 43f9e9c545bbc639ef429328f84c1766176c09cb Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Thu, 5 Dec 2019 13:50:49 +0100 Subject: [PATCH 09/10] Applied feedback to the ExternalSourceEntryUriListHandler --- .../handler/ExternalSourceEntryUriListHandler.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/ExternalSourceEntryUriListHandler.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/ExternalSourceEntryUriListHandler.java index d40a72044c..a822c19daf 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/ExternalSourceEntryUriListHandler.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/ExternalSourceEntryUriListHandler.java @@ -19,6 +19,7 @@ import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.Logger; +import org.dspace.app.rest.model.ExternalSourceRest; import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.service.AuthorizeService; import org.dspace.content.Collection; @@ -59,7 +60,7 @@ public class ExternalSourceEntryUriListHandler implements UriListHandler { return false; } for (String string : uriList) { - if (!(StringUtils.contains(string, "api/integration/externalsources") && + if (!(StringUtils.contains(string, ExternalSourceRest.CATEGORY + "/" + ExternalSourceRest.PLURAL_NAME) && StringUtils.contains(string, "entryValues"))) { return false; } @@ -81,6 +82,9 @@ public class ExternalSourceEntryUriListHandler implements UriListHandler { return false; } try { + if (!authorizeService.isAdmin(context)) { + throw new AuthorizeException("Only admins are allowed to create items using external data"); + } Collection collection = collectionService.find(context, UUID.fromString(owningCollectionString)); if (collection == null) { return false; @@ -89,7 +93,8 @@ public class ExternalSourceEntryUriListHandler implements UriListHandler { throw new AuthorizeException("Only admins are allowed to create items using external data"); } } catch (SQLException e) { - log.error(e.getMessage(), e); + log.error("Search for owningCollection with UUID:" + owningCollectionString + " resulted in an error", + e); return false; } return true; @@ -107,7 +112,8 @@ public class ExternalSourceEntryUriListHandler implements UriListHandler { collection = collectionService.find(context, UUID.fromString(owningCollectionUuid)); item = externalDataService.createItemFromExternalDataObject(context, dataObject, collection); } catch (AuthorizeException | SQLException e) { - log.error(e.getMessage(), e); + log.error("An error occured when trying to create item in collection with uuid: " + owningCollectionUuid, + e); throw e; } return item; From 30eb5962244c061ed5b93fb084925952fd8ab354 Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Thu, 5 Dec 2019 14:49:00 +0100 Subject: [PATCH 10/10] Removed redundant admin check in ExternalSourceEntryUriListHandler --- .../repository/handler/ExternalSourceEntryUriListHandler.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/ExternalSourceEntryUriListHandler.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/ExternalSourceEntryUriListHandler.java index a822c19daf..cce12e63a6 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/ExternalSourceEntryUriListHandler.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/handler/ExternalSourceEntryUriListHandler.java @@ -89,9 +89,6 @@ public class ExternalSourceEntryUriListHandler implements UriListHandler { if (collection == null) { return false; } - if (!authorizeService.isAdmin(context)) { - throw new AuthorizeException("Only admins are allowed to create items using external data"); - } } catch (SQLException e) { log.error("Search for owningCollection with UUID:" + owningCollectionString + " resulted in an error", e);