mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 06:53:09 +00:00
Applied feedback to the external sources entity post feature in ExternalDataService and ExternalSourceEntryUriListHandler
This commit is contained in:
@@ -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
|
||||
|
@@ -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<ExternalDataObject> 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(),
|
||||
|
@@ -76,10 +76,15 @@ public class ExternalSourceEntryUriListHandler implements UriListHandler<Item> {
|
||||
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> {
|
||||
item = externalDataService.createItemFromExternalDataObject(context, dataObject, collection);
|
||||
} catch (AuthorizeException | SQLException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
Reference in New Issue
Block a user