[TLC-249] Improve 'findByFields' browse refactor

This commit is contained in:
Kim Shepherd
2023-01-26 14:47:02 +13:00
parent d85de89261
commit 1c2a1538fd
2 changed files with 47 additions and 0 deletions

View File

@@ -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
*

View File

@@ -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