This is an automated email from the ASF dual-hosted git repository.
xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 27fce4723 [ISSUE #3258]add plugin page list api (#3259)
27fce4723 is described below
commit 27fce47237d85b3feb58d15b07350cbf168b8b6b
Author: likeguo <[email protected]>
AuthorDate: Mon Apr 18 13:54:45 2022 +0800
[ISSUE #3258]add plugin page list api (#3259)
* add plugin page list api
* add plugin page list api
* add plugin page list api
---
.../src/http/http-debug-plugin-controller-api.http | 30 +++++++++
.../shenyu/admin/controller/PluginController.java | 9 ++-
.../apache/shenyu/admin/mapper/PluginMapper.java | 12 +++-
.../condition/BaseExcludedSearchCondition.java | 72 ++++++++++++++++++++
.../model/page/condition/SearchCondition.java | 32 +++++++++
.../model/page/condition/SwitchCondition.java | 33 +++++++++
.../admin/model/query/PluginQueryCondition.java | 78 ++++++++++++++++++++++
.../apache/shenyu/admin/service/PluginService.java | 3 +-
.../admin/service/impl/PluginServiceImpl.java | 7 ++
.../src/main/resources/mappers/plugin-sqlmap.xml | 27 ++++++++
10 files changed, 300 insertions(+), 3 deletions(-)
diff --git a/shenyu-admin/src/http/http-debug-plugin-controller-api.http
b/shenyu-admin/src/http/http-debug-plugin-controller-api.http
index a568d8d45..27b9e6d1c 100644
--- a/shenyu-admin/src/http/http-debug-plugin-controller-api.http
+++ b/shenyu-admin/src/http/http-debug-plugin-controller-api.http
@@ -17,6 +17,36 @@
# if you debug api, replace your own token
+### plugin list search
+POST http://localhost:9095/plugin/list/search
+Accept: application/json
+Content-Type: application/json
+X-Access-Token:
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZSI6ImFkbWluIiwiZXhwIjoxNjUwMjc3MTA4fQ.CbE5VuGp7cTQWt0tL87RcsLAJs5swk8YId35b8gYtHQ
+
+{
+ "pageNum": 1,
+ "pageSize": 12,
+ "condition": {
+ "keyword": "a",
+ "switchStatus": false
+ }
+}
+
+### plugin list search adaptor
+POST http://localhost:9095/plugin/list/search/adaptor
+Accept: application/json
+Content-Type: application/json
+X-Access-Token:
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZSI6ImFkbWluIiwiZXhwIjoxNjUwMjc3MTA4fQ.CbE5VuGp7cTQWt0tL87RcsLAJs5swk8YId35b8gYtHQ
+
+{
+ "pageNum": 1,
+ "pageSize": 12,
+ "condition": {
+ "keyword": "a!b",
+ "switchStatus": true
+ }
+}
+
### plugin list by page
GET http://localhost:9095/plugin?currentPage=1&pageSize=10
Accept: application/json
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/PluginController.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/PluginController.java
index a1d01c71f..15a0eaca9 100644
---
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/PluginController.java
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/PluginController.java
@@ -24,8 +24,10 @@ import org.apache.shenyu.admin.model.dto.PluginDTO;
import org.apache.shenyu.admin.model.page.CommonPager;
import org.apache.shenyu.admin.model.page.PageParameter;
import org.apache.shenyu.admin.model.query.PluginQuery;
+import org.apache.shenyu.admin.model.query.PluginQueryCondition;
import org.apache.shenyu.admin.model.result.ShenyuAdminResult;
import org.apache.shenyu.admin.model.vo.PluginVO;
+import org.apache.shenyu.admin.service.PageService;
import org.apache.shenyu.admin.service.PluginService;
import org.apache.shenyu.admin.service.SyncDataService;
import org.apache.shenyu.admin.utils.ShenyuResultMessage;
@@ -55,7 +57,7 @@ import java.util.List;
@Validated
@RestController
@RequestMapping("/plugin")
-public class PluginController {
+public class PluginController implements PagedController<PluginQueryCondition,
PluginVO> {
private final PluginService pluginService;
@@ -208,4 +210,9 @@ public class PluginController {
public ShenyuAdminResult activePluginSnapshot() {
return ShenyuAdminResult.success(pluginService.activePluginSnapshot());
}
+
+ @Override
+ public PageService<PluginQueryCondition, PluginVO> pageService() {
+ return pluginService;
+ }
}
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/PluginMapper.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/PluginMapper.java
index bcfaa1f8e..a976e657c 100644
---
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/PluginMapper.java
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/PluginMapper.java
@@ -21,7 +21,9 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.shenyu.admin.model.entity.PluginDO;
import org.apache.shenyu.admin.model.query.PluginQuery;
+import org.apache.shenyu.admin.model.query.PluginQueryCondition;
import org.apache.shenyu.admin.model.vo.PluginSnapshotVO;
+import org.apache.shenyu.admin.model.vo.PluginVO;
import org.apache.shenyu.admin.validation.ExistProvider;
import java.io.Serializable;
@@ -182,7 +184,7 @@ public interface PluginMapper extends ExistProvider {
/**
* plugin existed.
*
- * @param name name
+ * @param name name
* @param exclude exclude
* @return existed
*/
@@ -194,4 +196,12 @@ public interface PluginMapper extends ExistProvider {
* @return plugin list
*/
List<PluginSnapshotVO> activePluginSnapshot();
+
+ /**
+ * search by condition.
+ *
+ * @param condition condition.
+ * @return list
+ */
+ List<PluginVO> searchByCondition(@Param("condition") PluginQueryCondition
condition);
}
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/page/condition/BaseExcludedSearchCondition.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/page/condition/BaseExcludedSearchCondition.java
new file mode 100644
index 000000000..897840542
--- /dev/null
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/page/condition/BaseExcludedSearchCondition.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.admin.model.page.condition;
+
+import org.apache.commons.lang3.StringUtils;
+
+/**
+ * ExcludedSearchCondition.
+ */
+public abstract class BaseExcludedSearchCondition implements SearchCondition {
+
+ /**
+ * excluded code.
+ */
+ public static final String EXCLUDED_CODE = "!";
+
+ /**
+ * excluded keyword.
+ */
+ private String excluded;
+
+ /**
+ * build keyword contains excluded.
+ */
+ public void init() {
+ if (StringUtils.isNotBlank(getKeyword())) {
+ setExcluded(StringUtils.substringAfter(getKeyword(),
EXCLUDED_CODE));
+ setKeyword(StringUtils.substringBefore(getKeyword(),
EXCLUDED_CODE));
+ }
+ }
+
+
+ /**
+ * set keyword.
+ *
+ * @param keyword keyword
+ */
+ public abstract void setKeyword(String keyword);
+
+ /**
+ * get excluded.
+ *
+ * @return excluded keyword
+ */
+ public String getExcluded() {
+ return excluded;
+ }
+
+ /**
+ * set excluded.
+ *
+ * @param excluded excluded keyword
+ */
+ public void setExcluded(final String excluded) {
+ this.excluded = excluded;
+ }
+}
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/page/condition/SearchCondition.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/page/condition/SearchCondition.java
new file mode 100644
index 000000000..22acac641
--- /dev/null
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/page/condition/SearchCondition.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.admin.model.page.condition;
+
+
+/**
+ * search condition.For general fuzzy search.
+ */
+public interface SearchCondition {
+
+ /**
+ * get search keyword.
+ *
+ * @return keyword
+ */
+ String getKeyword();
+}
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/page/condition/SwitchCondition.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/page/condition/SwitchCondition.java
new file mode 100644
index 000000000..649f5e6cf
--- /dev/null
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/page/condition/SwitchCondition.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.admin.model.page.condition;
+
+/**
+ * search condition. used boolean status condition.
+ */
+public interface SwitchCondition {
+
+ /**
+ * get switch status.<br>
+ * <p>the true is open,enable,yes... </p>
+ * <p>the false is close,unable,no... </p>
+ *
+ * @return status
+ */
+ Boolean getSwitchStatus();
+}
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/PluginQueryCondition.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/PluginQueryCondition.java
new file mode 100644
index 000000000..31bb2aa05
--- /dev/null
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/PluginQueryCondition.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.admin.model.query;
+
+import
org.apache.shenyu.admin.model.page.condition.BaseExcludedSearchCondition;
+import org.apache.shenyu.admin.model.page.condition.SearchCondition;
+import org.apache.shenyu.admin.model.page.condition.SwitchCondition;
+
+/**
+ * this is plugin query condition.
+ */
+public class PluginQueryCondition extends BaseExcludedSearchCondition
implements SearchCondition, SwitchCondition {
+
+ /**
+ * search keyword: plugin name or role name.
+ */
+ private String keyword;
+
+ /**
+ * switch status: plugin status[close or open].
+ */
+ private Boolean switchStatus;
+
+
+ /**
+ * get switchStatus.
+ *
+ * @return status
+ */
+ @Override
+ public Boolean getSwitchStatus() {
+ return switchStatus;
+ }
+
+ /**
+ * set switchStatus.
+ *
+ * @param switchStatus status
+ */
+ public void setSwitchStatus(final Boolean switchStatus) {
+ this.switchStatus = switchStatus;
+ }
+
+ /**
+ * get keyword.
+ *
+ * @return keyword
+ */
+ @Override
+ public String getKeyword() {
+ return keyword;
+ }
+
+ /**
+ * set keyword.
+ *
+ * @param keyword keyword
+ */
+ @Override
+ public void setKeyword(final String keyword) {
+ this.keyword = keyword;
+ }
+}
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/PluginService.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/PluginService.java
index 38f814c99..e732446ed 100644
---
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/PluginService.java
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/PluginService.java
@@ -22,6 +22,7 @@ import org.apache.shenyu.admin.model.dto.PluginDTO;
import org.apache.shenyu.admin.model.entity.PluginDO;
import org.apache.shenyu.admin.model.page.CommonPager;
import org.apache.shenyu.admin.model.query.PluginQuery;
+import org.apache.shenyu.admin.model.query.PluginQueryCondition;
import org.apache.shenyu.admin.model.vo.PluginSnapshotVO;
import org.apache.shenyu.admin.model.vo.PluginVO;
import org.apache.shenyu.common.dto.PluginData;
@@ -31,7 +32,7 @@ import java.util.List;
/**
* this is plugin service.
*/
-public interface PluginService {
+public interface PluginService extends PageService<PluginQueryCondition,
PluginVO> {
/**
* Create or update string.
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/PluginServiceImpl.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/PluginServiceImpl.java
index 285fe4327..e76d21392 100644
---
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/PluginServiceImpl.java
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/PluginServiceImpl.java
@@ -36,6 +36,7 @@ import org.apache.shenyu.admin.model.entity.SelectorDO;
import org.apache.shenyu.admin.model.page.CommonPager;
import org.apache.shenyu.admin.model.page.PageResultUtils;
import org.apache.shenyu.admin.model.query.PluginQuery;
+import org.apache.shenyu.admin.model.query.PluginQueryCondition;
import org.apache.shenyu.admin.model.vo.PluginSnapshotVO;
import org.apache.shenyu.admin.model.vo.PluginVO;
import org.apache.shenyu.admin.model.vo.ResourceVO;
@@ -103,6 +104,12 @@ public class PluginServiceImpl implements PluginService {
this.resourceService = resourceService;
}
+ @Override
+ public List<PluginVO> searchByCondition(final PluginQueryCondition
condition) {
+ condition.init();
+ return pluginMapper.searchByCondition(condition);
+ }
+
/**
* create or update plugin.
*
diff --git a/shenyu-admin/src/main/resources/mappers/plugin-sqlmap.xml
b/shenyu-admin/src/main/resources/mappers/plugin-sqlmap.xml
index d42fd2611..0b6249fd5 100644
--- a/shenyu-admin/src/main/resources/mappers/plugin-sqlmap.xml
+++ b/shenyu-admin/src/main/resources/mappers/plugin-sqlmap.xml
@@ -159,6 +159,33 @@
order by p.sort, p.id
</select>
+ <select id="searchByCondition"
resultType="org.apache.shenyu.admin.model.vo.PluginVO">
+
+ SELECT
+ <include refid="Base_Column_List"/>
+ FROM plugin
+ <where>
+ <if test="condition.keyword != null and condition.keyword != ''">
+ <bind name="keyword" value="('%' + condition.keyword + '%')"/>
+ AND (
+ name LIKE #{keyword, jdbcType=VARCHAR}
+ OR role LIKE #{keyword, jdbcType=VARCHAR}
+ )
+ </if>
+ <if test="condition.excluded != null and condition.excluded != ''">
+ <bind name="excluded" value="('%' + condition.excluded +
'%')"/>
+ AND (
+ name NOT LIKE #{excluded, jdbcType=VARCHAR}
+ OR role NOT LIKE #{excluded, jdbcType=VARCHAR}
+ )
+ </if>
+ <if test="condition.switchStatus != null">
+ AND enabled = #{condition.switchStatus, jdbcType=BOOLEAN}
+ </if>
+ </where>
+ ORDER BY sort, date_created
+ </select>
+
<insert id="insert"
parameterType="org.apache.shenyu.admin.model.entity.PluginDO">
INSERT INTO plugin
(id,