mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 23:13:10 +00:00
Merge branch 'w2p-59343_support-ordered-metadata' into w2p-58898_place-column-calculation-error
# Conflicts: # dspace-spring-rest/src/main/java/org/dspace/app/rest/repository/DSpaceRestRepository.java
This commit is contained in:
@@ -27,7 +27,6 @@ import org.dspace.content.authority.Choices;
|
|||||||
import org.dspace.content.authority.service.ChoiceAuthorityService;
|
import org.dspace.content.authority.service.ChoiceAuthorityService;
|
||||||
import org.dspace.content.authority.service.MetadataAuthorityService;
|
import org.dspace.content.authority.service.MetadataAuthorityService;
|
||||||
import org.dspace.content.service.DSpaceObjectService;
|
import org.dspace.content.service.DSpaceObjectService;
|
||||||
import org.dspace.content.service.ItemService;
|
|
||||||
import org.dspace.content.service.MetadataFieldService;
|
import org.dspace.content.service.MetadataFieldService;
|
||||||
import org.dspace.content.service.MetadataValueService;
|
import org.dspace.content.service.MetadataValueService;
|
||||||
import org.dspace.content.service.RelationshipService;
|
import org.dspace.content.service.RelationshipService;
|
||||||
@@ -65,8 +64,6 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
|||||||
@Autowired(required = true)
|
@Autowired(required = true)
|
||||||
protected MetadataAuthorityService metadataAuthorityService;
|
protected MetadataAuthorityService metadataAuthorityService;
|
||||||
@Autowired(required = true)
|
@Autowired(required = true)
|
||||||
protected ItemService itemService;
|
|
||||||
@Autowired(required = true)
|
|
||||||
protected RelationshipService relationshipService;
|
protected RelationshipService relationshipService;
|
||||||
|
|
||||||
public DSpaceObjectServiceImpl() {
|
public DSpaceObjectServiceImpl() {
|
||||||
@@ -559,7 +556,7 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
|||||||
Map<MetadataField, Integer> fieldToLastPlace = new HashMap<>();
|
Map<MetadataField, Integer> fieldToLastPlace = new HashMap<>();
|
||||||
List<MetadataValue> metadataValues = new LinkedList<>();
|
List<MetadataValue> metadataValues = new LinkedList<>();
|
||||||
if (dso.getType() == Constants.ITEM) {
|
if (dso.getType() == Constants.ITEM) {
|
||||||
metadataValues = itemService.getMetadata((Item) dso, Item.ANY, Item.ANY, Item.ANY, Item.ANY);
|
metadataValues = getMetadata(dso, Item.ANY, Item.ANY, Item.ANY, Item.ANY);
|
||||||
} else {
|
} else {
|
||||||
metadataValues = dso.getMetadata();
|
metadataValues = dso.getMetadata();
|
||||||
}
|
}
|
||||||
|
@@ -11,6 +11,7 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@@ -18,6 +19,8 @@ import java.util.LinkedList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@@ -1329,6 +1332,8 @@ prevent the generation of resource policy entry values with null dspace_object a
|
|||||||
listToReturn.add(metadataValue);
|
listToReturn.add(metadataValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
listToReturn = sortMetadataValueList(listToReturn);
|
||||||
|
|
||||||
return listToReturn;
|
return listToReturn;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -1346,11 +1351,28 @@ prevent the generation of resource policy entry values with null dspace_object a
|
|||||||
finalList.add(metadataValue);
|
finalList.add(metadataValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
finalList = sortMetadataValueList(finalList);
|
||||||
return finalList;
|
return finalList;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<MetadataValue> sortMetadataValueList(List<MetadataValue> listToReturn) {
|
||||||
|
Comparator<MetadataValue> comparator = Comparator.comparing(
|
||||||
|
metadataValue -> metadataValue.getMetadataField().getMetadataSchema().getName(),
|
||||||
|
Comparator.nullsFirst(Comparator.naturalOrder()));
|
||||||
|
comparator = comparator.thenComparing(metadataValue -> metadataValue.getMetadataField().getElement(),
|
||||||
|
Comparator.nullsFirst(Comparator.naturalOrder()));
|
||||||
|
comparator = comparator.thenComparing(metadataValue -> metadataValue.getMetadataField().getQualifier(),
|
||||||
|
Comparator.nullsFirst(Comparator.naturalOrder()));
|
||||||
|
comparator = comparator.thenComparing(metadataValue -> metadataValue.getPlace(),
|
||||||
|
Comparator.nullsFirst(Comparator.naturalOrder()));
|
||||||
|
|
||||||
|
Stream<MetadataValue> metadataValueStream = listToReturn.stream().sorted(comparator);
|
||||||
|
listToReturn = metadataValueStream.collect(Collectors.toList());
|
||||||
|
return listToReturn;
|
||||||
|
}
|
||||||
|
|
||||||
private List<RelationshipMetadataValue> handleItemRelationship(Context context, Item item, String entityType,
|
private List<RelationshipMetadataValue> handleItemRelationship(Context context, Item item, String entityType,
|
||||||
Relationship relationship,
|
Relationship relationship,
|
||||||
boolean enableVirtualMetadata)
|
boolean enableVirtualMetadata)
|
||||||
|
@@ -122,10 +122,11 @@ public class RelationshipServiceImpl implements RelationshipService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateItem(Context context, Item leftItem)
|
@Override
|
||||||
|
public void updateItem(Context context, Item relatedItem)
|
||||||
throws SQLException, AuthorizeException {
|
throws SQLException, AuthorizeException {
|
||||||
leftItem.setMetadataModified();
|
relatedItem.setMetadataModified();
|
||||||
itemService.update(context, leftItem);
|
itemService.update(context, relatedItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -102,6 +102,17 @@ public interface RelationshipService extends DSpaceCRUDService<Relationship> {
|
|||||||
public void updatePlaceInRelationship(Context context, Relationship relationship, boolean isCreation)
|
public void updatePlaceInRelationship(Context context, Relationship relationship, boolean isCreation)
|
||||||
throws SQLException, AuthorizeException;
|
throws SQLException, AuthorizeException;
|
||||||
|
|
||||||
public void updateItem(Context context, Item leftItem) throws SQLException, AuthorizeException;
|
/**
|
||||||
|
* This method will update the given item's metadata order.
|
||||||
|
* If the relationships for the item have been modified and will calculate the place based on a
|
||||||
|
* metadata field, this function will ensure the place is calculated.
|
||||||
|
* @param context The relevant DSpace context
|
||||||
|
* @param relatedItem The Item for which the list of Relationship location is calculated
|
||||||
|
* based on a metadata field
|
||||||
|
* @throws SQLException If something goes wrong
|
||||||
|
* @throws AuthorizeException
|
||||||
|
* If the user is not authorized to update the item
|
||||||
|
*/
|
||||||
|
public void updateItem(Context context, Item relatedItem) throws SQLException, AuthorizeException;
|
||||||
|
|
||||||
}
|
}
|
@@ -95,8 +95,7 @@ public class ItemConverter extends DSpaceObjectConverter<org.dspace.content.Item
|
|||||||
item.setRelationships(relationshipRestList);
|
item.setRelationships(relationshipRestList);
|
||||||
|
|
||||||
List<MetadataValue> fullList = new LinkedList<>();
|
List<MetadataValue> fullList = new LinkedList<>();
|
||||||
fullList.addAll(obj.getMetadata());
|
fullList = itemService.getMetadata(obj, Item.ANY, Item.ANY, Item.ANY, Item.ANY, true);
|
||||||
fullList.addAll(itemService.getRelationshipMetadata(obj, true));
|
|
||||||
|
|
||||||
List<MetadataEntryRest> metadata = super.convertMetadataToRest(fullList);
|
List<MetadataEntryRest> metadata = super.convertMetadataToRest(fullList);
|
||||||
item.setMetadata(metadata);
|
item.setMetadata(metadata);
|
||||||
|
@@ -493,11 +493,17 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
|||||||
|
|
||||||
List<MetadataValue> list = itemService.getMetadata(publication, "dc", "contributor", "author", Item.ANY);
|
List<MetadataValue> list = itemService.getMetadata(publication, "dc", "contributor", "author", Item.ANY);
|
||||||
|
|
||||||
|
assertEquals(2, list.size());
|
||||||
for (MetadataValue mdv : list) {
|
for (MetadataValue mdv : list) {
|
||||||
if (StringUtils.equals(mdv.getValue(), "plain text")) {
|
if (StringUtils.equals(mdv.getValue(), "plain text")) {
|
||||||
assertEquals(1, mdv.getPlace());
|
assertEquals(1, mdv.getPlace());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
MetadataValue author0MD = list.get(0);
|
||||||
|
assertEquals("Smith, Donald", author0MD.getValue());
|
||||||
|
MetadataValue author1MD = list.get(1);
|
||||||
|
assertEquals("plain text", author1MD.getValue());
|
||||||
|
|
||||||
|
|
||||||
getClient(adminToken).perform(get("/api/core/relationships/" + firstRelationshipIdString))
|
getClient(adminToken).perform(get("/api/core/relationships/" + firstRelationshipIdString))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
@@ -520,10 +526,19 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
|||||||
map = mapper.readValue(content, Map.class);
|
map = mapper.readValue(content, Map.class);
|
||||||
String secondRelationshipIdString = String.valueOf(map.get("id"));
|
String secondRelationshipIdString = String.valueOf(map.get("id"));
|
||||||
|
|
||||||
|
list = itemService.getMetadata(publication, "dc", "contributor", "author", Item.ANY);
|
||||||
|
assertEquals(3, list.size());
|
||||||
getClient(adminToken).perform(get("/api/core/relationships/" + secondRelationshipIdString))
|
getClient(adminToken).perform(get("/api/core/relationships/" + secondRelationshipIdString))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(jsonPath("leftPlace", is(2)));
|
.andExpect(jsonPath("leftPlace", is(2)));
|
||||||
|
|
||||||
|
author0MD = list.get(0);
|
||||||
|
assertEquals("Smith, Donald", author0MD.getValue());
|
||||||
|
author1MD = list.get(1);
|
||||||
|
assertEquals("plain text", author1MD.getValue());
|
||||||
|
MetadataValue author2MD = list.get(2);
|
||||||
|
assertEquals("Smith, Maria", author2MD.getValue());
|
||||||
|
|
||||||
publication = itemService.find(context, publication.getID());
|
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 two");
|
||||||
// itemService.addMetadata(context, publication, "dc", "contributor", "author", Item.ANY, "plain text three");
|
// itemService.addMetadata(context, publication, "dc", "contributor", "author", Item.ANY, "plain text three");
|
||||||
@@ -533,12 +548,22 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
|||||||
// itemService.update(context, publication);
|
// itemService.update(context, publication);
|
||||||
list = itemService.getMetadata(publication, "dc", "contributor", "author", Item.ANY);
|
list = itemService.getMetadata(publication, "dc", "contributor", "author", Item.ANY);
|
||||||
|
|
||||||
|
assertEquals(4, list.size());
|
||||||
for (MetadataValue mdv : list) {
|
for (MetadataValue mdv : list) {
|
||||||
if (StringUtils.equals(mdv.getValue(), "plain text two")) {
|
if (StringUtils.equals(mdv.getValue(), "plain text two")) {
|
||||||
assertEquals(3, mdv.getPlace());
|
assertEquals(3, mdv.getPlace());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
author0MD = list.get(0);
|
||||||
|
assertEquals("Smith, Donald", author0MD.getValue());
|
||||||
|
author1MD = list.get(1);
|
||||||
|
assertEquals("plain text", author1MD.getValue());
|
||||||
|
author2MD = list.get(2);
|
||||||
|
assertEquals("Smith, Maria", author2MD.getValue());
|
||||||
|
MetadataValue author3MD = list.get(3);
|
||||||
|
assertEquals("plain text two", author3MD.getValue());
|
||||||
|
|
||||||
|
|
||||||
mvcResult = getClient(adminToken).perform(post("/api/core/relationships")
|
mvcResult = getClient(adminToken).perform(post("/api/core/relationships")
|
||||||
.param("leftItem", publication.getID().toString())
|
.param("leftItem", publication.getID().toString())
|
||||||
@@ -557,21 +582,102 @@ public class RelationshipRestRepositoryIT extends AbstractControllerIntegrationT
|
|||||||
map = mapper.readValue(content, Map.class);
|
map = mapper.readValue(content, Map.class);
|
||||||
String thirdRelationshipIdString = String.valueOf(map.get("id"));
|
String thirdRelationshipIdString = String.valueOf(map.get("id"));
|
||||||
|
|
||||||
|
list = itemService.getMetadata(publication, "dc", "contributor", "author", Item.ANY);
|
||||||
|
assertEquals(5, list.size());
|
||||||
getClient(adminToken).perform(get("/api/core/relationships/" + thirdRelationshipIdString))
|
getClient(adminToken).perform(get("/api/core/relationships/" + thirdRelationshipIdString))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(jsonPath("leftPlace", is(4)));
|
.andExpect(jsonPath("leftPlace", is(4)));
|
||||||
|
|
||||||
|
author0MD = list.get(0);
|
||||||
|
assertEquals("Smith, Donald", author0MD.getValue());
|
||||||
|
author1MD = list.get(1);
|
||||||
|
assertEquals("plain text", author1MD.getValue());
|
||||||
|
author2MD = list.get(2);
|
||||||
|
assertEquals("Smith, Maria", author2MD.getValue());
|
||||||
|
author3MD = list.get(3);
|
||||||
|
assertEquals("plain text two", author3MD.getValue());
|
||||||
|
MetadataValue author4MD = list.get(4);
|
||||||
|
assertEquals("Maybe, Maybe", author4MD.getValue());
|
||||||
|
|
||||||
publication = itemService.find(context, publication.getID());
|
publication = itemService.find(context, publication.getID());
|
||||||
itemService.addMetadata(context, publication, "dc", "contributor", "author", Item.ANY, "plain text three");
|
itemService.addMetadata(context, publication, "dc", "contributor", "author", Item.ANY, "plain text three");
|
||||||
itemService.update(context, publication);
|
itemService.update(context, publication);
|
||||||
|
|
||||||
list = itemService.getMetadata(publication, "dc", "contributor", "author", Item.ANY);
|
list = itemService.getMetadata(publication, "dc", "contributor", "author", Item.ANY);
|
||||||
|
|
||||||
|
assertEquals(6, list.size());
|
||||||
for (MetadataValue mdv : list) {
|
for (MetadataValue mdv : list) {
|
||||||
if (StringUtils.equals(mdv.getValue(), "plain text three")) {
|
if (StringUtils.equals(mdv.getValue(), "plain text three")) {
|
||||||
assertEquals(5, mdv.getPlace());
|
assertEquals(5, mdv.getPlace());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
author0MD = list.get(0);
|
||||||
|
assertEquals("Smith, Donald", author0MD.getValue());
|
||||||
|
author1MD = list.get(1);
|
||||||
|
assertEquals("plain text", author1MD.getValue());
|
||||||
|
author2MD = list.get(2);
|
||||||
|
assertEquals("Smith, Maria", author2MD.getValue());
|
||||||
|
author3MD = list.get(3);
|
||||||
|
assertEquals("plain text two", author3MD.getValue());
|
||||||
|
author4MD = list.get(4);
|
||||||
|
assertEquals("Maybe, Maybe", author4MD.getValue());
|
||||||
|
MetadataValue author5MD = list.get(5);
|
||||||
|
assertEquals("plain text three", author5MD.getValue());
|
||||||
|
|
||||||
|
publication = itemService.find(context, publication.getID());
|
||||||
|
itemService.addMetadata(context, publication, "dc", "contributor", "author", Item.ANY, "plain text four");
|
||||||
|
itemService.addMetadata(context, publication, "dc", "contributor", "author", Item.ANY, "plain text five");
|
||||||
|
itemService.addMetadata(context, publication, "dc", "contributor", "author", Item.ANY, "plain text six");
|
||||||
|
itemService.addMetadata(context, publication, "dc", "contributor", "author", Item.ANY, "plain text seven");
|
||||||
|
itemService.update(context, publication);
|
||||||
|
|
||||||
|
list = itemService.getMetadata(publication, "dc", "contributor", "author", Item.ANY);
|
||||||
|
|
||||||
|
assertEquals(10, list.size());
|
||||||
|
for (MetadataValue mdv : list) {
|
||||||
|
if (StringUtils.equals(mdv.getValue(), "plain text four")) {
|
||||||
|
assertEquals(6, mdv.getPlace());
|
||||||
|
}
|
||||||
|
if (StringUtils.equals(mdv.getValue(), "plain text five")) {
|
||||||
|
assertEquals(7, mdv.getPlace());
|
||||||
|
}
|
||||||
|
if (StringUtils.equals(mdv.getValue(), "plain text six")) {
|
||||||
|
assertEquals(8, mdv.getPlace());
|
||||||
|
}
|
||||||
|
if (StringUtils.equals(mdv.getValue(), "plain text seven")) {
|
||||||
|
assertEquals(9, mdv.getPlace());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
author0MD = list.get(0);
|
||||||
|
assertEquals("Smith, Donald", author0MD.getValue());
|
||||||
|
author1MD = list.get(1);
|
||||||
|
assertEquals("plain text", author1MD.getValue());
|
||||||
|
author2MD = list.get(2);
|
||||||
|
assertEquals("Smith, Maria", author2MD.getValue());
|
||||||
|
author3MD = list.get(3);
|
||||||
|
assertEquals("plain text two", author3MD.getValue());
|
||||||
|
author4MD = list.get(4);
|
||||||
|
assertEquals("Maybe, Maybe", author4MD.getValue());
|
||||||
|
author5MD = list.get(5);
|
||||||
|
assertEquals("plain text three", author5MD.getValue());
|
||||||
|
MetadataValue author6MD = list.get(6);
|
||||||
|
assertEquals("plain text four", author6MD.getValue());
|
||||||
|
MetadataValue author7MD = list.get(7);
|
||||||
|
assertEquals("plain text five", author7MD.getValue());
|
||||||
|
MetadataValue author8MD = list.get(8);
|
||||||
|
assertEquals("plain text six", author8MD.getValue());
|
||||||
|
MetadataValue author9MD = list.get(9);
|
||||||
|
assertEquals("plain text seven", author9MD.getValue());
|
||||||
|
|
||||||
|
list = itemService.getMetadata(publication, "dc", "contributor", Item.ANY, Item.ANY);
|
||||||
|
assertEquals(10, list.size()); //same size as authors
|
||||||
|
list = itemService.getMetadata(publication, "dc", Item.ANY, Item.ANY, Item.ANY);
|
||||||
|
assertEquals(16, list.size()); //also includes title, 4 date fields, uri
|
||||||
|
list = itemService.getMetadata(publication, Item.ANY, Item.ANY, Item.ANY, Item.ANY);
|
||||||
|
assertEquals(20, list.size()); //also includes type and 3 relation.isAuthorOfPublication values
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user