use of org.sonar.db.audit.model.ComponentKeyNewValue in project sonarqube by SonarSource.
the class ComponentKeyUpdaterDao method runBatchUpdateForAllResources.
private void runBatchUpdateForAllResources(Collection<ResourceDto> resources, String oldKey, String newKey, ComponentKeyUpdaterMapper mapper, @Nullable BiConsumer<ResourceDto, String> consumer, DbSession dbSession) {
for (ResourceDto resource : resources) {
String oldResourceKey = resource.getKey();
String newResourceKey = newKey + oldResourceKey.substring(oldKey.length());
resource.setKey(newResourceKey);
String oldResourceDeprecatedKey = resource.getDeprecatedKey();
if (StringUtils.isNotBlank(oldResourceDeprecatedKey)) {
String newResourceDeprecatedKey = newKey + oldResourceDeprecatedKey.substring(oldKey.length());
resource.setDeprecatedKey(newResourceDeprecatedKey);
}
mapper.updateComponent(resource);
if (resource.getScope().equals(Scopes.PROJECT) && (resource.getQualifier().equals(Qualifiers.PROJECT) || resource.getQualifier().equals(Qualifiers.APP))) {
auditPersister.componentKeyUpdate(dbSession, new ComponentKeyNewValue(resource.getUuid(), oldResourceKey, newResourceKey), resource.getQualifier());
mapper.updateProject(oldResourceKey, newResourceKey);
}
if (consumer != null) {
consumer.accept(resource, oldResourceKey);
}
}
}
use of org.sonar.db.audit.model.ComponentKeyNewValue in project sonarqube by SonarSource.
the class ComponentKeyUpdaterDao method updateApplicationBranchKey.
public void updateApplicationBranchKey(DbSession dbSession, String appBranchUuid, String appKey, String newBranchName) {
ComponentKeyUpdaterMapper mapper = dbSession.getMapper(ComponentKeyUpdaterMapper.class);
String newAppBranchKey = generateBranchKey(appKey, newBranchName);
checkExistentKey(mapper, newAppBranchKey);
ResourceDto appBranch = mapper.selectProjectByUuid(appBranchUuid);
String appBranchOldKey = appBranch.getKey();
appBranch.setKey(newAppBranchKey);
mapper.updateComponent(appBranch);
auditPersister.componentKeyBranchUpdate(dbSession, new ComponentKeyNewValue(appBranchUuid, appBranchOldKey, newAppBranchKey), Qualifiers.APP);
String oldAppBranchFragment = appBranchOldKey.replace(BRANCH_KEY_SEPARATOR, "");
String newAppBranchFragment = appKey + newBranchName;
for (ResourceDto appBranchResource : mapper.selectProjectResources(appBranchUuid)) {
String newKey = computeNewKey(appBranchResource.getKey(), oldAppBranchFragment, newAppBranchFragment);
appBranchResource.setKey(newKey);
mapper.updateComponent(appBranchResource);
}
}
Aggregations