From ebeadfc3d5cb912cd86efc8a2f17e9b0e8528ed7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?L=C3=A9o=20Geoffroy?= Date: Wed, 6 Dec 2023 10:57:10 +0100 Subject: [PATCH] SONAR-21131 Use same enums between request and response and map parameters --- .../server/common/rule/service/RuleService.java | 10 ++++++++-- .../rule/controller/DefaultRuleController.java | 10 ++++++---- .../converter/RuleRestResponseGenerator.java | 8 ++++---- .../CleanCodeAttributeCategoryRestEnum.java | 4 ++++ .../rule/enums/CleanCodeAttributeRestEnum.java | 4 ++++ .../api/rule/enums/ImpactSeverityRestEnum.java | 4 ++++ .../v2/api/rule/enums/RuleStatusRestEnum.java | 4 ++++ .../v2/api/rule/enums/RuleTypeRestEnum.java | 4 ++++ .../api/rule/enums/SoftwareQualityRestEnum.java | 4 ++++ .../api/rule/request/RuleCreateRestRequest.java | 11 ++++++----- .../Impact.java} | 6 +++--- .../rule/{ressource => resource}/Parameter.java | 5 +++-- .../{ressource => resource}/package-info.java | 2 +- .../v2/api/rule/response/RuleRestResponse.java | 9 +++++---- .../org/sonar/server/rule/ws/CreateAction.java | 17 ++++++++++------- 15 files changed, 70 insertions(+), 32 deletions(-) rename server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/{response/RuleImpactRestResponse.java => resource/Impact.java} (89%) rename server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/{ressource => resource}/Parameter.java (90%) rename server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/{ressource => resource}/package-info.java (95%) diff --git a/server/sonar-webserver-common/src/main/java/org/sonar/server/common/rule/service/RuleService.java b/server/sonar-webserver-common/src/main/java/org/sonar/server/common/rule/service/RuleService.java index 9a55ea1965e..ebdf2021b74 100644 --- a/server/sonar-webserver-common/src/main/java/org/sonar/server/common/rule/service/RuleService.java +++ b/server/sonar-webserver-common/src/main/java/org/sonar/server/common/rule/service/RuleService.java @@ -19,11 +19,15 @@ */ package org.sonar.server.common.rule.service; -import java.util.ArrayList; +import java.util.List; import org.sonar.db.DbClient; import org.sonar.db.DbSession; +import org.sonar.db.rule.RuleDto; +import org.sonar.db.rule.RuleParamDto; import org.sonar.server.common.rule.RuleCreator; +import static java.util.Collections.singletonList; + public class RuleService { private final DbClient dbClient; @@ -41,6 +45,8 @@ public class RuleService { } public RuleInformation createCustomRule(NewCustomRule newCustomRule, DbSession dbSession) { - return new RuleInformation(ruleCreator.create(dbSession, newCustomRule), new ArrayList<>()); + RuleDto ruleDto = ruleCreator.create(dbSession, newCustomRule); + List ruleParameters = dbClient.ruleDao().selectRuleParamsByRuleUuids(dbSession, singletonList(ruleDto.getUuid())); + return new RuleInformation(ruleDto, ruleParameters); } } diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/controller/DefaultRuleController.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/controller/DefaultRuleController.java index 34fad2f218e..c5fe2dcb123 100644 --- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/controller/DefaultRuleController.java +++ b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/controller/DefaultRuleController.java @@ -28,12 +28,14 @@ import org.sonar.server.common.rule.service.RuleInformation; import org.sonar.server.common.rule.service.RuleService; import org.sonar.server.user.UserSession; import org.sonar.server.v2.api.rule.converter.RuleRestResponseGenerator; -import org.sonar.server.v2.api.rule.request.Impact; +import org.sonar.server.v2.api.rule.enums.RuleStatusRestEnum; import org.sonar.server.v2.api.rule.request.RuleCreateRestRequest; +import org.sonar.server.v2.api.rule.resource.Impact; import org.sonar.server.v2.api.rule.response.RuleRestResponse; import org.springframework.http.HttpStatus; import org.springframework.web.server.ResponseStatusException; +import static java.util.Optional.ofNullable; import static org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_PROFILES; public class DefaultRuleController implements RuleController { @@ -64,8 +66,8 @@ public class DefaultRuleController implements RuleController { NewCustomRule newCustomRule = NewCustomRule.createForCustomRule(RuleKey.parse(request.key()), RuleKey.parse(request.templateKey())) .setName(request.name()) .setMarkdownDescription(request.markdownDescription()) - .setStatus(request.status()) - .setCleanCodeAttribute(request.cleanCodeAttribute()) + .setStatus(ofNullable(request.status()).map(RuleStatusRestEnum::getRuleStatus).orElse(null)) + .setCleanCodeAttribute(request.cleanCodeAttribute().getCleanCodeAttribute()) .setImpacts(request.impacts().stream().map(DefaultRuleController::toNewCustomRuleImpact).toList()) .setPreventReactivation(true); if (request.parameters() != null) { @@ -77,6 +79,6 @@ public class DefaultRuleController implements RuleController { } private static NewCustomRule.Impact toNewCustomRuleImpact(Impact impact) { - return new NewCustomRule.Impact(impact.softwareQuality(), impact.severity()); + return new NewCustomRule.Impact(impact.softwareQuality().getSoftwareQuality(), impact.severity().getSeverity()); } } diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/converter/RuleRestResponseGenerator.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/converter/RuleRestResponseGenerator.java index 2e06e4ff9d8..ebb87d72f65 100644 --- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/converter/RuleRestResponseGenerator.java +++ b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/converter/RuleRestResponseGenerator.java @@ -47,10 +47,10 @@ import org.sonar.server.v2.api.rule.enums.ImpactSeverityRestEnum; import org.sonar.server.v2.api.rule.enums.RuleStatusRestEnum; import org.sonar.server.v2.api.rule.enums.RuleTypeRestEnum; import org.sonar.server.v2.api.rule.enums.SoftwareQualityRestEnum; +import org.sonar.server.v2.api.rule.resource.Impact; +import org.sonar.server.v2.api.rule.resource.Parameter; import org.sonar.server.v2.api.rule.response.RuleDescriptionSectionContextRestResponse; import org.sonar.server.v2.api.rule.response.RuleDescriptionSectionRestResponse; -import org.sonar.server.v2.api.rule.response.RuleImpactRestResponse; -import org.sonar.server.v2.api.rule.ressource.Parameter; import org.sonar.server.v2.api.rule.response.RuleRestResponse; import static java.util.Optional.ofNullable; @@ -167,9 +167,9 @@ public class RuleRestResponseGenerator { return new RuleDescriptionSectionRestResponse(RuleDescriptionSectionDto.DEFAULT_KEY, macroInterpreter.interpret(description), null); } - private static List toImpactRestResponse(Set defaultImpacts) { + private static List toImpactRestResponse(Set defaultImpacts) { return defaultImpacts.stream() - .map(i -> new RuleImpactRestResponse(SoftwareQualityRestEnum.from(i.getSoftwareQuality()), ImpactSeverityRestEnum.from(i.getSeverity()))) + .map(i -> new Impact(SoftwareQualityRestEnum.from(i.getSoftwareQuality()), ImpactSeverityRestEnum.from(i.getSeverity()))) .toList(); } diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/enums/CleanCodeAttributeCategoryRestEnum.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/enums/CleanCodeAttributeCategoryRestEnum.java index bd07a53efb1..72bed69456f 100644 --- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/enums/CleanCodeAttributeCategoryRestEnum.java +++ b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/enums/CleanCodeAttributeCategoryRestEnum.java @@ -36,6 +36,10 @@ public enum CleanCodeAttributeCategoryRestEnum { this.cleanCodeAttributeCategory = cleanCodeAttributeCategory; } + public CleanCodeAttributeCategory getCleanCodeAttributeCategory() { + return cleanCodeAttributeCategory; + } + @CheckForNull public static CleanCodeAttributeCategoryRestEnum from(@Nullable CleanCodeAttributeCategory cleanCodeAttributeCategory) { if (cleanCodeAttributeCategory == null) { diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/enums/CleanCodeAttributeRestEnum.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/enums/CleanCodeAttributeRestEnum.java index 6bfa406ec02..34bb49a553e 100644 --- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/enums/CleanCodeAttributeRestEnum.java +++ b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/enums/CleanCodeAttributeRestEnum.java @@ -49,6 +49,10 @@ public enum CleanCodeAttributeRestEnum { this.cleanCodeAttribute = cleanCodeAttribute; } + public CleanCodeAttribute getCleanCodeAttribute() { + return cleanCodeAttribute; + } + @CheckForNull public static CleanCodeAttributeRestEnum from(@Nullable CleanCodeAttribute cleanCodeAttribute) { if (cleanCodeAttribute == null) { diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/enums/ImpactSeverityRestEnum.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/enums/ImpactSeverityRestEnum.java index 469797cd31c..84a1f6bb6ca 100644 --- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/enums/ImpactSeverityRestEnum.java +++ b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/enums/ImpactSeverityRestEnum.java @@ -34,6 +34,10 @@ public enum ImpactSeverityRestEnum { this.severity = severity; } + public Severity getSeverity() { + return severity; + } + public static ImpactSeverityRestEnum from(Severity severity) { return Arrays.stream(ImpactSeverityRestEnum.values()) .filter(severityRestResponse -> severityRestResponse.severity.equals(severity)) diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/enums/RuleStatusRestEnum.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/enums/RuleStatusRestEnum.java index 071b6ad53d4..5333892237a 100644 --- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/enums/RuleStatusRestEnum.java +++ b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/enums/RuleStatusRestEnum.java @@ -34,6 +34,10 @@ public enum RuleStatusRestEnum { this.ruleStatus = ruleStatus; } + public RuleStatus getRuleStatus() { + return ruleStatus; + } + public static RuleStatusRestEnum from(RuleStatus ruleStatus) { return Arrays.stream(RuleStatusRestEnum.values()) .filter(ruleStatusRestEnum -> ruleStatusRestEnum.ruleStatus.equals(ruleStatus)) diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/enums/RuleTypeRestEnum.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/enums/RuleTypeRestEnum.java index 09b2179f018..e9b2c4bdfc1 100644 --- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/enums/RuleTypeRestEnum.java +++ b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/enums/RuleTypeRestEnum.java @@ -35,6 +35,10 @@ public enum RuleTypeRestEnum { this.ruleType = ruleType; } + public RuleType getRuleType() { + return ruleType; + } + public static RuleTypeRestEnum from(RuleType ruleType) { return Arrays.stream(RuleTypeRestEnum.values()) .filter(ruleTypeRestEnum -> ruleTypeRestEnum.ruleType.equals(ruleType)) diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/enums/SoftwareQualityRestEnum.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/enums/SoftwareQualityRestEnum.java index 95ab51416dd..59e749a5f77 100644 --- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/enums/SoftwareQualityRestEnum.java +++ b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/enums/SoftwareQualityRestEnum.java @@ -35,6 +35,10 @@ public enum SoftwareQualityRestEnum { this.softwareQuality = softwareQuality; } + public SoftwareQuality getSoftwareQuality() { + return softwareQuality; + } + public static SoftwareQualityRestEnum from(SoftwareQuality softwareQuality) { return Arrays.stream(SoftwareQualityRestEnum.values()) .filter(softwareQualityRest -> softwareQualityRest.softwareQuality.equals(softwareQuality)) diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/request/RuleCreateRestRequest.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/request/RuleCreateRestRequest.java index fde9c475ae6..ff8ba1b7a15 100644 --- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/request/RuleCreateRestRequest.java +++ b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/request/RuleCreateRestRequest.java @@ -26,9 +26,10 @@ import javax.validation.Valid; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; -import org.sonar.api.rule.RuleStatus; -import org.sonar.api.rules.CleanCodeAttribute; -import org.sonar.server.v2.api.rule.ressource.Parameter; +import org.sonar.server.v2.api.rule.enums.CleanCodeAttributeRestEnum; +import org.sonar.server.v2.api.rule.enums.RuleStatusRestEnum; +import org.sonar.server.v2.api.rule.resource.Impact; +import org.sonar.server.v2.api.rule.resource.Parameter; public record RuleCreateRestRequest( @@ -53,7 +54,7 @@ public record RuleCreateRestRequest( @Nullable @Schema(description = "Rule status", defaultValue = "READY") - RuleStatus status, + RuleStatusRestEnum status, @Nullable @Schema(description = "Custom rule parameters") @@ -61,7 +62,7 @@ public record RuleCreateRestRequest( @NotNull @Schema(description = "Clean code attribute") - CleanCodeAttribute cleanCodeAttribute, + CleanCodeAttributeRestEnum cleanCodeAttribute, @Valid @NotEmpty diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/response/RuleImpactRestResponse.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/resource/Impact.java similarity index 89% rename from server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/response/RuleImpactRestResponse.java rename to server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/resource/Impact.java index a0efcf716b8..a9c1b25e543 100644 --- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/response/RuleImpactRestResponse.java +++ b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/resource/Impact.java @@ -17,14 +17,14 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.server.v2.api.rule.response; +package org.sonar.server.v2.api.rule.resource; import io.swagger.v3.oas.annotations.media.Schema; import org.sonar.server.v2.api.rule.enums.ImpactSeverityRestEnum; import org.sonar.server.v2.api.rule.enums.SoftwareQualityRestEnum; -@Schema(accessMode = Schema.AccessMode.READ_ONLY) -public record RuleImpactRestResponse( +@Schema(accessMode = Schema.AccessMode.READ_WRITE) +public record Impact( SoftwareQualityRestEnum softwareQuality, ImpactSeverityRestEnum severity ) { diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/ressource/Parameter.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/resource/Parameter.java similarity index 90% rename from server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/ressource/Parameter.java rename to server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/resource/Parameter.java index 97245423098..9d77f3df57e 100644 --- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/ressource/Parameter.java +++ b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/resource/Parameter.java @@ -17,12 +17,13 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.server.v2.api.rule.ressource; +package org.sonar.server.v2.api.rule.resource; import io.swagger.v3.oas.annotations.media.Schema; import javax.annotation.Nullable; -import static io.swagger.v3.oas.annotations.media.Schema.AccessMode.*; +import static io.swagger.v3.oas.annotations.media.Schema.AccessMode.READ_ONLY; +import static io.swagger.v3.oas.annotations.media.Schema.AccessMode.READ_WRITE; public record Parameter( diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/ressource/package-info.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/resource/package-info.java similarity index 95% rename from server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/ressource/package-info.java rename to server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/resource/package-info.java index cfa25b5b679..1dfa76e9bb9 100644 --- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/ressource/package-info.java +++ b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/resource/package-info.java @@ -18,6 +18,6 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ @ParametersAreNonnullByDefault -package org.sonar.server.v2.api.rule.ressource; +package org.sonar.server.v2.api.rule.resource; import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/response/RuleRestResponse.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/response/RuleRestResponse.java index aef6c0d2a6a..c7ad59c6cfe 100644 --- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/response/RuleRestResponse.java +++ b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/rule/response/RuleRestResponse.java @@ -26,7 +26,8 @@ import org.sonar.server.v2.api.rule.enums.CleanCodeAttributeCategoryRestEnum; import org.sonar.server.v2.api.rule.enums.CleanCodeAttributeRestEnum; import org.sonar.server.v2.api.rule.enums.RuleStatusRestEnum; import org.sonar.server.v2.api.rule.enums.RuleTypeRestEnum; -import org.sonar.server.v2.api.rule.ressource.Parameter; +import org.sonar.server.v2.api.rule.resource.Impact; +import org.sonar.server.v2.api.rule.resource.Parameter; @Schema(accessMode = Schema.AccessMode.READ_ONLY) public record RuleRestResponse( @@ -37,7 +38,7 @@ public record RuleRestResponse( @Nullable String severity, RuleTypeRestEnum type, - List impacts, + List impacts, @Nullable CleanCodeAttributeRestEnum cleanCodeAttribute, @Nullable @@ -81,7 +82,7 @@ public record RuleRestResponse( private String name; private String severity; private RuleTypeRestEnum type; - private List impacts; + private List impacts; private CleanCodeAttributeRestEnum cleanCodeAttribute; private CleanCodeAttributeCategoryRestEnum cleanCodeAttributeCategory; private RuleStatusRestEnum status; @@ -141,7 +142,7 @@ public record RuleRestResponse( return this; } - public Builder setImpacts(List impacts) { + public Builder setImpacts(List impacts) { this.impacts = impacts; return this; } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/CreateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/CreateAction.java index 69b6c04a6fd..121b32594ee 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/CreateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/CreateAction.java @@ -42,6 +42,7 @@ import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; import org.sonar.server.common.rule.ReactivationException; import org.sonar.server.common.rule.service.NewCustomRule; +import org.sonar.server.common.rule.service.RuleInformation; import org.sonar.server.common.rule.service.RuleService; import org.sonarqube.ws.Rules; @@ -172,7 +173,8 @@ public class CreateAction implements RulesWsAction { try (DbSession dbSession = dbClient.openSession(false)) { try { NewCustomRule newCustomRule = toNewCustomRule(request); - writeResponse(dbSession, request, response, ruleService.createCustomRule(newCustomRule, dbSession).ruleDto()); + RuleInformation customRule = ruleService.createCustomRule(newCustomRule, dbSession); + writeResponse(dbSession, request, response, customRule.ruleDto(), customRule.params()); } catch (ReactivationException e) { response.stream().setStatus(HTTP_CONFLICT); writeResponse(dbSession, request, response, e.ruleKey()); @@ -204,25 +206,26 @@ public class CreateAction implements RulesWsAction { return newRule; } - private void writeResponse(DbSession dbSession, Request request, Response response, RuleDto rule) { - writeProtobuf(createResponse(dbSession, rule), request, response); + private void writeResponse(DbSession dbSession, Request request, Response response, RuleDto rule, List params) { + writeProtobuf(createResponse(dbSession, rule, params), request, response); } private void writeResponse(DbSession dbSession, Request request, Response response, RuleKey ruleKey) { RuleDto rule = dbClient.ruleDao().selectByKey(dbSession, ruleKey) .orElseThrow(() -> new IllegalStateException(String.format("Cannot load rule, that has just been created '%s'", ruleKey))); - writeProtobuf(createResponse(dbSession, rule), request, response); + List ruleParameters = dbClient.ruleDao().selectRuleParamsByRuleUuids(dbSession, singletonList(rule.getUuid())); + writeProtobuf(createResponse(dbSession, rule, ruleParameters), request, response); } - private Rules.CreateResponse createResponse(DbSession dbSession, RuleDto rule) { + private Rules.CreateResponse createResponse(DbSession dbSession, RuleDto rule, List params) { List templateRules = new ArrayList<>(); if (rule.isCustomRule()) { Optional templateRule = dbClient.ruleDao().selectByUuid(rule.getTemplateUuid(), dbSession); templateRule.ifPresent(templateRules::add); } - List ruleParameters = dbClient.ruleDao().selectRuleParamsByRuleUuids(dbSession, singletonList(rule.getUuid())); + RulesResponseFormatter.SearchResult searchResult = new RulesResponseFormatter.SearchResult() - .setRuleParameters(ruleParameters) + .setRuleParameters(params) .setTemplateRules(templateRules) .setTotal(1L); return Rules.CreateResponse.newBuilder() -- 2.39.5