Skip to content

Commit

Permalink
fix(browse): Fix identifier types limit for browse config (#706)
Browse files Browse the repository at this point in the history
* fix(browse): Fix identifier types limit for browse config

- Change type_id column type from varchar to array in browse config database table
- Migrate existing type ids

Closes: MSEARCH-890
  • Loading branch information
viacheslavkol authored Dec 3, 2024
1 parent 191f7e6 commit efe54b7
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 42 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Remove shelving order calculation for local call-number types
* Use keyword_icu instead of keyword_lowercase for fulltext fields plain values ([MSEARCH-857](https://folio-org.atlassian.net/browse/MSEARCH-857))
* Populate typeId and sourceId on subjects re-indexing ([MSEARCH-891](https://folio-org.atlassian.net/browse/MSEARCH-891))
* Change browse_config type_ids column type from varchar to array ([MSEARCH-890](https://folio-org.atlassian.net/browse/MSEARCH-890))

### Tech Dept
* Description ([ISSUE](https://folio-org.atlassian.net/browse/ISSUE))
Expand Down
2 changes: 1 addition & 1 deletion PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ _How does this change fulfill the purpose? Provide a high-level overview of the
- [ ] **NEWS**: Confirm that the NEWS file is updated with relevant information about the changes made in this pull request.

### Related Issues
_List any Jira issues related to this pull request._
[MSEARCH-XXX](https://folio-org.atlassian.net/browse/MSEARCH-XXX)
_List any Jira issues related to this pull request._

### Learning and Resources (if applicable)
_Discuss any research conducted during the development of this pull request. Include links to relevant blog posts, patterns, libraries, or addons that were used to solve the problem._
Expand Down
11 changes: 0 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,6 @@
<artifactId>folio-isbn-util</artifactId>
<version>${folio-isbn-utils.version}</version>
</dependency>
<!--todo: remove 2 following dependencies after https://folio-org.atlassian.net/browse/ISBNUTIL-25-->
<dependency>
<groupId>com.github.ladutsko</groupId>
<artifactId>isbn-core</artifactId>
<version>1.5.3</version>
</dependency>
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.9.0</version>
</dependency>

<dependency>
<groupId>org.folio</groupId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.folio.search.model.config;

import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.EmbeddedId;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
Expand All @@ -12,7 +11,6 @@
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.folio.search.configuration.jpa.StringListConverter;
import org.hibernate.Hibernate;

@Getter
Expand All @@ -29,7 +27,6 @@ public class BrowseConfigEntity {
@Column(name = "shelving_algorithm", nullable = false)
private String shelvingAlgorithm;

@Convert(converter = StringListConverter.class)
@Column(name = "type_ids")
private List<String> typeIds = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.collections4.CollectionUtils;
import org.folio.search.domain.dto.BrowseConfig;
import org.folio.search.domain.dto.BrowseType;
import org.folio.search.domain.dto.ClassificationNumberBrowseItem;
Expand Down Expand Up @@ -104,14 +105,15 @@ protected BrowseResult<ClassificationNumberBrowseItem> mapToBrowseResult(BrowseC

private static QueryBuilder getQuery(BrowseContext ctx, BrowseConfig config, TermQueryBuilder anchorQuery) {
var typeIds = config.getTypeIds();
if (config.getTypeIds().isEmpty() && ctx.getFilters().isEmpty()) {
var typeIdsEmpty = CollectionUtils.isEmpty(config.getTypeIds());
if (typeIdsEmpty && ctx.getFilters().isEmpty()) {
if (anchorQuery != null) {
return anchorQuery;
}
return matchAllQuery();
} else {
var boolQueryMain = boolQuery();
if (!config.getTypeIds().isEmpty()) {
if (!typeIdsEmpty) {
var boolQuery = boolQuery();
for (var typeId : typeIds) {
boolQuery.should(termQuery(CLASSIFICATION_TYPE_ID_FIELD, typeId.toString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
import lombok.NonNull;
Expand Down Expand Up @@ -80,7 +81,9 @@ public void deleteTypeIdsFromConfigs(@NonNull BrowseType type, @NonNull List<Str
}
var configs = repository.findByConfigId_BrowseType(type.getValue());
for (BrowseConfigEntity config : configs) {
var newTypeIds = new ArrayList<>(config.getTypeIds());
var newTypeIds = Optional.ofNullable(config.getTypeIds())
.map(ArrayList::new)
.orElse(new ArrayList<>());
newTypeIds.removeAll(typeIds);
config.setTypeIds(newTypeIds);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/changelog/changelog-master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
<include file="changes/v3.2/create_browse_config_table.xml" relativeToChangelogFile="true"/>
<include file="changes/v4.0/create-reindex-entity-tables.xml" relativeToChangelogFile="true"/>
<include file="changes/v4.0/delete-instance-trigger.xml" relativeToChangelogFile="true"/>
<include file="changes/v4.1/alter-browse-config-type-ids.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.27.xsd">

<changeSet id="MSEARCH-890@@alter-browse_config-type_ids" author="viacheslav_kolesnyk">
<preConditions>
<tableExists tableName="browse_config"/>
</preConditions>

<sql>
ALTER TABLE browse_config
ALTER COLUMN type_ids TYPE char(36)[] USING
CASE WHEN type_ids IS NULL OR type_ids = '[null]' THEN NULL
ELSE string_to_array(type_ids, ';')
END;
</sql>
</changeSet>
</databaseChangeLog>

0 comments on commit efe54b7

Please sign in to comment.