Пример #1
0
  public List<DefaultIssue> loadForComponentUuid(String componentUuid) {
    DbSession session = dbClient.openSession(false);
    final List<DefaultIssue> result = new ArrayList<>();
    try {
      session
          .getMapper(IssueMapper.class)
          .selectNonClosedByComponentUuid(
              componentUuid,
              new ResultHandler() {
                @Override
                public void handleResult(ResultContext resultContext) {
                  DefaultIssue issue =
                      ((IssueDto) resultContext.getResultObject()).toDefaultIssue();

                  // TODO this field should be set outside this class
                  if (!isActive(issue.ruleKey())
                      || ruleRepository.getByKey(issue.ruleKey()).getStatus()
                          == RuleStatus.REMOVED) {
                    issue.setOnDisabledRule(true);
                    // TODO to be improved, why setOnDisabledRule(true) is not enough ?
                    issue.setBeingClosed(true);
                  }
                  // FIXME
                  issue.setSelectedAt(System.currentTimeMillis());
                  result.add(issue);
                }
              });
      return result;
    } finally {
      MyBatis.closeQuietly(session);
    }
  }
 public void delete(List<NotificationQueueDto> dtos) {
   DbSession session = mybatis.openSession(true);
   NotificationQueueMapper mapper = session.getMapper(NotificationQueueMapper.class);
   try {
     for (NotificationQueueDto dto : dtos) {
       mapper.delete(dto.getId());
     }
     session.commit();
   } finally {
     MyBatis.closeQuietly(session);
   }
 }
Пример #3
0
  public void bulkUpdateKey(
      DbSession session, long projectId, String stringToReplace, String replacementString) {
    ResourceKeyUpdaterMapper mapper = session.getMapper(ResourceKeyUpdaterMapper.class);
    // must SELECT first everything
    Set<ResourceDto> modules = collectAllModules(projectId, stringToReplace, mapper);
    checkNewNameOfAllModules(modules, stringToReplace, replacementString, mapper);
    Map<ResourceDto, List<ResourceDto>> allResourcesByModuleMap = Maps.newHashMap();
    for (ResourceDto module : modules) {
      allResourcesByModuleMap.put(module, mapper.selectProjectResources(module.getId()));
    }

    // and then proceed with the batch UPDATE at once
    for (ResourceDto module : modules) {
      String oldModuleKey = module.getKey();
      String newModuleKey = computeNewKey(module, stringToReplace, replacementString);
      Collection<ResourceDto> resources = Lists.newArrayList(module);
      resources.addAll(allResourcesByModuleMap.get(module));
      runBatchUpdateForAllResources(resources, oldModuleKey, newModuleKey, mapper);
    }
  }
Пример #4
0
  /**
   * Deactivate a user and drops all his preferences.
   *
   * @return false if the user does not exist, true if the existing user has been deactivated
   */
  public boolean deactivateUserByLogin(DbSession dbSession, String login) {
    UserMapper mapper = dbSession.getMapper(UserMapper.class);
    UserDto dto = mapper.selectUserByLogin(login);
    if (dto == null) {
      return false;
    }

    mapper.removeUserFromGroups(dto.getId());
    mapper.deleteUserActiveDashboards(dto.getId());
    mapper.deleteUnsharedUserDashboards(dto.getId());
    mapper.deleteUnsharedUserIssueFilters(dto.getLogin());
    mapper.deleteUserIssueFilterFavourites(dto.getLogin());
    mapper.deleteUnsharedUserMeasureFilters(dto.getId());
    mapper.deleteUserMeasureFilterFavourites(dto.getId());
    mapper.deleteUserProperties(dto.getId());
    mapper.deleteUserRoles(dto.getId());
    mapper.deactivateUser(dto.getId(), system2.now());
    dbSession.commit();
    return true;
  }
Пример #5
0
  public void updateKey(long projectId, String newKey) {
    DbSession session = mybatis.openSession(true);
    ResourceKeyUpdaterMapper mapper = session.getMapper(ResourceKeyUpdaterMapper.class);
    try {
      if (mapper.countResourceByKey(newKey) > 0) {
        throw new IllegalStateException(
            "Impossible to update key: a resource with \"" + newKey + "\" key already exists.");
      }

      // must SELECT first everything
      ResourceDto project = mapper.selectProject(projectId);
      String projectOldKey = project.getKey();
      List<ResourceDto> resources = mapper.selectProjectResources(projectId);
      resources.add(project);

      // and then proceed with the batch UPDATE at once
      runBatchUpdateForAllResources(resources, projectOldKey, newKey, mapper);

      session.commit();
    } finally {
      MyBatis.closeQuietly(session);
    }
  }
Пример #6
0
 private SnapshotMapper mapper(DbSession session) {
   return session.getMapper(SnapshotMapper.class);
 }
Пример #7
0
 private static CeActivityMapper mapper(DbSession dbSession) {
   return dbSession.getMapper(CeActivityMapper.class);
 }
Пример #8
0
 private MeasureMapper mapper(DbSession session) {
   return session.getMapper(MeasureMapper.class);
 }
Пример #9
0
 private static UserPermissionMapper mapper(DbSession dbSession) {
   return dbSession.getMapper(UserPermissionMapper.class);
 }
Пример #10
0
 private static CeScannerContextMapper mapper(DbSession dbSession) {
   return dbSession.getMapper(CeScannerContextMapper.class);
 }
Пример #11
0
 @CheckForNull
 public UserDto selectActiveUserByLogin(DbSession session, String login) {
   UserMapper mapper = session.getMapper(UserMapper.class);
   return mapper.selectUserByLogin(login);
 }
Пример #12
0
 protected UserMapper mapper(DbSession session) {
   return session.getMapper(UserMapper.class);
 }