Skip to content

Commit

Permalink
feat(search-locations): Allow Unified Inventory Locations in Consorti…
Browse files Browse the repository at this point in the history
…um to be fetched by member tenants

Closes: MSEARCH-660
  • Loading branch information
mukhiddin-yusuf committed Jun 5, 2024
1 parent 0578c3b commit 0a0df33
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Return Unified List of Inventory Locations in a Consortium ([MSEARCH-681](https://folio-org.atlassian.net/browse/MSEARCH-681))
* Remove ability to match on LCCN searches without a prefix ([MSEARCH-752](https://folio-org.atlassian.net/browse/MSEARCH-752))
* Search consolidated items/holdings data in consortium ([MSEARCH-759](https://folio-org.atlassian.net/browse/MSEARCH-759))
* Allow Unified List of Inventory Locations in a Consortium to be fetched by member tenants ([MSEARCH-660](https://folio-org.atlassian.net/browse/MSEARCH-660))

### Bug fixes
* Do not delete kafka topics if collection topic is enabled ([MSEARCH-725](https://folio-org.atlassian.net/browse/MSEARCH-725))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public ResponseEntity<ConsortiumLocationCollection> getConsortiumLocations(Strin
Integer offset,
String sortBy,
SortOrder sortOrder) {
verifyAndGetTenant(tenantHeader);
var result = locationService.fetchLocations(tenantHeader, tenantId, limit, offset, sortBy, sortOrder);

return ResponseEntity.ok(new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class ConsortiumLocationService {
public static final String ID = "id";
public static final String TENANT_ID = "tenantId";
private final ConsortiumLocationRepository repository;
private final ConsortiumTenantExecutor executor;

public SearchResult<ConsortiumLocation> fetchLocations(String tenantHeader,
String tenantId,
Expand All @@ -29,7 +30,9 @@ public SearchResult<ConsortiumLocation> fetchLocations(String tenantHeader,
tenantId,
sortBy);
validateSortByValue(sortBy);
return repository.fetchLocations(tenantHeader, tenantId, limit, offset, sortBy, sortOrder);
return executor.execute(
tenantHeader,
() -> repository.fetchLocations(tenantHeader, tenantId, limit, offset, sortBy, sortOrder));
}

private void validateSortByValue(String sortBy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static org.folio.search.utils.TestUtils.parseResponse;

import java.util.List;
import java.util.stream.Stream;
import org.folio.search.domain.dto.ConsortiumLocationCollection;
import org.folio.search.model.Pair;
import org.folio.search.support.base.BaseConsortiumIntegrationTest;
Expand Down Expand Up @@ -44,11 +45,17 @@ static void cleanUp() {
void doGetConsortiumLocations_returns200AndRecords() {
List<Pair<String, String>> queryParams = List.of();

var result = doGet(consortiumLocationsSearchPath(queryParams), CENTRAL_TENANT_ID);
var result = doGet(consortiumLocationsSearchPath(queryParams), MEMBER_TENANT_ID);
var actual = parseResponse(result, ConsortiumLocationCollection.class);

assertThat(actual.getLocations()).hasSize(7);
assertThat(actual.getTotalRecords()).isEqualTo(7);
assertThat(actual.getLocations()).hasSize(14);
assertThat(actual.getTotalRecords()).isEqualTo(14);
assertThat(actual.getLocations())
.filteredOn(location -> location.getTenantId().equals(MEMBER_TENANT_ID))
.hasSize(7);
assertThat(actual.getLocations())
.filteredOn(location -> location.getTenantId().equals(CENTRAL_TENANT_ID))
.hasSize(7);
assertThat(actual.getLocations())
.allSatisfy(location -> {
assertThat(location.getId()).isNotBlank();
Expand Down Expand Up @@ -79,12 +86,15 @@ void doGetConsortiumLocations_returns200AndRecords_withAllQueryParams() {
}

private static void saveLocationRecords() {
getLocationsSampleAsMap().stream().map(
location -> kafkaResourceEvent(CENTRAL_TENANT_ID, CREATE, location, null))
.forEach(event -> kafkaTemplate.send(inventoryLocationTopic(CENTRAL_TENANT_ID), event));
getLocationsSampleAsMap().stream()
.flatMap(location -> Stream.of(
kafkaResourceEvent(CENTRAL_TENANT_ID, CREATE, location, null),
kafkaResourceEvent(MEMBER_TENANT_ID, CREATE, location, null)))
.forEach(event -> kafkaTemplate.send(inventoryLocationTopic(event.getTenant()), event));

await().atMost(ONE_MINUTE).pollInterval(ONE_SECOND).untilAsserted(() -> {
var totalHits = countIndexDocument(LOCATION_RESOURCE, CENTRAL_TENANT_ID);
assertThat(totalHits).isEqualTo(7);
assertThat(totalHits).isEqualTo(14);
});
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package org.folio.search.service.consortium;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.util.List;
import java.util.function.Supplier;
import org.folio.search.domain.dto.ConsortiumLocation;
import org.folio.search.domain.dto.SortOrder;
import org.folio.search.model.SearchResult;
Expand All @@ -27,6 +30,8 @@ public class ConsortiumLocationServiceTest {
public static final String NAME = "name";
@Mock
private ConsortiumLocationRepository repository;
@Mock
private ConsortiumTenantExecutor executor;

@InjectMocks
private ConsortiumLocationService service;
Expand All @@ -43,6 +48,8 @@ void fetchLocations_ValidSortBy() {

when(repository.fetchLocations(tenantHeader, tenantId, limit, offset, sortBy, sortOrder))
.thenReturn(searchResult);
when(executor.execute(eq(tenantId), any(Supplier.class)))
.thenAnswer(invocation -> ((Supplier<ConsortiumLocation>) invocation.getArgument(1)).get());

var actual = service.fetchLocations(tenantHeader, tenantId, limit, offset, sortBy, sortOrder);

Expand All @@ -52,6 +59,7 @@ void fetchLocations_ValidSortBy() {
assertThat(actual.getRecords().get(0).getName()).isEqualTo(LOCATION_NAME);
assertThat(actual.getRecords().get(0).getId()).isEqualTo(ID);
verify(repository).fetchLocations(tenantHeader, tenantId, limit, offset, sortBy, sortOrder);
verify(executor).execute(eq(tenantId), any(Supplier.class));
}

@NotNull
Expand Down

0 comments on commit 0a0df33

Please sign in to comment.