mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 10:04:21 +00:00
Implemented the Item Mapper functionality
This commit is contained in:

committed by
Andrew Wood

parent
e5ec0164f7
commit
b42dafe166
@@ -636,6 +636,7 @@ public class CollectionServiceImpl extends DSpaceObjectServiceImpl<Collection> i
|
||||
//Remove the item from the collection if we have multiple collections
|
||||
item.removeCollection(collection);
|
||||
|
||||
|
||||
}
|
||||
|
||||
context.addEvent(new Event(Event.REMOVE, Constants.COLLECTION,
|
||||
|
@@ -25,6 +25,8 @@ public class EmbeddedPageHeader {
|
||||
protected boolean totalElementsIsKnown;
|
||||
protected UriComponentsBuilder self;
|
||||
|
||||
|
||||
|
||||
public EmbeddedPageHeader(UriComponentsBuilder self, Page page, boolean totalElementsIsKnown) {
|
||||
this.page = page;
|
||||
this.self = self;
|
||||
|
@@ -27,8 +27,7 @@ public abstract class HALResource<T> extends Resource<T> {
|
||||
|
||||
protected final Map<String, Object> embedded = new HashMap<String, Object>();
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
@JsonUnwrapped
|
||||
|
||||
private EmbeddedPageHeader pageHeader;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
@@ -50,5 +49,9 @@ public abstract class HALResource<T> extends Resource<T> {
|
||||
public void setPageHeader(EmbeddedPageHeader page) {
|
||||
this.pageHeader = page;
|
||||
}
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
@JsonUnwrapped
|
||||
public EmbeddedPageHeader getPageHeader() {
|
||||
return pageHeader;
|
||||
}
|
||||
}
|
@@ -0,0 +1,126 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.rest.converter.CollectionConverter;
|
||||
import org.dspace.app.rest.link.HalLinkService;
|
||||
import org.dspace.app.rest.model.CollectionRest;
|
||||
import org.dspace.app.rest.model.MappingCollectionRestWrapper;
|
||||
import org.dspace.app.rest.model.hateoas.MappingCollectionResourceWrapper;
|
||||
import org.dspace.app.rest.utils.ContextUtil;
|
||||
import org.dspace.app.rest.utils.Utils;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.service.CollectionService;
|
||||
import org.dspace.content.service.ItemService;
|
||||
import org.dspace.core.Context;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/core/items/" +
|
||||
"{uuid:[0-9a-fxA-FX]{8}-[0-9a-fxA-FX]{4}-[0-9a-fxA-FX]{4}-[0-9a-fxA-FX]{4}-[0-9a-fxA-FX]{12}}/mappingCollections")
|
||||
public class MappingCollectionRestController {
|
||||
|
||||
private static final Logger log = Logger.getLogger(MappingCollectionRestController.class);
|
||||
|
||||
|
||||
@Autowired
|
||||
private ItemService itemService;
|
||||
|
||||
@Autowired
|
||||
private CollectionConverter collectionConverter;
|
||||
|
||||
@Autowired
|
||||
private CollectionService collectionService;
|
||||
|
||||
@Autowired
|
||||
Utils utils;
|
||||
|
||||
@Autowired
|
||||
private HalLinkService halLinkService;
|
||||
|
||||
@RequestMapping(method = {RequestMethod.GET, RequestMethod.HEAD})
|
||||
public MappingCollectionResourceWrapper retrieve(@PathVariable UUID uuid, HttpServletResponse response,
|
||||
HttpServletRequest request, Pageable pageable)
|
||||
throws SQLException {
|
||||
Context context = ContextUtil.obtainContext(request);
|
||||
Item item = itemService.find(context, uuid);
|
||||
List<Collection> collections = item.getCollections();
|
||||
UUID owningCollectionUuid = item.getOwningCollection().getID();
|
||||
List<CollectionRest> mappingCollectionRest = new LinkedList<>();
|
||||
for (Collection collection : collections) {
|
||||
if (collection.getID() != owningCollectionUuid) {
|
||||
mappingCollectionRest.add(collectionConverter.fromModel(collection));
|
||||
}
|
||||
}
|
||||
|
||||
MappingCollectionRestWrapper mappingCollectionRestWrapper = new MappingCollectionRestWrapper();
|
||||
mappingCollectionRestWrapper.setMappingCollectionRestList(mappingCollectionRest);
|
||||
mappingCollectionRestWrapper.setItem(item);
|
||||
MappingCollectionResourceWrapper mappingCollectionResourceWrapper = new MappingCollectionResourceWrapper(
|
||||
mappingCollectionRestWrapper, utils, pageable);
|
||||
|
||||
|
||||
halLinkService.addLinks(mappingCollectionResourceWrapper);
|
||||
|
||||
return mappingCollectionResourceWrapper;
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/{collectionUuid}")
|
||||
public void createCollectionToItemRelation(@PathVariable UUID uuid, @PathVariable UUID collectionUuid,
|
||||
HttpServletResponse response, HttpServletRequest request)
|
||||
throws SQLException, AuthorizeException {
|
||||
|
||||
Context context = ContextUtil.obtainContext(request);
|
||||
Collection collection = collectionService.find(context, collectionUuid);
|
||||
Item item = itemService.find(context, uuid);
|
||||
if (collection != null && item != null) {
|
||||
collectionService.addItem(context, collection, item);
|
||||
collectionService.update(context, collection);
|
||||
itemService.update(context, item);
|
||||
context.commit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = "/{collectionUuid}")
|
||||
public void deleteCollectionToItemRelation(@PathVariable UUID uuid, @PathVariable UUID collectionUuid,
|
||||
HttpServletResponse response, HttpServletRequest request)
|
||||
throws SQLException, AuthorizeException, IOException {
|
||||
|
||||
Context context = ContextUtil.obtainContext(request);
|
||||
Collection collection = collectionService.find(context, collectionUuid);
|
||||
Item item = itemService.find(context, uuid);
|
||||
if (collection != null && item != null) {
|
||||
UUID owningCollectionUuid = item.getOwningCollection().getID();
|
||||
if (collection.getID() != owningCollectionUuid && item.getCollections().contains(collection)) {
|
||||
collectionService.removeItem(context, collection, item);
|
||||
collectionService.update(context, collection);
|
||||
itemService.update(context, item);
|
||||
context.commit();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.rest.converter.ItemConverter;
|
||||
import org.dspace.app.rest.link.HalLinkService;
|
||||
import org.dspace.app.rest.model.ItemRest;
|
||||
import org.dspace.app.rest.model.MappingItemRestWrapper;
|
||||
import org.dspace.app.rest.model.hateoas.MappingItemResourceWrapper;
|
||||
import org.dspace.app.rest.utils.ContextUtil;
|
||||
import org.dspace.app.rest.utils.Utils;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.service.CollectionService;
|
||||
import org.dspace.content.service.ItemService;
|
||||
import org.dspace.core.Context;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/core/collections/" +
|
||||
"{uuid:[0-9a-fxA-FX]{8}-[0-9a-fxA-FX]{4}-[0-9a-fxA-FX]{4}-[0-9a-fxA-FX]{4}-[0-9a-fxA-FX]{12}}/mappingItems")
|
||||
public class MappingItemRestController {
|
||||
|
||||
private static final Logger log = Logger.getLogger(MappingItemRestController.class);
|
||||
|
||||
@Autowired
|
||||
private CollectionService collectionService;
|
||||
|
||||
@Autowired
|
||||
private ItemService itemService;
|
||||
|
||||
@Autowired
|
||||
private ItemConverter itemConverter;
|
||||
|
||||
@Autowired
|
||||
Utils utils;
|
||||
|
||||
@Autowired
|
||||
private HalLinkService halLinkService;
|
||||
|
||||
@RequestMapping(method = {RequestMethod.GET, RequestMethod.HEAD})
|
||||
public MappingItemResourceWrapper retrieve(@PathVariable UUID uuid, HttpServletResponse response,
|
||||
HttpServletRequest request, Pageable pageable) throws Exception {
|
||||
Context context = ContextUtil.obtainContext(request);
|
||||
Collection collection = collectionService.find(context, uuid);
|
||||
Iterator<Item> itemIterator = itemService.findByCollectionMapping(context, collection, pageable.getPageSize(),
|
||||
pageable.getOffset());
|
||||
int totalElements = itemService.countByCollectionMapping(context, collection);
|
||||
List<ItemRest> mappedItemRestList = new LinkedList<>();
|
||||
while (itemIterator.hasNext()) {
|
||||
Item item = itemIterator.next();
|
||||
if (item.getOwningCollection().getID() != uuid) {
|
||||
mappedItemRestList.add(itemConverter.fromModel(item));
|
||||
}
|
||||
}
|
||||
|
||||
MappingItemRestWrapper mappingItemRestWrapper = new MappingItemRestWrapper();
|
||||
mappingItemRestWrapper.setMappingItemRestList(mappedItemRestList);
|
||||
mappingItemRestWrapper.setCollectionUuid(uuid);
|
||||
MappingItemResourceWrapper mappingItemResourceWrapper =
|
||||
new MappingItemResourceWrapper(mappingItemRestWrapper, utils, totalElements);
|
||||
|
||||
halLinkService.addLinks(mappingItemResourceWrapper, pageable);
|
||||
return mappingItemResourceWrapper;
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 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.link;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.dspace.app.rest.model.MappingCollectionRestWrapper;
|
||||
import org.dspace.app.rest.model.hateoas.MappingCollectionResourceWrapper;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
@Component
|
||||
public class MappingCollectionResourceWrapperHalLinkFactory
|
||||
extends MappingCollectionRestHalLinkFactory<MappingCollectionResourceWrapper> {
|
||||
|
||||
protected void addLinks(MappingCollectionResourceWrapper halResource, Pageable pageable, LinkedList<Link> list)
|
||||
throws Exception {
|
||||
|
||||
MappingCollectionRestWrapper mappingCollectionRestWrapper = halResource.getContent();
|
||||
if (mappingCollectionRestWrapper != null) {
|
||||
|
||||
UriComponentsBuilder uriBuilderSelfLink = uriBuilder(getMethodOn()
|
||||
.retrieve(
|
||||
mappingCollectionRestWrapper.getItem().getID(),
|
||||
null, null, null));
|
||||
list.add(buildLink(Link.REL_SELF, uriBuilderSelfLink.build().toString()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected Class<MappingCollectionResourceWrapper> getResourceClass() {
|
||||
return MappingCollectionResourceWrapper.class;
|
||||
}
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* 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.link;
|
||||
|
||||
import org.dspace.app.rest.MappingCollectionRestController;
|
||||
|
||||
public abstract class MappingCollectionRestHalLinkFactory<T>
|
||||
extends HalLinkFactory<T, MappingCollectionRestController> {
|
||||
|
||||
@Override
|
||||
protected Class<MappingCollectionRestController> getControllerClass() {
|
||||
return MappingCollectionRestController.class;
|
||||
}
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* 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.link;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.dspace.app.rest.model.MappingItemRestWrapper;
|
||||
import org.dspace.app.rest.model.hateoas.EmbeddedPageHeader;
|
||||
import org.dspace.app.rest.model.hateoas.ItemResource;
|
||||
import org.dspace.app.rest.model.hateoas.MappingItemResourceWrapper;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
@Component
|
||||
public class MappingItemResourceWrapperHalLinkFactory
|
||||
extends MappingItemRestHalLinkFactory<MappingItemResourceWrapper> {
|
||||
protected void addLinks(MappingItemResourceWrapper halResource, Pageable pageable, LinkedList<Link> list)
|
||||
throws Exception {
|
||||
|
||||
MappingItemRestWrapper mappingItemRestWrapper = halResource.getContent();
|
||||
if (mappingItemRestWrapper != null) {
|
||||
|
||||
PageImpl<ItemResource> page = new PageImpl<>(halResource.getItemResources(), pageable,
|
||||
halResource.getTotalElements());
|
||||
|
||||
halResource.setPageHeader(new EmbeddedPageHeader(getSelfLink(mappingItemRestWrapper, pageable),
|
||||
page, true));
|
||||
}
|
||||
|
||||
}
|
||||
public String getSelfLink(MappingItemRestWrapper mappingItemRestWrapper, Pageable pageable) throws Exception {
|
||||
if (mappingItemRestWrapper != null) {
|
||||
UriComponentsBuilder uriBuilderSelfLink = uriBuilder(getMethodOn()
|
||||
.retrieve(
|
||||
mappingItemRestWrapper.getCollectionUuid(),
|
||||
null, null, pageable));
|
||||
return uriBuilderSelfLink.build().toString();
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
protected Class<MappingItemResourceWrapper> getResourceClass() {
|
||||
return MappingItemResourceWrapper.class;
|
||||
}
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* 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.link;
|
||||
|
||||
import org.dspace.app.rest.MappingItemRestController;
|
||||
|
||||
public abstract class MappingItemRestHalLinkFactory<T> extends HalLinkFactory<T, MappingItemRestController> {
|
||||
|
||||
@Override
|
||||
protected Class<MappingItemRestController> getControllerClass() {
|
||||
return MappingItemRestController.class;
|
||||
}
|
||||
}
|
@@ -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.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.dspace.app.rest.MappingCollectionRestController;
|
||||
import org.dspace.content.Item;
|
||||
|
||||
public class MappingCollectionRestWrapper implements RestAddressableModel {
|
||||
|
||||
@JsonIgnore
|
||||
private List<CollectionRest> mappingCollectionRestList;
|
||||
|
||||
@JsonIgnore
|
||||
private Item item;
|
||||
public List<CollectionRest> getMappingCollectionRestList() {
|
||||
return mappingCollectionRestList;
|
||||
}
|
||||
|
||||
public void setMappingCollectionRestList(List<CollectionRest> mappingCollectionRestList) {
|
||||
this.mappingCollectionRestList = mappingCollectionRestList;
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
return "core";
|
||||
}
|
||||
|
||||
public Class getController() {
|
||||
return MappingCollectionRestController.class;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return "collection";
|
||||
}
|
||||
|
||||
public Item getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public void setItem(Item item) {
|
||||
this.item = item;
|
||||
}
|
||||
}
|
@@ -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.model;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.dspace.app.rest.MappingItemRestController;
|
||||
|
||||
public class MappingItemRestWrapper implements RestAddressableModel {
|
||||
|
||||
@JsonIgnore
|
||||
private List<ItemRest> mappingItemRestList;
|
||||
|
||||
private UUID collectionUuid;
|
||||
|
||||
public UUID getCollectionUuid() {
|
||||
return collectionUuid;
|
||||
}
|
||||
|
||||
public void setCollectionUuid(UUID collectionUuid) {
|
||||
this.collectionUuid = collectionUuid;
|
||||
}
|
||||
|
||||
public List<ItemRest> getMappingItemRestList() {
|
||||
return mappingItemRestList;
|
||||
}
|
||||
|
||||
public void setMappingItemRestList(List<ItemRest> mappingItemRestList) {
|
||||
this.mappingItemRestList = mappingItemRestList;
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
return "core";
|
||||
}
|
||||
|
||||
public Class getController() {
|
||||
return MappingItemRestController.class;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return "collection";
|
||||
}
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* 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.model.hateoas;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.dspace.app.rest.model.CollectionRest;
|
||||
import org.dspace.app.rest.model.MappingCollectionRestWrapper;
|
||||
import org.dspace.app.rest.utils.Utils;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
public class MappingCollectionResourceWrapper extends HALResource<MappingCollectionRestWrapper> {
|
||||
|
||||
@JsonIgnore
|
||||
private List<CollectionResource> collectionResources = new LinkedList<>();
|
||||
|
||||
public MappingCollectionResourceWrapper(MappingCollectionRestWrapper content, Utils utils, Pageable pageable,
|
||||
String... rels) {
|
||||
super(content);
|
||||
addEmbeds(content, utils, pageable);
|
||||
}
|
||||
|
||||
private void addEmbeds(final MappingCollectionRestWrapper data, final Utils utils, Pageable pageable) {
|
||||
|
||||
for (CollectionRest collectionRest : data.getMappingCollectionRestList()) {
|
||||
|
||||
collectionResources.add(new CollectionResource(collectionRest, utils));
|
||||
}
|
||||
|
||||
|
||||
embedResource("mappingCollections", collectionResources);
|
||||
|
||||
}
|
||||
|
||||
public List<CollectionResource> getCollectionResources() {
|
||||
return collectionResources;
|
||||
}
|
||||
}
|
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* 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.model.hateoas;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.dspace.app.rest.model.ItemRest;
|
||||
import org.dspace.app.rest.model.MappingItemRestWrapper;
|
||||
import org.dspace.app.rest.utils.Utils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class MappingItemResourceWrapper extends HALResource<MappingItemRestWrapper> {
|
||||
private static final Logger log = LoggerFactory.getLogger(MappingItemResourceWrapper.class);
|
||||
|
||||
@JsonIgnore
|
||||
private List<ItemResource> itemResources;
|
||||
@JsonIgnore
|
||||
private Integer totalElements;
|
||||
|
||||
public MappingItemResourceWrapper(MappingItemRestWrapper content, Utils utils,
|
||||
Integer totalElements, String... rels) {
|
||||
super(content);
|
||||
embed(utils);
|
||||
this.totalElements = totalElements;
|
||||
}
|
||||
|
||||
private void embed(Utils utils) {
|
||||
List<ItemResource> itemResources = new LinkedList<>();
|
||||
for (ItemRest itemRest : getContent().getMappingItemRestList()) {
|
||||
itemResources.add(new ItemResource(itemRest, utils));
|
||||
}
|
||||
this.itemResources = itemResources;
|
||||
embedResource("mappingItems", itemResources);
|
||||
}
|
||||
|
||||
public List<ItemResource> getItemResources() {
|
||||
return itemResources;
|
||||
}
|
||||
|
||||
public Integer getTotalElements() {
|
||||
return totalElements;
|
||||
}
|
||||
}
|
@@ -0,0 +1,647 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import org.dspace.app.rest.builder.CollectionBuilder;
|
||||
import org.dspace.app.rest.builder.CommunityBuilder;
|
||||
import org.dspace.app.rest.builder.ItemBuilder;
|
||||
import org.dspace.app.rest.matcher.CollectionMatcher;
|
||||
import org.dspace.app.rest.matcher.ItemMatcher;
|
||||
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.service.CollectionService;
|
||||
import org.dspace.content.service.ItemService;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public class MappingCollectionRestRepositoryIT extends AbstractControllerIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private CollectionService collectionService;
|
||||
|
||||
@Autowired
|
||||
private ItemService itemService;
|
||||
|
||||
@Test
|
||||
public void itemHasNoExtraCollectionsAndCollectionHasNoExtraItemsTest() throws Exception {
|
||||
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();
|
||||
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();
|
||||
|
||||
//2. Three public items that are readable by Anonymous with different subjects
|
||||
Item publicItem1 = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
Item publicItem2 = ItemBuilder.createItem(context, col2)
|
||||
.withTitle("Public item 2")
|
||||
.withIssueDate("2016-02-13")
|
||||
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
|
||||
.withSubject("TestingForMore").withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
Item publicItem3 = ItemBuilder.createItem(context, col2)
|
||||
.withTitle("Public item 3")
|
||||
.withIssueDate("2016-02-13")
|
||||
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
|
||||
.withSubject("AnotherTest").withSubject("TestingForMore")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
|
||||
// collectionService.addItem(context, col2, publicItem1);
|
||||
// collectionService.update(context, col2);
|
||||
// itemService.update(context, publicItem1);
|
||||
|
||||
getClient().perform(get("/api/core/items/" + publicItem1.getID() + "/mappingCollections"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$._embedded.mappingCollections", Matchers.not(Matchers.contains(
|
||||
CollectionMatcher.matchCollectionEntry("Collection 1", col1.getID(), col1.getHandle()),
|
||||
CollectionMatcher.matchCollectionEntry("Collection 3", col2.getID(), col2.getHandle()))
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/items")))
|
||||
;
|
||||
|
||||
getClient().perform(get("/api/core/collections/" + col1.getID() + "/mappingItems"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$._embedded.mappingItems", Matchers.not(Matchers.contains(
|
||||
ItemMatcher.matchItemProperties(publicItem1))
|
||||
)));
|
||||
getClient().perform(get("/api/core/collections/" + col2.getID() + "/mappingItems"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$._embedded.mappingItems", Matchers.not(Matchers.contains(
|
||||
ItemMatcher.matchItemProperties(publicItem1))
|
||||
)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itemAndCollectionHaveOneMappingTest() throws Exception {
|
||||
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();
|
||||
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();
|
||||
|
||||
//2. Three public items that are readable by Anonymous with different subjects
|
||||
Item publicItem1 = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
Item publicItem2 = ItemBuilder.createItem(context, col2)
|
||||
.withTitle("Public item 2")
|
||||
.withIssueDate("2016-02-13")
|
||||
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
|
||||
.withSubject("TestingForMore").withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
Item publicItem3 = ItemBuilder.createItem(context, col2)
|
||||
.withTitle("Public item 3")
|
||||
.withIssueDate("2016-02-13")
|
||||
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
|
||||
.withSubject("AnotherTest").withSubject("TestingForMore")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
|
||||
String adminToken = getAuthToken(admin.getEmail(), password);
|
||||
|
||||
getClient(adminToken)
|
||||
.perform(post("/api/core/items/" + publicItem1.getID() + "/mappingCollections/" + col2.getID()));
|
||||
|
||||
getClient().perform(get("/api/core/items/" + publicItem1.getID() + "/mappingCollections"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$._embedded.mappingCollections", Matchers.containsInAnyOrder(
|
||||
CollectionMatcher.matchCollectionEntry("Collection 2", col2.getID(), col2.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/items")))
|
||||
;
|
||||
|
||||
getClient().perform(get("/api/core/collections/" + col1.getID() + "/mappingItems"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$._embedded.mappingItems", Matchers.not(Matchers.contains(
|
||||
ItemMatcher.matchItemProperties(publicItem1))
|
||||
)));
|
||||
getClient().perform(get("/api/core/collections/" + col2.getID() + "/mappingItems"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$._embedded.mappingItems", Matchers.contains(
|
||||
ItemMatcher.matchItemProperties(publicItem1))
|
||||
));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itemAndTwoCollectionsHaveTwoMappingsTest() throws Exception {
|
||||
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();
|
||||
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();
|
||||
Collection col3 = CollectionBuilder.createCollection(context, child1).withName("Collection 3").build();
|
||||
|
||||
//2. Three public items that are readable by Anonymous with different subjects
|
||||
Item publicItem1 = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
Item publicItem2 = ItemBuilder.createItem(context, col2)
|
||||
.withTitle("Public item 2")
|
||||
.withIssueDate("2016-02-13")
|
||||
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
|
||||
.withSubject("TestingForMore").withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
Item publicItem3 = ItemBuilder.createItem(context, col2)
|
||||
.withTitle("Public item 3")
|
||||
.withIssueDate("2016-02-13")
|
||||
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
|
||||
.withSubject("AnotherTest").withSubject("TestingForMore")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
|
||||
String adminToken = getAuthToken(admin.getEmail(), password);
|
||||
getClient(adminToken)
|
||||
.perform(post("/api/core/items/" + publicItem1.getID() + "/mappingCollections/" + col2.getID()));
|
||||
getClient(adminToken)
|
||||
.perform(post("/api/core/items/" + publicItem1.getID() + "/mappingCollections/" + col3.getID()));
|
||||
|
||||
getClient().perform(get("/api/core/items/" + publicItem1.getID() + "/mappingCollections"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$._embedded.mappingCollections", Matchers.containsInAnyOrder(
|
||||
CollectionMatcher.matchCollectionEntry("Collection 2", col2.getID(), col2.getHandle()),
|
||||
CollectionMatcher.matchCollectionEntry("Collection 3", col3.getID(), col3.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/items")))
|
||||
;
|
||||
|
||||
getClient().perform(get("/api/core/collections/" + col1.getID() + "/mappingItems"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$._embedded.mappingItems", Matchers.not(Matchers.contains(
|
||||
ItemMatcher.matchItemProperties(publicItem1))
|
||||
)));
|
||||
getClient().perform(get("/api/core/collections/" + col2.getID() + "/mappingItems"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$._embedded.mappingItems", Matchers.contains(
|
||||
ItemMatcher.matchItemProperties(publicItem1))
|
||||
));
|
||||
getClient().perform(get("/api/core/collections/" + col3.getID() + "/mappingItems"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$._embedded.mappingItems", Matchers.contains(
|
||||
ItemMatcher.matchItemProperties(publicItem1))
|
||||
));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itemHasNoDuplicatesInMappingCollectionAndCollectionHasNoDuplicatesInMappingItemsTest()
|
||||
throws Exception {
|
||||
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();
|
||||
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();
|
||||
Collection col3 = CollectionBuilder.createCollection(context, child1).withName("Collection 3").build();
|
||||
|
||||
//2. Three public items that are readable by Anonymous with different subjects
|
||||
Item publicItem1 = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
Item publicItem2 = ItemBuilder.createItem(context, col2)
|
||||
.withTitle("Public item 2")
|
||||
.withIssueDate("2016-02-13")
|
||||
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
|
||||
.withSubject("TestingForMore").withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
Item publicItem3 = ItemBuilder.createItem(context, col2)
|
||||
.withTitle("Public item 3")
|
||||
.withIssueDate("2016-02-13")
|
||||
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
|
||||
.withSubject("AnotherTest").withSubject("TestingForMore")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
|
||||
String adminToken = getAuthToken(admin.getEmail(), password);
|
||||
getClient(adminToken)
|
||||
.perform(post("/api/core/items/" + publicItem1.getID() + "/mappingCollections/" + col2.getID()));
|
||||
getClient(adminToken)
|
||||
.perform(post("/api/core/items/" + publicItem1.getID() + "/mappingCollections/" + col2.getID()));
|
||||
getClient(adminToken)
|
||||
.perform(post("/api/core/items/" + publicItem1.getID() + "/mappingCollections/" + col3.getID()));
|
||||
|
||||
getClient().perform(get("/api/core/items/" + publicItem1.getID() + "/mappingCollections"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$._embedded.mappingCollections", Matchers.containsInAnyOrder(
|
||||
CollectionMatcher.matchCollectionEntry("Collection 2", col2.getID(), col2.getHandle()),
|
||||
CollectionMatcher.matchCollectionEntry("Collection 3", col3.getID(), col3.getHandle())
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/items")))
|
||||
;
|
||||
|
||||
getClient().perform(get("/api/core/collections/" + col2.getID() + "/mappingItems"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$._embedded.mappingItems", Matchers.not(Matchers.containsInAnyOrder(
|
||||
ItemMatcher.matchItemProperties(publicItem1),
|
||||
ItemMatcher.matchItemProperties(publicItem1)))
|
||||
));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itemHasNoOriginalCollectionInMappingCollectionAndCollectionHasNoOriginalItemInMappingItemsTest()
|
||||
throws Exception {
|
||||
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();
|
||||
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();
|
||||
Collection col3 = CollectionBuilder.createCollection(context, child1).withName("Collection 3").build();
|
||||
|
||||
//2. Three public items that are readable by Anonymous with different subjects
|
||||
Item publicItem1 = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
Item publicItem2 = ItemBuilder.createItem(context, col2)
|
||||
.withTitle("Public item 2")
|
||||
.withIssueDate("2016-02-13")
|
||||
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
|
||||
.withSubject("TestingForMore").withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
Item publicItem3 = ItemBuilder.createItem(context, col2)
|
||||
.withTitle("Public item 3")
|
||||
.withIssueDate("2016-02-13")
|
||||
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
|
||||
.withSubject("AnotherTest").withSubject("TestingForMore")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
|
||||
String adminToken = getAuthToken(admin.getEmail(), password);
|
||||
getClient(adminToken)
|
||||
.perform(post("/api/core/items/" + publicItem1.getID() + "/mappingCollections/" + col2.getID()));
|
||||
getClient(adminToken)
|
||||
.perform(post("/api/core/items/" + publicItem1.getID() + "/mappingCollections/" + col3.getID()));
|
||||
getClient(adminToken)
|
||||
.perform(post("/api/core/items/" + publicItem1.getID() + "/mappingCollections/" + col3.getID()));
|
||||
getClient(adminToken)
|
||||
.perform(post("/api/core/items/" + publicItem1.getID() + "/mappingCollections/" + col1.getID()));
|
||||
getClient().perform(get("/api/core/items/" + publicItem1.getID() + "/mappingCollections"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$._embedded.mappingCollections", Matchers.not(Matchers.contains(
|
||||
CollectionMatcher.matchCollectionEntry("Collection 1", col1.getID(), col1.getHandle())
|
||||
))))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/items")))
|
||||
;
|
||||
getClient().perform(get("/api/core/collections/" + col1.getID() + "/mappingItems"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$._embedded.mappingItems", Matchers.not(Matchers.contains(
|
||||
ItemMatcher.matchItemProperties(publicItem1))
|
||||
)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeMappingCollectionTest() throws Exception {
|
||||
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();
|
||||
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();
|
||||
Collection col3 = CollectionBuilder.createCollection(context, child1).withName("Collection 3").build();
|
||||
|
||||
//2. Three public items that are readable by Anonymous with different subjects
|
||||
Item publicItem1 = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
Item publicItem2 = ItemBuilder.createItem(context, col2)
|
||||
.withTitle("Public item 2")
|
||||
.withIssueDate("2016-02-13")
|
||||
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
|
||||
.withSubject("TestingForMore").withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
Item publicItem3 = ItemBuilder.createItem(context, col2)
|
||||
.withTitle("Public item 3")
|
||||
.withIssueDate("2016-02-13")
|
||||
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
|
||||
.withSubject("AnotherTest").withSubject("TestingForMore")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
|
||||
String adminToken = getAuthToken(admin.getEmail(), password);
|
||||
getClient(adminToken)
|
||||
.perform(post("/api/core/items/" + publicItem1.getID() + "/mappingCollections/" + col2.getID()));
|
||||
getClient(adminToken)
|
||||
.perform(post("/api/core/items/" + publicItem1.getID() + "/mappingCollections/" + col2.getID()));
|
||||
getClient(adminToken)
|
||||
.perform(post("/api/core/items/" + publicItem1.getID() + "/mappingCollections/" + col1.getID()));
|
||||
getClient(adminToken)
|
||||
.perform(post("/api/core/items/" + publicItem1.getID() + "/mappingCollections/" + col3.getID()));
|
||||
itemService.update(context, publicItem1);
|
||||
|
||||
getClient().perform(get("/api/core/items/" + publicItem1.getID() + "/mappingCollections"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$._embedded.mappingCollections", Matchers.not(Matchers.contains(
|
||||
CollectionMatcher.matchCollectionEntry("Collection 1", col1.getID(), col1.getHandle()))
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/items")))
|
||||
;
|
||||
getClient().perform(get("/api/core/collections/" + col1.getID() + "/mappingItems"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$._embedded.mappingItems", Matchers.not(Matchers.contains(
|
||||
ItemMatcher.matchItemProperties(publicItem1))
|
||||
)));
|
||||
|
||||
getClient(adminToken)
|
||||
.perform(delete("/api/core/items/" + publicItem1.getID() + "/mappingCollections/" + col2.getID()));
|
||||
|
||||
getClient().perform(get("/api/core/items/" + publicItem1.getID() + "/mappingCollections"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$._embedded.mappingCollections", Matchers.not(Matchers.containsInAnyOrder(
|
||||
CollectionMatcher.matchCollectionEntry("Collection 2", col2.getID(), col2.getHandle()),
|
||||
CollectionMatcher.matchCollectionEntry("Collection 1", col1.getID(), col1.getHandle())
|
||||
))))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/items")))
|
||||
;
|
||||
getClient().perform(get("/api/core/collections/" + col1.getID() + "/mappingItems"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$._embedded.mappingItems", Matchers.not(Matchers.contains(
|
||||
ItemMatcher.matchItemProperties(publicItem1))
|
||||
)));
|
||||
getClient().perform(get("/api/core/collections/" + col2.getID() + "/mappingItems"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$._embedded.mappingItems", Matchers.not(Matchers.contains(
|
||||
ItemMatcher.matchItemProperties(publicItem1))
|
||||
)));
|
||||
getClient().perform(get("/api/core/collections/" + col3.getID() + "/mappingItems"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$._embedded.mappingItems", Matchers.contains(
|
||||
ItemMatcher.matchItemProperties(publicItem1))
|
||||
));
|
||||
|
||||
getClient(adminToken)
|
||||
.perform(delete("/api/core/items/" + publicItem1.getID() + "/mappingCollections/" + col1.getID()));
|
||||
|
||||
|
||||
getClient().perform(get("/api/core/items/" + publicItem1.getID() + "/mappingCollections"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$._embedded.mappingCollections", Matchers.not(Matchers.containsInAnyOrder(
|
||||
CollectionMatcher.matchCollectionEntry("Collection 2", col2.getID(), col2.getHandle()),
|
||||
CollectionMatcher.matchCollectionEntry("Collection 1", col1.getID(), col1.getHandle())
|
||||
))))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/items")))
|
||||
;
|
||||
getClient().perform(get("/api/core/collections/" + col1.getID() + "/mappingItems"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$._embedded.mappingItems", Matchers.not(Matchers.contains(
|
||||
ItemMatcher.matchItemProperties(publicItem1))
|
||||
)));
|
||||
getClient().perform(get("/api/core/collections/" + col2.getID() + "/mappingItems"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$._embedded.mappingItems", Matchers.not(Matchers.contains(
|
||||
ItemMatcher.matchItemProperties(publicItem1))
|
||||
)));
|
||||
getClient().perform(get("/api/core/collections/" + col3.getID() + "/mappingItems"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$._embedded.mappingItems", Matchers.contains(
|
||||
ItemMatcher.matchItemProperties(publicItem1))
|
||||
));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itemHasNoExtraCollectionsCanBeRetrievedAnonymouslyTest() throws Exception {
|
||||
|
||||
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();
|
||||
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();
|
||||
|
||||
//2. Three public items that are readable by Anonymous with different subjects
|
||||
Item publicItem1 = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
Item publicItem2 = ItemBuilder.createItem(context, col2)
|
||||
.withTitle("Public item 2")
|
||||
.withIssueDate("2016-02-13")
|
||||
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
|
||||
.withSubject("TestingForMore").withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
Item publicItem3 = ItemBuilder.createItem(context, col2)
|
||||
.withTitle("Public item 3")
|
||||
.withIssueDate("2016-02-13")
|
||||
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
|
||||
.withSubject("AnotherTest").withSubject("TestingForMore")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
|
||||
// collectionService.addItem(context, col2, publicItem1);
|
||||
// collectionService.update(context, col2);
|
||||
// itemService.update(context, publicItem1);
|
||||
|
||||
context.restoreAuthSystemState();
|
||||
context.setCurrentUser(null);
|
||||
getClient().perform(get("/api/core/items/" + publicItem1.getID() + "/mappingCollections"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$._embedded.mappingCollections", Matchers.not(Matchers.contains(
|
||||
CollectionMatcher.matchCollectionEntry("Collection 1", col1.getID(), col1.getHandle()),
|
||||
CollectionMatcher.matchCollectionEntry("Collection 3", col2.getID(), col2.getHandle()))
|
||||
)))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/items")))
|
||||
;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mappingNewCollectionCannotBeDoneAnonymouslyTest() throws Exception {
|
||||
|
||||
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();
|
||||
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();
|
||||
|
||||
//2. Three public items that are readable by Anonymous with different subjects
|
||||
Item publicItem1 = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
Item publicItem2 = ItemBuilder.createItem(context, col2)
|
||||
.withTitle("Public item 2")
|
||||
.withIssueDate("2016-02-13")
|
||||
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
|
||||
.withSubject("TestingForMore").withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
Item publicItem3 = ItemBuilder.createItem(context, col2)
|
||||
.withTitle("Public item 3")
|
||||
.withIssueDate("2016-02-13")
|
||||
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
|
||||
.withSubject("AnotherTest").withSubject("TestingForMore")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
|
||||
// collectionService.addItem(context, col2, publicItem1);
|
||||
// collectionService.update(context, col2);
|
||||
// itemService.update(context, publicItem1);
|
||||
|
||||
getClient().perform(post("/api/core/items/" + publicItem1.getID() + "/mappingCollections/" + col2.getID()))
|
||||
.andExpect(status().is(401));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removingMappingCollectionCannotBeDoneAnonymouslyTest() throws Exception {
|
||||
|
||||
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();
|
||||
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();
|
||||
|
||||
//2. Three public items that are readable by Anonymous with different subjects
|
||||
Item publicItem1 = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
Item publicItem2 = ItemBuilder.createItem(context, col2)
|
||||
.withTitle("Public item 2")
|
||||
.withIssueDate("2016-02-13")
|
||||
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
|
||||
.withSubject("TestingForMore").withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
Item publicItem3 = ItemBuilder.createItem(context, col2)
|
||||
.withTitle("Public item 3")
|
||||
.withIssueDate("2016-02-13")
|
||||
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
|
||||
.withSubject("AnotherTest").withSubject("TestingForMore")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
|
||||
// collectionService.addItem(context, col2, publicItem1);
|
||||
// collectionService.update(context, col2);
|
||||
// itemService.update(context, publicItem1);
|
||||
|
||||
|
||||
String adminToken = getAuthToken(admin.getEmail(), password);
|
||||
|
||||
getClient(adminToken).perform(post("/api/core/items/" + publicItem1.getID() + "/mappingCollections/"
|
||||
+ col2.getID()));
|
||||
getClient().perform(delete("/api/core/items/" + publicItem1.getID() + "/mappingCollections/"
|
||||
+ col2.getID()))
|
||||
.andExpect(status().is(401));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user