Skip to content

Commit

Permalink
MODEXPW-548 Changed display format of stat codes
Browse files Browse the repository at this point in the history
  • Loading branch information
obozhko-folio committed Jan 3, 2025
1 parent f6adce2 commit 5847aa1
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 4 deletions.
2 changes: 1 addition & 1 deletion folio-export-common
15 changes: 15 additions & 0 deletions src/main/java/org/folio/dew/client/StatisticalCodeTypeClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.folio.dew.client;

import org.folio.dew.config.feign.FeignClientConfiguration;
import org.folio.dew.domain.dto.StatisticalCodeType;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@FeignClient(name = "statistical-code-types", configuration = FeignClientConfiguration.class)
public interface StatisticalCodeTypeClient {

@GetMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
StatisticalCodeType getById(@PathVariable String id);
}
22 changes: 22 additions & 0 deletions src/main/java/org/folio/dew/service/InstanceReferenceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,26 @@ public String getStatisticalCodeNameById(String statisticalCodeId, ErrorServiceA
return statisticalCodeId;
}
}

public String getStatisticalCodeCodeById(String statisticalCodeId, ErrorServiceArgs args) {
try {
return instanceReferenceServiceCache.getStatisticalCodeCodeById(statisticalCodeId);
} catch (NotFoundException e) {
var msg = "Statistical code not found by id=" + statisticalCodeId;
log.error(msg);
errorsService.saveErrorInCSV(args.getJobId(), args.getIdentifier(), new BulkEditException(msg), args.getFileName());
return statisticalCodeId;
}
}

