Skip to content

Commit

Permalink
Merge branch 'master' into MSEARCH-558
Browse files Browse the repository at this point in the history
  • Loading branch information
viacheslavkol authored Sep 14, 2023
2 parents 6e2ce29 + 1518543 commit c9d1ab6
Show file tree
Hide file tree
Showing 62 changed files with 496 additions and 649 deletions.
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Requires `identifier-types v1.0`
* Requires `call-number-types v1.0`
* Provides `indices v0.6`
* Provides `search v1.1`
* Provides `search v1.2`
* Provides `browse v1.2`

### Features
Expand All @@ -22,6 +22,7 @@
* Implement Active Affiliation Context for stream IDs in Consortia Mode ([MSEARCH-576](https://issues.folio.org/browse/MSEARCH-576))
* Restrict central tenant queries to only shared records ([MSEARCH-588](https://issues.folio.org/browse/MSEARCH-588))
* Implement Active Affiliation Context for browsing ([MSEARCH-580](https://issues.folio.org/browse/MSEARCH-580))
* Add new facets for shared/local flag and tenantId ([MSEARCH-534](https://issues.folio.org/browse/MSEARCH-534))

### Bug fixes
* Fix bug when number of titles response is greater than real ([MSEARCH-526](https://issues.folio.org/browse/MSEARCH-526))
Expand Down
56 changes: 35 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,13 @@ Consortium feature on module enable is defined by 'centralTenantId' tenant param

### Search API

| METHOD | URL | DESCRIPTION |
|:-------|:------------------------------|:------------------------------------------------------------------------------|
| GET | `/search/instances` | Search by instances and to this instance items and holding-records |
| GET | `/search/authorities` | Search by authority records |
| GET | `/search/{recordType}/facets` | Get facets where recordType could be: instances, authorities, or contributors |
| GET | ~~`/search/instances/ids`~~ | (DEPRECATED) Stream instance ids as JSON or plain text |
| GET | ~~`/search/holdings/ids`~~ | (DEPRECATED) Stream holding record ids as JSON or plain text |
| METHOD | URL | DESCRIPTION |
|:-------|:------------------------------|:-------------------------------------------------------------------------------------|
| GET | `/search/instances` | Search by instances and to this instance items and holding-records |
| GET | `/search/authorities` | Search by authority records |
| GET | `/search/{recordType}/facets` | Get facets where recordType could be: instances, authorities, contributors, subjects |
| GET | ~~`/search/instances/ids`~~ | (DEPRECATED) Stream instance ids as JSON or plain text |
| GET | ~~`/search/holdings/ids`~~ | (DEPRECATED) Stream holding record ids as JSON or plain text |

#### Searching and filtering

Expand Down Expand Up @@ -636,20 +636,22 @@ GET /instances/facets?query=title all book&facet=source:5,discoverySuppress:2

##### Instance facets

| Option | Type | Description |
|:-------------------------|:-------:|:---------------------------------------------------------------------|
| `source` | term | Requests a source facet |
| `instanceTypeId` | term | Requests a type id facet |
| `statusId` | term | Requests a status id facet |
| `instanceFormatIds` | term | Requests a format id facet |
| `modeOfIssuanceId` | term | Requests a mode of issuance id facet |
| `natureOfContentTermIds` | term | Requests a nature of content terms id facet |
| `languages` | term | Requests a language code facet |
| `instanceTags` | term | Requests a tags facet |
| `staffSuppress` | boolean | Requests a staff suppress facet |
| `discoverySuppress` | boolean | Requests a discovery suppress facet |
| `statisticalCodeIds` | term | Requests a statistical code ids facet |
| `statisticalCodes` | term | Requests a statistical code ids from instance, holdings, item facet |
| Option | Type | Description |
|:-------------------------|:-------:|:--------------------------------------------------------------------|
| `source` | term | Requests a source facet |
| `instanceTypeId` | term | Requests a type id facet |
| `statusId` | term | Requests a status id facet |
| `instanceFormatIds` | term | Requests a format id facet |
| `modeOfIssuanceId` | term | Requests a mode of issuance id facet |
| `natureOfContentTermIds` | term | Requests a nature of content terms id facet |
| `languages` | term | Requests a language code facet |
| `instanceTags` | term | Requests a tags facet |
| `staffSuppress` | boolean | Requests a staff suppress facet |
| `discoverySuppress` | boolean | Requests a discovery suppress facet |
| `statisticalCodeIds` | term | Requests a statistical code ids facet |
| `statisticalCodes` | term | Requests a statistical code ids from instance, holdings, item facet |
| `tenantId` | term | Requests a tenantId facet |
| `shared` | term | Requests a shared/local facet |

##### Holdings facets

Expand All @@ -661,6 +663,7 @@ GET /instances/facets?query=title all book&facet=source:5,discoverySuppress:2
| `holdings.sourceId` | term | Requests a holdings sourceId facet |
| `holdingsTypeId` | term | Requests a holdings typeId facet |
| `holdingsTags` | term | Requests a holdings tag facet |
| `holdings.tenantId` | term | Requests a holdings tenantId facet |

##### Item facets

Expand All @@ -680,12 +683,23 @@ GET /instances/facets?query=title all book&facet=source:5,discoverySuppress:2
| `headingType` | term | Requests a heading type facet |
| `subjectHeadings` | term | Requests a subject headings facet |
| `sourceFileId` | term | Requests a source files facet (default value: `NULL`) |
| `tenantId` | term | Requests a tenantId facet |
| `shared` | term | Requests a shared/local facet |

##### Contributors facets

| Option | Type | Description |
|:------------------------|:----:|:---------------------------------------|
| `contributorNameTypeId` | term | Requests a contributor name type facet |
| `instances.tenantId` | term | Requests a tenantId facet |
| `instances.shared` | term | Requests a shared/local facet |

##### Subjects facets

| Option | Type | Description |
|:------------------------|:----:|:---------------------------------------|
| `instances.tenantId` | term | Requests a tenantId facet |
| `instances.shared` | term | Requests a shared/local facet |

#### Sorting results

Expand Down
6 changes: 5 additions & 1 deletion descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
{
"id": "search",
"version": "1.1",
"version": "1.2",
"handlers": [
{
"methods": [ "GET" ],
Expand Down Expand Up @@ -246,6 +246,10 @@
"id": "instance-reindex",
"version": "0.1"
},
{
"id": "authority-reindex",
"version": "0.1"
},
{
"id": "alternative-title-types",
"version": "1.0"
Expand Down
15 changes: 10 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,27 @@
src/main/java/org/folio/search/configuration/properties/**
</sonar.exclusions>

<folio-spring-base.version>7.1.2</folio-spring-base.version>
<folio-spring-support.version>7.2.0-SNAPSHOT</folio-spring-support.version>
<folio-service-tools.version>3.1.0-SNAPSHOT</folio-service-tools.version>
<folio-isbn-utils.version>1.5.0</folio-isbn-utils.version>
<folio-cql2pgjson.version>35.0.6</folio-cql2pgjson.version>
<opensearch.version>2.9.0</opensearch.version>
<mapstruct.version>1.5.5.Final</mapstruct.version>
<spring-kafka.version>3.0.10</spring-kafka.version>
<spring-kafka.version>3.0.11</spring-kafka.version>
<apache-commons-io.version>2.13.0</apache-commons-io.version>
<apache-commons-collections.version>4.4</apache-commons-collections.version>
<marc4j.version>2.9.4</marc4j.version>
<lombok.version>1.18.28</lombok.version>
<lombok.mapstruct-binding.version>0.2.0</lombok.mapstruct-binding.version>
<streamex.version>0.8.1</streamex.version>
<streamex.version>0.8.2</streamex.version>

<!-- Test dependencies versions -->
<testcontainers.version>1.19.0</testcontainers.version>
<wiremock.version>2.27.2</wiremock.version>
<awaitility.version>4.2.0</awaitility.version>

<!-- Plugins versions -->
<maven-openapi-generator-plugin.version>6.6.0</maven-openapi-generator-plugin.version>
<maven-openapi-generator-plugin.version>7.0.0</maven-openapi-generator-plugin.version>
<maven-copy-rename-plugin.version>1.0.1</maven-copy-rename-plugin.version>
<maven-build-helper-plugin.version>3.4.0</maven-build-helper-plugin.version>
<maven-clean-plugin.version>3.3.1</maven-clean-plugin.version>
Expand All @@ -70,7 +70,12 @@
<dependency>
<groupId>org.folio</groupId>
<artifactId>folio-spring-base</artifactId>
<version>${folio-spring-base.version}</version>
<version>${folio-spring-support.version}</version>
</dependency>
<dependency>
<groupId>org.folio</groupId>
<artifactId>folio-spring-system-user</artifactId>
<version>${folio-spring-support.version}</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.apache.kafka.common.serialization.StringSerializer;
import org.folio.search.domain.dto.ResourceEvent;
import org.folio.search.model.event.ConsortiumInstanceEvent;
import org.folio.spring.tools.config.properties.FolioEnvironment;
import org.folio.spring.config.properties.FolioEnvironment;
import org.folio.spring.tools.kafka.FolioKafkaTopic;
import org.folio.spring.tools.kafka.FolioMessageProducer;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
Expand Down Expand Up @@ -71,7 +71,7 @@ public ConcurrentKafkaListenerContainerFactory<String, ConsortiumInstanceEvent>
*/
@Bean
public ConsumerFactory<String, ResourceEvent> resourceEventConsumerFactory() {
var deserializer = new JsonDeserializer<>(ResourceEvent.class);
var deserializer = new JsonDeserializer<>(ResourceEvent.class, false);
Map<String, Object> config = new HashMap<>(kafkaProperties.buildConsumerProperties());
config.put(KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
config.put(VALUE_DESERIALIZER_CLASS_CONFIG, deserializer);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.folio.search.utils.SearchUtils.AUTHORITY_RESOURCE;
import static org.folio.search.utils.SearchUtils.CONTRIBUTOR_RESOURCE;
import static org.folio.search.utils.SearchUtils.INSTANCE_RESOURCE;
import static org.folio.search.utils.SearchUtils.INSTANCE_SUBJECT_RESOURCE;

import java.util.List;
import java.util.Map;
Expand All @@ -27,7 +28,8 @@ public class FacetsController implements FacetsApi {
private static final Map<RecordType, String> RECORD_TYPE_TO_RESOURCE_MAP = Map.of(
RecordType.INSTANCES, INSTANCE_RESOURCE,
RecordType.AUTHORITIES, AUTHORITY_RESOURCE,
RecordType.CONTRIBUTORS, CONTRIBUTOR_RESOURCE
RecordType.CONTRIBUTORS, CONTRIBUTOR_RESOURCE,
RecordType.SUBJECTS, INSTANCE_SUBJECT_RESOURCE
);

private final FacetService facetService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public SearchSourceBuilder convert(String query, String resource) {
*/
public SearchSourceBuilder convertForConsortia(String query, String resource) {
var sourceBuilder = convert(query, resource);
var queryBuilder = consortiumSearchHelper.filterQueryForActiveAffiliation(sourceBuilder.query());
var queryBuilder = consortiumSearchHelper.filterQueryForActiveAffiliation(sourceBuilder.query(), resource);

return sourceBuilder.query(queryBuilder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.folio.search.model.event.ConsortiumInstanceEvent;
import org.folio.search.service.ResourceService;
import org.folio.search.utils.KafkaConstants;
import org.folio.spring.tools.systemuser.SystemUserScopedExecutionService;
import org.folio.spring.service.SystemUserScopedExecutionService;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import lombok.With;
import org.folio.spring.FolioExecutionContext;
import org.folio.spring.FolioModuleMetadata;
import org.folio.spring.tools.model.SystemUser;
import org.folio.spring.model.SystemUser;
import org.springframework.stereotype.Component;

@Component
@Component("searchFolioExecutionContextBuilder")
@RequiredArgsConstructor
public class FolioExecutionContextBuilder {
private final FolioModuleMetadata moduleMetadata;
Expand All @@ -25,7 +25,7 @@ public FolioExecutionContext forSystemUser(SystemUser systemUser) {
return builder()
.withTenantId(systemUser.tenantId())
.withOkapiUrl(systemUser.okapiUrl())
.withToken(systemUser.token())
.withToken(systemUser.token() == null ? null : systemUser.token().accessToken())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.folio.search.repository;

import static java.util.Locale.ROOT;
import static org.folio.spring.tools.config.properties.FolioEnvironment.getFolioEnvName;
import static org.folio.spring.config.properties.FolioEnvironment.getFolioEnvName;

import lombok.extern.log4j.Log4j2;
import org.folio.search.domain.dto.ResourceEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.folio.search.model.config.LanguageConfigEntity;
import org.folio.search.repository.LanguageConfigRepository;
import org.folio.search.service.metadata.LocalSearchFieldProvider;
import org.folio.spring.service.SystemUserScopedExecutionService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
Expand All @@ -30,7 +31,7 @@ public class LanguageConfigService {

private final LanguageConfigRepository configRepository;
private final LocalSearchFieldProvider searchFieldProvider;
private final TenantScopedExecutionService executionService;
private final SystemUserScopedExecutionService executionService;
private final SearchConfigurationProperties searchConfiguration;

/**
Expand Down Expand Up @@ -133,7 +134,7 @@ public Set<String> getAllLanguageCodes() {
* @return {@link Set} with language configuration codes.
*/
public Set<String> getAllLanguagesForTenant(String tenant) {
return executionService.executeTenantScoped(tenant,
return executionService.executeSystemUserScoped(tenant,
() -> configRepository.findAll().stream()
.map(LanguageConfigEntity::getCode)
.collect(Collectors.toSet()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.folio.search.repository.ResourceIdsJobRepository;
import org.folio.search.repository.ResourceIdsTemporaryRepository;
import org.folio.search.repository.SearchRepository;
import org.folio.spring.tools.systemuser.SystemUserScopedExecutionService;
import org.folio.spring.service.SystemUserScopedExecutionService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import org.folio.search.service.metadata.ResourceDescriptionService;
import org.folio.spring.FolioExecutionContext;
import org.folio.spring.liquibase.FolioSpringLiquibase;
import org.folio.spring.service.PrepareSystemUserService;
import org.folio.spring.service.TenantService;
import org.folio.spring.tools.kafka.KafkaAdminService;
import org.folio.spring.tools.systemuser.PrepareSystemUserService;
import org.folio.tenant.domain.dto.Parameter;
import org.folio.tenant.domain.dto.TenantAttributes;
import org.springframework.context.annotation.Primary;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.folio.search.model.context.FolioExecutionContextBuilder;
import org.folio.spring.FolioExecutionContext;
import org.folio.spring.scope.FolioExecutionContextSetter;
import org.folio.spring.tools.systemuser.SystemUserService;
import org.folio.spring.service.SystemUserService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static org.folio.search.model.index.AuthRefType.REFERENCE;
import static org.folio.search.model.types.ResponseGroupType.BROWSE;
import static org.folio.search.utils.LogUtils.collectionToLogMsg;
import static org.folio.search.utils.SearchUtils.AUTHORITY_RESOURCE;
import static org.opensearch.index.query.QueryBuilders.boolQuery;
import static org.opensearch.index.query.QueryBuilders.termQuery;
import static org.opensearch.index.query.QueryBuilders.termsQuery;
Expand Down Expand Up @@ -64,7 +65,7 @@ protected SearchSourceBuilder getSearchQuery(BrowseRequest request, BrowseContex

var boolQuery = boolQuery().filter(FILTER_QUERY);
ctx.getFilters().forEach(boolQuery::filter);
var query = consortiumSearchHelper.filterQueryForActiveAffiliation(boolQuery);
var query = consortiumSearchHelper.filterQueryForActiveAffiliation(boolQuery, AUTHORITY_RESOURCE);
return searchSource().query(query)
.searchAfter(new Object[] {ctx.getAnchor().toLowerCase(ROOT)})
.sort(fieldSort(request.getTargetField()).order(isBrowsingForward ? ASC : DESC))
Expand All @@ -80,7 +81,7 @@ protected SearchSourceBuilder getAnchorSearchQuery(BrowseRequest request, Browse

var boolQuery = boolQuery().filter(FILTER_QUERY).must(termQuery(request.getTargetField(), context.getAnchor()));
context.getFilters().forEach(boolQuery::filter);
var query = consortiumSearchHelper.filterQueryForActiveAffiliation(boolQuery);
var query = consortiumSearchHelper.filterQueryForActiveAffiliation(boolQuery, AUTHORITY_RESOURCE);
return searchSource().query(query).from(0).size(1).fetchSource(getIncludedSourceFields(request), null);
}

Expand Down
Loading

0 comments on commit c9d1ab6

Please sign in to comment.