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(); } }
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); }
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); }
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); } }
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())); }