From 15eb54baf8c96e23a362dad1c577bec48d008af2 Mon Sep 17 00:00:00 2001 From: zhiyaoPCCW <110662017+zhiyaoPCCW@users.noreply.github.com> Date: Fri, 22 Nov 2024 14:16:27 +0800 Subject: [PATCH 1/2] fix completionDate issue (#224) Co-authored-by: zhiyaoPCCW --- .../gateway/runner/MappingTransformer.java | 19 +++++++++++++++---- .../gateway/MappingTransformerTest.java | 18 ++++++++++++++++++ ...target-mapper.order.eline.read.delete.yaml | 4 ++++ .../api-target-mapper.order.eline.read.yaml | 4 ++++ ...i-target-mapper.order.uni.read.delete.yaml | 4 ++++ .../api-target-mapper.order.uni.read.yaml | 4 ++++ .../main/resources/mef-sonata/product.yaml | 2 +- .../template-upgrade/release.1.5.21.yaml | 13 ------------- .../template-upgrade/release.1.5.22.yaml | 13 +++++++++++++ 9 files changed, 63 insertions(+), 18 deletions(-) delete mode 100644 kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/template-upgrade/release.1.5.21.yaml create mode 100644 kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/template-upgrade/release.1.5.22.yaml diff --git a/kraken-java-sdk/kraken-java-sdk-gateway/src/main/java/com/consoleconnect/kraken/operator/gateway/runner/MappingTransformer.java b/kraken-java-sdk/kraken-java-sdk-gateway/src/main/java/com/consoleconnect/kraken/operator/gateway/runner/MappingTransformer.java index b0687b91..f29668c4 100644 --- a/kraken-java-sdk/kraken-java-sdk-gateway/src/main/java/com/consoleconnect/kraken/operator/gateway/runner/MappingTransformer.java +++ b/kraken-java-sdk/kraken-java-sdk-gateway/src/main/java/com/consoleconnect/kraken/operator/gateway/runner/MappingTransformer.java @@ -11,6 +11,7 @@ import com.jayway.jsonpath.JsonPath; import java.util.*; import lombok.extern.slf4j.Slf4j; +import net.minidev.json.JSONArray; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; @@ -134,15 +135,17 @@ default String deleteNodeByPath(Map checkPathMap, String json) { String.format( "Json Path read key error, key:%s, value:%s will be deleted", key, value); LogHolder.log.error(err, e); - doc.delete(value); + deleteByPath(value, doc); return; } if (null == obj || (obj instanceof String str && (StringUtils.isBlank(str)))) { - doc.delete(value); + deleteByPath(value, doc); } else if (obj instanceof Integer i && i <= 0) { - doc.delete(value); + deleteByPath(value, doc); } else if (obj instanceof Boolean b && !b) { - doc.delete(value); + deleteByPath(value, doc); + } else if (obj instanceof JSONArray array && array.isEmpty()) { + deleteByPath(value, doc); } else { LogHolder.log.warn("Reserved key:{}, value:{}", key, value); } @@ -150,6 +153,14 @@ default String deleteNodeByPath(Map checkPathMap, String json) { return doc.jsonString(); } + default void deleteByPath(String path, DocumentContext doc) { + try { + doc.delete(path); + } catch (Exception e) { + LogHolder.log.warn("Delete path {} error: {}", path, e.getMessage()); + } + } + default String calculateBasedOnResponseBody(String responseBody, Map context) { String replace = responseBody.replace("((", "${").replace("))", "}"); LogHolder.log.info("calculateBasedOnResponseBody replace:{}", replace); diff --git a/kraken-java-sdk/kraken-java-sdk-gateway/src/test/java/com/consoleconnect/kraken/operator/gateway/MappingTransformerTest.java b/kraken-java-sdk/kraken-java-sdk-gateway/src/test/java/com/consoleconnect/kraken/operator/gateway/MappingTransformerTest.java index 7206bee3..50977268 100644 --- a/kraken-java-sdk/kraken-java-sdk-gateway/src/test/java/com/consoleconnect/kraken/operator/gateway/MappingTransformerTest.java +++ b/kraken-java-sdk/kraken-java-sdk-gateway/src/test/java/com/consoleconnect/kraken/operator/gateway/MappingTransformerTest.java @@ -1,5 +1,9 @@ package com.consoleconnect.kraken.operator.gateway; +import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.notNullValue; + import com.consoleconnect.kraken.operator.gateway.runner.MappingTransformer; import java.util.HashMap; import java.util.Map; @@ -18,4 +22,18 @@ void givenJsonInput_whenDeleteNode_thenReturnOK() { String result = deleteNodeByPath(checkPathMap, input); Assertions.assertEquals("{\"key\":\"hello kraken\"}", result); } + + @Test + void givenJson_whenDeleteNodeByPath_thenDeleteNodeSuccess() { + Map checkPathMap = new HashMap<>(); + String input = + "{\"state\":\"completed1\",\"completionDate\":\"123\",\"productOrderItem\":[{\"state\":\"completed\",\"completionDate\":\"123\"}]}\n"; + checkPathMap.put("$[?(@.state == 'completed')]", "$.completionDate"); + checkPathMap.put( + "$.productOrderItem[?(@.state == 'completed')]", + "$.productOrderItem[?(@.state != 'completed')].completionDate"); + checkPathMap.put("$.notFound", "$.notFound"); + String s = deleteNodeByPath(checkPathMap, input); + assertThat(s, hasJsonPath("$.productOrderItem[0].completionDate"), notNullValue()); + } } diff --git a/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/api-targets-mappers/api-target-mapper.order.eline.read.delete.yaml b/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/api-targets-mappers/api-target-mapper.order.eline.read.delete.yaml index d06b5b90..6b455cbc 100644 --- a/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/api-targets-mappers/api-target-mapper.order.eline.read.delete.yaml +++ b/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/api-targets-mappers/api-target-mapper.order.eline.read.delete.yaml @@ -63,6 +63,8 @@ spec: source: "" sourceLocation: "BODY" target: "@{{completionDate}}" + checkPath: "$[?(@.state == 'completed')]" + deletePath: "$.completionDate" targetLocation: "BODY" requiredMapping: false - name: mapper.order.eline.read.delete.instanceId @@ -80,6 +82,8 @@ spec: sourceLocation: "BODY" target: "@{{productOrderItem[0].completionDate}}" targetLocation: "BODY" + checkPath: "$.productOrderItem[?(@.state == 'completed')]" + deletePath: "$.productOrderItem[?(@.state != 'completed')].completionDate" requiredMapping: false - name: mapper.order.eline.read.delete.productOrderItem.expectedCompleteDate title: "order item expected complete date" diff --git a/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/api-targets-mappers/api-target-mapper.order.eline.read.yaml b/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/api-targets-mappers/api-target-mapper.order.eline.read.yaml index 4a0c8130..f95bdb20 100644 --- a/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/api-targets-mappers/api-target-mapper.order.eline.read.yaml +++ b/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/api-targets-mappers/api-target-mapper.order.eline.read.yaml @@ -65,6 +65,8 @@ spec: sourceLocation: "BODY" target: "@{{completionDate}}" targetLocation: "BODY" + checkPath: "$[?(@.state == 'completed')]" + deletePath: "$.completionDate" requiredMapping: false - name: mapper.order.eline.read.instanceId title: "instance id from seller" @@ -82,6 +84,8 @@ spec: target: "@{{productOrderItem[0].completionDate}}" targetLocation: "BODY" requiredMapping: false + checkPath: "$.productOrderItem[?(@.state == 'completed')]" + deletePath: "$.productOrderItem[?(@.state != 'completed')].completionDate" - name: mapper.order.eline.read.productOrderItem.expectedCompleteDate title: "order item expected complete date" description: "" diff --git a/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/api-targets-mappers/api-target-mapper.order.uni.read.delete.yaml b/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/api-targets-mappers/api-target-mapper.order.uni.read.delete.yaml index 26121e84..3f98cd33 100644 --- a/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/api-targets-mappers/api-target-mapper.order.uni.read.delete.yaml +++ b/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/api-targets-mappers/api-target-mapper.order.uni.read.delete.yaml @@ -64,6 +64,8 @@ spec: source: "" sourceLocation: "BODY" target: "@{{completionDate}}" + checkPath: "$[?(@.state == 'completed')]" + deletePath: "$.completionDate" targetLocation: "BODY" requiredMapping: false - name: mapper.order.uni.read.delete.instanceId @@ -80,6 +82,8 @@ spec: source: "" sourceLocation: "BODY" target: "@{{productOrderItem[0].completionDate}}" + checkPath: "$.productOrderItem[?(@.state == 'completed')]" + deletePath: "$.productOrderItem[?(@.state != 'completed')].completionDate" targetLocation: "BODY" requiredMapping: false - name: mapper.order.uni.read.delete.productOrderItem.expectedCompleteDate diff --git a/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/api-targets-mappers/api-target-mapper.order.uni.read.yaml b/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/api-targets-mappers/api-target-mapper.order.uni.read.yaml index ce54ef58..96535569 100644 --- a/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/api-targets-mappers/api-target-mapper.order.uni.read.yaml +++ b/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/api-targets-mappers/api-target-mapper.order.uni.read.yaml @@ -65,6 +65,8 @@ spec: source: "" sourceLocation: "BODY" target: "@{{completionDate}}" + checkPath: "$[?(@.state == 'completed')]" + deletePath: "$.completionDate" targetLocation: "BODY" requiredMapping: false - name: mapper.order.uni.read.instanceId @@ -82,6 +84,8 @@ spec: sourceLocation: "BODY" target: "@{{productOrderItem[0].completionDate}}" targetLocation: "BODY" + checkPath: "$.productOrderItem[?(@.state == 'completed')]" + deletePath: "$.productOrderItem[?(@.state != 'completed')].completionDate" requiredMapping: false - name: mapper.order.uni.read.productOrderItem.expectedCompleteDate title: "order item expected complete date" 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 95af1402..23d87bec 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 @@ -98,7 +98,7 @@ spec: - classpath:/mef-sonata/mapping-matrix/mapping.matrix.inventory.eline.read.yaml - classpath:/mef-sonata/mapping-matrix/mapping.matrix.inventory.uni.list.yaml - classpath:/mef-sonata/mapping-matrix/mapping.matrix.inventory.eline.list.yaml - - classpath:/mef-sonata/template-upgrade/release.1.5.21.yaml + - classpath:/mef-sonata/template-upgrade/release.1.5.22.yaml templateUpgradePaths: diff --git a/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/template-upgrade/release.1.5.21.yaml b/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/template-upgrade/release.1.5.21.yaml deleted file mode 100644 index 56b23a2e..00000000 --- a/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/template-upgrade/release.1.5.21.yaml +++ /dev/null @@ -1,13 +0,0 @@ ---- -kind: kraken.product.template-upgrade -apiVersion: v1 -metadata: - key: kraken.product.template-upgrade.1.5.21 - name: V1.5.21 - labels: - productSpec: grace - productVersion: V1.5.21 - publishDate: 2024-11-21 - description: | - Added state and changeDate under the stateChange node for order detail query. - version: 2 \ No newline at end of file diff --git a/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/template-upgrade/release.1.5.22.yaml b/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/template-upgrade/release.1.5.22.yaml new file mode 100644 index 00000000..0c218953 --- /dev/null +++ b/kraken-java-sdk/kraken-java-sdk-mef/src/main/resources/mef-sonata/template-upgrade/release.1.5.22.yaml @@ -0,0 +1,13 @@ +--- +kind: kraken.product.template-upgrade +apiVersion: v1 +metadata: + key: kraken.product.template-upgrade.1.5.22 + name: V1.5.22 + labels: + productSpec: grace + productVersion: V1.5.22 + publishDate: 2024-11-22 + description: | + Remove completionDate when state != completed. + version: 2 \ No newline at end of file From e160ea902f590c39bbebc601aafb39c827f027a5 Mon Sep 17 00:00:00 2001 From: james-tran-3005 <117259948+james-tran-3005@users.noreply.github.com> Date: Fri, 22 Nov 2024 13:38:02 +0700 Subject: [PATCH 2/2] fix(portal): fix buyer management pagination doesn't work properly (#225) --- .../src/hooks/product/index.ts | 1 + .../src/pages/Buyer/index.tsx | 25 ++++++++----------- .../src/stores/buyer.store.tsx | 2 +- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/kraken-app/kraken-app-portal/src/hooks/product/index.ts b/kraken-app/kraken-app-portal/src/hooks/product/index.ts index 088145e1..946b71c3 100644 --- a/kraken-app/kraken-app-portal/src/hooks/product/index.ts +++ b/kraken-app/kraken-app-portal/src/hooks/product/index.ts @@ -575,6 +575,7 @@ export const useGetBuyerList = ( queryFn: () => getBuyerList(productId, params), enabled: Boolean(productId) && Boolean(params.envId), select: (data) => data?.data, + staleTime: STALE_TIME, }); }; diff --git a/kraken-app/kraken-app-portal/src/pages/Buyer/index.tsx b/kraken-app/kraken-app-portal/src/pages/Buyer/index.tsx index 64093431..4f361df5 100644 --- a/kraken-app/kraken-app-portal/src/pages/Buyer/index.tsx +++ b/kraken-app/kraken-app-portal/src/pages/Buyer/index.tsx @@ -13,7 +13,7 @@ import { useAppStore } from "@/stores/app.store"; import { useBuyerStore } from "@/stores/buyer.store"; import { IBuyer } from "@/utils/types/component.type"; import { Button, Flex, Popconfirm, Table, notification } from "antd"; -import { get, isEmpty, omitBy } from "lodash"; +import { get } from "lodash"; import { useEffect, useMemo, useRef } from "react"; import { useBoolean } from "usehooks-ts"; import { ContentTime } from "../NewAPIMapping/components/DeployHistory/ContentTime"; @@ -26,7 +26,7 @@ const Buyer = () => { const { params, setParams, resetParams } = useBuyerStore(); const { data: dataList, isLoading } = useGetBuyerList( currentProduct, - omitBy(params, isEmpty) + params ); const { value: isModalVisible, @@ -180,18 +180,15 @@ const Buyer = () => {
{ - setParams({ page: page - 1, size: pageSize }); - }, - } - } + pagination={{ + current: dataList?.page + 1, + total: dataList?.total, + size: dataList?.size, + showSizeChanger: true, + onChange: (page, pageSize) => { + setParams({ page: page - 1, size: pageSize }); + }, + }} dataSource={dataList?.data} columns={columns} scroll={{ y: get(size, "height", 0) - 60, x: "auto" }} diff --git a/kraken-app/kraken-app-portal/src/stores/buyer.store.tsx b/kraken-app/kraken-app-portal/src/stores/buyer.store.tsx index b3a0f490..6d67b4ca 100644 --- a/kraken-app/kraken-app-portal/src/stores/buyer.store.tsx +++ b/kraken-app/kraken-app-portal/src/stores/buyer.store.tsx @@ -15,7 +15,7 @@ type BuyerStore = { const DEFAULT_PARAMS = { page: 0, - size: 50, + size: 20, orderBy: "createdAt", direction: "DESC", };