public String getStatisticalCodeTypeNameById(String statisticalCodeId, ErrorServiceArgs args) {
try {
return instanceReferenceServiceCache.getStatisticalCodeTypeNameById(statisticalCodeId);
} catch (NotFoundException e) {
var msg = "Statistical code type not found by statistical code id=" + statisticalCodeId;
log.error(msg);
errorsService.saveErrorInCSV(args.getJobId(), args.getIdentifier(), new BulkEditException(msg), args.getFileName());
return statisticalCodeId;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.folio.dew.client.InstanceTypesClient;
import org.folio.dew.client.NatureOfContentTermsClient;
import org.folio.dew.client.StatisticalCodeClient;
import org.folio.dew.client.StatisticalCodeTypeClient;
import org.folio.dew.domain.dto.IdentifierTypeReferenceCollection;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
Expand All @@ -34,6 +35,7 @@ public class InstanceReferenceServiceCache {
private final IdentifierTypeClient identifierTypeClient;
private final InstanceNoteTypesClient instanceNoteTypesClient;
private final StatisticalCodeClient statisticalCodeClient;
private final StatisticalCodeTypeClient statisticalCodeTypeClient;


@Cacheable(cacheNames = "instanceStatusNames")
Expand Down Expand Up @@ -86,4 +88,21 @@ public String getStatisticalCodeNameById(String id) {
}
return statisticalCodeClient.getById(id).getName();
}

@Cacheable(cacheNames = "instanceStatisticalCodeCodes")
public String getStatisticalCodeCodeById(String id) {
if (StringUtils.isEmpty(id)) {
return EMPTY;
}
return statisticalCodeClient.getById(id).getCode();
}

@Cacheable(cacheNames = "instanceStatisticalCodeTypeNames")
public String getStatisticalCodeTypeNameById(String id) {
if (StringUtils.isEmpty(id)) {
return EMPTY;
}
var codeTypeId = statisticalCodeClient.getById(id).getStatisticalCodeTypeId();
return statisticalCodeTypeClient.getById(codeTypeId).getName();
}
}
14 changes: 12 additions & 2 deletions src/main/java/org/folio/dew/service/mapper/InstanceMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import static org.folio.dew.utils.BulkEditProcessorHelper.booleanToStringNullSafe;
import static org.folio.dew.utils.Constants.ARRAY_DELIMITER;
import static org.folio.dew.utils.Constants.ARRAY_DELIMITER_SPACED;
import static org.folio.dew.utils.Constants.ITEM_DELIMITER;
import static org.folio.dew.utils.Constants.ITEM_DELIMITER_SPACED;
import static org.folio.dew.utils.Constants.JOB_NAME_POSTFIX_SEPARATOR;
import static org.folio.dew.utils.Constants.KEY_VALUE_DELIMITER;
import static org.folio.dew.utils.DateTimeHelper.formatDate;

import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -108,8 +111,15 @@ private String noteToString(InstanceNotesInner note, ErrorServiceArgs errorServi
private String getStatisticalCodeNames(List<String> codeIds, ErrorServiceArgs args) {
return isEmpty(codeIds) ? EMPTY : codeIds.stream()
.filter(Objects::nonNull)
.map(id -> instanceReferenceService.getStatisticalCodeNameById(id, args))
.map(id -> getStatisticalCodeFormat(id, args))
.map(specialCharacterEscaper::escape)
.collect(Collectors.joining(ARRAY_DELIMITER));
.collect(Collectors.joining(ITEM_DELIMITER));
}

private String getStatisticalCodeFormat(String id, ErrorServiceArgs args) {
var typeName = instanceReferenceService.getStatisticalCodeTypeNameById(id, args);
var code = instanceReferenceService.getStatisticalCodeCodeById(id, args);
var name = instanceReferenceService.getStatisticalCodeNameById(id, args);
return typeName + KEY_VALUE_DELIMITER + " " + code + " " + JOB_NAME_POSTFIX_SEPARATOR + name;
}
}
2 changes: 2 additions & 0 deletions src/main/resources/swagger.api/bulk-edit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ components:
$ref: '../../../../folio-export-common/schemas/inventory/electronicAccessRelationship.json#/ElectronicAccessRelationship'
statisticalCode:
$ref: '../../../../folio-export-common/schemas/inventory/statisticalCode.json#/StatisticalCode'
statisticalCodeType:
$ref: '../../../../folio-export-common/schemas/inventory/statisticalCodeType.json#/StatisticalCodeType'
itemLocationCollection:
$ref: '../../../../folio-export-common/schemas/inventory/locationCollection.json#/ItemLocationCollection'
callNumberTypes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ void shouldMapInstanceStatisticalCodes() {

var instanceFormat = mapper.mapToInstanceFormat(instance, "identifier", UUID.randomUUID().toString(), "errorFile");

assertThat(instanceFormat.getStatisticalCode()).isEqualTo("Book, print (books);Book, print (books)");
assertThat(instanceFormat.getStatisticalCode()).isEqualTo("Code Type 1 (CD)%3A books -Book, print (books)|Code Type 1 (CD)%3A books -Book, print (books)");
}
}
29 changes: 29 additions & 0 deletions src/test/resources/mappings/statisticalCodeTypes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"mappings": [
{
"request": {
"method": "GET",
"url": "/statistical-code-types/3abd6fc2-b3e4-4879-b1e1-78be41769fe3"
},
"response": {
"status": 200,
"body": "{\n \"id\": \"3abd6fc2-b3e4-4879-b1e1-78be41769fe3\",\n \"name\": \"Code Type 1 (CD)\",\n \"source\": \"UC\",\n \"metadata\": {\n \"createdDate\": \"2022-03-15T01:50:23.674+00:00\",\n \"updatedDate\": \"2022-03-15T01:50:23.674+00:00\"\n }\n}",
"headers": {
"Content-Type": "application/json"
}
}
},
{
"request": {
"method": "GET",
"url": "/statistical-code-types/1d51c4da-0d5f-4303-a922-3e9d7a9b22f3"
},
"response": {
"status": 404,
"headers": {
"Content-Type": "application/json"
}
}
}
]
}

0 comments on commit 5847aa1

Please sign in to comment.