From 2cb3a4de191963dcd12cc4f8a385a8ac301ff76d Mon Sep 17 00:00:00 2001 From: Viachaslau Khandramai Date: Mon, 12 Aug 2024 13:04:36 +0200 Subject: [PATCH 1/3] MODEXPW-495 - ECS | Incorrect "totalRecords" value when search Items by Former identifier on Member tenant (#558) * MODEXPW-495 - ECS | Incorrect "totalRecords" value when search Items by Former identifier on Member tenant * MODEXPW-495 - ECS | Incorrect "totalRecords" value when search Items by Former identifier on Member tenant --- .../jobs/processidentifiers/ItemFetcher.java | 8 +++---- .../bulkedit/jobs/BulkEditProcessorsTest.java | 5 +++-- src/test/resources/mappings/inventory.json | 18 +++++++-------- .../mappings/items_bad_reference.json | 22 +++++++++---------- 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/folio/dew/batch/bulkedit/jobs/processidentifiers/ItemFetcher.java b/src/main/java/org/folio/dew/batch/bulkedit/jobs/processidentifiers/ItemFetcher.java index 8bcc24d9..2f5759ae 100644 --- a/src/main/java/org/folio/dew/batch/bulkedit/jobs/processidentifiers/ItemFetcher.java +++ b/src/main/java/org/folio/dew/batch/bulkedit/jobs/processidentifiers/ItemFetcher.java @@ -93,8 +93,8 @@ public ExtendedItemCollection process(ItemIdentifier itemIdentifier) throws Bulk tenantIds.forEach(tenantId -> { try (var context = new FolioExecutionContextSetter(refreshAndGetFolioExecutionContext(tenantId, folioExecutionContext))) { var url = format(getMatchPattern(identifierType), idType, identifier); - var itemCollection = inventoryClient.getItemByQuery(url, limit); - if (itemCollection.getTotalRecords() > limit) { + var itemCollection = inventoryClient.getItemByQuery(url, Integer.MAX_VALUE); + if (itemCollection.getItems().size() > limit) { log.error("Central tenant case: response from {} for tenant {}: {}", url, tenantId, getResponseAsString(itemCollection)); throw new BulkEditException(MULTIPLE_MATCHES_MESSAGE); } @@ -118,8 +118,8 @@ public ExtendedItemCollection process(ItemIdentifier itemIdentifier) throws Bulk // Process local tenant case var url = format(getMatchPattern(identifierType), idType, identifier); var currentTenantId = folioExecutionContext.getTenantId(); - var itemCollection = inventoryClient.getItemByQuery(url, limit); - if (itemCollection.getTotalRecords() > limit) { + var itemCollection = inventoryClient.getItemByQuery(url, Integer.MAX_VALUE); + if (itemCollection.getItems().size() > limit) { log.error("Member/local tenant case: response from {} for tenant {}: {}", url, currentTenantId, getResponseAsString(itemCollection)); throw new BulkEditException(MULTIPLE_MATCHES_MESSAGE); } diff --git a/src/test/java/org/folio/dew/batch/bulkedit/jobs/BulkEditProcessorsTest.java b/src/test/java/org/folio/dew/batch/bulkedit/jobs/BulkEditProcessorsTest.java index d8284d32..e6d65690 100644 --- a/src/test/java/org/folio/dew/batch/bulkedit/jobs/BulkEditProcessorsTest.java +++ b/src/test/java/org/folio/dew/batch/bulkedit/jobs/BulkEditProcessorsTest.java @@ -40,6 +40,7 @@ import java.nio.file.Path; import java.util.Collections; +import java.util.List; class BulkEditProcessorsTest extends BaseBatchTest { @Autowired @@ -127,8 +128,8 @@ void shouldNotIncludeDuplicatedUsers(String identifierType) { @ValueSource(strings = {"ID", "HRID", "BARCODE", "FORMER_IDS", "ACCESSION_NUMBER"}) @SneakyThrows void shouldNotIncludeDuplicatedItems(String identifierType) { - when(inventoryClient.getItemByQuery(String.format(getMatchPattern(identifierType), resolveIdentifier(identifierType), "duplicateIdentifier"), 1)).thenReturn(new ItemCollection().items(Collections.singletonList(new Item())).totalRecords(2)); - when(inventoryClient.getItemByQuery("barcode==\"duplicateIdentifier\"", 1)).thenReturn(new ItemCollection().items(Collections.singletonList(new Item())).totalRecords(2)); + when(inventoryClient.getItemByQuery(String.format(getMatchPattern(identifierType), resolveIdentifier(identifierType), "duplicateIdentifier"), Integer.MAX_VALUE)).thenReturn(new ItemCollection().items(List.of(new Item(), new Item())).totalRecords(2)); + when(inventoryClient.getItemByQuery("barcode==\"duplicateIdentifier\"", Integer.MAX_VALUE)).thenReturn(new ItemCollection().items(List.of(new Item(), new Item())).totalRecords(2)); StepExecution stepExecution = MetaDataInstanceFactory.createStepExecution(new JobParameters(Collections.singletonMap("identifierType", new JobParameter<>(identifierType, String.class)))); StepScopeTestUtils.doInStepScope(stepExecution, () -> { var identifier = new ItemIdentifier("duplicateIdentifier"); diff --git a/src/test/resources/mappings/inventory.json b/src/test/resources/mappings/inventory.json index 3a23e805..3a9fa8fb 100644 --- a/src/test/resources/mappings/inventory.json +++ b/src/test/resources/mappings/inventory.json @@ -16,7 +16,7 @@ { "request": { "method": "GET", - "url": "/inventory/items?query=barcode%3D%3D%2290000%22&limit=1" + "url": "/inventory/items?query=barcode%3D%3D%2290000%22&limit=2147483647" }, "response": { "status": 200, @@ -29,7 +29,7 @@ { "request": { "method": "GET", - "url": "/inventory/items?query=formerIds%3D90000&limit=1" + "url": "/inventory/items?query=formerIds%3D90000&limit=2147483647" }, "response": { "status": 200, @@ -42,7 +42,7 @@ { "request": { "method": "GET", - "url": "/inventory/items?query=barcode%3D%3D%2212345%22&limit=1" + "url": "/inventory/items?query=barcode%3D%3D%2212345%22&limit=2147483647" }, "response": { "status": 200, @@ -55,7 +55,7 @@ { "request": { "method": "GET", - "url": "/inventory/items?query=barcode%3D%3D%22invalid_date%22&limit=1" + "url": "/inventory/items?query=barcode%3D%3D%22invalid_date%22&limit=2147483647" }, "response": { "status": 200, @@ -68,7 +68,7 @@ { "request": { "method": "GET", - "urlPattern": "/inventory/items\\?query=barcode%3D%3D%22bar\\d*%22&limit=1" + "urlPattern": "/inventory/items\\?query=barcode%3D%3D%22bar\\d*%22&limit=2147483647" }, "response": { "status": 200, @@ -81,7 +81,7 @@ { "request": { "method": "GET", - "urlPattern": "/inventory/items\\?query=barcode%3D%3D%22foo\\d*%22&limit=1" + "urlPattern": "/inventory/items\\?query=barcode%3D%3D%22foo\\d*%22&limit=2147483647" }, "response": { "status": 200, @@ -107,7 +107,7 @@ { "request": { "method": "GET", - "url": "/inventory/items?query=barcode%3D%3D%2210101%22&limit=1" + "url": "/inventory/items?query=barcode%3D%3D%2210101%22&limit=2147483647" }, "response": { "status": 200, @@ -120,7 +120,7 @@ { "request": { "method": "GET", - "url": "/inventory/items?query=formerIds%3D10101&limit=1" + "url": "/inventory/items?query=formerIds%3D10101&limit=2147483647" }, "response": { "status": 200, @@ -133,7 +133,7 @@ { "request": { "method": "GET", - "url": "/inventory/items?query=barcode%3D%3D%22double_quote%22&limit=1" + "url": "/inventory/items?query=barcode%3D%3D%22double_quote%22&limit=2147483647" }, "response": { "status": 200, diff --git a/src/test/resources/mappings/items_bad_reference.json b/src/test/resources/mappings/items_bad_reference.json index 4cc5839b..f61610c8 100644 --- a/src/test/resources/mappings/items_bad_reference.json +++ b/src/test/resources/mappings/items_bad_reference.json @@ -3,7 +3,7 @@ { "request": { "method": "GET", - "url": "/inventory/items?query=barcode%3D%3D%22badCallNumberType%22&limit=1" + "url": "/inventory/items?query=barcode%3D%3D%22badCallNumberType%22&limit=2147483647" }, "response": { "status": 200, @@ -16,7 +16,7 @@ { "request": { "method": "GET", - "url": "/inventory/items?query=barcode%3D%3D%22badDamagedStatus%22&limit=1" + "url": "/inventory/items?query=barcode%3D%3D%22badDamagedStatus%22&limit=2147483647" }, "response": { "status": 200, @@ -29,7 +29,7 @@ { "request": { "method": "GET", - "url": "/inventory/items?query=barcode%3D%3D%22badNoteType%22&limit=1" + "url": "/inventory/items?query=barcode%3D%3D%22badNoteType%22&limit=2147483647" }, "response": { "status": 200, @@ -42,7 +42,7 @@ { "request": { "method": "GET", - "url": "/inventory/items?query=barcode%3D%3D%22badStatisticalCode%22&limit=1" + "url": "/inventory/items?query=barcode%3D%3D%22badStatisticalCode%22&limit=2147483647" }, "response": { "status": 200, @@ -55,7 +55,7 @@ { "request": { "method": "GET", - "url": "/inventory/items?query=barcode%3D%3D%22badServicePoint%22&limit=1" + "url": "/inventory/items?query=barcode%3D%3D%22badServicePoint%22&limit=2147483647" }, "response": { "status": 200, @@ -68,7 +68,7 @@ { "request": { "method": "GET", - "url": "/inventory/items?query=barcode%3D%3D%22badUserName%22&limit=1" + "url": "/inventory/items?query=barcode%3D%3D%22badUserName%22&limit=2147483647" }, "response": { "status": 200, @@ -81,7 +81,7 @@ { "request": { "method": "GET", - "url": "/inventory/items?query=barcode%3D%3D%22emptyCallNumberType%22&limit=1" + "url": "/inventory/items?query=barcode%3D%3D%22emptyCallNumberType%22&limit=2147483647" }, "response": { "status": 200, @@ -94,7 +94,7 @@ { "request": { "method": "GET", - "url": "/inventory/items?query=barcode%3D%3D%22emptyDamagedStatus%22&limit=1" + "url": "/inventory/items?query=barcode%3D%3D%22emptyDamagedStatus%22&limit=2147483647" }, "response": { "status": 200, @@ -107,7 +107,7 @@ { "request": { "method": "GET", - "url": "/inventory/items?query=barcode%3D%3D%22emptyNoteType%22&limit=1" + "url": "/inventory/items?query=barcode%3D%3D%22emptyNoteType%22&limit=2147483647" }, "response": { "status": 200, @@ -120,7 +120,7 @@ { "request": { "method": "GET", - "url": "/inventory/items?query=barcode%3D%3D%22emptyServicePoint%22&limit=1" + "url": "/inventory/items?query=barcode%3D%3D%22emptyServicePoint%22&limit=2147483647" }, "response": { "status": 200, @@ -133,7 +133,7 @@ { "request": { "method": "GET", - "url": "/inventory/items?query=barcode%3D%3D%22emptyUserName%22&limit=1" + "url": "/inventory/items?query=barcode%3D%3D%22emptyUserName%22&limit=2147483647" }, "response": { "status": 200, From fba02e882a5da36e00eeab3c5d1371ff77dbce4d Mon Sep 17 00:00:00 2001 From: Azizbek Khushvakov <113523904+azizbekxm@users.noreply.github.com> Date: Mon, 12 Aug 2024 17:55:33 +0500 Subject: [PATCH 2/3] [MODORDERS-1152] - Fix additional fields in EDIFACT order syntax (#556) * [MODORDERS-1152] - Fix additional fields in EDIFACT order syntax * [MODORDERS-1152] - Fix additional fields in EDIFACT order syntax * [MODORDERS-1152] - Fix additional fields in EDIFACT order syntax * Implemented Cacheable, updated unit price calculation, fixed unit test * fixed test * minor improvements * minor improvments * Revert "minor improvments" This reverts commit 0dad75278e59ebd7e16205b0168886b7baa42845. * Revert "minor improvements" This reverts commit 868bb9a0f1d59ddb09df8a49ad327a0d37f40a81. * Revert "fixed test" This reverts commit 143cfb23c044b3647a01d455e12159e2249bbeca. * Revert "Implemented Cacheable, updated unit price calculation, fixed unit test" This reverts commit 5f4429b2993f872d1af84af40274c36780374b45. * Reapply "Implemented Cacheable, updated unit price calculation, fixed unit test" This reverts commit 23707536c40544bb47658dd6ebbada451253d9cb. * Reapply "fixed test" This reverts commit fc0291a6022e5e30578945c989d50477943fd59c. * Reapply "minor improvements" This reverts commit 876c7b0aae3562319fa451c3e47c31b1f7d00fcf. * Reapply "minor improvments" This reverts commit 873417e9f1c58bfa5bc7bda2c68e97129da722ba. * Fixed test context issue * Increased code coverage * Increased code coverage * improved test * Changed to Object Mapper and simplified condition * Changed to Object Mapper and simplified condition * Fixed possible NP * Minor improvements * small fix * added comment * added comment * removed unnessary if statement --- pom.xml | 7 +++ .../edifact/CompositePOConverter.java | 26 +++++++--- .../edifact/CompositePOLineConverter.java | 50 +++++++++++++++++++ .../services/ConfigurationService.java | 47 +++++++++++------ .../folio/dew/client/ConfigurationClient.java | 4 ++ .../edifact/ConfigurationServiceTest.java | 28 ++++++++--- .../edifact/MappingOrdersToEdifactTest.java | 5 +- ...omprehensive_composite_purchase_order.json | 4 +- .../acquisitions/edifact_orders_result.edi | 31 ++++++------ .../resources/mappings/configurations.json | 39 +++++++++++++++ 10 files changed, 194 insertions(+), 47 deletions(-) diff --git a/pom.xml b/pom.xml index 2c99e624..ed379fb5 100644 --- a/pom.xml +++ b/pom.xml @@ -249,6 +249,13 @@ ${marc4j.version} + + org.javamoney + moneta + 1.4.2 + pom + + diff --git a/src/main/java/org/folio/dew/batch/acquisitions/edifact/CompositePOConverter.java b/src/main/java/org/folio/dew/batch/acquisitions/edifact/CompositePOConverter.java index 09d52eaa..d94c95dc 100644 --- a/src/main/java/org/folio/dew/batch/acquisitions/edifact/CompositePOConverter.java +++ b/src/main/java/org/folio/dew/batch/acquisitions/edifact/CompositePOConverter.java @@ -8,6 +8,7 @@ import org.folio.dew.domain.dto.CompositePoLine; import org.folio.dew.domain.dto.CompositePurchaseOrder; import org.folio.dew.domain.dto.acquisitions.edifact.EdiFileConfig; +import org.folio.dew.error.NotFoundException; import java.text.DateFormat; import java.text.SimpleDateFormat; @@ -37,21 +38,26 @@ public void convertPOtoEdifact(EDIStreamWriter writer, CompositePurchaseOrder co messageSegmentCount++; writeOrderDate(compPO, writer); + String shipToAddress = configurationService.getAddressConfig(compPO.getShipTo()); messageSegmentCount++; - writeLibrary(ediFileConfig, writer); + writeLibrary(ediFileConfig, shipToAddress, writer); messageSegmentCount++; writeVendor(ediFileConfig, writer); - if (!compPO.getCompositePoLines().isEmpty() - && compPO.getCompositePoLines().get(0).getVendorDetail() != null - && StringUtils.isNotBlank(compPO.getCompositePoLines().get(0).getVendorDetail().getVendorAccount())){ + if (compPO.getCompositePoLines().isEmpty()) { + String errMsg = String.format("CompositePoLines is not found for CompositeOrder '%s'", compPO.getId()); + throw new NotFoundException(errMsg); + } + + var comPoLine = compPO.getCompositePoLines().get(0); + if (comPoLine.getVendorDetail() != null && StringUtils.isNotBlank(comPoLine.getVendorDetail().getVendorAccount())){ messageSegmentCount++; - writeAccountNumber(compPO.getCompositePoLines().get(0).getVendorDetail().getVendorAccount(), writer); + writeAccountNumber(comPoLine.getVendorDetail().getVendorAccount(), writer); } messageSegmentCount++; - String currency = configurationService.getSystemCurrency(); + String currency = comPoLine.getCost().getCurrency(); writeCurrency(currency, writer); // Order lines @@ -113,7 +119,7 @@ private void writeOrderDate(CompositePurchaseOrder compPO, EDIStreamWriter write } // Library ID and ID type - private void writeLibrary(EdiFileConfig ediFileConfig, EDIStreamWriter writer) throws EDIStreamException { + private void writeLibrary(EdiFileConfig ediFileConfig, String shipToAddress, EDIStreamWriter writer) throws EDIStreamException { writer.writeStartSegment("NAD") .writeElement("BY") .writeStartElement() @@ -121,6 +127,12 @@ private void writeLibrary(EdiFileConfig ediFileConfig, EDIStreamWriter writer) t .writeComponent("") .writeComponent(ediFileConfig.getLibEdiType()) .endElement() + .writeStartElement() + .writeComponent("") + .endElement() + .writeStartElement() + .writeComponent(shipToAddress) + .endElement() .writeEndSegment(); } diff --git a/src/main/java/org/folio/dew/batch/acquisitions/edifact/CompositePOLineConverter.java b/src/main/java/org/folio/dew/batch/acquisitions/edifact/CompositePOLineConverter.java index 453561a1..f4b354e9 100644 --- a/src/main/java/org/folio/dew/batch/acquisitions/edifact/CompositePOLineConverter.java +++ b/src/main/java/org/folio/dew/batch/acquisitions/edifact/CompositePOLineConverter.java @@ -1,5 +1,9 @@ package org.folio.dew.batch.acquisitions.edifact; +import javax.money.CurrencyUnit; +import javax.money.Monetary; +import javax.money.MonetaryAmount; + import io.xlate.edi.stream.EDIStreamException; import io.xlate.edi.stream.EDIStreamWriter; import liquibase.util.StringUtil; @@ -10,10 +14,12 @@ import org.folio.dew.batch.acquisitions.edifact.services.MaterialTypeService; import org.folio.dew.domain.dto.CompositePoLine; import org.folio.dew.domain.dto.Contributor; +import org.folio.dew.domain.dto.Cost; import org.folio.dew.domain.dto.FundDistribution; import org.folio.dew.domain.dto.Location; import org.folio.dew.domain.dto.ProductIdentifier; import org.folio.dew.domain.dto.ReferenceNumberItem; +import org.javamoney.moneta.Money; import org.springframework.beans.factory.annotation.Autowired; import java.math.BigDecimal; @@ -106,6 +112,12 @@ public int convertPOLine(CompositePoLine poLine, EDIStreamWriter writer, int cur writePrice(poLine.getCost().getPoLineEstimatedPrice(), writer); } + if (poLine.getCost().getListUnitPrice() != null || poLine.getCost().getListUnitPriceElectronic() != null) { + messageSegmentCount++; + String totalUnitPrice = calculateCostUnitsTotal(poLine.getCost()); + writeUnitPrice(totalUnitPrice, writer); + } + messageSegmentCount++; writePoLineCurrency(poLine, writer); @@ -291,6 +303,15 @@ private void writePrice(BigDecimal price, EDIStreamWriter writer) throws EDIStre .writeEndSegment(); } + private void writeUnitPrice(String price, EDIStreamWriter writer) throws EDIStreamException { + writer.writeStartSegment("PRI") + .writeStartElement() + .writeComponent("AAB") + .writeComponent(price) + .endElement() + .writeEndSegment(); + } + private void writePoLineCurrency(CompositePoLine poLine, EDIStreamWriter writer) throws EDIStreamException { writer.writeStartSegment("CUX") .writeStartElement() @@ -452,4 +473,33 @@ private String getLocationCode(Location location) { } return ""; } + + + /** + * The method is using calculation that similar to calculation in mod-order (HelperUtils -> calculateCostUnitsTotal), + * but without additional cost and discount. + * + * @param cost Cost object of ComPoLine + * @return unit price without discount and additional cost + */ + private String calculateCostUnitsTotal(Cost cost) { + CurrencyUnit currency = Monetary.getCurrency(cost.getCurrency()); + MonetaryAmount total = Money.of(0, currency); + + // Physical resources price + if (cost.getListUnitPrice() != null && cost.getQuantityPhysical() != null) { + MonetaryAmount pPrice = Money.of(cost.getListUnitPrice(), currency) + .multiply(cost.getQuantityPhysical()); + total = total.add(pPrice); + } + + // Electronic resources price + if (cost.getListUnitPriceElectronic() != null && cost.getQuantityElectronic() != null) { + MonetaryAmount ePrice = Money.of(cost.getListUnitPriceElectronic(), currency) + .multiply(cost.getQuantityElectronic()); + total = total.add(ePrice); + } + + return total.toString(); + } } diff --git a/src/main/java/org/folio/dew/batch/acquisitions/edifact/services/ConfigurationService.java b/src/main/java/org/folio/dew/batch/acquisitions/edifact/services/ConfigurationService.java index c75b4fbe..17ba800f 100644 --- a/src/main/java/org/folio/dew/batch/acquisitions/edifact/services/ConfigurationService.java +++ b/src/main/java/org/folio/dew/batch/acquisitions/edifact/services/ConfigurationService.java @@ -1,35 +1,50 @@ package org.folio.dew.batch.acquisitions.edifact.services; +import java.util.UUID; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import org.folio.dew.client.ConfigurationClient; -import org.folio.dew.domain.dto.ConfigurationCollection; -import org.springframework.stereotype.Service; import lombok.RequiredArgsConstructor; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.folio.dew.client.ConfigurationClient; +import org.folio.dew.domain.dto.ModelConfiguration; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Service; @Service @RequiredArgsConstructor public class ConfigurationService { + + private static final Logger logger = LogManager.getLogger(); + private final ConfigurationClient configurationClient; private final ObjectMapper objectMapper; - private ConfigurationCollection getLocaleSettings() { - return configurationClient.getConfigurations("(module==ORG and configName==localeSettings)"); + private ModelConfiguration getConfigById(String configId) { + return configurationClient.getConfigById(configId); } - public String getSystemCurrency() { - ConfigurationCollection configs = getLocaleSettings(); - - if (configs == null || configs.getTotalRecords() == 0) { - return "USD"; + @Cacheable(cacheNames = "addressConfiguration") + public String getAddressConfig(UUID shipToConfigId) { + if (shipToConfigId == null) { + logger.warn("getAddressConfig:: 'shipTo' field of composite purchase order is null"); + return ""; } - var jsonObject = objectMapper.valueToTree(configs.getConfigs().get(0).getValue()); - - if (!jsonObject.has("currency")) { - return "USD"; + var addressConfig = getConfigById(shipToConfigId.toString()); + if (addressConfig.getValue() == null) { + logger.warn("getAddressConfig:: 'address config with id '{}' is not found", shipToConfigId); + return ""; + } + try { + JsonNode valueJsonObject = objectMapper.readTree(addressConfig.getValue()); + return valueJsonObject.has("address") ? valueJsonObject.get("address").asText() : ""; + } catch (JsonProcessingException e) { + logger.error("getAddressConfig:: Couldn't convert configValue: {} to json", addressConfig, e); + return ""; } - - return String.valueOf(jsonObject.get("currency")); } } diff --git a/src/main/java/org/folio/dew/client/ConfigurationClient.java b/src/main/java/org/folio/dew/client/ConfigurationClient.java index 7a8abf21..4c404a78 100644 --- a/src/main/java/org/folio/dew/client/ConfigurationClient.java +++ b/src/main/java/org/folio/dew/client/ConfigurationClient.java @@ -6,6 +6,7 @@ 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; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; @@ -16,6 +17,9 @@ public interface ConfigurationClient { @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) ConfigurationCollection getConfigurations(@RequestParam("query") String query); + @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE, path = "/{entryId}") + ModelConfiguration getConfigById(@PathVariable String entryId); + @PostMapping ModelConfiguration postConfiguration(@RequestBody ModelConfiguration config); } diff --git a/src/test/java/org/folio/dew/batch/acquisitions/edifact/ConfigurationServiceTest.java b/src/test/java/org/folio/dew/batch/acquisitions/edifact/ConfigurationServiceTest.java index 63da8f3e..b92a0323 100644 --- a/src/test/java/org/folio/dew/batch/acquisitions/edifact/ConfigurationServiceTest.java +++ b/src/test/java/org/folio/dew/batch/acquisitions/edifact/ConfigurationServiceTest.java @@ -2,19 +2,35 @@ import static org.junit.jupiter.api.Assertions.assertEquals; +import java.util.UUID; +import java.util.stream.Stream; + import org.folio.dew.BaseBatchTest; import org.folio.dew.batch.acquisitions.edifact.services.ConfigurationService; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.springframework.beans.factory.annotation.Autowired; - class ConfigurationServiceTest extends BaseBatchTest { + @Autowired private ConfigurationService configurationService; - @Test - void getCurrency() { - String currency = configurationService.getSystemCurrency(); - assertEquals("USD", currency); + static Stream provideAddressConfigData() { + return Stream.of( + Arguments.of("1947e709-8d60-42e2-8dde-7566ae446d24", "Address 123"), // existing config + Arguments.of(null, ""), // null config ID + Arguments.of("116a38c2-cac3-4f08-816b-afebfebe453d", ""), // non-existing config + Arguments.of("8ea92aa2-7b11-4f0e-9ed2-ab8fe281f37f", "") // config without address value + ); + } + + @ParameterizedTest + @MethodSource("provideAddressConfigData") + void testGetAddressConfig(String addressConfigId, String expectedAddress) { + UUID configId = addressConfigId != null ? UUID.fromString(addressConfigId) : null; + String address = configurationService.getAddressConfig(configId); + assertEquals(expectedAddress, address); } } diff --git a/src/test/java/org/folio/dew/batch/acquisitions/edifact/MappingOrdersToEdifactTest.java b/src/test/java/org/folio/dew/batch/acquisitions/edifact/MappingOrdersToEdifactTest.java index 9934ae3c..d8f1cec5 100644 --- a/src/test/java/org/folio/dew/batch/acquisitions/edifact/MappingOrdersToEdifactTest.java +++ b/src/test/java/org/folio/dew/batch/acquisitions/edifact/MappingOrdersToEdifactTest.java @@ -4,6 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.AdditionalMatchers.not; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; @@ -137,8 +138,8 @@ private void serviceMocks() { .thenReturn("KU/CC/DI/M"); Mockito.when(holdingService.getPermanentLocationByHoldingId(anyString())) .thenReturn("fcd64ce1-6995-48f0-840e-89ffa2288371"); - Mockito.when(configurationService.getSystemCurrency()) - .thenReturn("GBP"); + Mockito.when(configurationService.getAddressConfig(any())) + .thenReturn("Bockenheimer Landstr. 134-13"); } private void validateEdifactOrders(String ediOrder, String fileId) throws IOException { diff --git a/src/test/resources/edifact/acquisitions/comprehensive_composite_purchase_order.json b/src/test/resources/edifact/acquisitions/comprehensive_composite_purchase_order.json index b3d87d6f..1e40c4d3 100644 --- a/src/test/resources/edifact/acquisitions/comprehensive_composite_purchase_order.json +++ b/src/test/resources/edifact/acquisitions/comprehensive_composite_purchase_order.json @@ -35,11 +35,11 @@ } ], "cost": { - "listUnitPrice": 2.0, + "listUnitPriceElectronic": 2.0, "currency": "USD", "discount": 10.0, "discountType": "percentage", - "quantityPhysical": 1, + "quantityElectronic": 1, "poLineEstimatedPrice": 1.8 }, "details": { diff --git a/src/test/resources/edifact/acquisitions/edifact_orders_result.edi b/src/test/resources/edifact/acquisitions/edifact_orders_result.edi index 7c7716b8..14572e28 100644 --- a/src/test/resources/edifact/acquisitions/edifact_orders_result.edi +++ b/src/test/resources/edifact/acquisitions/edifact_orders_result.edi @@ -3,10 +3,10 @@ UNB+UNOC:3+901494200:014+0142948:31B+ddmmyy:hhmm+{fileId}' UNH+10000+ORDERS:D:96A:UN:EAN008' BGM+220+10000+9' DTM+137::102' -NAD+BY+901494200::014' +NAD+BY+901494200::014++Bockenheimer Landstr. 134-13' NAD+SU+0142948::31B' RFF+API:BRXXXXX-01' -CUX+2:GBP:9' +CUX+2:USD:9' LIN+1++9783319643991:EN' PIA+5+9783319643991:IS' IMD+L+009+:::Moutinho, Luiz' @@ -15,6 +15,7 @@ IMD+L+050+:::kele, editors' IMD+L+109+:::Palgrave Macmillan' QTY+21:1' PRI+AAF:1.8' +PRI+AAB:USD 2.00' CUX+2:USD:9' RFF+LI:10000-1' RFF+BFN:USHIST' @@ -22,14 +23,14 @@ LOC+7+KU/CC/DI/M::92' UNS+S' CNT+1:1' CNT+2:1' -UNT+23+10000' +UNT+24+10000' UNH+10001+ORDERS:D:96A:UN:EAN008' BGM+224+10001+9' DTM+137::102' -NAD+BY+901494200::014' +NAD+BY+901494200::014++Bockenheimer Landstr. 134-13' NAD+SU+0142948::31B' RFF+API:BRXXXXX-01' -CUX+2:GBP:9' +CUX+2:USD:9' LIN+1++9783319643991:EN' PIA+5+9783319643991:IM' IMD+L+009+:::Moutinho, Luiz' @@ -39,6 +40,7 @@ IMD+L+109+:::Palgrave Macmillan' IMD+L+170+:::[2017]' QTY+21:1' PRI+AAF:1.8' +PRI+AAB:USD 2.00' CUX+2:USD:9' RFF+LI:10001-1' RFF+BFN:USHIST' @@ -67,6 +69,7 @@ IMD+L+109+:::Otá Records, ' IMD+L+180+:::Book' QTY+21:3' PRI+AAF:1.5' +PRI+AAB:USD 1.65' CUX+2:USD:9' FTX+LIN++::+Test vendor instruction text.' RFF+LI:10001-2' @@ -78,13 +81,13 @@ LOC+7+KU/CC/DI/M::92' UNS+S' CNT+1:4' CNT+2:2' -UNT+56+10001' +UNT+58+10001' UNH+10002+ORDERS:D:96A:UN:EAN008' BGM+220+10002+9' DTM+137::102' -NAD+BY+901494200::014' +NAD+BY+901494200::014++Bockenheimer Landstr. 134-13' NAD+SU+0142948::31B' -CUX+2:GBP:9' +CUX+2:USD:9' LIN+1++:' IMD+L+050+:::empty' QTY+21:0' @@ -97,9 +100,9 @@ UNT+15+10002' UNH+10003+ORDERS:D:96A:UN:EAN008' BGM+220+10003+9' DTM+137::102' -NAD+BY+901494200::014' +NAD+BY+901494200::014++Bockenheimer Landstr. 134-13' NAD+SU+0142948::31B' -CUX+2:GBP:9' +CUX+2:USD:9' LIN+1++:' IMD+L+050+:::empty' QTY+21:0' @@ -112,9 +115,9 @@ UNT+15+10003' UNH+10004+ORDERS:D:96A:UN:EAN008' BGM+220+10004+9' DTM+137::102' -NAD+BY+901494200::014' +NAD+BY+901494200::014++Bockenheimer Landstr. 134-13' NAD+SU+0142948::31B' -CUX+2:GBP:9' +CUX+2:USD:9' LIN+1++12345679:IS' PIA+5+12345679:IS' IMD+L+050+:::empty' @@ -140,9 +143,9 @@ UNT+28+10004' UNH+10005+ORDERS:D:96A:UN:EAN008' BGM+220+10005+9' DTM+137::102' -NAD+BY+901494200::014' +NAD+BY+901494200::014++Bockenheimer Landstr. 134-13' NAD+SU+0142948::31B' -CUX+2:GBP:9' +CUX+2:USD:9' LIN+1++:' IMD+L+050+:::UNOA special chars need to be escaped are ???:?+?'' QTY+21:0' diff --git a/src/test/resources/mappings/configurations.json b/src/test/resources/mappings/configurations.json index d49fab46..3d9044ed 100644 --- a/src/test/resources/mappings/configurations.json +++ b/src/test/resources/mappings/configurations.json @@ -13,6 +13,45 @@ } } }, + { + "request": { + "method": "GET", + "url": "/configurations/entries/1947e709-8d60-42e2-8dde-7566ae446d24" + }, + "response": { + "status": 200, + "body": "{\n \"id\": \"1947e709-8d60-42e2-8dde-7566ae446d24\",\n \"module\": \"TENANT\",\n \"configName\": \"tenant.addresses\",\n \"code\": \"ADDRESS_1723093000876\",\n \"enabled\": true,\n \"value\": \"{\\\"name\\\":\\\"Name 1\\\",\\\"address\\\":\\\"Address 123\\\"}\",\n \"metadata\": {\n \"createdDate\": \"2024-08-08T04:56:41.232+00:00\",\n \"createdByUserId\": \"0c79340d-ad6e-4c9a-8384-bac681d24f8c\",\n \"updatedDate\": \"2024-08-08T04:56:51.654+00:00\",\n \"updatedByUserId\": \"0c79340d-ad6e-4c9a-8384-bac681d24f8c\"\n }\n}\n", + "headers": { + "Content-Type": "application/json" + } + } + }, + { + "request": { + "method": "GET", + "url": "/configurations/entries/116a38c2-cac3-4f08-816b-afebfebe453d" + }, + "response": { + "status": 200, + "body": "{}", + "headers": { + "Content-Type": "application/json" + } + } + }, + { + "request": { + "method": "GET", + "url": "/configurations/entries/8ea92aa2-7b11-4f0e-9ed2-ab8fe281f37f" + }, + "response": { + "status": 200, + "body": "{\n \"id\": \"1947e709-8d60-42e2-8dde-7566ae446d24\",\n \"module\": \"TENANT\",\n \"configName\": \"tenant.addresses\",\n \"code\": \"ADDRESS_1723093000876\",\n \"enabled\": true,\n \"value\": \"{\\\"name\\\":\\\"Name 1\\\"}\",\n \"metadata\": {\n \"createdDate\": \"2024-08-08T04:56:41.232+00:00\",\n \"createdByUserId\": \"0c79340d-ad6e-4c9a-8384-bac681d24f8c\",\n \"updatedDate\": \"2024-08-08T04:56:51.654+00:00\",\n \"updatedByUserId\": \"0c79340d-ad6e-4c9a-8384-bac681d24f8c\"\n }\n}\n", + "headers": { + "Content-Type": "application/json" + } + } + }, { "scenarioName": "First call should return empty collection", "requiredScenarioState": "Started", From 3a926600cbf91c7883adfa2349510cfc2494c42b Mon Sep 17 00:00:00 2001 From: Viachaslau Khandramai Date: Mon, 12 Aug 2024 21:52:41 +0200 Subject: [PATCH 3/3] MODEXPW-498 - HoldingsRecordsSource schema alignment (schemas pointing) (#559) --- folio-export-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/folio-export-common b/folio-export-common index ab00570d..4aae4a20 160000 --- a/folio-export-common +++ b/folio-export-common @@ -1 +1 @@ -Subproject commit ab00570df71eedccb73b771564f847b40e368085 +Subproject commit 4aae4a204d0e69a2056632ad36715d774843479a