throw new BadRequestException(String.format("Either '%s' or '%s' parameters should be set", PARAM_CUSTOM_KEY, PARAM_MANUAL_KEY));
}
try {
if (!Strings.isNullOrEmpty(customKey)) {
NewRule newRule = NewRule.createForCustomRule(customKey, RuleKey.parse(request.mandatoryParam(PARAM_TEMPLATE_KEY)))
.setName(request.mandatoryParam(PARAM_NAME))
.setMarkdownDescription(request.mandatoryParam(PARAM_DESCRIPTION))
.setSeverity(request.mandatoryParam(PARAM_SEVERITY))
.setStatus(RuleStatus.valueOf(request.mandatoryParam(PARAM_STATUS)))
.setPreventReactivation(request.paramAsBoolean(PARAM_PREVENT_REACTIVATION));
String params = request.param(PARAMS);
if (!Strings.isNullOrEmpty(params)) {
newRule.setParameters(KeyValueFormat.parse(params));
}
writeResponse(response, service.create(newRule));
}
if (!Strings.isNullOrEmpty(manualKey)) {
NewRule newRule = NewRule.createForManualRule(manualKey)
.setName(request.mandatoryParam(PARAM_NAME))
.setMarkdownDescription(request.mandatoryParam(PARAM_DESCRIPTION))
.setSeverity(request.param(PARAM_SEVERITY))
.setPreventReactivation(request.paramAsBoolean(PARAM_PREVENT_REACTIVATION));
writeResponse(response, service.create(newRule));