This is an automated email from the ASF dual-hosted git repository. hefengen pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push: new 6f0d13f4ee [type:fix]fix namespace delete (#5740) 6f0d13f4ee is described below commit 6f0d13f4ee7c2f1f2360bbbae38cde5d5b733843 Author: xcsnx <1192709...@qq.com> AuthorDate: Thu Nov 14 22:27:29 2024 +0800 [type:fix]fix namespace delete (#5740) * fix * fix * fix * fix * fix * fix --------- Co-authored-by: ‘xcsnx’ <‘1192709...@qq.com’> Co-authored-by: aias00 <rok...@163.com> Co-authored-by: aias00 <liuhon...@apache.org> --- .../apache/shenyu/admin/mapper/AuthPathMapper.java | 16 +++++ .../shenyu/admin/mapper/DiscoveryMapper.java | 8 +++ .../apache/shenyu/admin/mapper/MetaDataMapper.java | 8 +++ .../admin/mapper/NamespacePluginRelMapper.java | 17 ++--- .../org/apache/shenyu/admin/mapper/RuleMapper.java | 8 +++ .../apache/shenyu/admin/mapper/SelectorMapper.java | 8 +++ .../service/impl/NamespacePluginServiceImpl.java | 4 +- .../admin/service/impl/NamespaceServiceImpl.java | 83 +++++++++++++++++++--- .../main/resources/mappers/auth-path-sqlmap.xml | 17 +++++ .../main/resources/mappers/discovery-sqlmap.xml | 10 +++ .../main/resources/mappers/meta-data-sqlmap.xml | 10 +++ .../mappers/namespace-plugin-rel-sqlmap.xml | 45 ++++++++++++ .../src/main/resources/mappers/rule-sqlmap.xml | 10 +++ .../src/main/resources/mappers/selector-sqlmap.xml | 10 +++ 14 files changed, 230 insertions(+), 24 deletions(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/AuthPathMapper.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/AuthPathMapper.java index 3a92625612..8c0ba91d11 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/AuthPathMapper.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/AuthPathMapper.java @@ -79,6 +79,22 @@ public interface AuthPathMapper extends ExistProvider { * @return the list */ List<AuthPathDO> findByAuthId(String authId); + + /** + * Find by namespace id list. + * + * @param namespaceId the namespaceId + * @return the list + */ + List<AuthPathDO> findByNamespaceId(String namespaceId); + + /** + * Find by namespace id list. + * + * @param namespaceIds the namespaceIds + * @return the list + */ + List<AuthPathDO> findByNamespaceIds(List<String> namespaceIds); /** * find all the {@link AuthPathDO} by authIdList. diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/DiscoveryMapper.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/DiscoveryMapper.java index a4100af1b3..d0f7c63c3d 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/DiscoveryMapper.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/DiscoveryMapper.java @@ -63,6 +63,14 @@ public interface DiscoveryMapper extends ExistProvider { */ List<DiscoveryDO> selectAllByNamespaceId(String namespaceId); + /** + * selectAllByNamespaceIds. + * + * @param namespaceIds the namespaceIds + * @return discoveryDOList + */ + List<DiscoveryDO> selectAllByNamespaceIds(List<String> namespaceIds); + /** * select discovery by plugin name and level. * diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/MetaDataMapper.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/MetaDataMapper.java index 723cdd8156..e4f33fa266 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/MetaDataMapper.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/MetaDataMapper.java @@ -72,6 +72,14 @@ public interface MetaDataMapper extends ExistProvider { * @return the list */ List<MetaDataDO> findAllByNamespaceId(String namespaceId); + + /** + * Find all list. + * + * @param namespaceIds the namespaceIds + * @return the list + */ + List<MetaDataDO> findAllByNamespaceIds(List<String> namespaceIds); /** * Find meta data do by path and namespaceId. 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 bcddba5f0a..81cd5c2921 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 @@ -137,21 +137,16 @@ public interface NamespacePluginRelMapper extends ExistProvider { * @return {@linkplain List} */ List<NamespacePluginVO> selectAllByNamespaceId(String namespaceId); - - /** - * select all. - * - * @return {@linkplain List} - */ - List<NamespacePluginVO> selectAllByNamespaceId(); - + /** - * select all by namespaceId. + * select all by namespaceId list. * - * @param namespaceId namespaceId. + * @param namespaceIds namespaceIds. * @return {@linkplain List} */ - List<NamespacePluginVO> selectByNamespaceId(String namespaceId); + List<NamespacePluginVO> selectAllByNamespaceIds(List<String> namespaceIds); + + List<NamespacePluginVO> selectAll(); /** * enable data by a list of ids. diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/RuleMapper.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/RuleMapper.java index bce950e7a2..39384cf494 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/RuleMapper.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/RuleMapper.java @@ -163,6 +163,14 @@ public interface RuleMapper extends ExistProvider { */ List<RuleDO> selectAllByNamespaceId(String namespaceId); + /** + * list all. + * + * @param namespaceIds the namespaceIds + * @return {@linkplain List} + */ + List<RuleDO> selectAllByNamespaceIds(List<String> namespaceIds); + /** * search by condition. * diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/SelectorMapper.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/SelectorMapper.java index fb29e66724..f1072eab1c 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/SelectorMapper.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/SelectorMapper.java @@ -194,6 +194,14 @@ public interface SelectorMapper extends ExistProvider { */ List<SelectorDO> selectAllByNamespaceId(String namespaceId); + /** + * list all by namespaceId list. + * + * @param namespaceIds the namespaceIds + * @return {@linkplain List} + */ + List<SelectorDO> selectAllByNamespaceIds(List<String> namespaceIds); + /** * select by condition. * 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 77bff91335..474f52cedc 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 @@ -130,12 +130,12 @@ public class NamespacePluginServiceImpl implements NamespacePluginService { @Override public List<PluginData> listAll() { - return ListUtil.map(namespacePluginRelMapper.selectAllByNamespaceId(), PluginTransfer.INSTANCE::mapToData); + return ListUtil.map(namespacePluginRelMapper.selectAll(), PluginTransfer.INSTANCE::mapToData); } @Override public List<NamespacePluginVO> listByNamespaceId(final String namespaceId) { - return namespacePluginRelMapper.selectByNamespaceId(namespaceId); + return namespacePluginRelMapper.selectAllByNamespaceId(namespaceId); } @Override diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/NamespaceServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/NamespaceServiceImpl.java index e0176198b1..d10a27cff4 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/NamespaceServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/NamespaceServiceImpl.java @@ -21,13 +21,25 @@ import com.google.common.collect.Lists; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.shenyu.admin.exception.ShenyuAdminException; +import org.apache.shenyu.admin.mapper.AuthPathMapper; +import org.apache.shenyu.admin.mapper.DiscoveryMapper; +import org.apache.shenyu.admin.mapper.MetaDataMapper; import org.apache.shenyu.admin.mapper.NamespaceMapper; +import org.apache.shenyu.admin.mapper.NamespacePluginRelMapper; +import org.apache.shenyu.admin.mapper.RuleMapper; +import org.apache.shenyu.admin.mapper.SelectorMapper; import org.apache.shenyu.admin.model.dto.NamespaceDTO; +import org.apache.shenyu.admin.model.entity.AuthPathDO; +import org.apache.shenyu.admin.model.entity.DiscoveryDO; +import org.apache.shenyu.admin.model.entity.MetaDataDO; import org.apache.shenyu.admin.model.entity.NamespaceDO; +import org.apache.shenyu.admin.model.entity.RuleDO; +import org.apache.shenyu.admin.model.entity.SelectorDO; import org.apache.shenyu.admin.model.event.namespace.NamespaceCreatedEvent; import org.apache.shenyu.admin.model.page.CommonPager; import org.apache.shenyu.admin.model.page.PageResultUtils; import org.apache.shenyu.admin.model.query.NamespaceQuery; +import org.apache.shenyu.admin.model.vo.NamespacePluginVO; import org.apache.shenyu.admin.model.vo.NamespaceVO; import org.apache.shenyu.admin.service.NamespaceService; import org.apache.shenyu.admin.service.NamespaceUserService; @@ -51,17 +63,42 @@ import java.util.stream.Collectors; public class NamespaceServiceImpl implements NamespaceService { private final NamespaceMapper namespaceMapper; - + private final NamespaceUserService namespaceUserService; - + private final NamespaceEventPublisher namespaceEventPublisher; + private final SelectorMapper selectorMapper; + + private final RuleMapper ruleMapper; + + private final AuthPathMapper authPathMapper; + + private final MetaDataMapper metaDataMapper; + + private final DiscoveryMapper discoveryMapper; + + private final NamespacePluginRelMapper namespacePluginRelMapper; + + public NamespaceServiceImpl(final NamespaceMapper namespaceMapper, final NamespaceUserService namespaceUserService, - final NamespaceEventPublisher namespaceEventPublisher) { + final NamespaceEventPublisher namespaceEventPublisher, + final NamespacePluginRelMapper namespacePluginRelMapper, + final SelectorMapper selectorMapper, + final RuleMapper ruleMapper, + final AuthPathMapper authPathMapper, + final MetaDataMapper metaDataMapper, + final DiscoveryMapper discoveryMapper) { this.namespaceMapper = namespaceMapper; this.namespaceUserService = namespaceUserService; this.namespaceEventPublisher = namespaceEventPublisher; + this.namespacePluginRelMapper = namespacePluginRelMapper; + this.selectorMapper = selectorMapper; + this.ruleMapper = ruleMapper; + this.authPathMapper = authPathMapper; + this.metaDataMapper = metaDataMapper; + this.discoveryMapper = discoveryMapper; } @Override @@ -87,11 +124,35 @@ public class NamespaceServiceImpl implements NamespaceService { @Override public String delete(final List<String> ids) { if (ids.contains(Constants.DEFAULT_NAMESPACE_PRIMARY_KEY)) { - return AdminConstants.SYS_DEFAULT_NAMESPACE_ID_DELETE; + throw new ShenyuAdminException(AdminConstants.SYS_DEFAULT_NAMESPACE_ID_DELETE); } - List<NamespaceDO> namespaceDOS = namespaceMapper.selectByIds(ids); - if (CollectionUtils.isEmpty(namespaceDOS)) { - return AdminConstants.SYS_NAMESPACE_ID_NOT_EXIST; + List<String> namespaceIdList = namespaceMapper.selectByIds(ids).stream().map(NamespaceDO::getNamespaceId).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(namespaceIdList)) { + throw new ShenyuAdminException(AdminConstants.SYS_NAMESPACE_ID_NOT_EXIST); + } + List<NamespacePluginVO> namespacePluginVOS = namespacePluginRelMapper.selectAllByNamespaceIds(namespaceIdList); + if (CollectionUtils.isNotEmpty(namespacePluginVOS)) { + throw new ShenyuAdminException("Plugins exist under those namespace!"); + } + List<SelectorDO> selectorDOS = selectorMapper.selectAllByNamespaceIds(namespaceIdList); + if (CollectionUtils.isNotEmpty(selectorDOS)) { + throw new ShenyuAdminException("selector exist under those namespace!"); + } + List<RuleDO> ruleDOList = ruleMapper.selectAllByNamespaceIds(namespaceIdList); + if (CollectionUtils.isNotEmpty(ruleDOList)) { + throw new ShenyuAdminException("rule exist under those namespace!"); + } + List<MetaDataDO> metaDataDOList = metaDataMapper.findAllByNamespaceIds(namespaceIdList); + if (CollectionUtils.isNotEmpty(metaDataDOList)) { + throw new ShenyuAdminException("metaData exist under those namespace!"); + } + List<AuthPathDO> authPathDOList = authPathMapper.findByNamespaceIds(namespaceIdList); + if (CollectionUtils.isNotEmpty(authPathDOList)) { + throw new ShenyuAdminException("authPath exist under those namespace!"); + } + List<DiscoveryDO> discoveryDOList = discoveryMapper.selectAllByNamespaceIds(namespaceIdList); + if (CollectionUtils.isNotEmpty(discoveryDOList)) { + throw new ShenyuAdminException("discovery exist under those namespace!"); } namespaceMapper.deleteByIds(ids); return ShenyuResultMessage.DELETE_SUCCESS; @@ -110,11 +171,11 @@ public class NamespaceServiceImpl implements NamespaceService { @Override public List<NamespaceVO> list(final String name) { List<String> namespaceIds = namespaceUserService.listNamespaceIdByUserId(SessionUtil.visitorId()); - + if (CollectionUtils.isEmpty(namespaceIds)) { return Lists.newArrayList(); } - + List<NamespaceDO> namespaceDOS = namespaceMapper.selectByNamespaceIdsAndName(namespaceIds, name); if (CollectionUtils.isEmpty(namespaceDOS)) { return Lists.newArrayList(); @@ -142,9 +203,9 @@ public class NamespaceServiceImpl implements NamespaceService { .dateUpdated(currentTime) .build(); namespaceMapper.insert(namespaceDO); - + namespaceEventPublisher.publish(new NamespaceCreatedEvent(namespaceDO, SessionUtil.visitorId())); - + return NamespaceTransfer.INSTANCE.mapToVo(namespaceDO); } diff --git a/shenyu-admin/src/main/resources/mappers/auth-path-sqlmap.xml b/shenyu-admin/src/main/resources/mappers/auth-path-sqlmap.xml index ce7619e27b..d33c02543b 100644 --- a/shenyu-admin/src/main/resources/mappers/auth-path-sqlmap.xml +++ b/shenyu-admin/src/main/resources/mappers/auth-path-sqlmap.xml @@ -45,6 +45,23 @@ WHERE auth_id = #{authId, jdbcType=VARCHAR} </select> + <select id="findByNamespaceId" parameterType="java.lang.String" resultMap="BaseResultMap"> + SELECT + <include refid="Base_Column_List"/> + FROM auth_path + WHERE namespace_id = #{namespaceId, jdbcType=VARCHAR} + </select> + + <select id="findByNamespaceIds" parameterType="java.lang.String" resultMap="BaseResultMap"> + SELECT + <include refid="Base_Column_List"/> + FROM auth_path + WHERE namespace_id IN + <foreach item="namespaceId" collection="namespaceIds" open="(" separator="," close=")"> + #{namespaceId, jdbcType=VARCHAR} + </foreach> + </select> + <select id="findByAuthIdList" parameterType="java.lang.String" resultMap="BaseResultMap"> SELECT <include refid="Base_Column_List"/> diff --git a/shenyu-admin/src/main/resources/mappers/discovery-sqlmap.xml b/shenyu-admin/src/main/resources/mappers/discovery-sqlmap.xml index e48107fa17..3e0148aaac 100644 --- a/shenyu-admin/src/main/resources/mappers/discovery-sqlmap.xml +++ b/shenyu-admin/src/main/resources/mappers/discovery-sqlmap.xml @@ -77,6 +77,16 @@ WHERE namespace_id = #{namespaceId, jdbcType=VARCHAR} </select> + <select id="selectAllByNamespaceIds" resultType="org.apache.shenyu.admin.model.entity.DiscoveryDO"> + SELECT + <include refid="Base_Column_List"/> + FROM discovery + WHERE namespace_id IN + <foreach item="namespaceId" collection="namespaceIds" open="(" separator="," close=")"> + #{namespaceId, jdbcType=VARCHAR} + </foreach> + </select> + <select id="selectBySelectorNameAndPluginName" resultType="org.apache.shenyu.admin.model.entity.DiscoveryDO"> SELECT d.id, diff --git a/shenyu-admin/src/main/resources/mappers/meta-data-sqlmap.xml b/shenyu-admin/src/main/resources/mappers/meta-data-sqlmap.xml index 9ee291b3bf..91a2fb6edb 100644 --- a/shenyu-admin/src/main/resources/mappers/meta-data-sqlmap.xml +++ b/shenyu-admin/src/main/resources/mappers/meta-data-sqlmap.xml @@ -102,6 +102,16 @@ WHERE namespace_id = #{namespaceId, jdbcType=VARCHAR} </select> + <select id="findAllByNamespaceIds" resultMap="BaseResultMap"> + SElECT + <include refid="Base_Column_List"/> + FROM meta_data + WHERE namespace_id IN + <foreach item="namespaceId" collection="namespaceIds" open="(" separator="," close=")"> + #{namespaceId, jdbcType=VARCHAR} + </foreach> + </select> + <select id="selectByQuery" parameterType="org.apache.shenyu.admin.model.query.MetaDataQuery" resultMap="BaseResultMap"> diff --git a/shenyu-admin/src/main/resources/mappers/namespace-plugin-rel-sqlmap.xml b/shenyu-admin/src/main/resources/mappers/namespace-plugin-rel-sqlmap.xml index 14421f49a4..c566e5cd0e 100644 --- a/shenyu-admin/src/main/resources/mappers/namespace-plugin-rel-sqlmap.xml +++ b/shenyu-admin/src/main/resources/mappers/namespace-plugin-rel-sqlmap.xml @@ -251,6 +251,51 @@ </delete> <select id="selectAllByNamespaceId" resultType="org.apache.shenyu.admin.model.vo.NamespacePluginVO"> + SELECT + npr.id as id, + npr.namespace_id AS namespaceId, + npr.plugin_id AS pluginId, + npr.config AS config, + npr.sort AS sort, + npr.enabled AS enabled, + npr.date_created AS dateCreated, + npr.date_updated AS dateUpdated, + p.role AS role, + p.name AS name, + p.plugin_jar AS pluginJar + FROM namespace_plugin_rel npr + LEFT JOIN plugin p ON p.id = npr.plugin_id + AND npr.namespace_id=#{namespaceId} + ORDER BY + sort, + npr.id ASC + </select> + + <select id="selectAllByNamespaceIds" resultType="org.apache.shenyu.admin.model.vo.NamespacePluginVO"> + SELECT + npr.id as id, + npr.namespace_id AS namespaceId, + npr.plugin_id AS pluginId, + npr.config AS config, + npr.sort AS sort, + npr.enabled AS enabled, + npr.date_created AS dateCreated, + npr.date_updated AS dateUpdated, + p.role AS role, + p.name AS name, + p.plugin_jar AS pluginJar + FROM namespace_plugin_rel npr + LEFT JOIN plugin p ON p.id = npr.plugin_id + AND npr.namespace_id IN + <foreach item="namespaceId" collection="namespaceIds" open="(" separator="," close=")"> + #{namespaceId, jdbcType=VARCHAR} + </foreach> + ORDER BY + sort, + npr.id ASC + </select> + + <select id="selectAll" resultType="org.apache.shenyu.admin.model.vo.NamespacePluginVO"> SELECT npr.id as id, npr.namespace_id AS namespaceId, diff --git a/shenyu-admin/src/main/resources/mappers/rule-sqlmap.xml b/shenyu-admin/src/main/resources/mappers/rule-sqlmap.xml index 1e26930352..79a48d91a9 100644 --- a/shenyu-admin/src/main/resources/mappers/rule-sqlmap.xml +++ b/shenyu-admin/src/main/resources/mappers/rule-sqlmap.xml @@ -143,6 +143,16 @@ WHERE namespace_id = #{namespaceId, jdbcType=VARCHAR} </select> + <select id="selectAllByNamespaceIds" resultType="org.apache.shenyu.admin.model.entity.RuleDO" resultMap="BaseResultMap"> + SELECT + <include refid="Base_Column_List"/> + FROM rule + WHERE namespace_id IN + <foreach item="namespaceId" collection="namespaceIds" open="(" separator="," close=")"> + #{namespaceId, jdbcType=VARCHAR} + </foreach> + </select> + <select id="existed" resultType="java.lang.Boolean"> SELECT TRUE FROM rule diff --git a/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml b/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml index 3edff2685f..96cee1fe85 100644 --- a/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml +++ b/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml @@ -196,6 +196,16 @@ WHERE namespace_id = #{namespaceId, jdbcType=VARCHAR} </select> + <select id="selectAllByNamespaceIds" resultType="org.apache.shenyu.admin.model.entity.SelectorDO" resultMap="BaseResultMap"> + SELECT + <include refid="Base_Column_List"/> + FROM selector + WHERE namespace_id IN + <foreach item="namespaceId" collection="namespaceIds" open="(" separator="," close=")"> + #{namespaceId, jdbcType=VARCHAR} + </foreach> + </select> + <select id="existed" resultType="java.lang.Boolean"> SELECT true FROM selector