Skip to content

Commit

Permalink
[type:feat]Selector module adapts to namespace transformation (apache…
Browse files Browse the repository at this point in the history
…#5604)

* commit

* commit

* first draft,not verified

* simplify verified

* simplify verified

* commit

* commit

* fix

* fix e2e checkstyle

* fix e2e

* fix test

* fix

* fix

* fix test

* fix

* fix

* trigger ci

* trigger ci

* fix sql

* fix sql

* fix sql

* fix

* trigger ci

* trigger ci

* fix

* trigger ci

* fix

* fix

* fix

* fix

* trigger ci

* trigger ci

* fix

* trigger ci

* trigger ci

* trigger ci

* fix cr

* fix cr

* fix comment

* fix comment

* fix

* fix

* trigger ci

* trigger ci

* fix cr

---------

Co-authored-by: ‘xcsnx’ <‘[email protected]’>
  • Loading branch information
xcsnx and ‘xcsnx’ authored Aug 17, 2024
1 parent 94553e4 commit ce123f1
Show file tree
Hide file tree
Showing 62 changed files with 1,040 additions and 327 deletions.
2 changes: 2 additions & 0 deletions db/init/mysql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2370,3 +2370,5 @@ INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_creat
INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1792779493541343265', '1346358560427216896', '1792749362445840484', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000');
INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1792779493541343266', '1346358560427216896', '1792749362445840485', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000');
INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1792779493541343267', '1346358560427216896', '1792749362445840486', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000');

ALTER TABLE `shenyu`.`selector` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`;
4 changes: 4 additions & 0 deletions db/init/og/create-table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2673,3 +2673,7 @@ INSERT INTO "public"."permission" VALUES ('1792779493541343265', '13463585604272
INSERT INTO "public"."permission" VALUES ('1792779493541343266', '1346358560427216896', '1792749362445840485', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000');
INSERT INTO "public"."permission" VALUES ('1792779493541343267', '1346358560427216896', '1792749362445840486', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000');


ALTER TABLE "public"."selector" ADD COLUMN namespace_id VARCHAR(50) NULL;
COMMENT ON COLUMN "public"."selector"."namespace_id" IS 'namespaceId';

4 changes: 4 additions & 0 deletions db/init/oracle/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2857,3 +2857,7 @@ INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (permission(id)) */ INTO permission (id, o
INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (permission(id)) */ INTO permission (id, object_id, resource_id) VALUES ('1792779493541343265', '1346358560427216896', '1792749362445840484');
INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (permission(id)) */ INTO permission (id, object_id, resource_id) VALUES ('1792779493541343266', '1346358560427216896', '1792749362445840485');
INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (permission(id)) */ INTO permission (id, object_id, resource_id) VALUES ('1792779493541343267', '1346358560427216896', '1792749362445840486');


ALTER TABLE selector ADD namespace_id VARCHAR2(50) NULL;
COMMENT ON COLUMN selector.namespace_id IS 'namespaceId';
2 changes: 2 additions & 0 deletions db/init/pg/create-table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2791,3 +2791,5 @@ INSERT INTO "public"."permission" VALUES ('1792779493541343265', '13463585604272
INSERT INTO "public"."permission" VALUES ('1792779493541343266', '1346358560427216896', '1792749362445840485', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000');
INSERT INTO "public"."permission" VALUES ('1792779493541343267', '1346358560427216896', '1792749362445840486', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000');

ALTER TABLE "public"."selector" ADD COLUMN namespace_id VARCHAR(50) NULL;
COMMENT ON COLUMN "public"."selector"."namespace_id" IS 'namespaceId';
7 changes: 7 additions & 0 deletions db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,10 @@ INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_creat

/* add column into dashboard_user table */
ALTER TABLE `shenyu`.`dashboard_user` ADD COLUMN `client_id` varchar(32) NULL DEFAULT NULL COMMENT 'client id';


ALTER TABLE `shenyu`.`selector` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`;

