mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 10:04:21 +00:00
Applied feedback
This commit is contained in:
@@ -249,7 +249,7 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
}
|
||||
}
|
||||
MetadataValue metadataValue = metadataValueService.create(context, dso, metadataField);
|
||||
// TODO Set place to list length
|
||||
//Set place to list length
|
||||
metadataValue.setPlace(this.getMetadata(dso, Item.ANY, Item.ANY, Item.ANY, Item.ANY).size());
|
||||
|
||||
metadataValue.setLanguage(lang == null ? null : lang.trim());
|
||||
@@ -560,6 +560,10 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
} else {
|
||||
metadataValues = dso.getMetadata();
|
||||
}
|
||||
//This inline sort function will sort the MetadataValues based on their place in ascending order
|
||||
//If two places are the same then the MetadataValue instance will be placed before the
|
||||
//RelationshipMetadataValue instance.
|
||||
//This is done to ensure that the order is correct.
|
||||
metadataValues.sort(new Comparator<MetadataValue>() {
|
||||
public int compare(MetadataValue o1, MetadataValue o2) {
|
||||
int compare = o1.getPlace() - o2.getPlace();
|
||||
|
@@ -1314,7 +1314,7 @@ prevent the generation of resource policy entry values with null dspace_object a
|
||||
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
log.error(e, e);
|
||||
log.error("Lookup for Relationships for item with uuid: " + item.getID() + " caused DSpace to crash", e);
|
||||
}
|
||||
return fullMetadataValueList;
|
||||
}
|
||||
@@ -1357,6 +1357,12 @@ prevent the generation of resource policy entry values with null dspace_object a
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will sort the List of MetadataValue objects based on the MetadataSchema, MetadataField Element,
|
||||
* MetadataField Qualifier and MetadataField Place in that order.
|
||||
* @param listToReturn The list to be sorted
|
||||
* @return The list sorted on those criteria
|
||||
*/
|
||||
private List<MetadataValue> sortMetadataValueList(List<MetadataValue> listToReturn) {
|
||||
Comparator<MetadataValue> comparator = Comparator.comparing(
|
||||
metadataValue -> metadataValue.getMetadataField().getMetadataSchema().getName(),
|
||||
@@ -1373,6 +1379,8 @@ prevent the generation of resource policy entry values with null dspace_object a
|
||||
return listToReturn;
|
||||
}
|
||||
|
||||
//This method processes the Relationship of an Item and will return a list of RelationshipMetadataValue objects
|
||||
//that are generated for this specfic relationship for the item through the config in VirtualMetadataPopulator
|
||||
private List<RelationshipMetadataValue> handleItemRelationship(Context context, Item item, String entityType,
|
||||
Relationship relationship,
|
||||
boolean enableVirtualMetadata)
|
||||
@@ -1399,7 +1407,7 @@ prevent the generation of resource policy entry values with null dspace_object a
|
||||
}
|
||||
|
||||
if (hashMaps != null && enableVirtualMetadata) {
|
||||
resultingMetadataValueList.addAll(handleRelationshipTypeMetadataMappping(context, item, hashMaps,
|
||||
resultingMetadataValueList.addAll(handleRelationshipTypeMetadataMapping(context, item, hashMaps,
|
||||
otherItem, relationName,
|
||||
relationship.getID(), place));
|
||||
}
|
||||
@@ -1411,7 +1419,10 @@ prevent the generation of resource policy entry values with null dspace_object a
|
||||
return resultingMetadataValueList;
|
||||
}
|
||||
|
||||
private List<RelationshipMetadataValue> handleRelationshipTypeMetadataMappping(Context context, Item item,
|
||||
//This method will retrieve a list of RelationshipMetadataValue objects based on the config passed along in the
|
||||
//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, VirtualBean>
|
||||
hashMaps,
|
||||
Item otherItem, String relationName,
|
||||
@@ -1475,6 +1486,8 @@ prevent the generation of resource policy entry values with null dspace_object a
|
||||
return metadataValue;
|
||||
}
|
||||
|
||||
//This method will construct a RelationshipMetadataValue object with proper schema, element and qualifier based
|
||||
//on the key String parameter passed along to it
|
||||
private RelationshipMetadataValue constructMetadataValue(Context context, String key) {
|
||||
String[] splittedKey = key.split("\\.");
|
||||
RelationshipMetadataValue metadataValue = new RelationshipMetadataValue();
|
||||
|
@@ -86,6 +86,8 @@ public class RelationshipServiceImpl implements RelationshipService {
|
||||
false);
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
//If useForPlace for the leftlabel is false for the relationshipType,
|
||||
// we need to sort the relationships here based on leftplace.
|
||||
if (!virtualMetadataPopulator.isUseForPlaceTrueForRelationshipType(relationship.getRelationshipType(), true)) {
|
||||
if (!leftRelationships.isEmpty()) {
|
||||
leftRelationships.sort(Comparator.comparingInt(Relationship::getLeftPlace));
|
||||
@@ -101,6 +103,8 @@ public class RelationshipServiceImpl implements RelationshipService {
|
||||
|
||||
}
|
||||
|
||||
//If useForPlace for the rightLabel is false for the relationshipType,
|
||||
// we need to sort the relationships here based on the rightplace.
|
||||
if (!virtualMetadataPopulator.isUseForPlaceTrueForRelationshipType(relationship.getRelationshipType(), false)) {
|
||||
if (!rightRelationships.isEmpty()) {
|
||||
rightRelationships.sort(Comparator.comparingInt(Relationship::getRightPlace));
|
||||
@@ -132,6 +136,8 @@ public class RelationshipServiceImpl implements RelationshipService {
|
||||
}
|
||||
|
||||
|
||||
//Sets the places for the Relationship properly if the updatePlaceInRelationship was called for a new creation
|
||||
//of this Relationship
|
||||
private void handleCreationPlaces(Context context, Relationship relationship) throws SQLException {
|
||||
List<Relationship> leftRelationships;
|
||||
List<Relationship> rightRelationships;
|
||||
|
@@ -40,6 +40,13 @@ public class VirtualMetadataPopulator {
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will return a boolean indicating whether the useForPlace is true or false for the given
|
||||
* RelationshipType for the left or right label as indicated by the second parameter.
|
||||
* @param relationshipType The relationshipType for which this should be checked
|
||||
* @param isLeft The boolean indicating whether to check the left or the right label
|
||||
* @return A boolean indicating whether the useForPlace is true or not for the given parameters
|
||||
*/
|
||||
public boolean isUseForPlaceTrueForRelationshipType(RelationshipType relationshipType, boolean isLeft) {
|
||||
HashMap<String, VirtualBean> hashMaps;
|
||||
if (isLeft) {
|
||||
|
@@ -30,6 +30,7 @@ import org.dspace.content.service.RelationshipService;
|
||||
import org.dspace.content.service.RelationshipTypeService;
|
||||
import org.dspace.core.Constants;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.eperson.EPerson;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -104,15 +105,21 @@ public class RelationshipRestRepository extends DSpaceRestRepository<Relationshi
|
||||
RelationshipType relationshipType = relationshipTypeService
|
||||
.find(context, Integer.parseInt(req.getParameter("relationshipType")));
|
||||
|
||||
EPerson ePerson = context.getCurrentUser();
|
||||
if (authorizeService.authorizeActionBoolean(context, leftItem, Constants.WRITE) ||
|
||||
authorizeService.authorizeActionBoolean(context, rightItem, Constants.WRITE)) {
|
||||
relationship.setLeftItem(leftItem);
|
||||
relationship.setRightItem(rightItem);
|
||||
relationship.setRelationshipType(relationshipType);
|
||||
try {
|
||||
relationship = relationshipService.create(context, relationship);
|
||||
} catch (AuthorizeException e) {
|
||||
context.turnOffAuthorisationSystem();
|
||||
relationshipService.updateItem(context, relationship.getLeftItem());
|
||||
relationshipService.updateItem(context, relationship.getRightItem());
|
||||
context.restoreAuthSystemState();
|
||||
return relationshipConverter.fromModel(relationship);
|
||||
} else {
|
||||
throw new AccessDeniedException("You do not have write rights on this relationship's items");
|
||||
}
|
||||
return relationshipConverter.fromModel(relationship);
|
||||
} else {
|
||||
throw new UnprocessableEntityException("The given items in the request were not valid items");
|
||||
}
|
||||
|
@@ -204,6 +204,8 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
Relationship relationship3 = RelationshipBuilder
|
||||
.createRelationshipBuilder(context, publication, auhor1, isAuthorOfPublicationRelationshipType).build();
|
||||
|
||||
context.restoreAuthSystemState();
|
||||
|
||||
getClient().perform(get("/api/core/relationships"))
|
||||
|
||||
.andExpect(status().isOk())
|
||||
@@ -266,13 +268,17 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
|
||||
authorizeService.addPolicy(context, publication, Constants.WRITE, user);
|
||||
|
||||
context.restoreAuthSystemState();
|
||||
|
||||
String token = getAuthToken(user.getEmail(), password);
|
||||
|
||||
MvcResult mvcResult = getClient(token).perform(post("/api/core/relationships")
|
||||
.param("relationshipType",
|
||||
isAuthorOfPublicationRelationshipType.getID()
|
||||
.toString())
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.contentType(MediaType.parseMediaType
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + publication.getID() + "\n" +
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + author1.getID()))
|
||||
@@ -329,6 +335,7 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
context.setCurrentUser(user);
|
||||
|
||||
authorizeService.addPolicy(context, author1, Constants.WRITE, user);
|
||||
context.restoreAuthSystemState();
|
||||
|
||||
String token = getAuthToken(user.getEmail(), password);
|
||||
|
||||
@@ -336,7 +343,9 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
.param("relationshipType",
|
||||
isAuthorOfPublicationRelationshipType.getID()
|
||||
.toString())
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.contentType(MediaType.parseMediaType
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + publication.getID() + "\n" +
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + author1.getID()))
|
||||
@@ -392,6 +401,7 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
// actually save the eperson to unit testing DB
|
||||
ePersonService.update(context, user);
|
||||
context.setCurrentUser(user);
|
||||
context.restoreAuthSystemState();
|
||||
|
||||
String token = getAuthToken(user.getEmail(), password);
|
||||
|
||||
@@ -399,7 +409,9 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
.param("relationshipType",
|
||||
isAuthorOfPublicationRelationshipType.getID()
|
||||
.toString())
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.contentType(MediaType.parseMediaType
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + publication.getID() + "\n" +
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + author1.getID()))
|
||||
@@ -408,6 +420,11 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will test the addition of a mixture of plain-text metadatavalues and relationships to then
|
||||
* verify that the place property is still being handled correctly.
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void addRelationshipsAndMetadataToValidatePlaceTest() throws Exception {
|
||||
|
||||
@@ -459,11 +476,15 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
|
||||
String adminToken = getAuthToken(admin.getEmail(), password);
|
||||
|
||||
// Here we create our first Relationship to the Publication to give it a dc.contributor.author virtual
|
||||
// metadata field.
|
||||
MvcResult mvcResult = getClient(adminToken).perform(post("/api/core/relationships")
|
||||
.param("relationshipType",
|
||||
isAuthorOfPublicationRelationshipType.getID()
|
||||
.toString())
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.contentType(MediaType.parseMediaType
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + publication.getID() + "\n" +
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + author1.getID()))
|
||||
@@ -475,38 +496,49 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
Map<String, Object> map = mapper.readValue(content, Map.class);
|
||||
String firstRelationshipIdString = String.valueOf(map.get("id"));
|
||||
|
||||
// Here we call the relationship and verify that the relationship's leftplace is 0
|
||||
getClient(adminToken).perform(get("/api/core/relationships/" + firstRelationshipIdString))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("leftPlace", is(0)));
|
||||
|
||||
|
||||
// Make sure we grab the latest instance of the Item from the database
|
||||
publication = itemService.find(context, publication.getID());
|
||||
// Add a plain text dc.contributor.author value
|
||||
itemService.addMetadata(context, publication, "dc", "contributor", "author", Item.ANY, "plain text");
|
||||
itemService.update(context, publication);
|
||||
|
||||
List<MetadataValue> list = itemService.getMetadata(publication, "dc", "contributor", "author", Item.ANY);
|
||||
|
||||
// Ensure that the list of dc.contributor.author values now holds two values ("Smith, Donald" and "plain text")
|
||||
assertEquals(2, list.size());
|
||||
for (MetadataValue mdv : list) {
|
||||
// Here we want to ensure that the "plain text" metadatavalue has place 1 because it was added later than
|
||||
// the Relationship, so the "Smith, Donald" should have place 0 and "plain text" should have place 1
|
||||
if (StringUtils.equals(mdv.getValue(), "plain text")) {
|
||||
assertEquals(1, mdv.getPlace());
|
||||
}
|
||||
}
|
||||
// Testing what was describe above
|
||||
MetadataValue author0MD = list.get(0);
|
||||
assertEquals("Smith, Donald", author0MD.getValue());
|
||||
MetadataValue author1MD = list.get(1);
|
||||
assertEquals("plain text", author1MD.getValue());
|
||||
|
||||
|
||||
// Verfiy the leftPlace of our relationship is still 0.
|
||||
getClient(adminToken).perform(get("/api/core/relationships/" + firstRelationshipIdString))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("leftPlace", is(0)));
|
||||
|
||||
// Create another Relationship for the Publication, thus creating a third dc.contributor.author mdv
|
||||
mvcResult = getClient(adminToken).perform(post("/api/core/relationships")
|
||||
.param("relationshipType",
|
||||
isAuthorOfPublicationRelationshipType.getID()
|
||||
.toString())
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.contentType(MediaType.parseMediaType
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + publication.getID() + "\n" +
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + author2.getID()))
|
||||
@@ -515,10 +547,16 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
|
||||
content = mvcResult.getResponse().getContentAsString();
|
||||
map = mapper.readValue(content, Map.class);
|
||||
// Grab the ID for the second relationship for future calling in the rest
|
||||
String secondRelationshipIdString = String.valueOf(map.get("id"));
|
||||
|
||||
list = itemService.getMetadata(publication, "dc", "contributor", "author", Item.ANY);
|
||||
// Ensure that we now have three dc.contributor.author mdv ("Smith, Donald", "plain text", "Smith, Maria"
|
||||
// In that order which will be checked below the rest call
|
||||
assertEquals(3, list.size());
|
||||
// Perform the REST call to the relationship to ensure its leftPlace is 2 even though it's only the second
|
||||
// Relationship. Note that leftPlace 1 was skipped due to the dc.contributor.author plain text value and
|
||||
// This is expected behaviour and should be tested
|
||||
getClient(adminToken).perform(get("/api/core/relationships/" + secondRelationshipIdString))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("leftPlace", is(2)));
|
||||
@@ -530,15 +568,16 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
MetadataValue author2MD = list.get(2);
|
||||
assertEquals("Smith, Maria", author2MD.getValue());
|
||||
|
||||
// Ensure we have the latest instance of the Item from the database
|
||||
publication = itemService.find(context, publication.getID());
|
||||
// Add a fourth dc.contributor.author mdv
|
||||
itemService.addMetadata(context, publication, "dc", "contributor", "author", Item.ANY, "plain text two");
|
||||
// itemService.addMetadata(context, publication, "dc", "contributor", "author", Item.ANY, "plain text three");
|
||||
itemService.update(context, publication);
|
||||
|
||||
// itemService.addMetadata(context, publication, "dc", "contributor", "author", Item.ANY, "plain text four");
|
||||
// itemService.update(context, publication);
|
||||
list = itemService.getMetadata(publication, "dc", "contributor", "author", Item.ANY);
|
||||
|
||||
// Assert that the list of dc.contributor.author mdv is now of size 4 in the following order:
|
||||
// "Smith, Donald", "plain text", "Smith, Maria", "plain text two"
|
||||
assertEquals(4, list.size());
|
||||
for (MetadataValue mdv : list) {
|
||||
if (StringUtils.equals(mdv.getValue(), "plain text two")) {
|
||||
@@ -556,11 +595,14 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
assertEquals("plain text two", author3MD.getValue());
|
||||
|
||||
|
||||
// Create the third Relationship thus adding a fifth dc.contributor.author mdv
|
||||
mvcResult = getClient(adminToken).perform(post("/api/core/relationships")
|
||||
.param("relationshipType",
|
||||
isAuthorOfPublicationRelationshipType.getID()
|
||||
.toString())
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.contentType(MediaType.parseMediaType
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + publication.getID() + "\n" +
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + author3.getID()))
|
||||
@@ -569,14 +611,21 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
|
||||
content = mvcResult.getResponse().getContentAsString();
|
||||
map = mapper.readValue(content, Map.class);
|
||||
// Save the third Relationship's ID for future calling
|
||||
String thirdRelationshipIdString = String.valueOf(map.get("id"));
|
||||
|
||||
list = itemService.getMetadata(publication, "dc", "contributor", "author", Item.ANY);
|
||||
// Assert that our dc.contributor.author mdv list is now of size 5
|
||||
assertEquals(5, list.size());
|
||||
// Assert that the third Relationship has leftPlace 4, even though 3 relationships were created.
|
||||
// This is because the plain text values 'occupy' place 1 and 3.
|
||||
getClient(adminToken).perform(get("/api/core/relationships/" + thirdRelationshipIdString))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("leftPlace", is(4)));
|
||||
|
||||
// Assert that the list is of size 5 and in the following order:
|
||||
// "Smith, Donald", "plain text", "Smith, Maria", "plain text two", "Maybe, Maybe"
|
||||
// Thus the order they were added in
|
||||
author0MD = list.get(0);
|
||||
assertEquals("Smith, Donald", author0MD.getValue());
|
||||
author1MD = list.get(1);
|
||||
@@ -588,6 +637,7 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
MetadataValue author4MD = list.get(4);
|
||||
assertEquals("Maybe, Maybe", author4MD.getValue());
|
||||
|
||||
// The following additions of Metadata will perform the same sequence of logic and tests as described above
|
||||
publication = itemService.find(context, publication.getID());
|
||||
itemService.addMetadata(context, publication, "dc", "contributor", "author", Item.ANY, "plain text three");
|
||||
itemService.update(context, publication);
|
||||
@@ -669,6 +719,11 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
assertEquals(20, list.size()); //also includes type and 3 relation.isAuthorOfPublication values
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will test the deletion of a plain-text metadatavalue to then
|
||||
* verify that the place property is still being handled correctly.
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void deleteMetadataValueAndValidatePlace() throws Exception {
|
||||
|
||||
@@ -720,12 +775,15 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
|
||||
String adminToken = getAuthToken(admin.getEmail(), password);
|
||||
|
||||
// First create the structure of 5 metadatavalues just like the additions test.
|
||||
|
||||
MvcResult mvcResult = getClient(adminToken).perform(post("/api/core/relationships")
|
||||
.param("relationshipType",
|
||||
isAuthorOfPublicationRelationshipType.getID()
|
||||
.toString())
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.contentType(MediaType.parseMediaType
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + publication.getID() + "\n" +
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + author1.getID()))
|
||||
@@ -762,7 +820,9 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
.param("relationshipType",
|
||||
isAuthorOfPublicationRelationshipType.getID()
|
||||
.toString())
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.contentType(MediaType.parseMediaType
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + publication.getID() + "\n" +
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + author2.getID()))
|
||||
@@ -779,11 +839,8 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
|
||||
publication = itemService.find(context, publication.getID());
|
||||
itemService.addMetadata(context, publication, "dc", "contributor", "author", Item.ANY, "plain text two");
|
||||
// itemService.addMetadata(context, publication, "dc", "contributor", "author", Item.ANY, "plain text three");
|
||||
itemService.update(context, publication);
|
||||
|
||||
// itemService.addMetadata(context, publication, "dc", "contributor", "author", Item.ANY, "plain text four");
|
||||
// itemService.update(context, publication);
|
||||
list = itemService.getMetadata(publication, "dc", "contributor", "author", Item.ANY);
|
||||
|
||||
for (MetadataValue mdv : list) {
|
||||
@@ -797,7 +854,9 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
.param("relationshipType",
|
||||
isAuthorOfPublicationRelationshipType.getID()
|
||||
.toString())
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.contentType(MediaType.parseMediaType
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + publication.getID() + "\n" +
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + author3.getID()))
|
||||
@@ -824,6 +883,8 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
}
|
||||
}
|
||||
|
||||
// Now we will have a dc.contributor.author metadatavalue list of size 5 in the following order:
|
||||
// "Smith, Donald", "plain text", "Smith, Maria", "plain text two", "Maybe, Maybe"
|
||||
List<MetadataValue> authors = itemService.getMetadata(publication, "dc", "contributor", "author", Item.ANY);
|
||||
List<MetadataValue> listToRemove = new LinkedList<>();
|
||||
for (MetadataValue metadataValue : authors) {
|
||||
@@ -831,6 +892,9 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
listToRemove.add(metadataValue);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the "plain text two" metadatavalue. Ensure that all mdvs prior to that in the list are unchanged
|
||||
// And ensure that the ones coming after this mdv have its place lowered by one.
|
||||
itemService.removeMetadataValues(context, publication, listToRemove);
|
||||
|
||||
itemService.update(context, publication);
|
||||
@@ -861,6 +925,11 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will test the deletion of a Relationship to then
|
||||
* verify that the place property is still being handled correctly.
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void deleteRelationshipsAndValidatePlace() throws Exception {
|
||||
|
||||
@@ -912,12 +981,15 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
|
||||
String adminToken = getAuthToken(admin.getEmail(), password);
|
||||
|
||||
// First create the structure of 5 metadatavalues just like the additions test.
|
||||
|
||||
MvcResult mvcResult = getClient(adminToken).perform(post("/api/core/relationships")
|
||||
.param("relationshipType",
|
||||
isAuthorOfPublicationRelationshipType.getID()
|
||||
.toString())
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.contentType(MediaType.parseMediaType
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + publication.getID() + "\n" +
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + author1.getID()))
|
||||
@@ -954,7 +1026,9 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
.param("relationshipType",
|
||||
isAuthorOfPublicationRelationshipType.getID()
|
||||
.toString())
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.contentType(MediaType.parseMediaType
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + publication.getID() + "\n" +
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + author2.getID()))
|
||||
@@ -986,7 +1060,9 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
.param("relationshipType",
|
||||
isAuthorOfPublicationRelationshipType.getID()
|
||||
.toString())
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.contentType(MediaType.parseMediaType
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + publication.getID() + "\n" +
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + author3.getID()))
|
||||
@@ -1014,6 +1090,12 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
}
|
||||
|
||||
|
||||
// Now we will have a dc.contributor.author metadatavalue list of size 5 in the following order:
|
||||
// "Smith, Donald", "plain text", "Smith, Maria", "plain text two", "Maybe, Maybe"
|
||||
|
||||
// Now we delete the second relationship, the one that made "Smith, Maria" metadatavalue
|
||||
// Ensure that all metadatavalues before this one in the list still hold the same place
|
||||
// Ensure that all the metadatavalues after this one have their place lowered by one
|
||||
getClient(adminToken).perform(delete("/api/core/relationships/" + secondRelationshipIdString));
|
||||
|
||||
getClient(adminToken).perform(get("/api/core/relationships/" + firstRelationshipIdString))
|
||||
@@ -1052,6 +1134,12 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This test will simply add Relationships between Items with a useForPlace attribute set to false for the
|
||||
* RelationshipType. We want to test that the Relationships that are created will still have their place
|
||||
* attributes handled in a correct way
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void addRelationshipsNotUseForPlace() throws Exception {
|
||||
|
||||
@@ -1101,11 +1189,15 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
|
||||
String adminToken = getAuthToken(admin.getEmail(), password);
|
||||
|
||||
// This is essentially a sequence of adding Relationships by POST and then checking with GET to see
|
||||
// if the place is being set properly.
|
||||
MvcResult mvcResult = getClient(adminToken).perform(post("/api/core/relationships")
|
||||
.param("relationshipType",
|
||||
isOrgUnitOfPersonRelationshipType.getID()
|
||||
.toString())
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.contentType(MediaType.parseMediaType
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + author1.getID() + "\n" +
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + orgUnit1.getID()))
|
||||
@@ -1124,7 +1216,9 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
mvcResult = getClient(adminToken).perform(post("/api/core/relationships")
|
||||
.param("relationshipType",
|
||||
isOrgUnitOfPersonRelationshipType.getID().toString())
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.contentType(MediaType.parseMediaType
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + author2.getID() + "\n" +
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + orgUnit1.getID()))
|
||||
@@ -1143,7 +1237,9 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
mvcResult = getClient(adminToken).perform(post("/api/core/relationships")
|
||||
.param("relationshipType",
|
||||
isOrgUnitOfPersonRelationshipType.getID().toString())
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.contentType(MediaType.parseMediaType
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + author3.getID() + "\n" +
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + orgUnit1.getID()))
|
||||
@@ -1160,6 +1256,13 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
.andExpect(jsonPath("rightPlace", is(2)));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test will simply add Relationships between Items with a useForPlace attribute set to false for the
|
||||
* RelationshipType. We want to test that the Relationships that are created will still have their place
|
||||
* attributes handled in a correct way. It will then delete a Relationship and once again ensure that the place
|
||||
* attributes are being handled correctly.
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void addAndDeleteRelationshipsNotUseForPlace() throws Exception {
|
||||
|
||||
@@ -1209,11 +1312,15 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
|
||||
String adminToken = getAuthToken(admin.getEmail(), password);
|
||||
|
||||
// This is essentially a sequence of adding Relationships by POST and then checking with GET to see
|
||||
// if the place is being set properly.
|
||||
MvcResult mvcResult = getClient(adminToken).perform(post("/api/core/relationships")
|
||||
.param("relationshipType",
|
||||
isOrgUnitOfPersonRelationshipType.getID()
|
||||
.toString())
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.contentType(MediaType.parseMediaType
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + author1.getID() + "\n" +
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + orgUnit1.getID()))
|
||||
@@ -1232,7 +1339,9 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
mvcResult = getClient(adminToken).perform(post("/api/core/relationships")
|
||||
.param("relationshipType",
|
||||
isOrgUnitOfPersonRelationshipType.getID().toString())
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.contentType(MediaType.parseMediaType
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + author2.getID() + "\n" +
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + orgUnit1.getID()))
|
||||
@@ -1251,7 +1360,9 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
mvcResult = getClient(adminToken).perform(post("/api/core/relationships")
|
||||
.param("relationshipType",
|
||||
isOrgUnitOfPersonRelationshipType.getID().toString())
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.contentType(MediaType.parseMediaType
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + author3.getID() + "\n" +
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + orgUnit1.getID()))
|
||||
@@ -1267,6 +1378,7 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("rightPlace", is(2)));
|
||||
|
||||
// Here we will delete the secondRelationship and then verify that the others have their place handled properly
|
||||
getClient(adminToken).perform(delete("/api/core/relationships/" + secondRelationshipIdString));
|
||||
|
||||
getClient(adminToken).perform(get("/api/core/relationships/" + firstRelationshipIdString))
|
||||
@@ -1328,7 +1440,9 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
.param("relationshipType",
|
||||
isAuthorOfPublicationRelationshipType.getID()
|
||||
.toString())
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.contentType(MediaType.parseMediaType
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + publication.getID() + "\n" +
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + author1.getID()))
|
||||
@@ -1341,7 +1455,9 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
String id = String.valueOf(map.get("id"));
|
||||
|
||||
MvcResult mvcResult2 = getClient(token).perform(put("/api/core/relationships/" + id)
|
||||
.contentType(MediaType.parseMediaType("text/uri-list"))
|
||||
.contentType(MediaType.parseMediaType
|
||||
(org.springframework.data.rest.webmvc.RestMediaTypes
|
||||
.TEXT_URI_LIST_VALUE))
|
||||
.content(
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + publication.getID() + "\n" +
|
||||
"https://localhost:8080/spring-rest/api/core/items/" + author2.getID()))
|
||||
|
Reference in New Issue
Block a user