mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 15:03:18 +00:00
[TLC-249] Improve 'findByFields' browse refactor
This commit is contained in:
@@ -86,6 +86,37 @@ public class BrowseIndexRestRepository extends DSpaceRestRepository<BrowseIndexR
|
||||
return bi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a browse index by a list of fields (first match will be returned)
|
||||
* @param fields
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
@SearchRestMethod(name = "byFields")
|
||||
public BrowseIndexRest findByFields(@Parameter(value = "fields", required = true) String[] fields)
|
||||
throws SQLException {
|
||||
BrowseIndexRest bi = null;
|
||||
BrowseIndex bix = null;
|
||||
try {
|
||||
// Find the browse index definition that matches any field - once found, return
|
||||
for (String field : fields) {
|
||||
CrossLinks cl = new CrossLinks();
|
||||
if (cl.hasLink(field)) {
|
||||
// Get the index name for this
|
||||
String browseIndexName = cl.getLinkType(field);
|
||||
bix = BrowseIndex.getBrowseIndex(browseIndexName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (BrowseException e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
if (bix != null) {
|
||||
bi = converter.toRest(bix, utils.obtainProjection());
|
||||
}
|
||||
return bi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get paginated list of all browse index definitions for configured browse links
|
||||
*
|
||||
|
@@ -2147,6 +2147,22 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe
|
||||
;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findTwoLinked() throws Exception {
|
||||
//When we call the root endpoint
|
||||
getClient().perform(get("/api/discover/browses/search/byFields?fields=dc.contributor.author,dc.date.issued"))
|
||||
//The status has to be 200 OK
|
||||
.andExpect(status().isOk())
|
||||
//We expect the content type to be "application/hal+json;charset=UTF-8"
|
||||
.andExpect(content().contentType(contentType))
|
||||
// The array of browse index should have a size 2 and contain both configured indices
|
||||
.andExpect(jsonPath("$._embedded.browses", hasSize(2)))
|
||||
.andExpect(jsonPath("$._embedded.browses", containsInAnyOrder(
|
||||
BrowseIndexMatcher.contributorBrowseIndex("asc"),
|
||||
BrowseIndexMatcher.subjectBrowseIndex("asc")
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Expect a list of browse definitions that are also configured for link rendering
|
||||
* @throws Exception
|
||||
|
Reference in New Issue
Block a user