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