mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Merge pull request #2617 from atmire/DS-4401
DS-4401 Enforce relational place ordering when place direction is known
This commit is contained in:
@@ -145,11 +145,13 @@ public class RelationshipDAOImpl extends AbstractHibernateDAO<Relationship> impl
|
||||
.where(criteriaBuilder.equal(relationshipRoot.get(Relationship_.relationshipType),
|
||||
relationshipType),
|
||||
criteriaBuilder.equal(relationshipRoot.get(Relationship_.leftItem), item));
|
||||
criteriaQuery.orderBy(criteriaBuilder.asc(relationshipRoot.get(Relationship_.leftPlace)));
|
||||
} else {
|
||||
criteriaQuery
|
||||
.where(criteriaBuilder.equal(relationshipRoot.get(Relationship_.relationshipType),
|
||||
relationshipType),
|
||||
criteriaBuilder.equal(relationshipRoot.get(Relationship_.rightItem), item));
|
||||
criteriaQuery.orderBy(criteriaBuilder.asc(relationshipRoot.get(Relationship_.rightPlace)));
|
||||
}
|
||||
return list(context, criteriaQuery, true, Relationship.class, limit, offset);
|
||||
}
|
||||
|
@@ -351,9 +351,13 @@ public class RelationshipRestRepository extends DSpaceRestRepository<Relationshi
|
||||
throw new ResourceNotFoundException("The request DSO with id: " + dsoId + " was not found");
|
||||
}
|
||||
for (RelationshipType relationshipType : relationshipTypeList) {
|
||||
boolean isLeft = false;
|
||||
if (relationshipType.getLeftwardType().equalsIgnoreCase(label)) {
|
||||
isLeft = true;
|
||||
}
|
||||
total += relationshipService.countByItemAndRelationshipType(context, item, relationshipType);
|
||||
relationships.addAll(relationshipService.findByItemAndRelationshipType(context, item, relationshipType,
|
||||
pageable.getPageSize(), pageable.getOffset()));
|
||||
isLeft, pageable.getPageSize(), pageable.getOffset()));
|
||||
}
|
||||
} else {
|
||||
for (RelationshipType relationshipType : relationshipTypeList) {
|
||||
|
@@ -86,6 +86,7 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
private Item author3;
|
||||
|
||||
private Item orgUnit1;
|
||||
private Item orgUnit2;
|
||||
private Item project1;
|
||||
|
||||
private Item publication1;
|
||||
@@ -157,6 +158,13 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
.withRelationshipType("OrgUnit")
|
||||
.build();
|
||||
|
||||
orgUnit2 = ItemBuilder.createItem(context, col3)
|
||||
.withTitle("OrgUnit2")
|
||||
.withAuthor("Testy, TEst")
|
||||
.withIssueDate("2015-01-01")
|
||||
.withRelationshipType("OrgUnit")
|
||||
.build();
|
||||
|
||||
project1 = ItemBuilder.createItem(context, col3)
|
||||
.withTitle("Project1")
|
||||
.withAuthor("Testy, TEst")
|
||||
@@ -2161,6 +2169,9 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
Relationship relationship1 = RelationshipBuilder
|
||||
.createRelationshipBuilder(context, author1, orgUnit1, isOrgUnitOfPersonRelationshipType).build();
|
||||
|
||||
Relationship relationshipOrgunitExtra = RelationshipBuilder
|
||||
.createRelationshipBuilder(context, author1, orgUnit2, isOrgUnitOfPersonRelationshipType).build();
|
||||
|
||||
// We're creating a Relationship of type isOrgUnitOfPerson between a different author and the same orgunit
|
||||
Relationship relationshipAuthorExtra = RelationshipBuilder
|
||||
.createRelationshipBuilder(context, author2, orgUnit1, isOrgUnitOfPersonRelationshipType).build();
|
||||
@@ -2186,10 +2197,16 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.page",
|
||||
is(PageMatcher.pageEntryWithTotalPagesAndElements(0, 20, 1, 1))))
|
||||
is(PageMatcher.pageEntryWithTotalPagesAndElements(0, 20, 1, 2))))
|
||||
.andExpect(jsonPath("$._embedded.relationships", hasItem(
|
||||
RelationshipMatcher.matchRelationship(relationship1)
|
||||
)))
|
||||
))) //check ordering
|
||||
.andExpect(jsonPath("$._embedded.relationships[0]._links.rightItem.href",
|
||||
containsString(orgUnit1.getID().toString())
|
||||
))
|
||||
.andExpect(jsonPath("$._embedded.relationships[1]._links.rightItem.href",
|
||||
containsString(orgUnit2.getID().toString())
|
||||
))
|
||||
;
|
||||
|
||||
// Perform a GET request to the searchByLabel endpoint, asking for Relationships of type isOrgUnitOfPerson
|
||||
@@ -2201,10 +2218,11 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
|
||||
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.page",
|
||||
is(PageMatcher.pageEntryWithTotalPagesAndElements(0, 20, 1, 2))))
|
||||
is(PageMatcher.pageEntryWithTotalPagesAndElements(0, 20, 1, 3))))
|
||||
.andExpect(jsonPath("$._embedded.relationships", containsInAnyOrder(
|
||||
RelationshipMatcher.matchRelationship(relationship1),
|
||||
RelationshipMatcher.matchRelationship(relationshipAuthorExtra)
|
||||
RelationshipMatcher.matchRelationship(relationshipAuthorExtra),
|
||||
RelationshipMatcher.matchRelationship(relationshipOrgunitExtra)
|
||||
)))
|
||||
;
|
||||
}
|
||||
|
Reference in New Issue
Block a user