mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-18 07:23:08 +00:00
[CST-5294] FIxed NBEventRestRepositoryIT test
This commit is contained in:
@@ -19,6 +19,7 @@ import org.dspace.content.Item;
|
|||||||
import org.dspace.content.Relationship;
|
import org.dspace.content.Relationship;
|
||||||
import org.dspace.content.RelationshipType;
|
import org.dspace.content.RelationshipType;
|
||||||
import org.dspace.content.WorkspaceItem;
|
import org.dspace.content.WorkspaceItem;
|
||||||
|
import org.dspace.content.service.CollectionService;
|
||||||
import org.dspace.content.service.EntityTypeService;
|
import org.dspace.content.service.EntityTypeService;
|
||||||
import org.dspace.content.service.InstallItemService;
|
import org.dspace.content.service.InstallItemService;
|
||||||
import org.dspace.content.service.ItemService;
|
import org.dspace.content.service.ItemService;
|
||||||
@@ -51,6 +52,9 @@ public class NBEntityMetadataAction implements NBAction {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private WorkspaceItemService workspaceItemService;
|
private WorkspaceItemService workspaceItemService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CollectionService collectionService;
|
||||||
|
|
||||||
public void setItemService(ItemService itemService) {
|
public void setItemService(ItemService itemService) {
|
||||||
this.itemService = itemService;
|
this.itemService = itemService;
|
||||||
}
|
}
|
||||||
@@ -96,11 +100,11 @@ public class NBEntityMetadataAction implements NBAction {
|
|||||||
if (relatedItem != null) {
|
if (relatedItem != null) {
|
||||||
link(context, item, relatedItem);
|
link(context, item, relatedItem);
|
||||||
} else {
|
} else {
|
||||||
Collection collection = item.getOwningCollection();
|
Collection collection = collectionService.retrieveCollectionByEntityType(context, item, entityType);
|
||||||
WorkspaceItem workspaceItem = workspaceItemService.create(context, collection, false);
|
WorkspaceItem workspaceItem = workspaceItemService.create(context, collection, false);
|
||||||
relatedItem = workspaceItem.getItem();
|
relatedItem = workspaceItem.getItem();
|
||||||
if (StringUtils.isNotBlank(entityType)) {
|
if (StringUtils.isNotBlank(entityType)) {
|
||||||
itemService.addMetadata(context, relatedItem, "relationship", "type", null, null, entityType);
|
itemService.addMetadata(context, relatedItem, "dspace", "entity", "type", null, entityType);
|
||||||
}
|
}
|
||||||
for (String key : entityMetadata.keySet()) {
|
for (String key : entityMetadata.keySet()) {
|
||||||
String value = getValue(message, key);
|
String value = getValue(message, key);
|
||||||
|
@@ -1017,6 +1017,58 @@ public class CollectionServiceImpl extends DSpaceObjectServiceImpl<Collection> i
|
|||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection retrieveCollectionByEntityType(Context context, Item item, String entityType)
|
||||||
|
throws SQLException {
|
||||||
|
Collection ownCollection = item.getOwningCollection();
|
||||||
|
return retrieveCollectionByEntityType(context, ownCollection.getCommunities(), entityType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Collection retrieveCollectionByEntityType(Context context, List<Community> communities, String entityType) {
|
||||||
|
|
||||||
|
for (Community community : communities) {
|
||||||
|
Collection collection = retrieveCollectionByCommunityAndEntityType(context, community, entityType);
|
||||||
|
if (collection != null) {
|
||||||
|
return collection;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Community community : communities) {
|
||||||
|
List<Community> parentCommunities = community.getParentCommunities();
|
||||||
|
Collection collection = retrieveCollectionByEntityType(context, parentCommunities, entityType);
|
||||||
|
if (collection != null) {
|
||||||
|
return collection;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return retrieveCollectionByCommunityAndEntityType(context, null, entityType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection retrieveCollectionByCommunityAndEntityType(Context context, Community community,
|
||||||
|
String entityType) {
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
List<Collection> collections;
|
||||||
|
try {
|
||||||
|
collections = findCollectionsWithSubmit(null, context, community, entityType, 0, 1);
|
||||||
|
} catch (SQLException | SearchServiceException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
if (collections != null && collections.size() > 0) {
|
||||||
|
return collections.get(0);
|
||||||
|
}
|
||||||
|
if (community != null) {
|
||||||
|
for (Community subCommunity : community.getSubcommunities()) {
|
||||||
|
Collection collection = retrieveCollectionByCommunityAndEntityType(context, subCommunity, entityType);
|
||||||
|
if (collection != null) {
|
||||||
|
return collection;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Collection> findCollectionsWithSubmit(String q, Context context, Community community, String entityType,
|
public List<Collection> findCollectionsWithSubmit(String q, Context context, Community community, String entityType,
|
||||||
int offset, int limit) throws SQLException, SearchServiceException {
|
int offset, int limit) throws SQLException, SearchServiceException {
|
||||||
|
@@ -412,6 +412,33 @@ public interface CollectionService
|
|||||||
public List<Collection> findCollectionsWithSubmit(String q, Context context, Community community,
|
public List<Collection> findCollectionsWithSubmit(String q, Context context, Community community,
|
||||||
int offset, int limit) throws SQLException, SearchServiceException;
|
int offset, int limit) throws SQLException, SearchServiceException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the first collection in the community or its descending that support
|
||||||
|
* the provided entityType
|
||||||
|
*
|
||||||
|
* @param context the DSpace context
|
||||||
|
* @param community the root from where the search start
|
||||||
|
* @param entityType the requested entity type
|
||||||
|
* @return the first collection in the community or its descending
|
||||||
|
* that support the provided entityType
|
||||||
|
*/
|
||||||
|
public Collection retrieveCollectionByCommunityAndEntityType(Context context, Community community,
|
||||||
|
String entityType);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the close collection to the item that support the provided
|
||||||
|
* entityType. Close mean the collection that can be reach with the minimum
|
||||||
|
* steps starting from the item (owningCollection, brothers collections, etc)
|
||||||
|
*
|
||||||
|
* @param context the DSpace context
|
||||||
|
* @param item the item from where the search start
|
||||||
|
* @param entityType the requested entity type
|
||||||
|
* @return the first collection in the community or its descending
|
||||||
|
* that support the provided entityType
|
||||||
|
*/
|
||||||
|
public Collection retrieveCollectionByEntityType(Context context, Item item, String entityType)
|
||||||
|
throws SQLException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Counts the number of Collection for which the current user has 'submit' privileges.
|
* Counts the number of Collection for which the current user has 'submit' privileges.
|
||||||
* NOTE: for better performance, this method retrieves its results from an index (cache)
|
* NOTE: for better performance, this method retrieves its results from an index (cache)
|
||||||
|
Reference in New Issue
Block a user