Merge branch 'w2p-75465_change-to-embed-size' into w2p-75404_self-links-contain-embeds

This commit is contained in:
Yana De Pauw
2021-02-10 08:24:05 +01:00
13 changed files with 614 additions and 5 deletions

View File

@@ -124,6 +124,7 @@ public class CollectionIndexFactoryImpl extends DSpaceObjectIndexFactoryImpl<Ind
addContainerMetadataField(doc, highlightedMetadataFields, toIgnoreMetadataFields, "dc.rights.license",
rights_license);
addContainerMetadataField(doc, highlightedMetadataFields, toIgnoreMetadataFields, "dc.title", title);
doc.addField("dc.title_sort", title);
return doc;
}

View File

@@ -101,6 +101,7 @@ public class CommunityIndexFactoryImpl extends DSpaceObjectIndexFactoryImpl<Inde
"dc.description.tableofcontents", description_table);
addContainerMetadataField(doc, highlightedMetadataFields, toIgnoreMetadataFields, "dc.rights", rights);
addContainerMetadataField(doc, highlightedMetadataFields, toIgnoreMetadataFields, "dc.title", title);
doc.addField("dc.title_sort", title);
return doc;
}

View File

@@ -11,6 +11,7 @@ import org.dspace.app.rest.model.LinkRest;
import org.dspace.app.rest.model.RestAddressableModel;
import org.dspace.app.rest.model.RestModel;
import org.dspace.app.rest.model.hateoas.HALResource;
import org.springframework.data.domain.PageRequest;
import org.springframework.hateoas.Link;
/**
@@ -45,4 +46,10 @@ public abstract class AbstractProjection implements Projection {
public boolean allowLinking(HALResource halResource, LinkRest linkRest) {
return true;
}
@Override
public PageRequest getPagingOptions(String rel) {
return null;
}
}

View File

@@ -22,7 +22,7 @@ import org.springframework.hateoas.Link;
* the constructor. Embedding will be allowed if any of the given projections allow them. Linking will
* be allowed if all of the given projections allow them.
*/
public class CompositeProjection implements Projection {
public class CompositeProjection extends AbstractProjection {
public final static String NAME = "composite";

View File

@@ -7,11 +7,16 @@
*/
package org.dspace.app.rest.projection;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.dspace.app.rest.model.LinkRest;
import org.dspace.app.rest.model.RestAddressableModel;
import org.dspace.app.rest.model.hateoas.HALResource;
import org.springframework.data.domain.PageRequest;
import org.springframework.hateoas.Link;
/**
@@ -25,8 +30,32 @@ public class EmbedRelsProjection extends AbstractProjection {
private final Set<String> embedRels;
public EmbedRelsProjection(Set<String> embedRels) {
/**
* This variable contains a map with the key being the rel as a String and the value being the size of the embed
* as an Integer
*/
private Map<String, Integer> embedSizes;
/**
* The EmbedRelsProjection will take a set of embed relations and embed sizes as a parameter that will be added to
* the projection.
* The set of embedRels contains strings representing the embedded relation.
* The set of embedSizes contains a string containing the embedded relation followed by a "=" and the size of the
* embedded relation.
* Example: embed=collections&embed.size=collections=5 - These parameters will ensure that the embedded collections
* size will be limited to 5
* @param embedRels The embedded relations
* @param embedSizes The sizes of the embedded relations defined as {relation}={size}
*/
public EmbedRelsProjection(Set<String> embedRels, Set<String> embedSizes) {
this.embedRels = embedRels;
this.embedSizes = embedSizes.stream()
.filter(embedSize -> StringUtils.contains(embedSize, "="))
.map(embedSize -> embedSize.split("="))
.collect(Collectors.toMap(
split -> split[0],
split -> NumberUtils.toInt(split[1], 0)
));
}
@Override
@@ -62,4 +91,21 @@ public class EmbedRelsProjection extends AbstractProjection {
}
return false;
}
@Override
public PageRequest getPagingOptions(String rel) {
Integer size = embedSizes.get(rel);
if (size != null && size > 0) {
return PageRequest.of(0, size);
}
return null;
}
public Map<String, Integer> getEmbedSizes() {
return embedSizes;
}
public void setEmbedSizes(final Map<String, Integer> embedSizes) {
this.embedSizes = embedSizes;
}
}

