Skip to content

Commit

Permalink
Merge branch 'refs/heads/master' into MSEARCH-762
Browse files Browse the repository at this point in the history
  • Loading branch information
viacheslavpoliakov committed Jun 14, 2024
2 parents f5903cf + 2f45cb5 commit daac323
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 36 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* Search consolidated items/holdings data in consortium ([MSEARCH-759](https://folio-org.atlassian.net/browse/MSEARCH-759))
* Create bibframe index and process bibframe events ([MSEARCH-781](https://folio-org.atlassian.net/browse/MSEARCH-781))
* 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))
* Extend response with additional Location fields for Inventory Locations in a Consortium endpoint ([MSEARCH-775](https://folio-org.atlassian.net/browse/MSEARCH-775))

### Bug fixes
* Do not delete kafka topics if collection topic is enabled ([MSEARCH-725](https://folio-org.atlassian.net/browse/MSEARCH-725))
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/folio/search/model/dto/LocationDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.Builder;
import lombok.Data;
import lombok.extern.jackson.Jacksonized;
import org.folio.search.domain.dto.Metadata;

/**
* Describes Location object that comes from external channels.
Expand Down Expand Up @@ -39,5 +40,7 @@ public class LocationDto {
private UUID primaryServicePoint;
@JsonProperty("servicePointIds")
private List<UUID> servicePointIds;
@JsonProperty("metadata")
private Metadata metadata;

}
51 changes: 45 additions & 6 deletions src/main/resources/model/location.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,62 @@
"index": "keyword_lowercase",
"showInResponse": [ "search" ]
},
"description": {
"index": "keyword_lowercase",
"showInResponse": [ "search" ]
},
"discoveryDisplayName": {
"index": "keyword_lowercase",
"showInResponse": [ "search" ]
},
"isActive": {
"index": "bool"
"index": "bool",
"showInResponse": [ "search" ]
},
"institutionId": {
"index": "keyword_lowercase"
"index": "keyword_lowercase",
"showInResponse": [ "search" ]
},
"campusId": {
"index": "keyword_lowercase"
"index": "keyword_lowercase",
"showInResponse": [ "search" ]
},
"libraryId": {
"index": "keyword_lowercase"
"index": "keyword_lowercase",
"showInResponse": [ "search" ]
},
"primaryServicePoint": {
"index": "keyword_lowercase"
"index": "keyword_lowercase",
"showInResponse": [ "search" ]
},
"servicePointIds": {
"index": "keyword_lowercase"
"index": "keyword_lowercase",
"showInResponse": [ "search" ]
},
"metadata": {
"type": "object",
"properties": {
"createdDate": {
"searchTypes": "filter",
"index": "date"
},
"createdByUserId": {
"index": "keyword_lowercase"
},
"createdByUsername": {
"index": "keyword_lowercase"
},
"updatedDate": {
"searchTypes": "filter",
"index": "date"
},
"updatedByUserId": {
"index": "keyword_lowercase"
},
"updatedByUsername": {
"index": "keyword_lowercase"
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,36 @@ properties:
tenantId:
description: Tenant ID of the Location
type: string
code:
description: Code of the (shelf) location, usually an abbreviation of the name.
type: string
description:
description: Description of the (shelf) location.
type: string
discoveryDisplayName:
description: Name of the (shelf) location to be shown in the discovery.
type: string
isActive:
description: Whether this (shelf) location is active. Inactive (shelf) locations can no longer been used.
type: string
institutionId:
description: The UUID of the institution, the first-level location unit, this (shelf) location belongs to.
type: string
campusId:
description: The UUID of the campus, the second-level location unit, this (shelf) location belongs to.
type: string
libraryId:
description: The UUID of the library, the third-level location unit, this (shelf) location belongs to.
type: string
primaryServicePoint:
description: The UUID of the primary service point of this (shelf) location.
type: string
format: uuid
servicePointIds:
description: All service points that this (shelf) location has.
type: array
items:
type: string
format: uuid
metadata:
$ref: "../dto/common/metadata.yaml"
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.folio.search.controller;

import static org.apache.commons.lang3.ObjectUtils.isNotEmpty;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.awaitility.Durations.ONE_MINUTE;
Expand All @@ -17,13 +18,16 @@

import java.util.List;
import java.util.stream.Stream;
import org.assertj.core.groups.Tuple;
import org.folio.search.domain.dto.ConsortiumLocation;
import org.folio.search.domain.dto.ConsortiumLocationCollection;
import org.folio.search.model.Pair;
import org.folio.search.support.base.BaseConsortiumIntegrationTest;
import org.folio.spring.testing.type.IntegrationTest;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.platform.commons.util.StringUtils;

@IntegrationTest
class ConsortiumSearchLocationsIT extends BaseConsortiumIntegrationTest {
Expand Down Expand Up @@ -57,11 +61,20 @@ void doGetConsortiumLocations_returns200AndRecords() {
.filteredOn(location -> location.getTenantId().equals(CENTRAL_TENANT_ID))
.hasSize(7);
assertThat(actual.getLocations())
.allSatisfy(location -> {
assertThat(location.getId()).isNotBlank();
assertThat(location.getName()).isNotBlank();
assertThat(location.getTenantId()).isNotBlank();
});
.extracting(ConsortiumLocation::getId, ConsortiumLocation::getName, ConsortiumLocation::getTenantId,
ConsortiumLocation::getInstitutionId, ConsortiumLocation::getCampusId, ConsortiumLocation::getLibraryId,
ConsortiumLocation::getPrimaryServicePoint)
.map(Tuple::toList)
.matches(locations -> locations.stream().allMatch(obj -> StringUtils.isNotBlank(obj.toString())));
assertThat(actual.getLocations())
.map(ConsortiumLocation::getMetadata)
.filteredOn(metadata -> metadata.getCreatedDate() != null && metadata.getUpdatedDate() != null)
.hasSize(14);

assertThat(actual.getLocations())
.filteredOn(location -> "true".equals(location.getIsActive()) && isNotEmpty(location.getServicePointIds()))
.filteredOn(location -> List.of(MEMBER_TENANT_ID, CENTRAL_TENANT_ID).contains(location.getTenantId()))
.hasSize(12);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import static org.folio.search.utils.TestUtils.toMap;

import java.io.IOException;
import java.util.List;
import java.util.UUID;
import org.folio.search.domain.dto.Metadata;
import org.folio.search.domain.dto.ResourceEvent;
import org.folio.search.model.dto.LocationDto;
import org.folio.search.support.base.BaseConsortiumIntegrationTest;
Expand Down Expand Up @@ -47,11 +50,7 @@ void tearDown() throws IOException {

@Test
void shouldIndexAndRemoveLocation() {
var locationId = randomId();
var location = LocationDto.builder().id(locationId)
.name("location name")
.code("CODE")
.build();
var location = location();
var createEvent = kafkaResourceEvent(CENTRAL_TENANT_ID, CREATE, toMap(location), null);
kafkaTemplate.send(inventoryLocationTopic(CENTRAL_TENANT_ID), createEvent);
awaitAssertLocationCount(1);
Expand All @@ -63,11 +62,7 @@ void shouldIndexAndRemoveLocation() {

@Test
void shouldIndexSameLocationFromDifferentTenantsAsSeparateDocs() {
var locationId = randomId();
var location = LocationDto.builder().id(locationId)
.name("location name")
.code("CODE")
.build();
var location = location();
var createCentralEvent = kafkaResourceEvent(CENTRAL_TENANT_ID, CREATE, toMap(location), null);
var createMemberEvent = kafkaResourceEvent(MEMBER_TENANT_ID, CREATE, toMap(location), null);
kafkaTemplate.send(inventoryLocationTopic(CENTRAL_TENANT_ID), createCentralEvent);
Expand All @@ -77,11 +72,7 @@ void shouldIndexSameLocationFromDifferentTenantsAsSeparateDocs() {

@Test
void shouldRemoveAllDocumentsByTenantIdOnDeleteAllEvent() {
var locationId = randomId();
var location = LocationDto.builder().id(locationId)
.name("location name")
.code("CODE")
.build();
var location = location();
var createCentralEvent = kafkaResourceEvent(CENTRAL_TENANT_ID, CREATE, toMap(location), null);
var createMemberEvent = kafkaResourceEvent(MEMBER_TENANT_ID, CREATE, toMap(location), null);
kafkaTemplate.send(inventoryLocationTopic(CENTRAL_TENANT_ID), createCentralEvent);
Expand All @@ -100,4 +91,22 @@ public static void awaitAssertLocationCount(int expected) {
});
}

private LocationDto location() {
var id = randomId();
return LocationDto.builder().id(id)
.name("location name")
.code("CODE")
.campusId(id)
.institutionId(id)
.description("desc")
.discoveryDisplayName("display name")
.primaryServicePoint(UUID.fromString(id))
.isActive(true)
.servicePointIds(List.of(UUID.fromString(id)))
.metadata(new Metadata()
.createdDate("2021-03-01T00:00:00.000+00:00")
.updatedDate("2021-03-01T00:00:00.000+00:00"))
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.mockito.Mockito.when;

import java.util.List;
import java.util.UUID;
import java.util.function.Supplier;
import org.folio.search.domain.dto.ConsortiumLocation;
import org.folio.search.domain.dto.SortOrder;
Expand All @@ -24,7 +25,7 @@
@ExtendWith(MockitoExtension.class)
public class ConsortiumLocationServiceTest {

public static final String ID = "id";
public static final String ID = UUID.randomUUID().toString();
public static final String LOCATION_NAME = "location name";
public static final String CONSORTIUM_TENANT = "consortium";
public static final String NAME = "name";
Expand Down Expand Up @@ -53,21 +54,23 @@ void fetchLocations_ValidSortBy() {

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

assertThat(actual).isNotNull();
assertThat(actual.getRecords()).hasSize(1);
assertThat(actual.getRecords().get(0).getTenantId()).isEqualTo(CONSORTIUM_TENANT);
assertThat(actual.getRecords().get(0).getName()).isEqualTo(LOCATION_NAME);
assertThat(actual.getRecords().get(0).getId()).isEqualTo(ID);
assertThat(actual).isEqualTo(searchResult);
verify(repository).fetchLocations(tenantHeader, tenantId, limit, offset, sortBy, sortOrder);
verify(executor).execute(eq(tenantId), any(Supplier.class));
}

@NotNull
private static SearchResult<ConsortiumLocation> prepareSearchResult() {
var location = new ConsortiumLocation();
location.setId(ID);
location.setName(LOCATION_NAME);
location.setTenantId(CONSORTIUM_TENANT);
var location = new ConsortiumLocation()
.id(ID)
.name(LOCATION_NAME)
.tenantId(CONSORTIUM_TENANT)
.description("desc")
.discoveryDisplayName("display-name")
.campusId(ID)
.libraryId(ID)
.institutionId(ID)
.servicePointIds(List.of(UUID.fromString(ID)));

var searchResult = new SearchResult<ConsortiumLocation>();
searchResult.records(List.of(location));
Expand Down

0 comments on commit daac323

Please sign in to comment.