-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into msearch-785
# Conflicts: # NEWS.md # README.md
- Loading branch information
Showing
55 changed files
with
1,947 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/org/folio/search/model/dto/locationunit/InstitutionDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.folio.search.model.dto.locationunit; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.With; | ||
import lombok.extern.jackson.Jacksonized; | ||
import org.folio.search.domain.dto.Metadata; | ||
|
||
/** | ||
* Describes Institution object that comes from external channels. | ||
*/ | ||
@Data | ||
@With | ||
@Builder | ||
@Jacksonized | ||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
public class InstitutionDto { | ||
|
||
@JsonProperty("id") | ||
private String id; | ||
@JsonProperty("name") | ||
private String name; | ||
@JsonProperty("code") | ||
private String code; | ||
@JsonProperty("metadata") | ||
private Metadata metadata; | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/org/folio/search/model/dto/locationunit/LibraryDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.folio.search.model.dto.locationunit; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.With; | ||
import lombok.extern.jackson.Jacksonized; | ||
import org.folio.search.domain.dto.Metadata; | ||
|
||
/** | ||
* Describes Campus object that comes from external channels. | ||
*/ | ||
@Data | ||
@With | ||
@Builder | ||
@Jacksonized | ||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
public class LibraryDto { | ||
|
||
@JsonProperty("id") | ||
private String id; | ||
@JsonProperty("name") | ||
private String name; | ||
@JsonProperty("code") | ||
private String code; | ||
@JsonProperty("campusId") | ||
private String campusId; | ||
@JsonProperty("metadata") | ||
private Metadata metadata; | ||
|
||
} |
79 changes: 79 additions & 0 deletions
79
src/main/java/org/folio/search/repository/ConsortiumCampusRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package org.folio.search.repository; | ||
|
||
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; | ||
import static org.opensearch.search.sort.SortOrder.DESC; | ||
|
||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.folio.search.domain.dto.ConsortiumCampus; | ||
import org.folio.search.domain.dto.SortOrder; | ||
import org.folio.search.model.SearchResult; | ||
import org.folio.search.service.converter.ElasticsearchDocumentConverter; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.opensearch.action.search.SearchRequest; | ||
import org.opensearch.action.search.SearchResponse; | ||
import org.opensearch.client.RequestOptions; | ||
import org.opensearch.client.RestHighLevelClient; | ||
import org.opensearch.index.query.QueryBuilders; | ||
import org.opensearch.search.builder.SearchSourceBuilder; | ||
import org.opensearch.search.sort.SortBuilders; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Log4j2 | ||
@Repository | ||
@RequiredArgsConstructor | ||
public class ConsortiumCampusRepository { | ||
|
||
public static final String CAMPUS_INDEX = "campus"; | ||
private static final String OPERATION_TYPE = "searchApi"; | ||
private final IndexNameProvider indexNameProvider; | ||
private final ElasticsearchDocumentConverter documentConverter; | ||
|
||
private final RestHighLevelClient client; | ||
|
||
public SearchResult<ConsortiumCampus> fetchCampuses(String tenantHeader, | ||
String tenantId, | ||
Integer limit, | ||
Integer offset, | ||
String sortBy, | ||
SortOrder sortOrder) { | ||
|
||
var sourceBuilder = getSearchSourceBuilder(tenantId, limit, offset, sortBy, sortOrder); | ||
var response = search(sourceBuilder, tenantHeader); | ||
return documentConverter.convertToSearchResult(response, ConsortiumCampus.class); | ||
} | ||
|
||
@NotNull | ||
private static SearchSourceBuilder getSearchSourceBuilder(String tenantId, | ||
Integer limit, | ||
Integer offset, | ||
String sortBy, | ||
SortOrder sortOrder) { | ||
var sourceBuilder = new SearchSourceBuilder(); | ||
Optional.ofNullable(tenantId) | ||
.ifPresent(id -> sourceBuilder | ||
.query(QueryBuilders | ||
.termQuery(TENANT_ID_FIELD_NAME, id))); | ||
|
||
return sourceBuilder | ||
.from(offset) | ||
.sort(SortBuilders | ||
.fieldSort(sortBy) | ||
.order(sortOrder == SortOrder.DESC ? DESC : ASC)) | ||
.size(limit); | ||
} | ||
|
||
private SearchResponse search(SearchSourceBuilder sourceBuilder, String tenantHeader) { | ||
var index = indexNameProvider.getIndexName(CAMPUS_INDEX, tenantHeader); | ||
var searchRequest = new SearchRequest(index); | ||
|
||
searchRequest.source(sourceBuilder); | ||
|
||
return performExceptionalOperation(() -> client.search(searchRequest, | ||
RequestOptions.DEFAULT), index, OPERATION_TYPE); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.