UPDATE selector
SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385'
WHERE namespaceId IS NULL;
5 changes: 5 additions & 0 deletions db/upgrade/2.6.1-upgrade-2.7.0-og.sql
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,8 @@ INSERT INTO "public"."permission" VALUES ('1792779493541343267', '13463585604272
/* add column into dashboard_user table */
ALTER TABLE "public"."dashboard_user" ADD COLUMN client_id VARCHAR(32) NULL;
COMMENT ON COLUMN "public"."dashboard_user".client_id IS 'client id';

ALTER TABLE "public"."selector" ADD COLUMN namespace_id VARCHAR(50) NULL;
COMMENT ON COLUMN "public"."selector"."namespace_id" IS 'namespaceId';

UPDATE "public"."selector" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;
5 changes: 5 additions & 0 deletions db/upgrade/2.6.1-upgrade-2.7.0-oracle.sql
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,8 @@ INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (permission(id)) */ INTO permission (id, o
/* add column into dashboard_user table */
ALTER TABLE dashboard_user ADD client_id VARCHAR(32) NULL;
COMMENT ON COLUMN dashboard_user.client_id IS 'client id';

ALTER TABLE selector ADD namespace_id VARCHAR2(50) NULL;
COMMENT ON COLUMN selector.namespace_id IS 'namespaceId';

UPDATE selector SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;
5 changes: 5 additions & 0 deletions db/upgrade/2.6.1-upgrade-2.7.0-pg.sql
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,8 @@ INSERT INTO "public"."permission" VALUES ('1792779493541343267', '13463585604272
/* add column into dashboard_user table */
ALTER TABLE "public"."dashboard_user" ADD COLUMN client_id VARCHAR(32) NULL;
COMMENT ON COLUMN "public"."dashboard_user".client_id IS 'client id';

ALTER TABLE "public"."selector" ADD COLUMN namespace_id VARCHAR(50) NULL;
COMMENT ON COLUMN "public"."selector"."namespace_id" IS 'namespaceId';

UPDATE "public"."selector" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@

package org.apache.shenyu.admin.controller;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.apache.shenyu.admin.aspect.annotation.RestApi;
import org.apache.shenyu.admin.mapper.NamespaceMapper;
import org.apache.shenyu.admin.mapper.SelectorMapper;
import org.apache.shenyu.admin.model.dto.BatchCommonDTO;
import org.apache.shenyu.admin.model.dto.BatchNamespaceCommonDTO;
import org.apache.shenyu.admin.model.dto.SelectorDTO;
import org.apache.shenyu.admin.model.page.CommonPager;
import org.apache.shenyu.admin.model.page.PageCondition;
Expand All @@ -41,12 +45,6 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import java.util.List;

/**
* this is selector controller.
*/
Expand All @@ -66,29 +64,37 @@ public SelectorController(final SelectorService selectorService) {
* @param name selector name.
* @param currentPage current page.
* @param pageSize page size.
* @param namespaceId namespaceId.
* @return {@linkplain ShenyuAdminResult}
*/
@GetMapping("")
public AdminResult<CommonPager<SelectorVO>> querySelectors(final String pluginId, final String name,
@RequestParam @NotNull final Integer currentPage,
@RequestParam @NotNull final Integer pageSize) {
@RequestParam @NotNull final Integer currentPage,
@RequestParam @NotNull final Integer pageSize,
@Valid @Existed(message = "namespaceId is not existed",
provider = NamespaceMapper.class) final String namespaceId
) {
final SelectorQueryCondition condition = new SelectorQueryCondition();
condition.setUserId(SessionUtil.visitor().getUserId());
condition.setPlugin(ListUtil.of(pluginId));
condition.setKeyword(name);
condition.setNamespaceId(namespaceId);
return searchAdaptor(new PageCondition<>(currentPage, pageSize, condition));
}

/**
* detail selector.
*
* @param id selector id.
* @param namespaceId namespaceId.
* @return {@linkplain ShenyuAdminResult}
*/
@GetMapping("/{id}")
@GetMapping("/{id}/{namespaceId}")
public ShenyuAdminResult detailSelector(@PathVariable("id") @Valid
@Existed(provider = SelectorMapper.class, message = "selector is not existed") final String id) {
SelectorVO selectorVO = selectorService.findById(id);
@Existed(provider = SelectorMapper.class, message = "selector is not existed") final String id,
@PathVariable("namespaceId") @Valid
@Existed(provider = NamespaceMapper.class, message = "namespaceId is not existed") final String namespaceId) {
SelectorVO selectorVO = selectorService.findByIdAndNamespaceId(id, namespaceId);
return ShenyuAdminResult.success(ShenyuResultMessage.DETAIL_SUCCESS, selectorVO);
}

Expand All @@ -113,8 +119,7 @@ public ShenyuAdminResult createSelector(@Valid @RequestBody final SelectorDTO se
*/
@PutMapping("/{id}")
public ShenyuAdminResult updateSelector(@PathVariable("id") @Valid
@Existed(provider = SelectorMapper.class,
message = "selector is not existed") final String id,
@Existed(provider = SelectorMapper.class, message = "selector is not existed") final String id,
@Valid @RequestBody final SelectorDTO selectorDTO) {
selectorDTO.setId(id);
Integer updateCount = selectorService.createOrUpdate(selectorDTO);
Expand All @@ -129,7 +134,7 @@ public ShenyuAdminResult updateSelector(@PathVariable("id") @Valid
*/
@PostMapping("/batchEnabled")
public ShenyuAdminResult batchEnabled(@Valid @RequestBody final BatchCommonDTO batchCommonDTO) {
if (!selectorService.enabled(batchCommonDTO.getIds(), batchCommonDTO.getEnabled())) {
if (!selectorService.enabledByIdsAndNamespaceId(batchCommonDTO.getIds(), batchCommonDTO.getEnabled(), batchCommonDTO.getNamespaceId())) {
return ShenyuAdminResult.error(ShenyuResultMessage.NOT_FOUND_EXCEPTION);
}
return ShenyuAdminResult.success(ShenyuResultMessage.ENABLE_SUCCESS);
Expand All @@ -138,12 +143,12 @@ public ShenyuAdminResult batchEnabled(@Valid @RequestBody final BatchCommonDTO b
/**
* delete Selectors.
*
* @param ids primary key.
* @param batchNamespaceCommonDTO batchNamespaceCommonDTO.
* @return {@linkplain ShenyuAdminResult}
*/
@DeleteMapping("/batch")
public ShenyuAdminResult deleteSelector(@RequestBody @NotEmpty final List<@NotBlank String> ids) {
Integer deleteCount = selectorService.delete(ids);
public ShenyuAdminResult deleteSelector(@Valid @RequestBody final BatchNamespaceCommonDTO batchNamespaceCommonDTO) {
Integer deleteCount = selectorService.deleteByNamespaceId(batchNamespaceCommonDTO.getIds(), batchNamespaceCommonDTO.getNamespaceId());
return ShenyuAdminResult.success(ShenyuResultMessage.DELETE_SUCCESS, deleteCount);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,21 @@ public interface NamespacePluginRelMapper extends ExistProvider {
List<NamespacePluginVO> selectByQuery(NamespacePluginQuery namespacePluginQuery);

/**
* select plugin by namespacePluginId.
* select plugin by PluginId and namespaceId.
*
* @param id primary key.
* @param namespaceId namespace id.
* @param pluginId primary key.
* @param namespaceId namespaceId.
* @return {@linkplain PluginVO}
*/
NamespacePluginVO selectById(String id, String namespaceId);
NamespacePluginVO selectByPluginIdAndNamespaceId(String pluginId, String namespaceId);

/**
* select plugin by pluginId.
*
* @param pluginId primary key.
* @param namespaceId namespace id.
* @return {@linkplain PluginVO}
*/
NamespacePluginVO selectByPluginId(String pluginId, String namespaceId);
NamespacePluginVO selectByPluginId(String pluginId);

/**
* search by condition.
Expand All @@ -93,7 +92,7 @@ public interface NamespacePluginRelMapper extends ExistProvider {
*
* @param name name
* @param exclude exclude
* @param namespaceId namespace id.
* @param namespaceId namespaceId.
* @return existed
*/
Boolean nameExistedExclude(@Param("name") Serializable name, @Param("exclude") List<String> exclude, @Param("namespaceId") String namespaceId);
Expand All @@ -108,38 +107,38 @@ public interface NamespacePluginRelMapper extends ExistProvider {
int updateSelective(NamespacePluginRelDO namespacePluginRelDO);

/**
* select plugin by id.
* select plugin by ids and namespaceId.
*
* @param ids primary keys.
* @param namespaceId namespace id.
* @param namespaceId namespaceId.
* @return {@linkplain NamespacePluginRelDO}
*/
List<NamespacePluginVO> selectByIds(List<String> ids, String namespaceId);
List<NamespacePluginVO> selectByIdsAndNamespaceId(List<String> ids, String namespaceId);


/**
* delete plugin.
* delete plugin by ids and namespaceId.
*
* @param ids primary keys.
* @param namespaceId namespace id.
* @param namespaceId namespaceId.
* @return rows int
*/
int deleteByIds(List<String> ids, String namespaceId);
int deleteByIdsAndNamespaceId(List<String> ids, String namespaceId);

/**
* select all.
* select all by namespaceId.
*
* @param namespaceId namespace id.
* @param namespaceId namespaceId.
* @return {@linkplain List}
*/
List<NamespacePluginVO> selectAll(String namespaceId);
List<NamespacePluginVO> selectAllByNamespaceId(String namespaceId);

/**
* select all.
*
* @return {@linkplain List}
*/
List<NamespacePluginVO> selectAll();
List<NamespacePluginVO> selectAllByNamespaceId();

/**
* enable data by a list of ids.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ public interface SelectorMapper extends ExistProvider {
@Override
Boolean existed(@Param("id") Serializable id);

/**
* select selector by id and namespaceId.
*
* @param id primary key.
* @param namespaceId namespaceId.
* @return {@linkplain SelectorDO}
*/
SelectorDO selectByIdAndNamespaceId(String id, String namespaceId);

/**
* select selector by id.
*
Expand All @@ -69,37 +78,43 @@ public interface SelectorMapper extends ExistProvider {
List<SelectorDO> selectByQuery(SelectorQuery selectorQuery);

/**
* Find by plugin id list.
* Find list by plugin id and namespaceId.
*
* @param pluginId the plugin id
* @param pluginId the plugin id
* @param namespaceId namespaceId.
* @return the list
*/
List<SelectorDO> findByPluginId(String pluginId);
List<SelectorDO> findByPluginIdAndNamespaceId(String pluginId, String namespaceId);

/**
* Find by plugin id list.
* Find list by plugin id and namespaceId.
*
* @param pluginIds the plugin ids
* @param pluginIds the plugin ids
* @param namespaceId namespaceId.
* @return the list
*/
List<SelectorDO> findByPluginIds(List<String> pluginIds);
List<SelectorDO> findByPluginIdsAndNamespaceId(@Param("list") List<String> pluginIds, String namespaceId);

/**
* select select by name.
* select list by name and namespaceId.
*
* @param name the name
* @param name the name
* @param namespaceId namespaceId.
* @return selector do list
*/
List<SelectorDO> selectByName(String name);
List<SelectorDO> selectByNameAndNamespaceId(String name, String namespaceId);

/**
* Find by name and plugin id selector do.
* Find selector entity by name and plugin id and namespaceId.
*
* @param name the name
* @param pluginId the plugin id
* @param name the name
* @param pluginId the plugin id
* @param namespaceId namespaceId.
* @return the selector do
*/
SelectorDO findByNameAndPluginId(@Param("name") String name, @Param("pluginId") String pluginId);
SelectorDO findByNameAndPluginIdAndNamespaceId(@Param("name") String name,
@Param("pluginId") String pluginId,
@Param("namespaceId") String namespaceId);

/**
* count selector by query.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import org.apache.shenyu.admin.mapper.NamespaceMapper;
import org.apache.shenyu.admin.validation.annotation.Existed;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;
Expand All @@ -37,6 +40,7 @@ public class BatchNamespaceCommonDTO implements Serializable {
private Boolean enabled;

@NotEmpty
@Existed(message = "namespaceId is not existed", provider = NamespaceMapper.class)
private String namespaceId;

/**
Expand Down
Loading

0 comments on commit ce123f1

Please sign in to comment.