Esempio n. 1
0
  /** 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 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();
 }
 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();
 }
  /** 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;
  }