Skip to content

Commit

Permalink
feat(cn-browse): showing one line in results list regardless of copy …
Browse files Browse the repository at this point in the history
…or enumeration data

Closes: MSEARCH-950
  • Loading branch information
psmagin committed Jan 28, 2025
1 parent 178ee3c commit 1ddbc3c
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 235 deletions.
55 changes: 9 additions & 46 deletions src/main/java/org/folio/search/model/entity/CallNumberEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,20 @@ public class CallNumberEntity implements Comparable<CallNumberEntity> {
private static final int CALL_NUMBER_PREFIX_MAX_LENGTH = 20;
private static final int CALL_NUMBER_SUFFIX_MAX_LENGTH = 25;
private static final int CALL_NUMBER_TYPE_MAX_LENGTH = 40;
private static final int VOLUME_MAX_LENGTH = 50;
private static final int ENUMERATION_MAX_LENGTH = 50;
private static final int CHRONOLOGY_MAX_LENGTH = 50;
private static final int COPY_NUMBER_MAX_LENGTH = 10;

private String id;
private String callNumber;
private String callNumberPrefix;
private String callNumberSuffix;
private String callNumberTypeId;
private String volume;
private String enumeration;
private String chronology;
private String copyNumber;

private final String id;
private final String callNumber;
private final String callNumberPrefix;
private final String callNumberSuffix;
private final String callNumberTypeId;

CallNumberEntity(String id, String callNumber, String callNumberPrefix, String callNumberSuffix,
String callNumberTypeId, String volume, String enumeration, String chronology, String copyNumber) {
String callNumberTypeId) {
this.id = id;
this.callNumber = callNumber;
this.callNumberPrefix = callNumberPrefix;
this.callNumberSuffix = callNumberSuffix;
this.callNumberTypeId = callNumberTypeId;
this.volume = volume;
this.enumeration = enumeration;
this.chronology = chronology;
this.copyNumber = copyNumber;
}

public static CallNumberEntityBuilder builder() {
Expand Down Expand Up @@ -70,10 +58,6 @@ public static class CallNumberEntityBuilder {
private String callNumberPrefix;
private String callNumberSuffix;
private String callNumberTypeId;
private String volume;
private String enumeration;
private String chronology;
private String copyNumber;

CallNumberEntityBuilder() { }

Expand Down Expand Up @@ -102,33 +86,12 @@ public CallNumberEntityBuilder callNumberTypeId(String callNumberTypeId) {
return this;
}

public CallNumberEntityBuilder volume(String volume) {
this.volume = truncate(volume, VOLUME_MAX_LENGTH);
return this;
}

public CallNumberEntityBuilder enumeration(String enumeration) {
this.enumeration = truncate(enumeration, ENUMERATION_MAX_LENGTH);
return this;
}

public CallNumberEntityBuilder chronology(String chronology) {
this.chronology = truncate(chronology, CHRONOLOGY_MAX_LENGTH);
return this;
}

public CallNumberEntityBuilder copyNumber(String copyNumber) {
this.copyNumber = truncate(copyNumber, COPY_NUMBER_MAX_LENGTH);
return this;
}

public CallNumberEntity build() {
if (id == null) {
this.id = ShaUtils.sha(callNumber, callNumberPrefix, callNumberSuffix, callNumberTypeId,
volume, enumeration, chronology, copyNumber);
this.id = ShaUtils.sha(callNumber, callNumberPrefix, callNumberSuffix, callNumberTypeId);
}
return new CallNumberEntity(this.id, this.callNumber, this.callNumberPrefix, this.callNumberSuffix,
this.callNumberTypeId, this.volume, this.enumeration, this.chronology, this.copyNumber);
this.callNumberTypeId);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,4 @@ public record CallNumberResource(
String callNumberPrefix,
String callNumberSuffix,
String callNumberTypeId,
String volume,
String enumeration,
String chronology,
String copyNumber,
Set<InstanceSubResource> instances) { }
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ protected BrowseResult<CallNumberBrowseItem> mapToBrowseResult(BrowseContext ctx
.callNumberPrefix(resource.callNumberPrefix())
.callNumberSuffix(resource.callNumberSuffix())
.callNumberTypeId(resource.callNumberTypeId())
.volume(resource.volume())
.chronology(resource.chronology())
.enumeration(resource.enumeration())
.copyNumber(resource.copyNumber())
.instanceTitle(getInstanceTitle(ctx, resource, CallNumberResource::instances))
.isAnchor(isAnchor ? true : null)
.totalRecords(getTotalRecords(ctx, resource, CallNumberResource::instances)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ public class CallNumberResourceExtractor extends ChildResourceExtractor {
public static final String PREFIX_FIELD = "prefix";
public static final String SUFFIX_FIELD = "suffix";
public static final String TYPE_ID_FIELD = "typeId";
public static final String VOLUME_FIELD = "volume";
public static final String CHRONOLOGY_FIELD = "chronology";
public static final String ENUMERATION_FIELD = "enumeration";
public static final String COPY_NUMBER_FIELD = "copyNumber";

private final JsonConverter jsonConverter;
private final FeatureConfigService featureConfigService;
Expand Down Expand Up @@ -96,10 +92,6 @@ private Optional<CallNumberEntity> toCallNumberEntity(Map<String, Object> entity
.callNumberPrefix(getString(callNumberComponents, PREFIX_FIELD))
.callNumberSuffix(getString(callNumberComponents, SUFFIX_FIELD))
.callNumberTypeId(getString(callNumberComponents, TYPE_ID_FIELD))
.volume(getString(entityProperties, VOLUME_FIELD))
.chronology(getString(entityProperties, CHRONOLOGY_FIELD))
.enumeration(getString(entityProperties, ENUMERATION_FIELD))
.copyNumber(getString(entityProperties, COPY_NUMBER_FIELD))
.build();
return Optional.of(callNumberEntity);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package org.folio.search.service.reindex.jdbc;

import static org.apache.commons.collections4.MapUtils.getString;
import static org.folio.search.service.converter.preprocessor.extractor.impl.CallNumberResourceExtractor.CHRONOLOGY_FIELD;
import static org.folio.search.service.converter.preprocessor.extractor.impl.CallNumberResourceExtractor.ENUMERATION_FIELD;
import static org.folio.search.service.converter.preprocessor.extractor.impl.CallNumberResourceExtractor.VOLUME_FIELD;
import static org.folio.search.service.reindex.ReindexConstants.CALL_NUMBER_TABLE;
import static org.folio.search.service.reindex.ReindexConstants.INSTANCE_CALL_NUMBER_TABLE;
import static org.folio.search.utils.CallNumberUtils.calculateFullCallNumber;
Expand All @@ -14,7 +11,6 @@
import static org.folio.search.utils.SearchUtils.CALL_NUMBER_PREFIX_FIELD;
import static org.folio.search.utils.SearchUtils.CALL_NUMBER_SUFFIX_FIELD;
import static org.folio.search.utils.SearchUtils.CALL_NUMBER_TYPE_ID_FIELD;
import static org.folio.search.utils.SearchUtils.COPY_NUMBER_FIELD;
import static org.folio.search.utils.SearchUtils.ID_FIELD;
import static org.folio.search.utils.SearchUtils.SUB_RESOURCE_INSTANCES_FIELD;

Expand Down Expand Up @@ -86,10 +82,6 @@ WITH cte AS (
call_number_prefix,
call_number_suffix,
call_number_type_id,
volume,
enumeration,
chronology,
copy_number,
last_updated_date
FROM %1$s.call_number
WHERE last_updated_date > ?
Expand All @@ -101,10 +93,6 @@ WITH cte AS (
c.call_number_prefix,
c.call_number_suffix,
c.call_number_type_id,
c.volume,
c.enumeration,
c.chronology,
c.copy_number,
c.last_updated_date,
json_agg(
CASE
Expand Down Expand Up @@ -140,10 +128,6 @@ LEFT JOIN (
c.call_number_prefix,
c.call_number_suffix,
c.call_number_type_id,
c.volume,
c.enumeration,
c.chronology,
c.copy_number,
c.last_updated_date
ORDER BY
last_updated_date ASC;
Expand All @@ -155,12 +139,8 @@ LEFT JOIN (
call_number,
call_number_prefix,
call_number_suffix,
call_number_type_id,
volume,
enumeration,
chronology,
copy_number
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
call_number_type_id
) VALUES (?, ?, ?, ?, ?)
ON CONFLICT (id) DO UPDATE SET last_updated_date = CURRENT_TIMESTAMP;
""";

Expand Down Expand Up @@ -250,23 +230,14 @@ protected RowMapper<Map<String, Object>> rowToMapMapper2() {
private Map<String, Object> getCallNumberMap(ResultSet rs) throws SQLException {
var callNumber = getCallNumber(rs);
var callNumberSuffix = getCallNumberSuffix(rs);
var volume = getVolume(rs);
var enumeration = getEnumeration(rs);
var chronology = getChronology(rs);
var copyNumber = getCopyNumber(rs);

Map<String, Object> callNumberMap = new HashMap<>();
callNumberMap.put(ID_FIELD, getId(rs));
callNumberMap.put(CALL_NUMBER_BROWSING_FIELD, calculateFullCallNumber(
callNumber, volume, enumeration, chronology, copyNumber, callNumberSuffix));
callNumberMap.put(CALL_NUMBER_BROWSING_FIELD, calculateFullCallNumber(callNumber, callNumberSuffix));
callNumberMap.put(CALL_NUMBER_FIELD, callNumber);
callNumberMap.put(CALL_NUMBER_PREFIX_FIELD, getCallNumberPrefix(rs));
callNumberMap.put(CALL_NUMBER_SUFFIX_FIELD, callNumberSuffix);
callNumberMap.put(CALL_NUMBER_TYPE_ID_FIELD, getCallNumberTypeId(rs));
callNumberMap.put(VOLUME_FIELD, volume);
callNumberMap.put(ENUMERATION_FIELD, enumeration);
callNumberMap.put(CHRONOLOGY_FIELD, chronology);
callNumberMap.put(COPY_NUMBER_FIELD, copyNumber);
var subResources = jsonConverter.toJson(parseInstanceSubResources(getInstances(rs)));
var maps = jsonConverter.fromJsonToListOfMaps(subResources).stream().filter(Objects::nonNull).toList();
if (!maps.isEmpty()) {
Expand All @@ -287,16 +258,12 @@ private void saveResourceEntities(ChildResourceEntityBatch entityBatch) {
statement.setString(3, getPrefix(entity));
statement.setString(4, getSuffix(entity));
statement.setString(5, getTypeId(entity));
statement.setString(6, getVolume(entity));
statement.setString(7, getEnumeration(entity));
statement.setString(8, getChronology(entity));
statement.setString(9, getCopyNumber(entity));
});
} catch (DataAccessException e) {
log.warn("saveAll::Failed to save entities batch. Starting processing one-by-one", e);
for (var entity : entityBatch.resourceEntities()) {
jdbcTemplate.update(callNumberSql, getId(entity), getCallNumber(entity), getPrefix(entity), getSuffix(entity),
getTypeId(entity), getVolume(entity), getEnumeration(entity), getChronology(entity), getCopyNumber(entity));
getTypeId(entity));
}
}
}
Expand Down Expand Up @@ -375,38 +342,6 @@ private String getId(ResultSet rs) throws SQLException {
return rs.getString("id");
}

private String getCopyNumber(Map<String, Object> item) {
return getString(item, "copyNumber");
}

private String getCopyNumber(ResultSet rs) throws SQLException {
return rs.getString("copy_number");
}

private String getEnumeration(Map<String, Object> item) {
return getString(item, "enumeration");
}

private String getEnumeration(ResultSet rs) throws SQLException {
return rs.getString("enumeration");
}

private String getChronology(Map<String, Object> item) {
return getString(item, "chronology");
}

private String getChronology(ResultSet rs) throws SQLException {
return rs.getString("chronology");
}

private String getVolume(Map<String, Object> item) {
return getString(item, "volume");
}

private String getVolume(ResultSet rs) throws SQLException {
return rs.getString("volume");
}

private String getTypeId(Map<String, Object> callNumberComponents) {
return getString(callNumberComponents, "callNumberTypeId");
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/org/folio/search/utils/CallNumberUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public static String calculateShelvingOrder(Item item) {
var callNumberComponents = item.getEffectiveCallNumberComponents();
if (callNumberComponents != null && isNotBlank(callNumberComponents.getCallNumber())) {
var fullCallNumber = calculateFullCallNumber(callNumberComponents.getCallNumber(),
item.getVolume(), item.getEnumeration(), item.getChronology(), item.getCopyNumber(),
callNumberComponents.getSuffix());

return getShelfKeyFromCallNumber(fullCallNumber).orElse(null);
Expand All @@ -45,12 +44,11 @@ public static String calculateShelvingOrder(Item item) {
return null;
}

public static String calculateFullCallNumber(String callNumber, String volume, String enumeration, String chronology,
String copyNumber, String suffix) {
public static String calculateFullCallNumber(String callNumber, String suffix) {
if (StringUtils.isBlank(callNumber)) {
throw new IllegalArgumentException("Call number is required to calculate full call number.");
}
return Stream.of(callNumber, suffix, volume, enumeration, chronology, copyNumber)
return Stream.of(callNumber, suffix)
.filter(StringUtils::isNotBlank)
.map(StringUtils::trim)
.collect(joining(" "));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
<column name="call_number_prefix" type="VARCHAR(20)"/>
<column name="call_number_suffix" type="VARCHAR(25)"/>
<column name="call_number_type_id" type="VARCHAR(40)"/>
<column name="volume" type="VARCHAR(50)"/>
<column name="enumeration" type="VARCHAR(50)"/>
<column name="chronology" type="VARCHAR(50)"/>
<column name="copy_number" type="VARCHAR(10)"/>
<column name="last_updated_date" type="DATETIME" defaultValueComputed="CURRENT_TIMESTAMP">
<constraints nullable="false"/>
</column>
Expand Down
16 changes: 0 additions & 16 deletions src/main/resources/model/instance_call_number.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,6 @@
"showInResponse": [ "browse" ],
"searchTermProcessor": "callNumberTypeIdSearchTermProcessor"
},
"volume": {
"index": "source",
"showInResponse": [ "browse" ]
},
"enumeration": {
"index": "source",
"showInResponse": [ "browse" ]
},
"chronology": {
"index": "source",
"showInResponse": [ "browse" ]
},
"copyNumber": {
"index": "source",
"showInResponse": [ "browse" ]
},
"instances": {
"type": "object",
"properties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ type: object
properties:
fullCallNumber:
type: string
description: Full call number (includes callNumber, volume, enumeration, chronology, copyNumber, callNumberPrefix)
description: Full call number (includes callNumber, callNumberSuffix)
callNumber:
type: string
description: Call number
Expand All @@ -16,18 +16,6 @@ properties:
callNumberTypeId:
type: string
description: Call number type ID
volume:
type: string
description: Volume
enumeration:
type: string
description: Enumeration
chronology:
type: string
description: Chronology
copyNumber:
type: string
description: Copy number
instanceTitle:
type: string
description: Instance title
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,6 @@ private static CallNumberBrowseItem cnBrowseItem(CallNumberResource resource, in
.callNumberPrefix(resource.callNumberPrefix())
.callNumberSuffix(resource.callNumberSuffix())
.callNumberTypeId(resource.callNumberTypeId())
.volume(resource.volume())
.chronology(resource.chronology())
.enumeration(resource.enumeration())
.copyNumber(resource.copyNumber())
.instanceTitle(count == 1 ? INSTANCES.get(instanceIndex).getTitle() : null)
.totalRecords(count)
.isAnchor(isAnchor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,6 @@ private static CallNumberBrowseItem cnBrowseItem(CallNumberResource resource, in
.callNumberPrefix(resource.callNumberPrefix())
.callNumberSuffix(resource.callNumberSuffix())
.callNumberTypeId(resource.callNumberTypeId())
.volume(resource.volume())
.chronology(resource.chronology())
.enumeration(resource.enumeration())
.copyNumber(resource.copyNumber())
.instanceTitle(instanceTitle)
.totalRecords(count)
.isAnchor(isAnchor);
Expand Down
Loading

0 comments on commit 1ddbc3c

Please sign in to comment.