use of org.sonar.db.ce.CeTaskMessageDto in project sonarqube by SonarSource.
the class DismissAnalysisWarningAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkLoggedIn();
String userLogin = requireNonNull(userSession.getLogin());
String projectKey = request.mandatoryParam(PARAM_COMPONENT_KEY);
String messageKey = request.mandatoryParam(PARAM_MESSAGE_KEY);
try (DbSession dbSession = dbClient.openSession(false)) {
UserDto user = getUser(dbSession, userLogin);
ProjectDto project = componentFinder.getProjectByKey(dbSession, projectKey);
userSession.checkProjectPermission(UserRole.USER, project);
CeTaskMessageDto messageDto = dbClient.ceTaskMessageDao().selectByUuid(dbSession, messageKey).orElseThrow(() -> new NotFoundException(format(MESSAGE_NOT_FOUND, messageKey)));
if (!messageDto.getType().isDismissible()) {
throw new IllegalArgumentException(format(MESSAGE_CANNOT_BE_DISMISSED, messageKey));
}
Optional<UserDismissedMessageDto> result = dbClient.userDismissedMessagesDao().selectByUserAndProjectAndMessageType(dbSession, user, project, messageDto.getType());
if (!result.isPresent()) {
dbClient.userDismissedMessagesDao().insert(dbSession, new UserDismissedMessageDto().setUuid(Uuids.create()).setUserUuid(user.getUuid()).setProjectUuid(project.getUuid()).setCeMessageType(messageDto.getType()));
dbSession.commit();
}
response.noContent();
}
}
use of org.sonar.db.ce.CeTaskMessageDto in project sonarqube by SonarSource.
the class PurgeDaoTest method insertCeTaskMessages.
private void insertCeTaskMessages(String uuid, int count) {
IntStream.range(0, count).mapToObj(i -> new CeTaskMessageDto().setUuid(UuidFactoryFast.getInstance().create()).setTaskUuid(uuid).setMessage("key_" + uuid.hashCode() + i).setType(CeTaskMessageType.GENERIC).setCreatedAt(2_333_444L + i)).forEach(dto -> dbClient.ceTaskMessageDao().insert(dbSession, dto));
dbSession.commit();
}
use of org.sonar.db.ce.CeTaskMessageDto in project sonarqube by SonarSource.
the class AnalysisStatusActionTest method return_warnings_for_last_analysis_of_pull_request.
@Test
public void return_warnings_for_last_analysis_of_pull_request() {
ComponentDto project = db.components().insertPrivateProject();
userSession.logIn().setSystemAdministrator().addProjectPermission(UserRole.USER, project);
ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> {
b.setBranchType(BranchType.PULL_REQUEST);
b.setKey(PULL_REQUEST);
});
SnapshotDto analysis = db.components().insertSnapshot(pullRequest);
CeActivityDto activity = insertActivity("task-uuid" + counter++, pullRequest, SUCCESS, analysis, REPORT);
CeTaskMessageDto taskMessage = createTaskMessage(activity, WARNING_IN_PR);
Ce.AnalysisStatusWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).setParam(PARAM_PULL_REQUEST, PULL_REQUEST).executeProtobuf(Ce.AnalysisStatusWsResponse.class);
assertThat(response.getComponent().getWarningsList()).extracting(Warning::getKey, Warning::getMessage, Warning::getDismissable).containsExactly(tuple(taskMessage.getUuid(), WARNING_IN_PR, false));
SnapshotDto analysis2 = db.components().insertSnapshot(pullRequest);
insertActivity("task-uuid" + counter++, pullRequest, SUCCESS, analysis2, REPORT);
insertActivity("task-uuid" + counter++, pullRequest, SUCCESS, null, "PROJECT_EXPORT");
Ce.AnalysisStatusWsResponse response2 = ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).setParam(PARAM_PULL_REQUEST, PULL_REQUEST).executeProtobuf(Ce.AnalysisStatusWsResponse.class);
assertThat(response2.getComponent().getWarningsList()).isEmpty();
}
use of org.sonar.db.ce.CeTaskMessageDto in project sonarqube by SonarSource.
the class AnalysisStatusActionTest method json_example.
@Test
public void json_example() {
ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey("com.github.kevinsawicki:http-request-parent").setName("HttpRequest"));
SnapshotDto analysis = db.components().insertSnapshot(project);
CeActivityDto activity = insertActivity("task-uuid" + counter++, project, SUCCESS, analysis, REPORT);
CeTaskMessageDto ceTaskMessage = new CeTaskMessageDto().setUuid("AU-Tpxb--iU5OvuD2FLy").setTaskUuid(activity.getUuid()).setMessage("Property \"sonar.jacoco.reportPaths\" is no longer supported. Use JaCoCo xml report and sonar-jacoco plugin.").setType(CeTaskMessageType.GENERIC).setCreatedAt(counter);
db.getDbClient().ceTaskMessageDao().insert(db.getSession(), ceTaskMessage);
db.commit();
userSession.logIn().setSystemAdministrator().addProjectPermission(UserRole.USER, project);
String result = ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).execute().getInput();
assertJson(result).isSimilarTo(getClass().getResource("analysis_status-example.json"));
}
use of org.sonar.db.ce.CeTaskMessageDto in project sonarqube by SonarSource.
the class AnalysisStatusActionTest method return_warnings_for_last_analysis_of_main.
@Test
public void return_warnings_for_last_analysis_of_main() {
ComponentDto project = db.components().insertPrivateProject();
userSession.logIn().setSystemAdministrator().addProjectPermission(UserRole.USER, project);
SnapshotDto analysis = db.components().insertSnapshot(project);
CeActivityDto activity = insertActivity("task-uuid" + counter++, project, SUCCESS, analysis, REPORT);
CeTaskMessageDto taskMessage = createTaskMessage(activity, WARNING_IN_MAIN);
CeTaskMessageDto taskMessageDismissible = createTaskMessage(activity, "Dismissible warning", CeTaskMessageType.SUGGEST_DEVELOPER_EDITION_UPGRADE);
Ce.AnalysisStatusWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).executeProtobuf(Ce.AnalysisStatusWsResponse.class);
assertThat(response.getComponent().getWarningsList()).extracting(Warning::getKey, Warning::getMessage, Warning::getDismissable).containsExactly(tuple(taskMessage.getUuid(), WARNING_IN_MAIN, false), tuple(taskMessageDismissible.getUuid(), taskMessageDismissible.getMessage(), true));
SnapshotDto analysis2 = db.components().insertSnapshot(project);
insertActivity("task-uuid" + counter++, project, SUCCESS, analysis2, REPORT);
insertActivity("task-uuid" + counter++, project, SUCCESS, null, "PROJECT_EXPORT");
Ce.AnalysisStatusWsResponse response2 = ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).executeProtobuf(Ce.AnalysisStatusWsResponse.class);
assertThat(response2.getComponent().getWarningsList()).isEmpty();
}
Aggregations