/** Create manual issue */ public Result<DefaultIssue> create(Map<String, String> params) { Result<DefaultIssue> result = Result.of(); try { // mandatory parameters String componentKey = params.get("component"); if (StringUtils.isBlank(componentKey)) { result.addError("Component is not set"); } RuleKey ruleKey = null; String rule = params.get("rule"); if (StringUtils.isBlank(rule)) { result.addError(Result.Message.ofL10n("issue.manual.missing_rule")); } else { ruleKey = RuleKey.parse(rule); } if (result.ok()) { DefaultIssue issue = issueService.createManualIssue( componentKey, ruleKey, RubyUtils.toInteger(params.get("line")), params.get("message"), params.get("severity"), RubyUtils.toDouble(params.get("effortToFix")), UserSession.get()); result.set(issue); } } catch (Exception e) { result.addError(e.getMessage()); } return result; }
private GroupMembershipQuery parseQuery(Map<String, Object> params) { GroupMembershipQuery.Builder builder = GroupMembershipQuery.builder(); builder.membership(membership(params)); builder.groupSearch((String) params.get("query")); builder.pageIndex(RubyUtils.toInteger(params.get("page"))); builder.pageSize(RubyUtils.toInteger(params.get("pageSize"))); builder.login((String) params.get("user")); return builder.build(); }
@VisibleForTesting DefaultIssueFilter createIssueFilterResult( Map<String, String> params, boolean checkId, boolean checkUser) { String id = params.get(ID_PARAM); String name = params.get(NAME_PARAM); String description = params.get(DESCRIPTION_PARAM); String data = params.get("data"); String user = params.get(USER_PARAM); Boolean sharedParam = RubyUtils.toBoolean(params.get("shared")); boolean shared = sharedParam != null ? sharedParam : false; if (checkId) { Validation.checkMandatoryParameter(id, ID_PARAM); } if (checkUser) { Validation.checkMandatoryParameter(user, USER_PARAM); } Validation.checkMandatorySizeParameter(name, NAME_PARAM, 100); checkOptionalSizeParameter(description, DESCRIPTION_PARAM, 4000); DefaultIssueFilter defaultIssueFilter = DefaultIssueFilter.create(name) .setDescription(description) .setShared(shared) .setUser(user) .setData(data); if (!Strings.isNullOrEmpty(id)) { defaultIssueFilter.setId(Long.valueOf(id)); } return defaultIssueFilter; }
/** Used in SQALE */ public PagedResult<RuleDto> find(Map<String, Object> params) { RuleQuery query = new RuleQuery(); query.setQueryText(Strings.emptyToNull((String) params.get("searchQuery"))); query.setKey(Strings.emptyToNull((String) params.get("key"))); query.setLanguages(RubyUtils.toStrings(params.get("languages"))); query.setRepositories(RubyUtils.toStrings(params.get("repositories"))); query.setSeverities(RubyUtils.toStrings(params.get("severities"))); query.setStatuses(RubyUtils.toEnums(params.get("statuses"), RuleStatus.class)); query.setTags(RubyUtils.toStrings(params.get("tags"))); query.setSortField(RuleIndexDefinition.FIELD_RULE_NAME); String profile = Strings.emptyToNull((String) params.get("profile")); if (profile != null) { query.setQProfileKey(profile); query.setActivation(true); } SearchOptions options = new SearchOptions(); Integer pageSize = RubyUtils.toInteger(params.get("pageSize")); int size = pageSize != null ? pageSize : 50; Integer page = RubyUtils.toInteger(params.get("p")); int pageIndex = page != null ? page : 1; options.setPage(pageIndex, size); SearchIdResult<RuleKey> result = service.search(query, options); List<RuleDto> ruleDtos = loadDtos(result.getIds()); return new PagedResult<>( ruleDtos, PagingResult.create(options.getLimit(), pageIndex, result.getTotal())); }
private Date checkAndReturnDeadline(String deadLineParam, Result<ActionPlan> result) { Date deadLine = null; if (!Strings.isNullOrEmpty(deadLineParam)) { try { deadLine = RubyUtils.toDate(deadLineParam); Date today = new Date(); if (deadLine != null && deadLine.before(today) && !org.apache.commons.lang.time.DateUtils.isSameDay(deadLine, today)) { result.addError(Result.Message.ofL10n("action_plans.date_cant_be_in_past")); } } catch (SonarException e) { result.addError(Result.Message.ofL10n("errors.is_not_valid", "date")); } } return deadLine; }
static ComponentQuery toQuery(Map<String, Object> props) { ComponentQuery.Builder builder = ComponentQuery.builder() .keys(RubyUtils.toStrings(props.get("keys"))) .names(RubyUtils.toStrings(props.get("names"))) .qualifiers(RubyUtils.toStrings(props.get("qualifiers"))) .pageSize(RubyUtils.toInteger(props.get("pageSize"))) .pageIndex(RubyUtils.toInteger(props.get("pageIndex"))); String sort = (String) props.get("sort"); if (!Strings.isNullOrEmpty(sort)) { builder.sort(sort); builder.asc(RubyUtils.toBoolean(props.get("asc"))); } return builder.build(); }