use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.
the class ActivityAction method loadComponentUuids.
@CheckForNull
private List<String> loadComponentUuids(DbSession dbSession, ActivityWsRequest request) {
String componentUuid = request.getComponentId();
String componentQuery = request.getQuery();
if (componentUuid != null) {
return singletonList(componentUuid);
}
if (componentQuery != null) {
ComponentQuery componentDtoQuery = ComponentQuery.builder().setNameOrKeyQuery(componentQuery).setQualifiers(POSSIBLE_QUALIFIERS.toArray(new String[0])).build();
List<ComponentDto> componentDtos = dbClient.componentDao().selectByQuery(dbSession, componentDtoQuery, 0, CeTaskQuery.MAX_COMPONENT_UUIDS);
return Lists.transform(componentDtos, ComponentDto::uuid);
}
return null;
}
use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.
the class IssuesAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
response.stream().setMediaType(MediaTypes.PROTOBUF);
try (DbSession session = dbClient.openSession(false)) {
String componentKey = request.mandatoryParam(PARAM_KEY);
ComponentDto component = componentFinder.getByKey(session, componentKey);
userSession.checkComponentPermission(USER, component);
Map<String, String> keysByUUid = keysByUUid(session, component);
ScannerInput.ServerIssue.Builder issueBuilder = ScannerInput.ServerIssue.newBuilder();
for (Iterator<IssueDoc> issueDocIterator = issueIndex.selectIssuesForBatch(component); issueDocIterator.hasNext(); ) {
handleIssue(issueDocIterator.next(), issueBuilder, keysByUUid, response.stream().output());
}
}
}
use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.
the class ComponentAction method handle.
@Override
public void handle(Request wsRequest, Response wsResponse) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto component = componentFinder.getByUuidOrKey(dbSession, wsRequest.param(PARAM_COMPONENT_ID), wsRequest.param(PARAM_COMPONENT_KEY), COMPONENT_ID_AND_KEY);
userSession.checkComponentPermission(UserRole.USER, component);
List<CeQueueDto> queueDtos = dbClient.ceQueueDao().selectByComponentUuid(dbSession, component.uuid());
CeTaskQuery activityQuery = new CeTaskQuery().setComponentUuid(component.uuid()).setOnlyCurrents(true);
List<CeActivityDto> activityDtos = dbClient.ceActivityDao().selectByQuery(dbSession, activityQuery, 0, 1);
ProjectResponse.Builder wsResponseBuilder = ProjectResponse.newBuilder();
wsResponseBuilder.addAllQueue(formatter.formatQueue(dbSession, queueDtos));
if (activityDtos.size() == 1) {
wsResponseBuilder.setCurrent(formatter.formatActivity(dbSession, activityDtos.get(0)));
}
writeProtobuf(wsResponseBuilder.build(), wsRequest, wsResponse);
}
}
use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.
the class TaskAction method handle.
@Override
public void handle(Request wsRequest, Response wsResponse) throws Exception {
String taskUuid = wsRequest.mandatoryParam(PARAM_TASK_UUID);
try (DbSession dbSession = dbClient.openSession(false)) {
WsCe.TaskResponse.Builder wsTaskResponse = WsCe.TaskResponse.newBuilder();
Optional<CeQueueDto> queueDto = dbClient.ceQueueDao().selectByUuid(dbSession, taskUuid);
if (queueDto.isPresent()) {
Optional<ComponentDto> component = loadComponent(dbSession, queueDto.get().getComponentUuid());
checkPermission(component);
wsTaskResponse.setTask(wsTaskFormatter.formatQueue(dbSession, queueDto.get(), component));
} else {
CeActivityDto ceActivityDto = WsUtils.checkFoundWithOptional(dbClient.ceActivityDao().selectByUuid(dbSession, taskUuid), "No activity found for task '%s'", taskUuid);
Optional<ComponentDto> component = loadComponent(dbSession, ceActivityDto.getComponentUuid());
checkPermission(component);
Set<AdditionalField> additionalFields = AdditionalField.getFromRequest(wsRequest);
maskErrorStacktrace(ceActivityDto, additionalFields);
wsTaskResponse.setTask(wsTaskFormatter.formatActivity(dbSession, ceActivityDto, component, extractScannerContext(dbSession, ceActivityDto, additionalFields)));
}
writeProtobuf(wsTaskResponse.build(), wsRequest, wsResponse);
}
}
use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.
the class ComponentUpdater method createRootComponent.
private ComponentDto createRootComponent(DbSession session, NewComponent newComponent) {
checkBranchFormat(newComponent.qualifier(), newComponent.branch());
String keyWithBranch = ComponentKeys.createKey(newComponent.key(), newComponent.branch());
checkRequest(!dbClient.componentDao().selectByKey(session, keyWithBranch).isPresent(), formatMessage("Could not create %s, key already exists: %s", newComponent.qualifier(), keyWithBranch));
String uuid = Uuids.create();
ComponentDto component = new ComponentDto().setOrganizationUuid(newComponent.getOrganizationUuid()).setUuid(uuid).setUuidPath(ComponentDto.UUID_PATH_OF_ROOT).setRootUuid(uuid).setModuleUuid(null).setModuleUuidPath(ComponentDto.UUID_PATH_SEPARATOR + uuid + ComponentDto.UUID_PATH_SEPARATOR).setProjectUuid(uuid).setKey(keyWithBranch).setDeprecatedKey(keyWithBranch).setName(newComponent.name()).setLongName(newComponent.name()).setScope(Scopes.PROJECT).setQualifier(newComponent.qualifier()).setCreatedAt(new Date(system2.now()));
dbClient.componentDao().insert(session, component);
return component;
}
Aggregations