mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 18:14:26 +00:00
implemented findSubmitAuthorizedByCommunityAndEntityType end point
This commit is contained in:
@@ -1037,7 +1037,7 @@ public class CollectionServiceImpl extends DSpaceObjectServiceImpl<Collection> i
|
|||||||
if (buildFilter.length() > 0) {
|
if (buildFilter.length() > 0) {
|
||||||
buildFilter.append(" AND ");
|
buildFilter.append(" AND ");
|
||||||
}
|
}
|
||||||
buildFilter.append("dspace.entity.type:").append(entityType);
|
buildFilter.append("search.entitytype:").append(entityType);
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotBlank(q)) {
|
if (StringUtils.isNotBlank(q)) {
|
||||||
StringBuilder buildQuery = new StringBuilder();
|
StringBuilder buildQuery = new StringBuilder();
|
||||||
|
@@ -11,6 +11,7 @@ import java.io.IOException;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.SortedMap;
|
import java.util.SortedMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import javax.servlet.ServletInputStream;
|
import javax.servlet.ServletInputStream;
|
||||||
@@ -235,7 +236,7 @@ public class CollectionRestRepository extends DSpaceObjectRestRepository<Collect
|
|||||||
}
|
}
|
||||||
List<Collection> collections = cs.findCollectionsWithSubmit(query, context, null, entityTypeLabel,
|
List<Collection> collections = cs.findCollectionsWithSubmit(query, context, null, entityTypeLabel,
|
||||||
Math.toIntExact(pageable.getOffset()),
|
Math.toIntExact(pageable.getOffset()),
|
||||||
Math.toIntExact(pageable.getOffset() + pageable.getPageSize()));
|
Math.toIntExact(pageable.getPageSize()));
|
||||||
int tot = cs.countCollectionsWithSubmit(query, context, null, entityTypeLabel);
|
int tot = cs.countCollectionsWithSubmit(query, context, null, entityTypeLabel);
|
||||||
return converter.toRestPage(collections, pageable, tot, utils.obtainProjection());
|
return converter.toRestPage(collections, pageable, tot, utils.obtainProjection());
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@@ -243,6 +244,33 @@ public class CollectionRestRepository extends DSpaceObjectRestRepository<Collect
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SearchRestMethod(name = "findSubmitAuthorizedByCommunityAndEntityType")
|
||||||
|
public Page<CollectionRest> findSubmitAuthorizedByCommunityAndEntityType(
|
||||||
|
@Parameter(value = "query") String query,
|
||||||
|
@Parameter(value = "uuid", required = true) UUID communityUuid,
|
||||||
|
@Parameter(value = "entityType", required = true) String entityTypeLabel,
|
||||||
|
Pageable pageable) {
|
||||||
|
try {
|
||||||
|
Context context = obtainContext();
|
||||||
|
EntityType entityType = entityTypeService.findByEntityType(context, entityTypeLabel);
|
||||||
|
if (Objects.isNull(entityType)) {
|
||||||
|
throw new ResourceNotFoundException("There was no entityType found with label: " + entityTypeLabel);
|
||||||
|
}
|
||||||
|
Community community = communityService.find(context, communityUuid);
|
||||||
|
if (Objects.isNull(community)) {
|
||||||
|
throw new ResourceNotFoundException(
|
||||||
|
CommunityRest.CATEGORY + "." + CommunityRest.NAME + " with id: " + communityUuid + " not found");
|
||||||
|
}
|
||||||
|
List<Collection> collections = cs.findCollectionsWithSubmit(query, context, community, entityTypeLabel,
|
||||||
|
Math.toIntExact(pageable.getOffset()),
|
||||||
|
Math.toIntExact(pageable.getPageSize()));
|
||||||
|
int total = cs.countCollectionsWithSubmit(query, context, community, entityTypeLabel);
|
||||||
|
return converter.toRestPage(collections, pageable, total, utils.obtainProjection());
|
||||||
|
} catch (SQLException | SearchServiceException e) {
|
||||||
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@PreAuthorize("hasPermission(#id, 'COLLECTION', 'WRITE')")
|
@PreAuthorize("hasPermission(#id, 'COLLECTION', 'WRITE')")
|
||||||
protected void patch(Context context, HttpServletRequest request, String apiCategory, String model, UUID id,
|
protected void patch(Context context, HttpServletRequest request, String apiCategory, String model, UUID id,
|
||||||
|
@@ -3363,4 +3363,184 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes
|
|||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findSubmitAuthorizedCollectionsByCommunityAndEntityTest() throws Exception {
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
|
||||||
|
EntityType publication = EntityTypeBuilder.createEntityTypeBuilder(context, "Publication").build();
|
||||||
|
|
||||||
|
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||||
|
.withName("Parent Community")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||||
|
.withName("Sub Community")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Community child2 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||||
|
.withName("Sub Community Two")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
CollectionBuilder.createCollection(context, child1)
|
||||||
|
.withEntityType(publication.getLabel())
|
||||||
|
.withName("Test Collection 1")
|
||||||
|
.withSubmitterGroup(eperson)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Collection col2 = CollectionBuilder.createCollection(context, child2)
|
||||||
|
.withEntityType(publication.getLabel())
|
||||||
|
.withName("Publication Collection 2")
|
||||||
|
.withSubmitterGroup(eperson)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Collection col3 = CollectionBuilder.createCollection(context, child2)
|
||||||
|
.withEntityType(publication.getLabel())
|
||||||
|
.withName("Publication Collection 3")
|
||||||
|
.withSubmitterGroup(eperson)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Collection colWithoutEntity = CollectionBuilder.createCollection(context, child2)
|
||||||
|
.withName(" Test Collection 4")
|
||||||
|
.withSubmitterGroup(eperson)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
|
String token = getAuthToken(eperson.getEmail(), password);
|
||||||
|
|
||||||
|
getClient(token).perform(get("/api/core/collections/search/findSubmitAuthorizedByCommunityAndEntityType")
|
||||||
|
.param("uuid", child2.getID().toString())
|
||||||
|
.param("entityType", publication.getLabel()))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().contentType(contentType))
|
||||||
|
.andExpect(jsonPath("$.page.totalElements", equalTo(2)))
|
||||||
|
.andExpect(jsonPath("$._embedded.collections", Matchers.containsInAnyOrder(
|
||||||
|
CollectionMatcher.matchCollection(col2),
|
||||||
|
CollectionMatcher.matchCollection(col3))))
|
||||||
|
.andExpect(jsonPath("$._embedded.collections", not(containsInAnyOrder(
|
||||||
|
CollectionMatcher.matchCollection(colWithoutEntity)))));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findSubmitAuthorizedCollectionsByCommunityAndEntityWithQueryTest() throws Exception {
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
|
||||||
|
EntityType journal = EntityTypeBuilder.createEntityTypeBuilder(context, "Journal").build();
|
||||||
|
EntityType publication = EntityTypeBuilder.createEntityTypeBuilder(context, "Publication").build();
|
||||||
|
|
||||||
|
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||||
|
.withName("Parent Community")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Collection col1 = CollectionBuilder.createCollection(context, parentCommunity)
|
||||||
|
.withEntityType(journal.getLabel())
|
||||||
|
.withName("Test Collection 1")
|
||||||
|
.withSubmitterGroup(eperson)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Collection col2 = CollectionBuilder.createCollection(context, parentCommunity)
|
||||||
|
.withEntityType(journal.getLabel())
|
||||||
|
.withName("Publication Collection 2")
|
||||||
|
.withSubmitterGroup(eperson)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Collection col3 = CollectionBuilder.createCollection(context, parentCommunity)
|
||||||
|
.withEntityType(publication.getLabel())
|
||||||
|
.withName("Publication Collection 3 Test")
|
||||||
|
.withSubmitterGroup(eperson)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Collection colWithoutEntity = CollectionBuilder.createCollection(context, parentCommunity)
|
||||||
|
.withName("Collection 4 Test")
|
||||||
|
.withSubmitterGroup(eperson)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
|
String token = getAuthToken(eperson.getEmail(), password);
|
||||||
|
getClient(token).perform(get("/api/core/collections/search/findSubmitAuthorizedByCommunityAndEntityType")
|
||||||
|
.param("uuid", parentCommunity.getID().toString())
|
||||||
|
.param("entityType", journal.getLabel())
|
||||||
|
.param("query", "test"))
|
||||||
|
.andExpect(status().isOk()).andExpect(content().contentType(contentType))
|
||||||
|
.andExpect(jsonPath("$.page.totalElements", equalTo(1)))
|
||||||
|
.andExpect(jsonPath("$._embedded.collections", contains(CollectionMatcher.matchCollection(col1))))
|
||||||
|
.andExpect(jsonPath("$._embedded.collections",not(contains(
|
||||||
|
CollectionMatcher.matchCollection(colWithoutEntity)))));
|
||||||
|
|
||||||
|
getClient(token).perform(get("/api/core/collections/search/findSubmitAuthorizedByCommunityAndEntityType")
|
||||||
|
.param("uuid", parentCommunity.getID().toString())
|
||||||
|
.param("entityType", publication.getLabel())
|
||||||
|
.param("query", "publication"))
|
||||||
|
.andExpect(status().isOk()).andExpect(content().contentType(contentType))
|
||||||
|
.andExpect(jsonPath("$.page.totalElements", equalTo(1)))
|
||||||
|
.andExpect(jsonPath("$._embedded.collections", contains(CollectionMatcher.matchCollection(col3))))
|
||||||
|
.andExpect(jsonPath("$._embedded.collections", not(containsInAnyOrder(
|
||||||
|
CollectionMatcher.matchCollection(colWithoutEntity),
|
||||||
|
CollectionMatcher.matchCollection(col2)))));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findSubmitAuthorizedAllCollectionsByCommunityAndEntityBadRequestTest() throws Exception {
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
|
||||||
|
EntityType publication = EntityTypeBuilder.createEntityTypeBuilder(context, "Publication").build();
|
||||||
|
|
||||||
|
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||||
|
.withName("Parent Community")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
CollectionBuilder.createCollection(context, parentCommunity)
|
||||||
|
.withEntityType(publication.getLabel())
|
||||||
|
.withName("Test Collection 1")
|
||||||
|
.withSubmitterGroup(eperson)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
|
String token = getAuthToken(eperson.getEmail(), password);
|
||||||
|
getClient(token).perform(get("/api/core/collections/search/findSubmitAuthorizedByCommunityAndEntityType"))
|
||||||
|
.andExpect(status().isBadRequest());
|
||||||
|
|
||||||
|
// missing entityType param
|
||||||
|
getClient(token).perform(get("/api/core/collections/search/findSubmitAuthorizedByCommunityAndEntityType")
|
||||||
|
.param("uuid", parentCommunity.getID().toString()))
|
||||||
|
.andExpect(status().isBadRequest());
|
||||||
|
|
||||||
|
// missing community uuid param
|
||||||
|
getClient(token).perform(get("/api/core/collections/search/findSubmitAuthorizedByCommunityAndEntityType")
|
||||||
|
.param("entityType", publication.getLabel()))
|
||||||
|
.andExpect(status().isBadRequest());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findSubmitAuthorizedByCommunityAndEntityTypeNotFoundTest() throws Exception {
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
|
||||||
|
EntityType publication = EntityTypeBuilder.createEntityTypeBuilder(context, "Publication").build();
|
||||||
|
|
||||||
|
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||||
|
.withName("Parent Community")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
CollectionBuilder.createCollection(context, parentCommunity)
|
||||||
|
.withEntityType(publication.getLabel())
|
||||||
|
.withName("Test Collection 1")
|
||||||
|
.withSubmitterGroup(eperson)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
|
String token = getAuthToken(eperson.getEmail(), password);
|
||||||
|
getClient(token).perform(get("/api/core/collections/search/findSubmitAuthorizedByCommunityAndEntityType")
|
||||||
|
.param("entityType", publication.getLabel())
|
||||||
|
.param("uuid", UUID.randomUUID().toString()))
|
||||||
|
.andExpect(status().isNotFound());
|
||||||
|
|
||||||
|
getClient(token).perform(get("/api/core/collections/search/findSubmitAuthorizedByCommunityAndEntityType")
|
||||||
|
.param("entityType", "test")
|
||||||
|
.param("uuid", parentCommunity.getID().toString()))
|
||||||
|
.andExpect(status().isNotFound());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -265,7 +265,7 @@
|
|||||||
<field name="submit" type="string" indexed="true" stored="true" omitNorms="true" multiValued="true" docValues="true" />
|
<field name="submit" type="string" indexed="true" stored="true" omitNorms="true" multiValued="true" docValues="true" />
|
||||||
|
|
||||||
<!-- used to track entity type of collections -->
|
<!-- used to track entity type of collections -->
|
||||||
<field name="dspace.entity.type" type="string" indexed="true" stored="true" required="false" />
|
<field name="search.entitytype" type="string" indexed="true" stored="true" required="false" />
|
||||||
|
|
||||||
<!-- Community and collection hierarchy of the Item of interest (candidate for hierarchical facetting ) -->
|
<!-- Community and collection hierarchy of the Item of interest (candidate for hierarchical facetting ) -->
|
||||||
<field name="location" type="lowerCaseSort" indexed="true" stored="true" multiValued="true" required="false" omitNorms="true" />
|
<field name="location" type="lowerCaseSort" indexed="true" stored="true" multiValued="true" required="false" omitNorms="true" />
|
||||||
@@ -345,5 +345,6 @@
|
|||||||
or to add multiple fields to the same field for easier/faster searching. -->
|
or to add multiple fields to the same field for easier/faster searching. -->
|
||||||
|
|
||||||
<copyField source="*" dest="search_text"/>
|
<copyField source="*" dest="search_text"/>
|
||||||
|
<copyField source="dspace.entity.type" dest="search.entitytype"/>
|
||||||
|
|
||||||
</schema>
|
</schema>
|
||||||
|
Reference in New Issue
Block a user