mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-18 15:33:09 +00:00
Merge branch 'feature-name-variants' of https://github.com/atmire/DSpace into feature-name-variants
# Conflicts: # dspace-api/src/main/java/org/dspace/content/ItemServiceImpl.java # dspace-api/src/main/java/org/dspace/content/RelationshipMetadataServiceImpl.java
This commit is contained in:
@@ -1341,8 +1341,8 @@ prevent the generation of resource policy entry values with null dspace_object a
|
||||
//except for relation.type which is the type of item in the model
|
||||
if (StringUtils.equals(schema, MetadataSchemaEnum.RELATION.getName()) && !StringUtils.equals(element, "type")) {
|
||||
|
||||
List<RelationshipMetadataValue> relationMetadata =
|
||||
relationshipMetadataService.getRelationshipMetadata(item, false);
|
||||
List<RelationshipMetadataValue> relationMetadata = relationshipMetadataService
|
||||
.getRelationshipMetadata(item, false);
|
||||
List<MetadataValue> listToReturn = new LinkedList<>();
|
||||
for (MetadataValue metadataValue : relationMetadata) {
|
||||
if (StringUtils.equals(metadataValue.getMetadataField().getElement(), element)) {
|
||||
@@ -1398,6 +1398,4 @@ prevent the generation of resource policy entry values with null dspace_object a
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@@ -85,19 +85,21 @@ public class RelationshipMetadataServiceImpl implements RelationshipMetadataServ
|
||||
String relationName;
|
||||
Item otherItem;
|
||||
int place = 0;
|
||||
boolean isLeft;
|
||||
boolean isLeftwards;
|
||||
if (StringUtils.equals(relationshipType.getLeftType().getLabel(), entityType)) {
|
||||
hashMaps = virtualMetadataPopulator.getMap().get(relationshipType.getLeftwardLabel());
|
||||
otherItem = relationship.getRightItem();
|
||||
relationName = relationship.getRelationshipType().getLeftwardLabel();
|
||||
place = relationship.getLeftPlace();
|
||||
isLeft = true;
|
||||
isLeftwards = false; //if the current item is stored on the left,
|
||||
// the name variant is retrieved from the rightwards label
|
||||
} else if (StringUtils.equals(relationshipType.getRightType().getLabel(), entityType)) {
|
||||
hashMaps = virtualMetadataPopulator.getMap().get(relationshipType.getRightwardLabel());
|
||||
otherItem = relationship.getLeftItem();
|
||||
relationName = relationship.getRelationshipType().getRightwardLabel();
|
||||
place = relationship.getRightPlace();
|
||||
isLeft = false;
|
||||
isLeftwards = true; //if the current item is stored on the right,
|
||||
// the name variant is retrieved from the leftwards label
|
||||
} else {
|
||||
//No virtual metadata can be created
|
||||
return resultingMetadataValueList;
|
||||
@@ -106,7 +108,7 @@ public class RelationshipMetadataServiceImpl implements RelationshipMetadataServ
|
||||
if (hashMaps != null && enableVirtualMetadata) {
|
||||
resultingMetadataValueList.addAll(handleRelationshipTypeMetadataMapping(context, item, hashMaps,
|
||||
otherItem, relationName,
|
||||
relationship, place, isLeft));
|
||||
relationship, place, isLeftwards));
|
||||
}
|
||||
RelationshipMetadataValue relationMetadataFromOtherItem =
|
||||
getRelationMetadataFromOtherItem(context, otherItem, relationName, relationship.getID(), place);
|
||||
@@ -120,10 +122,8 @@ public class RelationshipMetadataServiceImpl implements RelationshipMetadataServ
|
||||
//hashmaps parameter. The beans will be used to retrieve the values for the RelationshipMetadataValue objects
|
||||
//and the keys of the hashmap will be used to construct the RelationshipMetadataValue object.
|
||||
private List<RelationshipMetadataValue> handleRelationshipTypeMetadataMapping(Context context, Item item,
|
||||
HashMap<String, VirtualMetadataConfiguration> hashMaps,
|
||||
Item otherItem, String relationName,
|
||||
Relationship relationship, int place,
|
||||
boolean isLeft) throws SQLException {
|
||||
HashMap<String, VirtualMetadataConfiguration> hashMaps, Item otherItem, String relationName,
|
||||
Relationship relationship, int place, boolean isLeftwards) throws SQLException {
|
||||
|
||||
List<RelationshipMetadataValue> resultingMetadataValueList = new LinkedList<>();
|
||||
for (Map.Entry<String, VirtualMetadataConfiguration> entry : hashMaps.entrySet()) {
|
||||
@@ -131,20 +131,18 @@ public class RelationshipMetadataServiceImpl implements RelationshipMetadataServ
|
||||
VirtualMetadataConfiguration virtualBean = entry.getValue();
|
||||
|
||||
if (virtualBean.getPopulateWithNameVariant()) {
|
||||
String wardLabel = isLeft ? relationship.getLeftwardLabel() : relationship.getRightwardLabel();
|
||||
String wardLabel = isLeftwards ? relationship.getLeftwardLabel() : relationship.getRightwardLabel();
|
||||
if (wardLabel != null) {
|
||||
resultingMetadataValueList.add(
|
||||
constructRelationshipMetadataValue(
|
||||
context, item, relationship.getID(), place, key, virtualBean, wardLabel
|
||||
));
|
||||
constructRelationshipMetadataValue(context, item, relationship.getID(), place, key, virtualBean,
|
||||
wardLabel));
|
||||
} else {
|
||||
handleVirtualBeanValues(
|
||||
context, item, otherItem, relationship, place, resultingMetadataValueList, key, virtualBean);
|
||||
handleVirtualBeanValues(context, item, otherItem, relationship, place, resultingMetadataValueList,
|
||||
key, virtualBean);
|
||||
}
|
||||
} else {
|
||||
handleVirtualBeanValues(
|
||||
context, item, otherItem, relationship, place, resultingMetadataValueList, key, virtualBean
|
||||
);
|
||||
handleVirtualBeanValues(context, item, otherItem, relationship, place, resultingMetadataValueList, key,
|
||||
virtualBean);
|
||||
}
|
||||
}
|
||||
return resultingMetadataValueList;
|
||||
@@ -154,15 +152,20 @@ public class RelationshipMetadataServiceImpl implements RelationshipMetadataServ
|
||||
int place, List<RelationshipMetadataValue> resultingMetadataValueList,
|
||||
String key, VirtualMetadataConfiguration virtualBean) throws SQLException {
|
||||
for (String value : virtualBean.getValues(context, otherItem)) {
|
||||
resultingMetadataValueList.add(
|
||||
constructRelationshipMetadataValue(context, item, relationship.getID(), place, key, virtualBean, value)
|
||||
);
|
||||
RelationshipMetadataValue relationshipMetadataValue = constructRelationshipMetadataValue(context, item,
|
||||
relationship
|
||||
.getID(),
|
||||
place,
|
||||
key, virtualBean,
|
||||
value);
|
||||
if (relationshipMetadataValue != null) {
|
||||
resultingMetadataValueList.add(relationshipMetadataValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private RelationshipMetadataValue constructRelationshipMetadataValue(Context context, Item item,
|
||||
Integer relationshipId,
|
||||
int place,
|
||||
Integer relationshipId, int place,
|
||||
String key,
|
||||
VirtualMetadataConfiguration virtualBean,
|
||||
String value) {
|
||||
|
@@ -7,11 +7,14 @@
|
||||
*/
|
||||
package org.dspace.app.rest;
|
||||
|
||||
import static org.dspace.app.rest.matcher.MetadataMatcher.matchMetadata;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||
@@ -264,8 +267,10 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + publication1.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + publication1
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
|
||||
@@ -304,8 +309,10 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + publication1.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + publication1
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
|
||||
@@ -340,15 +347,17 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + publication1.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + publication1
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1
|
||||
.getID()))
|
||||
.andExpect(status().isForbidden())
|
||||
.andReturn();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createRelationShipWithLeftwardLabel() throws Exception {
|
||||
public void createRelationshipWithLeftwardLabel() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
authorizeService.addPolicy(context, publication1, Constants.WRITE, user1);
|
||||
@@ -362,14 +371,17 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
|
||||
MvcResult mvcResult = getClient(token).perform(post("/api/core/relationships")
|
||||
.param("relationshipType",
|
||||
isAuthorOfPublicationRelationshipType.getID().toString())
|
||||
isAuthorOfPublicationRelationshipType.getID()
|
||||
.toString())
|
||||
.param("leftwardLabel", leftwardLabel)
|
||||
.contentType(MediaType.parseMediaType
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + publication1.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + publication1
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
|
||||
@@ -387,7 +399,7 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createRelationShipWithRightWardLabel() throws Exception {
|
||||
public void createRelationshipWithRightwardLabel() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
authorizeService.addPolicy(context, publication1, Constants.WRITE, user1);
|
||||
@@ -401,14 +413,17 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
|
||||
MvcResult mvcResult = getClient(token).perform(post("/api/core/relationships")
|
||||
.param("relationshipType",
|
||||
isAuthorOfPublicationRelationshipType.getID().toString())
|
||||
isAuthorOfPublicationRelationshipType.getID()
|
||||
.toString())
|
||||
.param("rightwardLabel", rightwardLabel)
|
||||
.contentType(MediaType.parseMediaType
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + publication1.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + publication1
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
|
||||
@@ -426,7 +441,7 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createRelationShipWithRightWardlabelAndLeftWardLabel() throws Exception {
|
||||
public void createRelationshipWithRightwardLabelAndLeftwardLabel() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
authorizeService.addPolicy(context, publication1, Constants.WRITE, user1);
|
||||
@@ -441,15 +456,18 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
|
||||
MvcResult mvcResult = getClient(token).perform(post("/api/core/relationships")
|
||||
.param("relationshipType",
|
||||
isAuthorOfPublicationRelationshipType.getID().toString())
|
||||
isAuthorOfPublicationRelationshipType.getID()
|
||||
.toString())
|
||||
.param("leftwardLabel", leftwardLabel)
|
||||
.param("rightwardLabel", rightwardLabel)
|
||||
.contentType(MediaType.parseMediaType
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + publication1.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + publication1
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
|
||||
@@ -467,7 +485,7 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createRelationShipAndAddLeftWardLabelAfterwards() throws Exception {
|
||||
public void createRelationshipAndAddLeftwardLabelAfterwards() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
authorizeService.addPolicy(context, publication1, Constants.WRITE, user1);
|
||||
@@ -481,13 +499,16 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
|
||||
MvcResult mvcResult = getClient(token).perform(post("/api/core/relationships")
|
||||
.param("relationshipType",
|
||||
isAuthorOfPublicationRelationshipType.getID().toString())
|
||||
isAuthorOfPublicationRelationshipType.getID()
|
||||
.toString())
|
||||
.contentType(MediaType.parseMediaType
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + publication1.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + publication1
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
|
||||
@@ -522,7 +543,7 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createRelationShipThenAddLabelsAndRemoveThem() throws Exception {
|
||||
public void createRelationshipThenAddLabelsAndRemoveThem() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
authorizeService.addPolicy(context, publication1, Constants.WRITE, user1);
|
||||
@@ -537,13 +558,16 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
|
||||
MvcResult mvcResult = getClient(token).perform(post("/api/core/relationships")
|
||||
.param("relationshipType",
|
||||
isAuthorOfPublicationRelationshipType.getID().toString())
|
||||
isAuthorOfPublicationRelationshipType.getID()
|
||||
.toString())
|
||||
.contentType(MediaType.parseMediaType
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + publication1.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + publication1
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
|
||||
@@ -650,8 +674,11 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + publication1.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + publication1
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items" +
|
||||
"/" + author1
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
@@ -706,8 +733,10 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + publication1.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author2.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + publication1
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author2
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
|
||||
@@ -772,8 +801,10 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + publication1.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author3.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + publication1
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author3
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
|
||||
@@ -933,8 +964,11 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + publication1.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + publication1
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items" +
|
||||
"/" + author1
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
@@ -981,8 +1015,10 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + publication1.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author2.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + publication1
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author2
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
|
||||
@@ -1022,8 +1058,10 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + publication1.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author3.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + publication1
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author3
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
|
||||
@@ -1136,8 +1174,11 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + publication1.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + publication1
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items" +
|
||||
"/" + author1
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
@@ -1184,8 +1225,10 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + publication1.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author2.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + publication1
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author2
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
|
||||
@@ -1225,8 +1268,10 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + publication1.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author3.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + publication1
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author3
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
|
||||
@@ -1330,8 +1375,12 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + publication1.getID() + "\n" +
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + author1.getID()))
|
||||
"https://localhost:8080/spring-rest/api/core" +
|
||||
"/items/" + publication1
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/spring-rest/api/core" +
|
||||
"/items/" + author1
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
@@ -1368,8 +1417,10 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + publication1.getID() + "\n" +
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + author2.getID()))
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + publication1
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + author2
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
|
||||
@@ -1466,8 +1517,11 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + author1.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + orgUnit1.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + author1
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items" +
|
||||
"/" + orgUnit1
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
@@ -1487,8 +1541,10 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + author2.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + orgUnit1.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + author2
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + orgUnit1
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
mapper = new ObjectMapper();
|
||||
@@ -1508,8 +1564,10 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + author3.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + orgUnit1.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + author3
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + orgUnit1
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
mapper = new ObjectMapper();
|
||||
@@ -1545,8 +1603,11 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + author1.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + orgUnit1.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + author1
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items" +
|
||||
"/" + orgUnit1
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
@@ -1566,8 +1627,10 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + author2.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + orgUnit1.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + author2
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + orgUnit1
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
mapper = new ObjectMapper();
|
||||
@@ -1587,8 +1650,10 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + author3.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + orgUnit1.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + author3
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + orgUnit1
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
mapper = new ObjectMapper();
|
||||
@@ -1635,14 +1700,16 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + publication1.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + publication1
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String content = mvcResult.getResponse().getContentAsString();
|
||||
Map<String,Object> map = mapper.readValue(content, Map.class);
|
||||
Map<String, Object> map = mapper.readValue(content, Map.class);
|
||||
String id = String.valueOf(map.get("id"));
|
||||
|
||||
//Modify the left item in the relationship publication > publication 2
|
||||
@@ -1651,7 +1718,8 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + publication2.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + publication2
|
||||
.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andReturn();
|
||||
|
||||
@@ -1669,7 +1737,8 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + author2.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + author2
|
||||
.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andReturn();
|
||||
|
||||
@@ -1708,20 +1777,24 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
.toString())
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + publication1.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + publication1
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String content = mvcResult.getResponse().getContentAsString();
|
||||
Map<String,Object> map = mapper.readValue(content, Map.class);
|
||||
Map<String, Object> map = mapper.readValue(content, Map.class);
|
||||
String id = String.valueOf(map.get("id"));
|
||||
|
||||
//change right item from author 1 > author 2
|
||||
MvcResult mvcResult2 = getClient(token).perform(put("/api/core/relationships/" + id + "/rightItem")
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.content("https://localhost:8080/server/api/core/items/" + author2.getID()))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + author2
|
||||
.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andReturn();
|
||||
//verify change and other not changed
|
||||
@@ -1758,19 +1831,23 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
.toString())
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + publication1.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + publication1
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String content = mvcResult.getResponse().getContentAsString();
|
||||
Map<String,Object> map = mapper.readValue(content, Map.class);
|
||||
Map<String, Object> map = mapper.readValue(content, Map.class);
|
||||
String id = String.valueOf(map.get("id"));
|
||||
//change rightItem from author1 > author2
|
||||
MvcResult mvcResult2 = getClient(token).perform(put("/api/core/relationships/" + id + "/rightItem")
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.content("https://localhost:8080/server/api/core/items/" + author2.getID()))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + author2
|
||||
.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andReturn();
|
||||
//verify right item change and other not changed
|
||||
@@ -1809,19 +1886,23 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
.toString())
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + publication1.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + publication1
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String content = mvcResult.getResponse().getContentAsString();
|
||||
Map<String,Object> map = mapper.readValue(content, Map.class);
|
||||
Map<String, Object> map = mapper.readValue(content, Map.class);
|
||||
String id = String.valueOf(map.get("id"));
|
||||
//change leftItem
|
||||
MvcResult mvcResult2 = getClient(token).perform(put("/api/core/relationships/" + id + "/leftItem")
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.content("https://localhost:8080/server/api/core/items/" + publication2.getID()))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + publication2
|
||||
.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andReturn();
|
||||
//verify change and other not changed
|
||||
@@ -1866,12 +1947,14 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String content = mvcResult.getResponse().getContentAsString();
|
||||
Map<String,Object> map = mapper.readValue(content, Map.class);
|
||||
Map<String, Object> map = mapper.readValue(content, Map.class);
|
||||
String id = String.valueOf(map.get("id"));
|
||||
//change left item
|
||||
MvcResult mvcResult2 = getClient(token).perform(put("/api/core/relationships/" + id + "/leftItem")
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.content("https://localhost:8080/server/api/core/items/" + publication2.getID()))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + publication2
|
||||
.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andReturn();
|
||||
//verify change and other not changed
|
||||
@@ -1906,20 +1989,24 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
.toString())
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + publication1.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + publication1
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String content = mvcResult.getResponse().getContentAsString();
|
||||
Map<String,Object> map = mapper.readValue(content, Map.class);
|
||||
Map<String, Object> map = mapper.readValue(content, Map.class);
|
||||
String id = String.valueOf(map.get("id"));
|
||||
token = getAuthToken(user1.getEmail(), password);
|
||||
//attempt change, expect not allowed
|
||||
MvcResult mvcResult2 = getClient(token).perform(put("/api/core/relationships/" + id + "/rightItem")
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.content("https://localhost:8080/server/api/core/items/" + author2.getID()))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + author2
|
||||
.getID()))
|
||||
.andExpect(status().isForbidden())
|
||||
.andReturn();
|
||||
//verify nothing changed
|
||||
@@ -1955,20 +2042,24 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
.toString())
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + publication1.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + publication1
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String content = mvcResult.getResponse().getContentAsString();
|
||||
Map<String,Object> map = mapper.readValue(content, Map.class);
|
||||
Map<String, Object> map = mapper.readValue(content, Map.class);
|
||||
String id = String.valueOf(map.get("id"));
|
||||
token = getAuthToken(user1.getEmail(), password);
|
||||
//attempt right item change, expect not allowed
|
||||
MvcResult mvcResult2 = getClient(token).perform(put("/api/core/relationships/" + id + "/rightItem")
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.content("https://localhost:8080/server/api/core/items/" + author2.getID()))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + author2
|
||||
.getID()))
|
||||
.andExpect(status().isForbidden())
|
||||
.andReturn();
|
||||
//verify not changed
|
||||
@@ -2004,19 +2095,23 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
.toString())
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + publication1.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + publication1
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String content = mvcResult.getResponse().getContentAsString();
|
||||
Map<String,Object> map = mapper.readValue(content, Map.class);
|
||||
Map<String, Object> map = mapper.readValue(content, Map.class);
|
||||
String id = String.valueOf(map.get("id"));
|
||||
//attempt left item change, expect not allowed
|
||||
MvcResult mvcResult2 = getClient(token).perform(put("/api/core/relationships/" + id + "/leftItem")
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.content("https://localhost:8080/server/api/core/items/" + publication2.getID()))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + publication2
|
||||
.getID()))
|
||||
.andExpect(status().isForbidden())
|
||||
.andReturn();
|
||||
//verify not changed
|
||||
@@ -2131,8 +2226,10 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
.toString())
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + publication1.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1.getID()))
|
||||
"https://localhost:8080/server/api/core/items/" + publication1
|
||||
.getID() + "\n" +
|
||||
"https://localhost:8080/server/api/core/items/" + author1
|
||||
.getID()))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
|
||||
@@ -2145,9 +2242,163 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
//attempt left item change on non-existent relationship
|
||||
MvcResult mvcResult2 = getClient(token).perform(put("/api/core/relationships/" + id + "/leftItem")
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.content("https://localhost:8080/server/api/core/items/" + nonexistentItemID))
|
||||
.content(
|
||||
"https://localhost:8080/server/api/core/items/" + nonexistentItemID))
|
||||
.andExpect(status().isUnprocessableEntity())
|
||||
.andReturn();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void leftWardLabelRelationshipTest() throws Exception {
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
RelationshipType isAuthorOfPublicationRelationshipType = relationshipTypeService
|
||||
.findbyTypesAndLabels(context, entityTypeService.findByEntityType(context, "Publication"),
|
||||
entityTypeService.findByEntityType(context, "Person"),
|
||||
"isAuthorOfPublication", "isPublicationOfAuthor");
|
||||
|
||||
Relationship relationship3 = RelationshipBuilder
|
||||
.createRelationshipBuilder(context, publication1, author1, isAuthorOfPublicationRelationshipType)
|
||||
.withLeftWardLabel("LeftWardLabelTest").build();
|
||||
|
||||
context.restoreAuthSystemState();
|
||||
|
||||
getClient().perform(get("/api/core/relationships"))
|
||||
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.page",
|
||||
is(PageMatcher.pageEntryWithTotalPagesAndElements(0, 20, 1, 1))))
|
||||
.andExpect(jsonPath("$._embedded.relationships", containsInAnyOrder(
|
||||
RelationshipMatcher.matchRelationship(relationship3)
|
||||
)))
|
||||
;
|
||||
|
||||
getClient().perform(get("/api/core/items/" + publication1.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.metadata", allOf(
|
||||
matchMetadata("dc.contributor.author", "LeftWardLabelTest"),
|
||||
matchMetadata("dc.title", "Publication1"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonLeftWardLabelRelationshipTest() throws Exception {
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
RelationshipType isAuthorOfPublicationRelationshipType = relationshipTypeService
|
||||
.findbyTypesAndLabels(context, entityTypeService.findByEntityType(context, "Publication"),
|
||||
entityTypeService.findByEntityType(context, "Person"),
|
||||
"isAuthorOfPublication", "isPublicationOfAuthor");
|
||||
|
||||
Relationship relationship3 = RelationshipBuilder
|
||||
.createRelationshipBuilder(context, publication1, author3, isAuthorOfPublicationRelationshipType)
|
||||
.withLeftPlace(1).build();
|
||||
|
||||
context.restoreAuthSystemState();
|
||||
|
||||
getClient().perform(get("/api/core/relationships"))
|
||||
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.page",
|
||||
is(PageMatcher.pageEntryWithTotalPagesAndElements(0, 20, 1, 1))))
|
||||
.andExpect(jsonPath("$._embedded.relationships", containsInAnyOrder(
|
||||
RelationshipMatcher.matchRelationship(relationship3)
|
||||
)))
|
||||
;
|
||||
|
||||
getClient().perform(get("/api/core/items/" + publication1.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.metadata", allOf(
|
||||
matchMetadata("dc.contributor.author", "Maybe, Maybe"),
|
||||
matchMetadata("dc.contributor.author", "Testy, TEst"),
|
||||
matchMetadata("dc.title", "Publication1"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mixedLeftWardLabelAndRegularRelationshipTest() throws Exception {
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
RelationshipType isAuthorOfPublicationRelationshipType = relationshipTypeService
|
||||
.findbyTypesAndLabels(context, entityTypeService.findByEntityType(context, "Publication"),
|
||||
entityTypeService.findByEntityType(context, "Person"),
|
||||
"isAuthorOfPublication", "isPublicationOfAuthor");
|
||||
|
||||
Item author1 = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Author1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald")
|
||||
.withPersonIdentifierFirstName("testingFirstName")
|
||||
.withPersonIdentifierLastName("testingLastName")
|
||||
.withRelationshipType("Person")
|
||||
.build();
|
||||
|
||||
Relationship relationship3 = RelationshipBuilder
|
||||
.createRelationshipBuilder(context, publication1, author3, isAuthorOfPublicationRelationshipType)
|
||||
.withLeftPlace(1).build();
|
||||
|
||||
Relationship relationship2 = RelationshipBuilder
|
||||
.createRelationshipBuilder(context, publication1, author1, isAuthorOfPublicationRelationshipType)
|
||||
.withLeftWardLabel("TestingLeftWardLabel").build();
|
||||
|
||||
context.restoreAuthSystemState();
|
||||
|
||||
getClient().perform(get("/api/core/relationships"))
|
||||
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.page",
|
||||
is(PageMatcher.pageEntryWithTotalPagesAndElements(0, 20, 1, 2))))
|
||||
.andExpect(jsonPath("$._embedded.relationships", containsInAnyOrder(
|
||||
RelationshipMatcher.matchRelationship(relationship3),
|
||||
RelationshipMatcher.matchRelationship(relationship2)
|
||||
)))
|
||||
;
|
||||
|
||||
getClient().perform(get("/api/core/items/" + publication1.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.metadata", allOf(
|
||||
matchMetadata("dc.contributor.author", "Maybe, Maybe"),
|
||||
matchMetadata("dc.contributor.author", "Testy, TEst"),
|
||||
matchMetadata("dc.contributor.author", "TestingLeftWardLabel"),
|
||||
not(matchMetadata("dc.contributor.author", "testingLastName, testingFirstName")),
|
||||
matchMetadata("dc.title", "Publication1"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rightWardLabelRelationshipTest() throws Exception {
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
RelationshipType isAuthorOfPublicationRelationshipType = relationshipTypeService
|
||||
.findbyTypesAndLabels(context, entityTypeService.findByEntityType(context, "Publication"),
|
||||
entityTypeService.findByEntityType(context, "Person"),
|
||||
"isAuthorOfPublication", "isPublicationOfAuthor");
|
||||
|
||||
Relationship relationship3 = RelationshipBuilder
|
||||
.createRelationshipBuilder(context, publication1, author3, isAuthorOfPublicationRelationshipType)
|
||||
.withRightWardLabel("rightWardLabelTest").withLeftPlace(1).build();
|
||||
|
||||
context.restoreAuthSystemState();
|
||||
|
||||
getClient().perform(get("/api/core/relationships"))
|
||||
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.page",
|
||||
is(PageMatcher.pageEntryWithTotalPagesAndElements(0, 20, 1, 1))))
|
||||
.andExpect(jsonPath("$._embedded.relationships", containsInAnyOrder(
|
||||
RelationshipMatcher.matchRelationship(relationship3)
|
||||
)))
|
||||
;
|
||||
|
||||
getClient().perform(get("/api/core/items/" + publication1.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.metadata", allOf(
|
||||
matchMetadata("dc.contributor.author", "Maybe, Maybe"),
|
||||
matchMetadata("dc.contributor.author", "Testy, TEst"),
|
||||
matchMetadata("dc.title", "Publication1"))));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -84,4 +84,19 @@ public class RelationshipBuilder extends AbstractBuilder<Relationship, Relations
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public RelationshipBuilder withLeftWardLabel(String leftWardLabel) throws SQLException {
|
||||
relationship.setLeftwardLabel(leftWardLabel);
|
||||
return this;
|
||||
}
|
||||
|
||||
public RelationshipBuilder withRightWardLabel(String rightWardLabel) throws SQLException {
|
||||
relationship.setRightwardLabel(rightWardLabel);
|
||||
return this;
|
||||
}
|
||||
|
||||
public RelationshipBuilder withLeftPlace(int leftPlace) {
|
||||
relationship.setLeftPlace(leftPlace);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@
|
||||
package org.dspace.app.rest.matcher;
|
||||
|
||||
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
import org.hamcrest.Matcher;
|
||||
@@ -18,7 +18,8 @@ import org.hamcrest.Matcher;
|
||||
*/
|
||||
public class MetadataMatcher {
|
||||
|
||||
private MetadataMatcher() { }
|
||||
private MetadataMatcher() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a matcher to ensure a given value is present among all values for a given metadata key.
|
||||
@@ -28,7 +29,7 @@ public class MetadataMatcher {
|
||||
* @return the matcher.
|
||||
*/
|
||||
public static Matcher<? super Object> matchMetadata(String key, String value) {
|
||||
return hasJsonPath("$.['" + key + "'][*].value", contains(value));
|
||||
return hasJsonPath("$.['" + key + "'][*].value", hasItem(value));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user