Package org.sonar.core.persistence

Examples of org.sonar.core.persistence.DbSession


  }

  public Issue setSeverity(String issueKey, String severity) {
    verifyLoggedIn();

    DbSession session = dbClient.openSession(false);
    try {
      DefaultIssue issue = getByKeyForUpdate(session, issueKey).toDefaultIssue();
      UserSession.get().checkProjectPermission(UserRole.ISSUE_ADMIN, issue.projectKey());

      IssueChangeContext context = IssueChangeContext.createUser(new Date(), UserSession.get().login());
      if (issueUpdater.setManualSeverity(issue, severity, context)) {
        saveIssue(session, issue, context, null);
      }
      return issue;
    } finally {
      session.close();
    }
  }
View Full Code Here


  public DefaultIssue createManualIssue(String componentKey, RuleKey ruleKey, @Nullable Integer line, @Nullable String message, @Nullable String severity,
    @Nullable Double effortToFix) {
    verifyLoggedIn();

    DbSession session = dbClient.openSession(false);
    try {
      ComponentDto component = dbClient.componentDao().getByKey(session, componentKey);
      ComponentDto project = dbClient.componentDao().getRootProjectByKey(componentKey, session);

      UserSession.get().checkProjectPermission(UserRole.USER, project.getKey());
      if (!ruleKey.isManual()) {
        throw new IllegalArgumentException("Issues can be created only on rules marked as 'manual': " + ruleKey);
      }
      Rule rule = getNullableRuleByKey(ruleKey);
      if (rule == null) {
        throw new IllegalArgumentException("Unknown rule: " + ruleKey);
      }

      DefaultIssue issue = new DefaultIssueBuilder()
        .componentKey(component.getKey())
        .projectKey(project.getKey())
        .line(line)
        .message(!Strings.isNullOrEmpty(message) ? message : rule.getName())
        .severity(Objects.firstNonNull(severity, Severity.MAJOR))
        .effortToFix(effortToFix)
        .ruleKey(ruleKey)
        .reporter(UserSession.get().login())
        .build();

      Date now = new Date();
      issue.setCreationDate(now);
      issue.setUpdateDate(now);
      issueStorage.save(issue);
      dryRunCache.reportResourceModification(component.getKey());
      return issue;
    } finally {
      session.close();
    }
  }
View Full Code Here

    this.exporters = exporters;
  }

  public QProfileResult create(QProfileName name, @Nullable Map<String, String> xmlQProfilesByPlugin) {
    verifyAdminPermission();
    DbSession dbSession = db.openSession(false);
    try {
      QProfileResult result = new QProfileResult();
      QualityProfileDto profile = factory.create(dbSession, name);
      result.setProfile(profile);
      if (xmlQProfilesByPlugin != null) {
        for (Map.Entry<String, String> entry : xmlQProfilesByPlugin.entrySet()) {
          result.add(exporters.importXml(profile, entry.getKey(), entry.getValue(), dbSession));
        }
      }
      dbSession.commit();
      return result;
    } finally {
      dbSession.close();
    }
  }
View Full Code Here

   * Activate a rule on a Quality profile. Update configuration (severity/parameters) if the rule is already
   * activated.
   */
  public List<ActiveRuleChange> activate(String profileKey, RuleActivation activation) {
    verifyAdminPermission();
    DbSession dbSession = db.openSession(false);
    try {
      List<ActiveRuleChange> changes = ruleActivator.activate(dbSession, activation, profileKey);
      dbSession.commit();
      return changes;
    } finally {
      dbSession.close();
    }
  }
View Full Code Here

    UserSession.get().checkLoggedIn();
    UserSession.get().checkGlobalPermission(GlobalPermissions.QUALITY_PROFILE_ADMIN);
  }

  public Result<QProfileActivity> searchActivities(QProfileActivityQuery query, QueryContext options) {
    DbSession session = db.openSession(false);
    try {
      OrFilterBuilder activityFilter = FilterBuilders.orFilter();
      for (String profileKey : query.getQprofileKeys()) {
        activityFilter.add(FilterBuilders.nestedFilter("details",
          QueryBuilders.matchQuery("details.profileKey", profileKey)));
      }

      SearchResponse response = index.get(ActivityIndex.class).search(query, options, activityFilter);
      Result<QProfileActivity> result = new Result<QProfileActivity>(response);
      for (SearchHit hit : response.getHits().getHits()) {
        QProfileActivity profileActivity = new QProfileActivity(hit.getSource());
        RuleDto ruleDto = db.ruleDao().getNullableByKey(session, profileActivity.ruleKey());
        profileActivity.ruleName(ruleDto != null ? ruleDto.getName() : null);

        String login = profileActivity.login();
        if (login != null) {
          UserDto user = db.userDao().selectActiveUserByLogin(login, session);
          profileActivity.authorName(user != null ? user.getName() : null);
        }
        result.getHits().add(profileActivity);
      }
      return result;
    } finally {
      session.close();
    }
  }
View Full Code Here

  public List<DefaultIssueComment> findComments(DbSession session, String issueKey) {
    return findComments(session, newArrayList(issueKey));
  }

  public List<DefaultIssueComment> findComments(Collection<String> issueKeys) {
    DbSession session = dbClient.openSession(false);
    try {
      return findComments(session, issueKeys);
    } finally {
      session.close();
    }
  }
View Full Code Here

    verifyLoggedIn(userSession);
    if (StringUtils.isBlank(text)) {
      throw new BadRequestException("Cannot add empty comments to an issue");
    }

    DbSession session = dbClient.openSession(false);
    try {
      DefaultIssue issue = issueService.getByKeyForUpdate(session, issueKey).toDefaultIssue();
      IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.login());
      updater.addComment(issue, text, context);

      issueService.saveIssue(session, issue, context, text);
      session.commit();

      List<DefaultIssueComment> comments = findComments(issueKey);
      if (comments.isEmpty()) {
        throw new BadRequestException(String.format("Fail to add a comment on issue %s", issueKey));
      }
      return comments.get(comments.size() - 1);
    } finally {
      session.close();
    }
  }
View Full Code Here

    UserSession.get().checkComponentPermission(UserRole.CODEVIEWER, fileKey);
  }

  @CheckForNull
  private String findDataFromComponent(String fileKey, String metricKey) {
    DbSession session = dbClient.openSession(false);
    try {
      MeasureDto data = dbClient.measureDao().getNullableByKey(session, MeasureKey.of(fileKey, metricKey));
      if (data != null) {
        return data.getData();
      }
View Full Code Here

    return getSourceAsHtml(componentKey, null, null);
  }

  @CheckForNull
  public List<String> getSourceAsHtml(String componentKey, @Nullable Integer from, @Nullable Integer to) {
    DbSession session = mybatis.openSession(false);
    try {
      ResourceDto component = resourceDao.getResource(ResourceQuery.create().setKey(componentKey), session);
      if (component == null) {
        throw new NotFoundException("The component '" + componentKey + "' does not exists.");
      }
View Full Code Here

  public void handle(Request request, Response response) throws Exception {
    boolean hasScanPerm = UserSession.get().hasGlobalPermission(GlobalPermissions.SCAN_EXECUTION);
    boolean preview = request.mandatoryParamAsBoolean(PARAM_PREVIEW);
    checkPermission(preview);

    DbSession session = dbClient.openSession(false);
    try {
      ProjectReferentials ref = new ProjectReferentials();

      String projectOrModuleKey = request.mandatoryParam(PARAM_KEY);
      String profileName = request.param(PARAM_PROFILE);
View Full Code Here

TOP

Related Classes of org.sonar.core.persistence.DbSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.