Ejemplo n.º 1
0
 public boolean rename(String key, String newName) {
   Verifications.check(StringUtils.isNotBlank(newName), "Name must be set");
   Verifications.check(
       newName.length() < 100, String.format("Name is too long (>%d characters)", 100));
   DbSession dbSession = db.openSession(false);
   try {
     QualityProfileDto profile = db.qualityProfileDao().getNonNullByKey(dbSession, key);
     if (!StringUtils.equals(newName, profile.getName())) {
       if (db.qualityProfileDao().getByNameAndLanguage(newName, profile.getLanguage(), dbSession)
           != null) {
         throw new BadRequestException("Quality profile already exists: " + newName);
       }
       String previousName = profile.getName();
       profile.setName(newName);
       db.qualityProfileDao().update(dbSession, profile);
       db.propertiesDao()
           .updateProperties(
               PROFILE_PROPERTY_PREFIX + profile.getLanguage(), previousName, newName, dbSession);
       dbSession.commit();
       return true;
     }
     return false;
   } finally {
     dbSession.close();
   }
 }
Ejemplo n.º 2
0
 private void setDefault(DbSession session, QualityProfileDto profile) {
   PropertyDto property =
       new PropertyDto()
           .setKey(PROFILE_PROPERTY_PREFIX + profile.getLanguage())
           .setValue(profile.getName());
   db.propertiesDao().setProperty(property, session);
 }
Ejemplo n.º 3
0
 private void doDelete(DbSession session, QualityProfileDto profile) {
   db.activeRuleDao().deleteByProfileKey(session, profile.getKey());
   db.qualityProfileDao().delete(session, profile);
   db.propertiesDao()
       .deleteProjectProperties(
           PROFILE_PROPERTY_PREFIX + profile.getLanguage(), profile.getName(), session);
 }
Ejemplo n.º 4
0
  public void renameProfile(int profileId, String newName, UserSession userSession) {
    checkPermission(userSession);
    DbSession session = myBatis.openSession(false);
    try {
      QualityProfileDto profileDto = findNotNull(profileId, session);
      String oldName = profileDto.getName();

      QProfile profile = QProfile.from(profileDto);
      if (!oldName.equals(newName)) {
        checkNotAlreadyExists(newName, profile.language(), session);
      }
      profileDto.setName(newName);
      dao.update(session, profileDto);

      List<QProfile> children = profileLookup.children(profile, session);
      for (QProfile child : children) {
        dao.update(session, child.setParent(newName).toDto());
      }
      propertiesDao.updateProperties(
          PROFILE_PROPERTY_PREFIX + profile.language(), oldName, newName, session);

      session.commit();
    } finally {
      MyBatis.closeQuietly(session);
    }
  }
Ejemplo n.º 5
0
 boolean isDescendant(
     DbSession dbSession,
     QualityProfileDto childProfile,
     @Nullable QualityProfileDto parentProfile) {
   QualityProfileDto currentParent = parentProfile;
   while (currentParent != null) {
     if (childProfile.getName().equals(currentParent.getName())) {
       return true;
     }
     if (currentParent.getParent() != null) {
       currentParent = db.qualityProfileDao().getByKey(dbSession, currentParent.getParentKey());
     } else {
       currentParent = null;
     }
   }
   return false;
 }
 public QProfile get(String language, String name) {
   QualityProfileDto dto = qualityProfileDao.getByNameAndLanguage(name, language);
   if (dto == null) {
     return null;
   }
   return new org.sonar.batch.protocol.input.QProfile(
       dto.getKey(),
       dto.getName(),
       dto.getLanguage(),
       UtcDateUtils.parseDateTime(dto.getRulesUpdatedAt()));
 }