Skip to content

Commit

Permalink
[ISSUE #4853] Fixed could not update uri in PathPattern mode (#4854)
Browse files Browse the repository at this point in the history
Co-authored-by: tian-pengfei <[email protected]>
  • Loading branch information
tian-pengfei and tian-pengfei authored Jul 17, 2023
1 parent 701a11d commit 206c1b0
Showing 1 changed file with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.shenyu.admin.model.query.RuleQueryCondition;
import org.apache.shenyu.admin.model.vo.RuleVO;
import org.apache.shenyu.common.dto.RuleData;
import org.apache.shenyu.common.enums.OperatorEnum;
import org.apache.shenyu.common.enums.ParamTypeEnum;
import org.springframework.web.util.pattern.PathPatternParser;

Expand All @@ -36,98 +37,102 @@
* this is rule service.
*/
public interface RuleService extends PageService<RuleQueryCondition, RuleVO> {

/**
* Register string.
*
* @param ruleDTO the rule dto
* @return the string
*/
String registerDefault(RuleDTO ruleDTO);

/**
* create or update rule.
*
* @param ruleDTO {@linkplain RuleDTO}
* @return rows int
*/
default int createOrUpdate(final RuleDTO ruleDTO) {
// check rule uri condition

// now, only check rule uri condition in pathPattern mode
// todo check uri in other modes

try {
final List<RuleConditionDTO> ruleConditions = ruleDTO.getRuleConditions();
ruleConditions.stream()
.filter(conditionData -> ParamTypeEnum.URI.getName().equals(conditionData.getParamType()))
.filter(conditionData -> OperatorEnum.PATH_PATTERN.getAlias().equals(conditionData.getOperator()))
.map(RuleConditionDTO::getParamValue)
.forEach(PathPatternParser.defaultInstance::parse);
} catch (Exception e) {
throw new ShenyuAdminException("uri validation of Condition failed, please check.");
throw new ShenyuAdminException("uri validation of Condition failed, please check.", e);
}
return StringUtils.isBlank(ruleDTO.getId()) ? create(ruleDTO) : update(ruleDTO);
}

/**
* create rule.
*
* @param ruleDTO {@linkplain RuleDTO}
* @return rows int
*/
int create(RuleDTO ruleDTO);

/**
* update rule.
*
* @param ruleDTO {@linkplain RuleDTO}
* @return rows int
*/
int update(RuleDTO ruleDTO);

/**
* delete rules.
*
* @param ids primary key.
* @return rows int
*/
int delete(List<String> ids);

/**
* find rule by id.
*
* @param id primary key.
* @return {@linkplain RuleVO}
*/
RuleVO findById(String id);

/**
* find page of rule by query.
*
* @param ruleQuery {@linkplain RuleQuery}
* @return {@linkplain CommonPager}
*/
CommonPager<RuleVO> listByPage(RuleQuery ruleQuery);

/**
* List all list.
*
* @return the list
*/
List<RuleData> listAll();

/**
* Find by selector id list.
*
* @param selectorId the selector id
* @return the list
*/
List<RuleData> findBySelectorId(String selectorId);

/**
* Find by a list of selector ids.
*
* @param selectorIdList a list of selector ids
* @return the list of RuleDatas
*/
List<RuleData> findBySelectorIdList(List<String> selectorIdList);

/**
* Find rule by name.
*
Expand Down

0 comments on commit 206c1b0

Please sign in to comment.