From 817a25aa65e1143a1fb3cc52be090d1d4665a2f8 Mon Sep 17 00:00:00 2001 From: xuelianhan007 <148412906+xuelianhan007@users.noreply.github.com> Date: Thu, 14 Nov 2024 13:08:44 +0800 Subject: [PATCH] fix(sdk): fix status rendering in an array (#141) --- .../expected/expected-1-address.validation.json | 5 +++-- .../api-target-mapper.address.validate.yaml | 12 +++++++++++- .../api-target-mapper.inventory.eline.list.yaml | 6 +++--- .../api-target-mapper.inventory.uni.list.yaml | 2 +- .../api-target-mapper.order.uni.add.yaml | 8 ++++++++ .../src/test/resources/mock/apis/api.quote.yaml | 6 ++++-- .../core/toolkit/ConstructExpressionUtil.java | 10 ++++++++-- .../core/toolkit/ConstructExpressionUtilTest.java | 9 +++++++++ .../api-target-mapper.inventory.eline.list.yaml | 2 +- .../api-target-mapper.inventory.uni.list.yaml | 2 +- .../main/resources/mef-sonata/apis/api.quote.yaml | 6 ++++-- .../src/main/resources/mef-sonata/product.yaml | 1 + .../mef-sonata/template-upgrade/release.1.5.12.yaml | 13 +++++++++++++ 13 files changed, 67 insertions(+), 15 deletions(-) create mode 100644 kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/template-upgrade/release.1.5.12.yaml diff --git a/kraken-app/kraken-app-hub/src/test/resources/expected/expected-1-address.validation.json b/kraken-app/kraken-app-hub/src/test/resources/expected/expected-1-address.validation.json index 23feda2a..17ba3587 100644 --- a/kraken-app/kraken-app-hub/src/test/resources/expected/expected-1-address.validation.json +++ b/kraken-app/kraken-app-hub/src/test/resources/expected/expected-1-address.validation.json @@ -6,8 +6,9 @@ "@type": "FieldedAddress", "country": "${responseBody[*].company.addresses[0].country}", "city": "${responseBody[*].company.addresses[0].city}", - "streetName": "${responseBody[*].company.addresses[0].address}", - "locality": "${responseBody[*].dataCenterFacility.metroId}" + "streetName": "${responseBody[*].company.addresses[0].street}", + "locality": "${responseBody[*].dataCenterFacility.metroId}", + "tags": "${responseBody[*].tags}" } ], "provideAlternative": "${mefRequestBody.provideAlternative}", diff --git a/kraken-app/kraken-app-hub/src/test/resources/mock/api-targets-mappers/api-target-mapper.address.validate.yaml b/kraken-app/kraken-app-hub/src/test/resources/mock/api-targets-mappers/api-target-mapper.address.validate.yaml index d06ef6cc..8a901b4a 100644 --- a/kraken-app/kraken-app-hub/src/test/resources/mock/api-targets-mappers/api-target-mapper.address.validate.yaml +++ b/kraken-app/kraken-app-hub/src/test/resources/mock/api-targets-mappers/api-target-mapper.address.validate.yaml @@ -80,7 +80,7 @@ spec: - name: mapper.address.validation.streetName title: "The street of the identified alternate Geographic Address" description: address validation streetName mapping - source: "@{{[*].company.addresses[0].address}}" + source: "@{{[*].company.addresses[0].street}}" sourceLocation: BODY target: "@{{alternateGeographicAddress[*].streetName}}" targetType: string @@ -138,4 +138,14 @@ spec: target: "@{{bestMatchGeographicAddress.streetName}}" targetType: string targetLocation: BODY + replaceStar: false + - name: mapper.address.validation.tags + title: "tags of the identified alternate Geographic Address" + description: "" + source: "@{{[*].tags}}" + sourceLocation: BODY + target: "@{{alternateGeographicAddress[*].tags}}" + targetType: string + targetLocation: BODY + requiredMapping: false replaceStar: false \ No newline at end of file diff --git a/kraken-app/kraken-app-hub/src/test/resources/mock/api-targets-mappers/api-target-mapper.inventory.eline.list.yaml b/kraken-app/kraken-app-hub/src/test/resources/mock/api-targets-mappers/api-target-mapper.inventory.eline.list.yaml index 893de2d9..e88a15d1 100644 --- a/kraken-app/kraken-app-hub/src/test/resources/mock/api-targets-mappers/api-target-mapper.inventory.eline.list.yaml +++ b/kraken-app/kraken-app-hub/src/test/resources/mock/api-targets-mappers/api-target-mapper.inventory.eline.list.yaml @@ -61,7 +61,7 @@ spec: title: "Possible values for the status of a MEF product" source: "@{{responseBody.status}}" sourceLocation: BODY - target: "@{{status}}" + target: "@{{[*].status}}" targetType: enum targetLocation: BODY requiredMapping: true @@ -75,8 +75,8 @@ spec: - suspendedPendingTerminate - terminated valueMapping: - ACTIVE: active, - CANCELLED: canceled, + ACTIVE: active + CANCELLED: canceled PENDING: pendingActive DELETING: pendingTerminate DISABLED: suspended diff --git a/kraken-app/kraken-app-hub/src/test/resources/mock/api-targets-mappers/api-target-mapper.inventory.uni.list.yaml b/kraken-app/kraken-app-hub/src/test/resources/mock/api-targets-mappers/api-target-mapper.inventory.uni.list.yaml index 8b0e8f0e..87bf6641 100644 --- a/kraken-app/kraken-app-hub/src/test/resources/mock/api-targets-mappers/api-target-mapper.inventory.uni.list.yaml +++ b/kraken-app/kraken-app-hub/src/test/resources/mock/api-targets-mappers/api-target-mapper.inventory.uni.list.yaml @@ -60,7 +60,7 @@ spec: title: "Possible values for the status of a MEF product" source: "@{{responseBody.port.status}}" sourceLocation: BODY - target: "@{{status}}" + target: "@{{[*].status}}" targetType: enum targetLocation: BODY requiredMapping: true diff --git a/kraken-app/kraken-app-hub/src/test/resources/mock/api-targets-mappers/api-target-mapper.order.uni.add.yaml b/kraken-app/kraken-app-hub/src/test/resources/mock/api-targets-mappers/api-target-mapper.order.uni.add.yaml index a07cded2..1015ba6b 100644 --- a/kraken-app/kraken-app-hub/src/test/resources/mock/api-targets-mappers/api-target-mapper.order.uni.add.yaml +++ b/kraken-app/kraken-app-hub/src/test/resources/mock/api-targets-mappers/api-target-mapper.order.uni.add.yaml @@ -71,6 +71,14 @@ spec: title: >- the id of the place where the products' installation must be done. source: '@{{productOrderItem[0].product.place[0].id}}' + target: '@{{dataCenterFacilityId}}' + description: '' + sourceLocation: BODY + targetLocation: BODY + requiredMapping: false + - name: mapper.order.uni.add.place.name + title: the keyName of the place where the products' installation must be done. + source: '@{{productOrderItem[0].product.place[0].keyName}}' target: '@{{dataCenterFacility}}' description: '' sourceLocation: BODY diff --git a/kraken-app/kraken-app-hub/src/test/resources/mock/apis/api.quote.yaml b/kraken-app/kraken-app-hub/src/test/resources/mock/apis/api.quote.yaml index a23278f3..af5d281e 100644 --- a/kraken-app/kraken-app-hub/src/test/resources/mock/apis/api.quote.yaml +++ b/kraken-app/kraken-app-hub/src/test/resources/mock/apis/api.quote.yaml @@ -41,6 +41,7 @@ spec: console.log("input: " + jsonStr); let input = JSON.parse(jsonStr); let errorMsg = ''; + let errorArr = ['']; let targetAPIConfigKey = ''; let matrixConfigKey = ''; let forwardDownstream = true; @@ -73,9 +74,9 @@ spec: if (!syncQuote) { errorArr.push('disabled : instantSyncQuote==false'); } - errorMsg = errorArr.join(' '); targetAPIConfigKey = 'targetKey:notFound'; } + errorMsg = errorArr.join(' '); let ret = { quoteType: input.quoteItem['product']['productConfiguration']['@type'], instantSyncQuote: input.instantSyncQuote, @@ -183,6 +184,7 @@ spec: console.log("input: " + jsonStr); let input = JSON.parse(jsonStr); let errorMsg = ''; + let errorArr = ['']; let targetAPIConfigKey = ''; let forwardDownstream = true; let typeArr = ['UNI', 'ACCESS_E_LINE']; @@ -212,8 +214,8 @@ spec: if (!syncQuote) { errorArr.push('disabled : instantSyncQuote==false'); } - errorMsg = errorArr.join(' '); } + errorMsg = errorArr.join(' '); let ret = { quoteType: input.bizType, instantSyncQuote: input.instantSyncQuote, diff --git a/kraken-java-sdk/kraken-java-sdk-core/src/main/java/com/consoleconnect/kraken/operator/core/toolkit/ConstructExpressionUtil.java b/kraken-java-sdk/kraken-java-sdk-core/src/main/java/com/consoleconnect/kraken/operator/core/toolkit/ConstructExpressionUtil.java index 622331a8..f4366da1 100644 --- a/kraken-java-sdk/kraken-java-sdk-core/src/main/java/com/consoleconnect/kraken/operator/core/toolkit/ConstructExpressionUtil.java +++ b/kraken-java-sdk/kraken-java-sdk-core/src/main/java/com/consoleconnect/kraken/operator/core/toolkit/ConstructExpressionUtil.java @@ -4,9 +4,12 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.commons.lang3.StringUtils; public class ConstructExpressionUtil { + public static final String ARRAY_ROOT_PREFIX = "[*]."; + private ConstructExpressionUtil() {} public static List extractMapperParam(String param) { @@ -26,9 +29,12 @@ public static List extractParam(String param, String patternStr) { public static String convertToJsonPointer(String path) { List params = extractMapperParam(path); + String param = params.get(0); + if (StringUtils.isNotBlank(param) && param.startsWith(ARRAY_ROOT_PREFIX)) { + param = param.substring(ARRAY_ROOT_PREFIX.length(), param.length()); + } return "/" - + params - .get(0) + + param .replaceAll("\\[(\\*)\\]", "[0]") .replaceAll("(?)\\[", "\\/") .replaceAll("(?)\\].", "\\/") diff --git a/kraken-java-sdk/kraken-java-sdk-core/src/test/java/com/consoleconnect/kraken/operator/core/toolkit/ConstructExpressionUtilTest.java b/kraken-java-sdk/kraken-java-sdk-core/src/test/java/com/consoleconnect/kraken/operator/core/toolkit/ConstructExpressionUtilTest.java index cbed1b15..7e503aa0 100644 --- a/kraken-java-sdk/kraken-java-sdk-core/src/test/java/com/consoleconnect/kraken/operator/core/toolkit/ConstructExpressionUtilTest.java +++ b/kraken-java-sdk/kraken-java-sdk-core/src/test/java/com/consoleconnect/kraken/operator/core/toolkit/ConstructExpressionUtilTest.java @@ -5,6 +5,7 @@ import com.consoleconnect.kraken.operator.core.enums.ExpectTypeEnum; import java.util.List; import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @Slf4j @@ -37,4 +38,12 @@ void givenExpression_whenConvert_thenResponseOK() { log.info( "expected: {}, expectedExist: {}, expectedTrue: {}", expected, expectedExist, expectedTrue); } + + @Test + void givenStatusInArray_whenConvert_thenOK() { + String target = "@{{[*].status}}"; + String result = ConstructExpressionUtil.convertToJsonPointer(target); + String expected = "/status"; + Assertions.assertEquals(expected, result); + } } diff --git a/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/api-targets-mappers/api-target-mapper.inventory.eline.list.yaml b/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/api-targets-mappers/api-target-mapper.inventory.eline.list.yaml index 3feec9e8..02ccb64c 100644 --- a/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/api-targets-mappers/api-target-mapper.inventory.eline.list.yaml +++ b/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/api-targets-mappers/api-target-mapper.inventory.eline.list.yaml @@ -61,7 +61,7 @@ spec: title: "Possible values for the status of a MEF product" source: "" sourceLocation: "" - target: "@{{status}}" + target: "@{{[*].status}}" targetType: enum targetLocation: BODY requiredMapping: true diff --git a/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/api-targets-mappers/api-target-mapper.inventory.uni.list.yaml b/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/api-targets-mappers/api-target-mapper.inventory.uni.list.yaml index a4dd6841..1fa8c334 100644 --- a/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/api-targets-mappers/api-target-mapper.inventory.uni.list.yaml +++ b/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/api-targets-mappers/api-target-mapper.inventory.uni.list.yaml @@ -60,7 +60,7 @@ spec: title: "Possible values for the status of a MEF product" source: "" sourceLocation: "" - target: "@{{status}}" + target: "@{{[*].status}}" targetType: enum targetLocation: BODY requiredMapping: true diff --git a/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/apis/api.quote.yaml b/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/apis/api.quote.yaml index a23278f3..af5d281e 100644 --- a/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/apis/api.quote.yaml +++ b/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/apis/api.quote.yaml @@ -41,6 +41,7 @@ spec: console.log("input: " + jsonStr); let input = JSON.parse(jsonStr); let errorMsg = ''; + let errorArr = ['']; let targetAPIConfigKey = ''; let matrixConfigKey = ''; let forwardDownstream = true; @@ -73,9 +74,9 @@ spec: if (!syncQuote) { errorArr.push('disabled : instantSyncQuote==false'); } - errorMsg = errorArr.join(' '); targetAPIConfigKey = 'targetKey:notFound'; } + errorMsg = errorArr.join(' '); let ret = { quoteType: input.quoteItem['product']['productConfiguration']['@type'], instantSyncQuote: input.instantSyncQuote, @@ -183,6 +184,7 @@ spec: console.log("input: " + jsonStr); let input = JSON.parse(jsonStr); let errorMsg = ''; + let errorArr = ['']; let targetAPIConfigKey = ''; let forwardDownstream = true; let typeArr = ['UNI', 'ACCESS_E_LINE']; @@ -212,8 +214,8 @@ spec: if (!syncQuote) { errorArr.push('disabled : instantSyncQuote==false'); } - errorMsg = errorArr.join(' '); } + errorMsg = errorArr.join(' '); let ret = { quoteType: input.bizType, instantSyncQuote: input.instantSyncQuote, diff --git a/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/product.yaml b/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/product.yaml index 7758830e..646d1913 100644 --- a/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/product.yaml +++ b/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/product.yaml @@ -101,6 +101,7 @@ spec: - classpath:/mef-sonata/template-upgrade/release.1.5.9.yaml - classpath:/mef-sonata/template-upgrade/release.1.5.10.yaml - classpath:/mef-sonata/template-upgrade/release.1.5.11.yaml + - classpath:/mef-sonata/template-upgrade/release.1.5.12.yaml templateUpgradePaths: diff --git a/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/template-upgrade/release.1.5.12.yaml b/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/template-upgrade/release.1.5.12.yaml new file mode 100644 index 00000000..2513c657 --- /dev/null +++ b/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/template-upgrade/release.1.5.12.yaml @@ -0,0 +1,13 @@ +--- +kind: kraken.product.template-upgrade +apiVersion: v1 +metadata: + key: kraken.product.template-upgrade.1.5.12 + name: V1.5.12 + labels: + productSpec: grace + productVersion: V1.5.12 + publishDate: 2024-11-14 10:11 + description: | + Make some improvements to the status mapping in the array for inventory list + version: 2 \ No newline at end of file