From 429dc88102591dc2d5204e1751ced46829d06baf Mon Sep 17 00:00:00 2001 From: VampireAchao Date: Tue, 20 Aug 2024 15:55:38 +0800 Subject: [PATCH] [type:fix] Fix Plugin Edit Page Issue by Correcting Plugin ID Query and Updating Data Type (#5622) * [type:fix] Correct Plugin ID Query for Namespace Plugin Edit Page * [type:fix] use @GetMapping("/{pluginId}/{namespaceId}") --- db/init/oracle/schema.sql | 2 +- db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql | 2 +- .../controller/NamespacePluginController.java | 14 +++++++------- .../admin/mapper/NamespacePluginRelMapper.java | 4 ++-- .../admin/service/NamespacePluginService.java | 6 +++--- .../service/impl/NamespacePluginServiceImpl.java | 4 ++-- .../admin/service/impl/SyncDataServiceImpl.java | 2 +- .../resources/mappers/NamespacePluginRelMapper.xml | 2 +- .../src/main/resources/sql-script/h2/schema.sql | 2 +- .../shenyu/admin/service/SyncDataServiceTest.java | 2 +- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/db/init/oracle/schema.sql b/db/init/oracle/schema.sql index 1197f14fb219..9892187e0718 100644 --- a/db/init/oracle/schema.sql +++ b/db/init/oracle/schema.sql @@ -2776,7 +2776,7 @@ INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (namespace(id)) */ INTO `namespace` (`id`, CREATE TABLE plugin_ns_rel ( id VARCHAR2(128) COLLATE utf8mb4_unicode_ci NOT NULL, namespace_id VARCHAR2(50) COLLATE utf8mb4_unicode_ci NOT NULL, - plugin_id NUMBER(11) NOT NULL, + plugin_id VARCHAR2(128) COLLATE utf8mb4_unicode_ci NOT NULL, config CLOB COLLATE utf8mb4_unicode_ci, sort NUMBER(11), enabled NUMBER(4,0) NOT NULL DEFAULT 0 CHECK (enabled IN (0, 1)), diff --git a/db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql b/db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql index d0b2859f8aaa..5f2a18215ea0 100755 --- a/db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql +++ b/db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql @@ -88,7 +88,7 @@ INSERT INTO `shenyu`.`namespace` (`id`, `namespace_id`, `name`, `description`, ` CREATE TABLE `plugin_ns_rel` ( `id` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'primary key id', `namespace_id` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'namespace id', - `plugin_id` int(11) NOT NULL COMMENT 'plugin id', + `plugin_id` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'plugin id', `config` text COLLATE utf8mb4_unicode_ci COMMENT 'plugin configuration', `sort` int(11) DEFAULT NULL COMMENT 'sort', `enabled` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'whether to open (0, not open, 1 open)', diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/NamespacePluginController.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/NamespacePluginController.java index 67e09ec2a767..eee7d246abc3 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/NamespacePluginController.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/NamespacePluginController.java @@ -17,6 +17,8 @@ package org.apache.shenyu.admin.controller; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; import org.apache.commons.lang3.StringUtils; import org.apache.shenyu.admin.aspect.annotation.RestApi; import org.apache.shenyu.admin.mapper.NamespaceMapper; @@ -47,8 +49,6 @@ import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotNull; import java.util.List; /** @@ -103,16 +103,16 @@ public ShenyuAdminResult queryAllPlugins(@PathVariable("namespaceId") * detail plugin of namespace. * * @param namespaceId namespace id. - * @param id id. + * @param pluginId pluginId. * @return {@linkplain ShenyuAdminResult} */ - @GetMapping("/id={id}&namespaceId={namespaceId}") + @GetMapping("/{pluginId}/{namespaceId}") @RequiresPermissions("system:plugin:edit") public ShenyuAdminResult detailPlugin(@PathVariable("namespaceId") @Existed(message = "namespace is not existed", provider = NamespaceMapper.class) final String namespaceId, - @PathVariable("id") - @Existed(message = "id is not existed", provider = NamespacePluginRelMapper.class) final String id) { - NamespacePluginVO namespacePluginVO = namespacePluginService.findById(id, namespaceId); + @PathVariable("pluginId") + @Existed(message = "pluginId is not existed", provider = NamespacePluginRelMapper.class) final String pluginId) { + NamespacePluginVO namespacePluginVO = namespacePluginService.findByPluginId(pluginId, namespaceId); return ShenyuAdminResult.success(ShenyuResultMessage.DETAIL_SUCCESS, namespacePluginVO); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/NamespacePluginRelMapper.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/NamespacePluginRelMapper.java index 639129c03d11..e53214ee86be 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/NamespacePluginRelMapper.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/NamespacePluginRelMapper.java @@ -39,11 +39,11 @@ public interface NamespacePluginRelMapper extends ExistProvider { /** * existed. * - * @param id id + * @param pluginId pluginId * @return existed */ @Override - Boolean existed(@Param("id") Serializable id); + Boolean existed(@Param("pluginId") Serializable pluginId); /** diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/NamespacePluginService.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/NamespacePluginService.java index 7a598ff42253..b2b9ac6d331c 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/NamespacePluginService.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/NamespacePluginService.java @@ -53,13 +53,13 @@ public interface NamespacePluginService extends PageService ids, String namespaceId); /** - * find plugin namespace by id. + * find plugin namespace by pluginId. * - * @param id pk. + * @param pluginId the pluginId. * @param namespaceId the namespaceId * @return {@linkplain PluginVO} */ - NamespacePluginVO findById(String id, String namespaceId); + NamespacePluginVO findByPluginId(String pluginId, String namespaceId); /** * find page of plugin namespace by query. diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/NamespacePluginServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/NamespacePluginServiceImpl.java index b65fa25e340c..5f16442a682c 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/NamespacePluginServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/NamespacePluginServiceImpl.java @@ -96,8 +96,8 @@ public String delete(final List ids, final String namespaceId) { } @Override - public NamespacePluginVO findById(final String id, final String namespaceId) { - return this.namespacePluginRelMapper.selectByPluginIdAndNamespaceId(id, namespaceId); + public NamespacePluginVO findByPluginId(final String pluginId, final String namespaceId) { + return this.namespacePluginRelMapper.selectByPluginIdAndNamespaceId(pluginId, namespaceId); } @Override diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SyncDataServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SyncDataServiceImpl.java index a9cd1db100bb..caa251470d45 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SyncDataServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SyncDataServiceImpl.java @@ -127,7 +127,7 @@ public boolean syncAll(final DataEventTypeEnum type) { @Override public boolean syncPluginData(final String pluginId, final String namespaceId) { - NamespacePluginVO namespacePluginVO = namespacePluginService.findById(pluginId, namespaceId); + NamespacePluginVO namespacePluginVO = namespacePluginService.findByPluginId(pluginId, namespaceId); eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.PLUGIN, DataEventTypeEnum.UPDATE, Collections.singletonList(PluginTransfer.INSTANCE.mapToData(namespacePluginVO)))); diff --git a/shenyu-admin/src/main/resources/mappers/NamespacePluginRelMapper.xml b/shenyu-admin/src/main/resources/mappers/NamespacePluginRelMapper.xml index 035326420578..d66ead532fd2 100644 --- a/shenyu-admin/src/main/resources/mappers/NamespacePluginRelMapper.xml +++ b/shenyu-admin/src/main/resources/mappers/NamespacePluginRelMapper.xml @@ -43,7 +43,7 @@ diff --git a/shenyu-admin/src/main/resources/sql-script/h2/schema.sql b/shenyu-admin/src/main/resources/sql-script/h2/schema.sql index 3070489cee29..2fd9c03a3b45 100755 --- a/shenyu-admin/src/main/resources/sql-script/h2/schema.sql +++ b/shenyu-admin/src/main/resources/sql-script/h2/schema.sql @@ -1264,7 +1264,7 @@ INSERT IGNORE INTO `namespace` (`id`, `namespace_id`, `name`, `description`, `da CREATE TABLE IF NOT EXISTS `plugin_ns_rel` ( `id` VARCHAR(128) NOT NULL COMMENT 'primary key id', `namespace_id` VARCHAR(50) NOT NULL COMMENT 'namespace id', - `plugin_id` INT NOT NULL COMMENT 'plugin id', + `plugin_id` varchar(128) NOT NULL COMMENT 'plugin id', `config` TEXT COMMENT 'plugin configuration', `sort` INT DEFAULT NULL COMMENT 'sort', `enabled` TINYINT NOT NULL DEFAULT 0 COMMENT 'whether to open (0, not open, 1 open)', diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SyncDataServiceTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SyncDataServiceTest.java index dc33e858e53a..bbe42e14a14b 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SyncDataServiceTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SyncDataServiceTest.java @@ -108,7 +108,7 @@ public void syncAllTest() { public void syncPluginDataTest() { PluginVO pluginVO = buildPluginVO(); NamespacePluginVO namespacePluginVO = new NamespacePluginVO(); - given(this.namespacePluginService.findById(pluginVO.getId(), SYS_DEFAULT_NAMESPACE_ID)).willReturn(namespacePluginVO); + given(this.namespacePluginService.findByPluginId(pluginVO.getId(), SYS_DEFAULT_NAMESPACE_ID)).willReturn(namespacePluginVO); SelectorData selectorData = buildSelectorData(); given(this.selectorService.findByPluginIdAndNamespaceId(pluginVO.getId(), SYS_DEFAULT_NAMESPACE_ID)).willReturn(Collections.singletonList(selectorData));