View File

@@ -15,6 +15,7 @@ import org.dspace.app.rest.model.RestModel;
import org.dspace.app.rest.model.hateoas.HALResource;
import org.dspace.app.rest.repository.DSpaceRestRepository;
import org.dspace.app.rest.utils.Utils;
import org.springframework.data.domain.PageRequest;
import org.springframework.hateoas.Link;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RestController;
@@ -136,4 +137,11 @@ public interface Projection {
* @return true if allowed, false otherwise.
*/
boolean allowLinking(HALResource halResource, LinkRest linkRest);
/**
* This method will return the {@link PageRequest} object for a specific given rel
* @param rel The rel for which the {@link PageRequest} object will be made
* @return The {@link PageRequest} object for the given rel
*/
PageRequest getPagingOptions(String rel);
}

View File

@@ -71,6 +71,7 @@ public class CommunityCollectionLinkRepository extends AbstractDSpaceRestReposit
discoverQuery.addFilterQueries("location.parent:" + communityId);
discoverQuery.setStart(Math.toIntExact(pageable.getOffset()));
discoverQuery.setMaxResults(pageable.getPageSize());
discoverQuery.setSortField("dc.title_sort", DiscoverQuery.SORT_ORDER.asc);
DiscoverResult resp = searchService.search(context, scopeObject, discoverQuery);
long tot = resp.getTotalSearchResults();
for (IndexableObject solrCol : resp.getIndexableObjects()) {

View File

@@ -67,6 +67,7 @@ public class CommunitySubcommunityLinkRepository extends AbstractDSpaceRestRepos
discoverQuery.addFilterQueries("location.parent:" + communityId);
discoverQuery.setStart(Math.toIntExact(pageable.getOffset()));
discoverQuery.setMaxResults(pageable.getPageSize());
discoverQuery.setSortField("dc.title_sort", DiscoverQuery.SORT_ORDER.asc);
DiscoverResult resp = searchService.search(context, scopeObject, discoverQuery);
long tot = resp.getTotalSearchResults();
for (IndexableObject solrCommunities : resp.getIndexableObjects()) {

View File

@@ -547,8 +547,10 @@ public class Utils {
projections.add(converter.getProjection(projectionName));
}
if (!embedRels.isEmpty()) {
projections.add(new EmbedRelsProjection(embedRels));
Set<String> embedSizes = new HashSet<>(getValues(servletRequest, "embed.size"));
projections.add(new EmbedRelsProjection(embedRels, embedSizes));
}
if (projections.isEmpty()) {
@@ -676,7 +678,8 @@ public class Utils {
Method method = requireMethod(linkRepository.getClass(), linkRest.method());
Object contentId = getContentIdForLinkMethod(resource.getContent(), method);
try {
Object linkedObject = method.invoke(linkRepository, null, contentId, null, projection);
Object linkedObject = method
.invoke(linkRepository, null, contentId, projection.getPagingOptions(rel), projection);
resource.embedResource(rel, wrapForEmbedding(resource, linkedObject, link, oldLinks));
} catch (InvocationTargetException e) {
// This will be thrown from the LinkRepository if a Resource has been requested that'll try to embed

View File

@@ -33,6 +33,7 @@ import org.dspace.app.rest.converter.CollectionConverter;
import org.dspace.app.rest.matcher.CollectionMatcher;
import org.dspace.app.rest.matcher.CommunityMatcher;
import org.dspace.app.rest.matcher.HalMatcher;
import org.dspace.app.rest.matcher.ItemMatcher;
import org.dspace.app.rest.matcher.MetadataMatcher;
import org.dspace.app.rest.matcher.PageMatcher;
import org.dspace.app.rest.model.CollectionRest;
@@ -47,9 +48,12 @@ import org.dspace.builder.CollectionBuilder;
import org.dspace.builder.CommunityBuilder;
import org.dspace.builder.EPersonBuilder;
import org.dspace.builder.GroupBuilder;
import org.dspace.builder.ItemBuilder;
import org.dspace.builder.ResourcePolicyBuilder;
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.content.Item;
import org.dspace.content.service.CollectionService;
import org.dspace.core.Constants;
import org.dspace.eperson.EPerson;
import org.dspace.eperson.Group;
@@ -73,6 +77,9 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes
@Autowired
GroupService groupService;
@Autowired
CollectionService collectionService;
@Test
public void findAllTest() throws Exception {
@@ -2158,4 +2165,196 @@ public class CollectionRestRepositoryIT extends AbstractControllerIntegrationTes
.andExpect(jsonPath("$.page.totalElements", is(5)));
}
@Test
public void findOneTestWithEmbedsNoPageSize() throws Exception {
context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Collection collection = CollectionBuilder.createCollection(context, parentCommunity)
.withName("Collection")
.build();
Collection mappedCollection = CollectionBuilder.createCollection(context, parentCommunity)
.withName("Mapped Collection")
.build();
Item item0 = ItemBuilder.createItem(context, collection).withTitle("Item 0").build();
Item item1 = ItemBuilder.createItem(context, collection).withTitle("Item 1").build();
Item item2 = ItemBuilder.createItem(context, collection).withTitle("Item 2").build();
Item item3 = ItemBuilder.createItem(context, collection).withTitle("Item 3").build();
Item item4 = ItemBuilder.createItem(context, collection).withTitle("Item 4").build();
Item item5 = ItemBuilder.createItem(context, collection).withTitle("Item 5").build();
Item item6 = ItemBuilder.createItem(context, collection).withTitle("Item 6").build();
Item item7 = ItemBuilder.createItem(context, collection).withTitle("Item 7").build();
Item item8 = ItemBuilder.createItem(context, collection).withTitle("Item 8").build();
Item item9 = ItemBuilder.createItem(context, collection).withTitle("Item 9").build();
collectionService.addItem(context, mappedCollection, item0);
collectionService.addItem(context, mappedCollection, item1);
collectionService.addItem(context, mappedCollection, item2);
collectionService.addItem(context, mappedCollection, item3);
collectionService.addItem(context, mappedCollection, item4);
collectionService.addItem(context, mappedCollection, item5);
collectionService.addItem(context, mappedCollection, item6);
collectionService.addItem(context, mappedCollection, item7);
collectionService.addItem(context, mappedCollection, item8);
collectionService.addItem(context, mappedCollection, item9);
collectionService.update(context, mappedCollection);
context.restoreAuthSystemState();
getClient().perform(get("/api/core/collections/" + mappedCollection.getID())
.param("embed", "mappedItems"))
.andExpect(status().isOk())
.andExpect(jsonPath("$", CollectionMatcher.matchCollection(mappedCollection)))
.andExpect(jsonPath("$._embedded.mappedItems._embedded.mappedItems", Matchers.containsInAnyOrder(
ItemMatcher.matchItemProperties(item0),
ItemMatcher.matchItemProperties(item1),
ItemMatcher.matchItemProperties(item2),
ItemMatcher.matchItemProperties(item3),
ItemMatcher.matchItemProperties(item4),
ItemMatcher.matchItemProperties(item5),
ItemMatcher.matchItemProperties(item6),
ItemMatcher.matchItemProperties(item7),
ItemMatcher.matchItemProperties(item8),
ItemMatcher.matchItemProperties(item9)
)))
.andExpect(jsonPath("$._links.self.href",
Matchers.containsString("/api/core/collections/" + mappedCollection.getID())))
.andExpect(jsonPath("$._embedded.mappedItems.page.size", is(20)))
.andExpect(jsonPath("$._embedded.mappedItems.page.totalElements", is(10)));
}
@Test
public void findOneTestWithEmbedsWithPageSize() throws Exception {
context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Collection collection = CollectionBuilder.createCollection(context, parentCommunity)
.withName("Collection")
.build();
Collection mappedCollection = CollectionBuilder.createCollection(context, parentCommunity)
.withName("Mapped Collection")
.build();
Item item0 = ItemBuilder.createItem(context, collection).withTitle("Item 0").build();
Item item1 = ItemBuilder.createItem(context, collection).withTitle("Item 1").build();
Item item2 = ItemBuilder.createItem(context, collection).withTitle("Item 2").build();
Item item3 = ItemBuilder.createItem(context, collection).withTitle("Item 3").build();
Item item4 = ItemBuilder.createItem(context, collection).withTitle("Item 4").build();
Item item5 = ItemBuilder.createItem(context, collection).withTitle("Item 5").build();
Item item6 = ItemBuilder.createItem(context, collection).withTitle("Item 6").build();
Item item7 = ItemBuilder.createItem(context, collection).withTitle("Item 7").build();
Item item8 = ItemBuilder.createItem(context, collection).withTitle("Item 8").build();
Item item9 = ItemBuilder.createItem(context, collection).withTitle("Item 9").build();
collectionService.addItem(context, mappedCollection, item0);
collectionService.addItem(context, mappedCollection, item1);
collectionService.addItem(context, mappedCollection, item2);
collectionService.addItem(context, mappedCollection, item3);
collectionService.addItem(context, mappedCollection, item4);
collectionService.addItem(context, mappedCollection, item5);
collectionService.addItem(context, mappedCollection, item6);
collectionService.addItem(context, mappedCollection, item7);
collectionService.addItem(context, mappedCollection, item8);
collectionService.addItem(context, mappedCollection, item9);
collectionService.update(context, mappedCollection);
context.restoreAuthSystemState();
getClient().perform(get("/api/core/collections/" + mappedCollection.getID())
.param("embed", "mappedItems")
.param("embed.size", "mappedItems=5"))
.andExpect(status().isOk())
.andExpect(jsonPath("$", CollectionMatcher.matchCollection(mappedCollection)))
.andExpect(jsonPath("$._embedded.mappedItems._embedded.mappedItems", Matchers.containsInAnyOrder(
ItemMatcher.matchItemProperties(item0),
ItemMatcher.matchItemProperties(item1),
ItemMatcher.matchItemProperties(item2),
ItemMatcher.matchItemProperties(item3),
ItemMatcher.matchItemProperties(item4)
)))
.andExpect(jsonPath("$._links.self.href",
Matchers.containsString("/api/core/collections/" + mappedCollection.getID())))
.andExpect(jsonPath("$._embedded.mappedItems.page.size", is(5)))
.andExpect(jsonPath("$._embedded.mappedItems.page.totalElements", is(10)));
}
@Test
public void findOneTestWithEmbedsWithInvalidPageSize() throws Exception {
context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Collection collection = CollectionBuilder.createCollection(context, parentCommunity)
.withName("Collection")
.build();
Collection mappedCollection = CollectionBuilder.createCollection(context, parentCommunity)
.withName("Mapped Collection")
.build();
Item item0 = ItemBuilder.createItem(context, collection).withTitle("Item 0").build();
Item item1 = ItemBuilder.createItem(context, collection).withTitle("Item 1").build();
Item item2 = ItemBuilder.createItem(context, collection).withTitle("Item 2").build();
Item item3 = ItemBuilder.createItem(context, collection).withTitle("Item 3").build();
Item item4 = ItemBuilder.createItem(context, collection).withTitle("Item 4").build();
Item item5 = ItemBuilder.createItem(context, collection).withTitle("Item 5").build();
Item item6 = ItemBuilder.createItem(context, collection).withTitle("Item 6").build();
Item item7 = ItemBuilder.createItem(context, collection).withTitle("Item 7").build();
Item item8 = ItemBuilder.createItem(context, collection).withTitle("Item 8").build();
Item item9 = ItemBuilder.createItem(context, collection).withTitle("Item 9").build();
collectionService.addItem(context, mappedCollection, item0);
collectionService.addItem(context, mappedCollection, item1);
collectionService.addItem(context, mappedCollection, item2);
collectionService.addItem(context, mappedCollection, item3);
collectionService.addItem(context, mappedCollection, item4);
collectionService.addItem(context, mappedCollection, item5);
collectionService.addItem(context, mappedCollection, item6);
collectionService.addItem(context, mappedCollection, item7);
collectionService.addItem(context, mappedCollection, item8);
collectionService.addItem(context, mappedCollection, item9);
collectionService.update(context, mappedCollection);
context.restoreAuthSystemState();
getClient().perform(get("/api/core/collections/" + mappedCollection.getID())
.param("embed", "mappedItems")
.param("embed.size", "mappedItems=invalidPage"))
.andExpect(status().isOk())
.andExpect(jsonPath("$", CollectionMatcher.matchCollection(mappedCollection)))
.andExpect(jsonPath("$._embedded.mappedItems._embedded.mappedItems", Matchers.containsInAnyOrder(
ItemMatcher.matchItemProperties(item0),
ItemMatcher.matchItemProperties(item1),
ItemMatcher.matchItemProperties(item2),
ItemMatcher.matchItemProperties(item3),
ItemMatcher.matchItemProperties(item4),
ItemMatcher.matchItemProperties(item5),
ItemMatcher.matchItemProperties(item6),
ItemMatcher.matchItemProperties(item7),
ItemMatcher.matchItemProperties(item8),
ItemMatcher.matchItemProperties(item9)
)))
.andExpect(jsonPath("$._links.self.href",
Matchers.containsString("/api/core/collections/" + mappedCollection.getID())))
.andExpect(jsonPath("$._embedded.mappedItems.page.size", is(20)))
.andExpect(jsonPath("$._embedded.mappedItems.page.totalElements", is(10)));
}
}

View File

@@ -367,6 +367,202 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest
;
}
@Test
public void findOneTestWithEmbedsNoPageSize() 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 10 sub-communities
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child0 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 0")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 1")
.build();
Community child2 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 2")
.build();
Community child3 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 3")
.build();
Community child4 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 4")
.build();
Community child5 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 5")
.build();
Community child6 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 6")
.build();
Community child7 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 7")
.build();
Community child8 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 8")
.build();
Community child9 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 9")
.build();
context.restoreAuthSystemState();
getClient().perform(get("/api/core/communities/" + parentCommunity.getID())
.param("embed", "subcommunities"))
.andExpect(status().isOk())
.andExpect(jsonPath("$", CommunityMatcher.matchCommunity(parentCommunity)))
.andExpect(
jsonPath("$._embedded.subcommunities._embedded.subcommunities", Matchers.containsInAnyOrder(
CommunityMatcher.matchCommunity(child0),
CommunityMatcher.matchCommunity(child1),
CommunityMatcher.matchCommunity(child2),
CommunityMatcher.matchCommunity(child3),
CommunityMatcher.matchCommunity(child4),
CommunityMatcher.matchCommunity(child5),
CommunityMatcher.matchCommunity(child6),
CommunityMatcher.matchCommunity(child7),
CommunityMatcher.matchCommunity(child8),
CommunityMatcher.matchCommunity(child9)
)))
.andExpect(jsonPath("$._links.self.href",
Matchers.containsString("/api/core/communities/" + parentCommunity.getID())))
.andExpect(jsonPath("$._embedded.subcommunities.page.size", is(20)))
.andExpect(jsonPath("$._embedded.subcommunities.page.totalElements", is(10)));
}
@Test
public void findOneTestWithEmbedsWithPageSize() 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 10 sub-communities
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child0 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 0")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 1")
.build();
Community child2 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 2")
.build();
Community child3 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 3")
.build();
Community child4 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 4")
.build();
Community child5 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 5")
.build();
Community child6 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 6")
.build();
Community child7 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 7")
.build();
Community child8 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 8")
.build();
Community child9 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 9")
.build();
context.restoreAuthSystemState();
getClient().perform(get("/api/core/communities/" + parentCommunity.getID())
.param("embed", "subcommunities")
.param("embed.size", "subcommunities=5"))
.andExpect(status().isOk())
.andExpect(jsonPath("$", CommunityMatcher.matchCommunity(parentCommunity)))
.andExpect(
jsonPath("$._embedded.subcommunities._embedded.subcommunities", Matchers.containsInAnyOrder(
CommunityMatcher.matchCommunity(child0),
CommunityMatcher.matchCommunity(child1),
CommunityMatcher.matchCommunity(child2),
CommunityMatcher.matchCommunity(child3),
CommunityMatcher.matchCommunity(child4)
)))
.andExpect(jsonPath("$._links.self.href",
Matchers.containsString("/api/core/communities/" + parentCommunity.getID())))
.andExpect(jsonPath("$._embedded.subcommunities.page.size", is(5)))
.andExpect(jsonPath("$._embedded.subcommunities.page.totalElements", is(10)));
}
@Test
public void findOneTestWithEmbedsWithInvalidPageSize() 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 10 sub-communities
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child0 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 0")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 1")
.build();
Community child2 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 2")
.build();
Community child3 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 3")
.build();
Community child4 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 4")
.build();
Community child5 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 5")
.build();
Community child6 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 6")
.build();
Community child7 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 7")
.build();
Community child8 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 8")
.build();
Community child9 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community 9")
.build();
context.restoreAuthSystemState();
getClient().perform(get("/api/core/communities/" + parentCommunity.getID())
.param("embed", "subcommunities")
.param("embed.size", "subcommunities=invalidPage"))
.andExpect(status().isOk())
.andExpect(jsonPath("$", CommunityMatcher.matchCommunity(parentCommunity)))
.andExpect(
jsonPath("$._embedded.subcommunities._embedded.subcommunities", Matchers.containsInAnyOrder(
CommunityMatcher.matchCommunity(child0),
CommunityMatcher.matchCommunity(child1),
CommunityMatcher.matchCommunity(child2),
CommunityMatcher.matchCommunity(child3),
CommunityMatcher.matchCommunity(child4),
CommunityMatcher.matchCommunity(child5),
CommunityMatcher.matchCommunity(child6),
CommunityMatcher.matchCommunity(child7),
CommunityMatcher.matchCommunity(child8),
CommunityMatcher.matchCommunity(child9)
)))
.andExpect(jsonPath("$._links.self.href",
Matchers.containsString("/api/core/communities/" + parentCommunity.getID())))
.andExpect(jsonPath("$._embedded.subcommunities.page.size", is(20)))
.andExpect(jsonPath("$._embedded.subcommunities.page.totalElements", is(10)));
}
@Test
public void findAllNoDuplicatesOnMultipleCommunityTitlesTest() throws Exception {
context.turnOffAuthorisationSystem();

View File

@@ -35,6 +35,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.CharEncoding;
import org.dspace.app.rest.matcher.BitstreamMatcher;
import org.dspace.app.rest.matcher.BundleMatcher;
import org.dspace.app.rest.matcher.CollectionMatcher;
import org.dspace.app.rest.matcher.HalMatcher;
import org.dspace.app.rest.matcher.ItemMatcher;
@@ -46,6 +47,7 @@ import org.dspace.app.rest.model.patch.ReplaceOperation;
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
import org.dspace.app.rest.test.MetadataPatchSuite;
import org.dspace.builder.BitstreamBuilder;
import org.dspace.builder.BundleBuilder;
import org.dspace.builder.CollectionBuilder;
import org.dspace.builder.CommunityBuilder;
import org.dspace.builder.EPersonBuilder;
@@ -54,6 +56,7 @@ import org.dspace.builder.ItemBuilder;
import org.dspace.builder.ResourcePolicyBuilder;
import org.dspace.builder.WorkspaceItemBuilder;
import org.dspace.content.Bitstream;
import org.dspace.content.Bundle;
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.content.Item;
@@ -2740,5 +2743,148 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest {
}
@Test
public void findOneTestWithEmbedsWithNoPageSize() throws Exception {
context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Collection collection = CollectionBuilder.createCollection(context, parentCommunity)
.withName("Collection")
.build();
Item item = ItemBuilder.createItem(context, collection).withTitle("Item").build();
Bundle bundle0 = BundleBuilder.createBundle(context, item).withName("Bundle 0").build();
Bundle bundle1 = BundleBuilder.createBundle(context, item).withName("Bundle 1").build();
Bundle bundle2 = BundleBuilder.createBundle(context, item).withName("Bundle 2").build();
Bundle bundle3 = BundleBuilder.createBundle(context, item).withName("Bundle 3").build();
Bundle bundle4 = BundleBuilder.createBundle(context, item).withName("Bundle 4").build();
Bundle bundle5 = BundleBuilder.createBundle(context, item).withName("Bundle 5").build();
Bundle bundle6 = BundleBuilder.createBundle(context, item).withName("Bundle 6").build();
Bundle bundle7 = BundleBuilder.createBundle(context, item).withName("Bundle 7").build();
Bundle bundle8 = BundleBuilder.createBundle(context, item).withName("Bundle 8").build();
Bundle bundle9 = BundleBuilder.createBundle(context, item).withName("Bundle 9").build();
context.restoreAuthSystemState();
getClient().perform(get("/api/core/items/" + item.getID())
.param("embed", "bundles"))
.andExpect(status().isOk())
.andExpect(jsonPath("$", ItemMatcher.matchItemProperties(item)))
.andExpect(jsonPath("$._embedded.bundles._embedded.bundles",Matchers.containsInAnyOrder(
BundleMatcher.matchProperties(bundle0.getName(), bundle0.getID(), bundle0.getHandle(), bundle0.getType()),
BundleMatcher.matchProperties(bundle1.getName(), bundle1.getID(), bundle1.getHandle(), bundle1.getType()),
BundleMatcher.matchProperties(bundle2.getName(), bundle2.getID(), bundle2.getHandle(), bundle2.getType()),
BundleMatcher.matchProperties(bundle3.getName(), bundle3.getID(), bundle3.getHandle(), bundle3.getType()),
BundleMatcher.matchProperties(bundle4.getName(), bundle4.getID(), bundle4.getHandle(), bundle4.getType()),
BundleMatcher.matchProperties(bundle5.getName(), bundle5.getID(), bundle5.getHandle(), bundle5.getType()),
BundleMatcher.matchProperties(bundle6.getName(), bundle6.getID(), bundle6.getHandle(), bundle6.getType()),
BundleMatcher.matchProperties(bundle7.getName(), bundle7.getID(), bundle7.getHandle(), bundle7.getType()),
BundleMatcher.matchProperties(bundle8.getName(), bundle8.getID(), bundle8.getHandle(), bundle8.getType()),
BundleMatcher.matchProperties(bundle9.getName(), bundle9.getID(), bundle9.getHandle(), bundle9.getType())
)))
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/items/" + item.getID())))
.andExpect(jsonPath("$._embedded.bundles.page.size", is(20)))
.andExpect(jsonPath("$._embedded.bundles.page.totalElements", is(10)));
}
@Test
public void findOneTestWithEmbedsWithPageSize() throws Exception {
context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Collection collection = CollectionBuilder.createCollection(context, parentCommunity)
.withName("Collection")
.build();
Item item = ItemBuilder.createItem(context, collection).withTitle("Item").build();
Bundle bundle0 = BundleBuilder.createBundle(context, item).withName("Bundle 0").build();
Bundle bundle1 = BundleBuilder.createBundle(context, item).withName("Bundle 1").build();
Bundle bundle2 = BundleBuilder.createBundle(context, item).withName("Bundle 2").build();
Bundle bundle3 = BundleBuilder.createBundle(context, item).withName("Bundle 3").build();
Bundle bundle4 = BundleBuilder.createBundle(context, item).withName("Bundle 4").build();
Bundle bundle5 = BundleBuilder.createBundle(context, item).withName("Bundle 5").build();
Bundle bundle6 = BundleBuilder.createBundle(context, item).withName("Bundle 6").build();
Bundle bundle7 = BundleBuilder.createBundle(context, item).withName("Bundle 7").build();
Bundle bundle8 = BundleBuilder.createBundle(context, item).withName("Bundle 8").build();
Bundle bundle9 = BundleBuilder.createBundle(context, item).withName("Bundle 9").build();
context.restoreAuthSystemState();
getClient().perform(get("/api/core/items/" + item.getID())
.param("embed", "bundles")
.param("embed.size", "bundles=5"))
.andExpect(status().isOk())
.andExpect(jsonPath("$", ItemMatcher.matchItemProperties(item)))
.andExpect(jsonPath("$._embedded.bundles._embedded.bundles",Matchers.containsInAnyOrder(
BundleMatcher.matchProperties(bundle0.getName(), bundle0.getID(), bundle0.getHandle(), bundle0.getType()),
BundleMatcher.matchProperties(bundle1.getName(), bundle1.getID(), bundle1.getHandle(), bundle1.getType()),
BundleMatcher.matchProperties(bundle2.getName(), bundle2.getID(), bundle2.getHandle(), bundle2.getType()),
BundleMatcher.matchProperties(bundle3.getName(), bundle3.getID(), bundle3.getHandle(), bundle3.getType()),
BundleMatcher.matchProperties(bundle4.getName(), bundle4.getID(), bundle4.getHandle(), bundle4.getType())
)))
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/items/" + item.getID())))
.andExpect(jsonPath("$._embedded.bundles.page.size", is(5)))
.andExpect(jsonPath("$._embedded.bundles.page.totalElements", is(10)));
}
@Test
public void findOneTestWithEmbedsWithInvalidPageSize() throws Exception {
context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Collection collection = CollectionBuilder.createCollection(context, parentCommunity)
.withName("Collection")
.build();
Item item = ItemBuilder.createItem(context, collection).withTitle("Item").build();
Bundle bundle0 = BundleBuilder.createBundle(context, item).withName("Bundle 0").build();
Bundle bundle1 = BundleBuilder.createBundle(context, item).withName("Bundle 1").build();
Bundle bundle2 = BundleBuilder.createBundle(context, item).withName("Bundle 2").build();
Bundle bundle3 = BundleBuilder.createBundle(context, item).withName("Bundle 3").build();
Bundle bundle4 = BundleBuilder.createBundle(context, item).withName("Bundle 4").build();
Bundle bundle5 = BundleBuilder.createBundle(context, item).withName("Bundle 5").build();
Bundle bundle6 = BundleBuilder.createBundle(context, item).withName("Bundle 6").build();
Bundle bundle7 = BundleBuilder.createBundle(context, item).withName("Bundle 7").build();
Bundle bundle8 = BundleBuilder.createBundle(context, item).withName("Bundle 8").build();
Bundle bundle9 = BundleBuilder.createBundle(context, item).withName("Bundle 9").build();
context.restoreAuthSystemState();
getClient().perform(get("/api/core/items/" + item.getID())
.param("embed", "bundles")
.param("embed.size", "bundles=invalidPage"))
.andExpect(status().isOk())
.andExpect(jsonPath("$", ItemMatcher.matchItemProperties(item)))
.andExpect(jsonPath("$._embedded.bundles._embedded.bundles",Matchers.containsInAnyOrder(
BundleMatcher.matchProperties(bundle0.getName(), bundle0.getID(), bundle0.getHandle(), bundle0.getType()),
BundleMatcher.matchProperties(bundle1.getName(), bundle1.getID(), bundle1.getHandle(), bundle1.getType()),
BundleMatcher.matchProperties(bundle2.getName(), bundle2.getID(), bundle2.getHandle(), bundle2.getType()),
BundleMatcher.matchProperties(bundle3.getName(), bundle3.getID(), bundle3.getHandle(), bundle3.getType()),
BundleMatcher.matchProperties(bundle4.getName(), bundle4.getID(), bundle4.getHandle(), bundle4.getType()),
BundleMatcher.matchProperties(bundle5.getName(), bundle5.getID(), bundle5.getHandle(), bundle5.getType()),
BundleMatcher.matchProperties(bundle6.getName(), bundle6.getID(), bundle6.getHandle(), bundle6.getType()),
BundleMatcher.matchProperties(bundle7.getName(), bundle7.getID(), bundle7.getHandle(), bundle7.getType()),
BundleMatcher.matchProperties(bundle8.getName(), bundle8.getID(), bundle8.getHandle(), bundle8.getType()),
BundleMatcher.matchProperties(bundle9.getName(), bundle9.getID(), bundle9.getHandle(), bundle9.getType())
)))
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/items/" + item.getID())))
.andExpect(jsonPath("$._embedded.bundles.page.size", is(20)))
.andExpect(jsonPath("$._embedded.bundles.page.totalElements", is(10)));
}
}

View File

@@ -20,7 +20,7 @@ import org.springframework.hateoas.Link;
/**
* A projection for use in tests.
*/
public class MockProjection implements Projection {
public class MockProjection extends AbstractProjection {
public static final String NAME = "mock";