Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSEARCH-855: Update consortium library, campus, institution endpoints #682

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
### New APIs versions
* Provides `indices v0.8`
* Provides `search v1.3`
* Provides `consortium-search v2.0`
* Provides `consortium-search v2.1`
* Provides `browse v1.4`
* Requires `locations v3.0`
* Requires `instance-storage v10.3 or v11.0`
Expand Down Expand Up @@ -48,6 +48,7 @@
* Modify usage of shelving order for call number browse ([MSEARCH-831](https://folio-org.atlassian.net/browse/MSEARCH-831))
* Implement new re-index flow for instance records ([MSEARCH-793](https://folio-org.atlassian.net/issues/MSEARCH-793), [MSEARCH-794](https://folio-org.atlassian.net/issues/MSEARCH-794), [MSEARCH-796](https://folio-org.atlassian.net/issues/MSEARCH-796), [MSEARCH-797](https://folio-org.atlassian.net/issues/MSEARCH-797), [MSEARCH-798](https://folio-org.atlassian.net/issues/MSEARCH-798), [MSEARCH-799](https://folio-org.atlassian.net/issues/MSEARCH-799), [MSEARCH-800](https://folio-org.atlassian.net/issues/MSEARCH-800), [MSEARCH-801](https://folio-org.atlassian.net/issues/MSEARCH-801), [MSEARCH-802](https://folio-org.atlassian.net/issues/MSEARCH-802))
* Implement Linked Data HUB index and search API ([MSEARCH-844](https://folio-org.atlassian.net/browse/MSEARCH-844))
* Extend consortium library, campus, institution API with id param ([MSEARCH-855](https://folio-org.atlassian.net/browse/MSEARCH-855))

### Bug fixes
* Do not delete kafka topics if collection topic is enabled ([MSEARCH-725](https://folio-org.atlassian.net/browse/MSEARCH-725))
Expand Down
2 changes: 1 addition & 1 deletion descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
},
{
"id": "consortium-search",
"version": "2.0",
"version": "2.1",
"handlers": [
{
"methods": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,12 @@ public ResponseEntity<ConsortiumLocationCollection> getConsortiumLocations(Strin
@Override
public ResponseEntity<ConsortiumCampusCollection> getConsortiumCampuses(String tenantHeader,
String tenantId,
String id,
Integer limit,
Integer offset,
String sortBy,
SortOrder sortOrder) {
var result = campusService.fetchCampuses(tenantHeader, tenantId, limit, offset, sortBy, sortOrder);
var result = campusService.fetchCampuses(tenantHeader, tenantId, id, limit, offset, sortBy, sortOrder);

return ResponseEntity.ok(new
ConsortiumCampusCollection()
Expand All @@ -122,11 +123,12 @@ public ResponseEntity<ConsortiumCampusCollection> getConsortiumCampuses(String t
@Override
public ResponseEntity<ConsortiumLibraryCollection> getConsortiumLibraries(String tenantHeader,
String tenantId,
String id,
Integer limit,
Integer offset,
String sortBy,
SortOrder sortOrder) {
var result = libraryService.fetchLibraries(tenantHeader, tenantId, limit, offset, sortBy, sortOrder);
var result = libraryService.fetchLibraries(tenantHeader, tenantId, id, limit, offset, sortBy, sortOrder);

return ResponseEntity.ok(new
ConsortiumLibraryCollection()
Expand All @@ -137,11 +139,12 @@ public ResponseEntity<ConsortiumLibraryCollection> getConsortiumLibraries(String
@Override
public ResponseEntity<ConsortiumInstitutionCollection> getConsortiumInstitutions(String tenantHeader,
String tenantId,
String id,
Integer limit,
Integer offset,
String sortBy,
SortOrder sortOrder) {
var result = institutionService.fetchInstitutions(tenantHeader, tenantId, limit, offset, sortBy, sortOrder);
var result = institutionService.fetchInstitutions(tenantHeader, tenantId, id, limit, offset, sortBy, sortOrder);

return ResponseEntity.ok(new
ConsortiumInstitutionCollection()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.folio.search.repository;

import static org.folio.search.model.types.ResourceType.CAMPUS;
import static org.folio.search.utils.SearchUtils.ID_FIELD;
import static org.folio.search.utils.SearchUtils.TENANT_ID_FIELD_NAME;
import static org.folio.search.utils.SearchUtils.performExceptionalOperation;
import static org.opensearch.search.sort.SortOrder.ASC;
Expand Down Expand Up @@ -36,27 +37,38 @@ public class ConsortiumCampusRepository {

public SearchResult<ConsortiumCampus> fetchCampuses(String tenantHeader,
String tenantId,
String id,
Integer limit,
Integer offset,
String sortBy,
SortOrder sortOrder) {

var sourceBuilder = getSearchSourceBuilder(tenantId, limit, offset, sortBy, sortOrder);
var sourceBuilder = getSearchSourceBuilder(tenantId, id, limit, offset, sortBy, sortOrder);
var response = search(sourceBuilder, tenantHeader);
return documentConverter.convertToSearchResult(response, ConsortiumCampus.class);
}

@NotNull
private static SearchSourceBuilder getSearchSourceBuilder(String tenantId,
String campusId,
Integer limit,
Integer offset,
String sortBy,
SortOrder sortOrder) {
var sourceBuilder = new SearchSourceBuilder();
var boolQuery = QueryBuilders.boolQuery();

Optional.ofNullable(tenantId)
.ifPresent(id -> sourceBuilder
.query(QueryBuilders.boolQuery()
.filter(QueryBuilders.termQuery(TENANT_ID_FIELD_NAME, id))));
.ifPresent(id -> boolQuery
.filter(QueryBuilders.termQuery(TENANT_ID_FIELD_NAME, id)));

Optional.ofNullable(campusId)
.ifPresent(id -> boolQuery
.filter(QueryBuilders.termQuery(ID_FIELD, id)));

if (boolQuery.hasClauses()) {
sourceBuilder.query(boolQuery);
}

return sourceBuilder
.from(offset)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.folio.search.repository;

import static org.folio.search.model.types.ResourceType.INSTITUTION;
import static org.folio.search.utils.SearchUtils.ID_FIELD;
import static org.folio.search.utils.SearchUtils.TENANT_ID_FIELD_NAME;
import static org.folio.search.utils.SearchUtils.performExceptionalOperation;
import static org.opensearch.search.sort.SortOrder.ASC;
Expand Down Expand Up @@ -36,27 +37,38 @@ public class ConsortiumInstitutionRepository {

public SearchResult<ConsortiumInstitution> fetchInstitutions(String tenantHeader,
String tenantId,
String id,
Integer limit,
Integer offset,
String sortBy,
SortOrder sortOrder) {

var sourceBuilder = getSearchSourceBuilder(tenantId, limit, offset, sortBy, sortOrder);
var sourceBuilder = getSearchSourceBuilder(tenantId, id, limit, offset, sortBy, sortOrder);
var response = search(sourceBuilder, tenantHeader);
return documentConverter.convertToSearchResult(response, ConsortiumInstitution.class);
}

@NotNull
private static SearchSourceBuilder getSearchSourceBuilder(String tenantId,
String institutionId,
Integer limit,
Integer offset,
String sortBy,
SortOrder sortOrder) {
var sourceBuilder = new SearchSourceBuilder();
var boolQuery = QueryBuilders.boolQuery();

Optional.ofNullable(tenantId)
.ifPresent(id -> sourceBuilder
.query(QueryBuilders.boolQuery()
.filter(QueryBuilders.termQuery(TENANT_ID_FIELD_NAME, id))));
.ifPresent(id -> boolQuery
.filter(QueryBuilders.termQuery(TENANT_ID_FIELD_NAME, id)));

Optional.ofNullable(institutionId)
.ifPresent(id -> boolQuery
.filter(QueryBuilders.termQuery(ID_FIELD, id)));

if (boolQuery.hasClauses()) {
sourceBuilder.query(boolQuery);
}

return sourceBuilder
.from(offset)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.folio.search.repository;

import static org.folio.search.model.types.ResourceType.LIBRARY;
import static org.folio.search.utils.SearchUtils.ID_FIELD;
import static org.folio.search.utils.SearchUtils.TENANT_ID_FIELD_NAME;
import static org.folio.search.utils.SearchUtils.performExceptionalOperation;
import static org.opensearch.search.sort.SortOrder.ASC;
Expand Down Expand Up @@ -36,27 +37,38 @@ public class ConsortiumLibraryRepository {

public SearchResult<ConsortiumLibrary> fetchLibraries(String tenantHeader,
String tenantId,
String id,
Integer limit,
Integer offset,
String sortBy,
SortOrder sortOrder) {

var sourceBuilder = getSearchSourceBuilder(tenantId, limit, offset, sortBy, sortOrder);
var sourceBuilder = getSearchSourceBuilder(tenantId, id, limit, offset, sortBy, sortOrder);
var response = search(sourceBuilder, tenantHeader);
return documentConverter.convertToSearchResult(response, ConsortiumLibrary.class);
}

@NotNull
private static SearchSourceBuilder getSearchSourceBuilder(String tenantId,
String libraryId,
Integer limit,
Integer offset,
String sortBy,
SortOrder sortOrder) {
var sourceBuilder = new SearchSourceBuilder();
var boolQuery = QueryBuilders.boolQuery();

Optional.ofNullable(tenantId)
.ifPresent(id -> sourceBuilder
.query(QueryBuilders.boolQuery()
.filter(QueryBuilders.termQuery(TENANT_ID_FIELD_NAME, id))));
.ifPresent(id -> boolQuery
.filter(QueryBuilders.termQuery(TENANT_ID_FIELD_NAME, id)));

Optional.ofNullable(libraryId)
.ifPresent(id -> boolQuery
.filter(QueryBuilders.termQuery(ID_FIELD, id)));

if (boolQuery.hasClauses()) {
sourceBuilder.query(boolQuery);
}

return sourceBuilder
.from(offset)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@ public class ConsortiumCampusService {

public SearchResult<ConsortiumCampus> fetchCampuses(String tenantHeader,
String tenantId,
String id,
Integer limit,
Integer offset,
String sortBy,
SortOrder sortOrder) {
log.info("fetching consortium campuses for tenant: {}, tenantId: {}, sortBy: {}",
log.info("fetching consortium campuses for tenant: {}, tenantId: {}, id: {}, sortBy: {}",
tenantHeader,
tenantId,
id,
sortBy);

validateSortByValue(sortBy);

return executor.execute(
tenantHeader,
() -> repository.fetchCampuses(tenantHeader, tenantId, limit, offset, sortBy, sortOrder));
() -> repository.fetchCampuses(tenantHeader, tenantId, id, limit, offset, sortBy, sortOrder));
}

private void validateSortByValue(String sortBy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@ public class ConsortiumInstitutionService {

public SearchResult<ConsortiumInstitution> fetchInstitutions(String tenantHeader,
String tenantId,
String id,
Integer limit,
Integer offset,
String sortBy,
SortOrder sortOrder) {
log.info("fetching consortium institution for tenant: {}, tenantId: {}, sortBy: {}",
log.info("fetching consortium institution for tenant: {}, tenantId: {}, id: {}, sortBy: {}",
tenantHeader,
tenantId,
id,
sortBy);

validateSortByValue(sortBy);

return executor.execute(
tenantHeader,
() -> repository.fetchInstitutions(tenantHeader, tenantId, limit, offset, sortBy, sortOrder));
() -> repository.fetchInstitutions(tenantHeader, tenantId, id, limit, offset, sortBy, sortOrder));
}

private void validateSortByValue(String sortBy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@ public class ConsortiumLibraryService {

public SearchResult<ConsortiumLibrary> fetchLibraries(String tenantHeader,
String tenantId,
String id,
Integer limit,
Integer offset,
String sortBy,
SortOrder sortOrder) {
log.info("fetching consortium libraries for tenant: {}, tenantId: {}, sortBy: {}",
log.info("fetching consortium libraries for tenant: {}, tenantId: {}, id: {}, sortBy: {}",
tenantHeader,
tenantId,
id,
sortBy);

validateSortByValue(sortBy);

return executor.execute(
tenantHeader,
() -> repository.fetchLibraries(tenantHeader, tenantId, limit, offset, sortBy, sortOrder));
() -> repository.fetchLibraries(tenantHeader, tenantId, id, limit, offset, sortBy, sortOrder));
}

private void validateSortByValue(String sortBy) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
in: query
name: id
description: "ID to filter by"
required: false
schema:
type: string
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ get:
- search-consortium
parameters:
- $ref: '../../parameters/tenant-id-query-param.yaml'
- $ref: '../../parameters/id-query-param.yaml'
- $ref: '../../parameters/consortium-location-unit-limit-param.yaml'
- $ref: '../../parameters/offset-param.yaml'
- $ref: '../../parameters/sort-by-campus-name-param.yaml'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ get:
- search-consortium
parameters:
- $ref: '../../parameters/tenant-id-query-param.yaml'
- $ref: '../../parameters/id-query-param.yaml'
- $ref: '../../parameters/consortium-location-unit-limit-param.yaml'
- $ref: '../../parameters/offset-param.yaml'
- $ref: '../../parameters/sort-by-institution-name-param.yaml'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ get:
- search-consortium
parameters:
- $ref: '../../parameters/tenant-id-query-param.yaml'
- $ref: '../../parameters/id-query-param.yaml'
- $ref: '../../parameters/consortium-location-unit-limit-param.yaml'
- $ref: '../../parameters/offset-param.yaml'
- $ref: '../../parameters/sort-by-library-name-param.yaml'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ properties:
name:
description: Campus name
type: string
code:
description: Campus code
type: string
institutionId:
description: The UUID of the institution, the first-level location unit, this (shelf) campus belongs to.
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ properties:
name:
description: Institution name
type: string
code:
description: Institution code
type: string
metadata:
$ref: "../dto/common/metadata.yaml"
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ properties:
campusId:
description: The UUID of the campus, the second-level location unit, this (shelf) library belongs to.
type: string
code:
description: Library code
type: string
metadata:
$ref: "../dto/common/metadata.yaml"
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void doGetConsortiumCampuses_returns200AndRecords() {
}

@Test
void doGetConsortiumCampuses_returns200AndRecords_withAllQueryParams() {
void doGetConsortiumCampuses_returns200AndRecords_withTenantAndSortQueryParams() {
List<Pair<String, String>> queryParams = List.of(
pair("tenantId", "consortium"),
pair("limit", "5"),
Expand All @@ -99,6 +99,27 @@ void doGetConsortiumCampuses_returns200AndRecords_withAllQueryParams() {
assertThat(actual.getCampuses().get(1).getName()).isEqualTo("My campus 2");
}

@Test
void doGetConsortiumCampuses_returns200AndRecords_withAllQueryParams() {
List<Pair<String, String>> queryParams = List.of(
pair("tenantId", "consortium"),
pair("id", "83891666-dcb6-4cd7-ad3a-f4b305abfe21"),
pair("limit", "5"),
pair("offset", "0"),
pair("sortBy", "name"),
pair("sortOrder", "asc")
);

var result = doGet(consortiumCampusesSearchPath(queryParams), CENTRAL_TENANT_ID);
var actual = parseResponse(result, ConsortiumCampusCollection.class);

assertThat(actual.getCampuses()).hasSize(1);
assertThat(actual.getTotalRecords()).isEqualTo(1);
assertThat(actual.getCampuses().get(0).getTenantId()).isEqualTo(CENTRAL_TENANT_ID);
assertThat(actual.getCampuses().get(0).getName()).isEqualTo("My campus 1");
assertThat(actual.getCampuses().get(0).getCode()).isEqualTo("MC1");
}

private static void saveCampusRecords() {
getCampusesSampleAsMap().stream()
.flatMap(campus -> Stream.of(
Expand Down
Loading
Loading