mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-18 07:23:08 +00:00
Sort metadata values part 1
This commit is contained in:
@@ -0,0 +1,28 @@
|
|||||||
|
/**
|
||||||
|
* The contents of this file are subject to the license and copyright
|
||||||
|
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||||
|
* tree and available online at
|
||||||
|
*
|
||||||
|
* http://www.dspace.org/license/
|
||||||
|
*/
|
||||||
|
package org.dspace.content;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compares two {@link MetadataValue}s.
|
||||||
|
* The comparator will sort by schema, element, qualifier, place (in that order)
|
||||||
|
*/
|
||||||
|
public class MetadataValueComparator
|
||||||
|
implements Comparator<MetadataValue>, Serializable {
|
||||||
|
@Override
|
||||||
|
public int compare(MetadataValue mv1, MetadataValue mv2) {
|
||||||
|
int compare = mv1.getMetadataField().getMetadataSchema().getID().compareTo(mv2.getMetadataField().getMetadataSchema().getID());
|
||||||
|
if (compare != 0)
|
||||||
|
return compare;
|
||||||
|
compare = mv1.getMetadataField().getElement().compareTo(mv2.getMetadataField().getElement());
|
||||||
|
//TODO: continue comparison
|
||||||
|
return compare;
|
||||||
|
}
|
||||||
|
}
|
@@ -283,11 +283,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())
|
||||||
@@ -310,10 +316,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");
|
||||||
@@ -323,12 +338,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())
|
||||||
@@ -347,21 +372,80 @@ 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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