use of org.sonar.db.component.ProjectLinkDto in project sonarqube by SonarSource.
the class CreateAction method doHandle.
private CreateWsResponse doHandle(CreateRequest createWsRequest) {
String name = createWsRequest.getName();
String url = createWsRequest.getUrl();
try (DbSession dbSession = dbClient.openSession(false)) {
ProjectDto project = getProject(dbSession, createWsRequest);
userSession.checkProjectPermission(UserRole.ADMIN, project);
ProjectLinkDto link = new ProjectLinkDto().setUuid(uuidFactory.create()).setProjectUuid(project.getUuid()).setName(name).setHref(url).setType(nameToType(name));
dbClient.projectLinkDao().insert(dbSession, link);
dbSession.commit();
return buildResponse(link);
}
}
use of org.sonar.db.component.ProjectLinkDto in project sonarqube by SonarSource.
the class PersistProjectLinksStep method execute.
@Override
public void execute(ComputationStep.Context context) {
if (!analysisMetadataHolder.getBranch().isMain()) {
return;
}
try (DbSession session = dbClient.openSession(false)) {
Component project = treeRootHolder.getRoot();
ScannerReport.Component batchComponent = reportReader.readComponent(project.getReportAttributes().getRef());
List<ProjectLinkDto> previousLinks = dbClient.projectLinkDao().selectByProjectUuid(session, project.getUuid());
mergeLinks(session, project.getUuid(), batchComponent.getLinkList(), previousLinks);
session.commit();
}
}
use of org.sonar.db.component.ProjectLinkDto in project sonarqube by SonarSource.
the class PersistProjectLinksStep method mergeLinks.
private void mergeLinks(DbSession session, String componentUuid, List<ScannerReport.ComponentLink> links, List<ProjectLinkDto> previousLinks) {
Set<String> linkType = new HashSet<>();
links.forEach(link -> {
String type = convertType(link.getType());
checkArgument(!linkType.contains(type), "Link of type '%s' has already been declared on component '%s'", type, componentUuid);
linkType.add(type);
Optional<ProjectLinkDto> previousLink = previousLinks.stream().filter(input -> input != null && input.getType().equals(convertType(link.getType()))).findFirst();
if (previousLink.isPresent()) {
previousLink.get().setHref(link.getHref());
dbClient.projectLinkDao().update(session, previousLink.get());
} else {
dbClient.projectLinkDao().insert(session, new ProjectLinkDto().setUuid(uuidFactory.create()).setProjectUuid(componentUuid).setType(type).setHref(link.getHref()));
}
});
previousLinks.stream().filter(dto -> !linkType.contains(dto.getType())).filter(dto -> ProjectLinkDto.PROVIDED_TYPES.contains(dto.getType())).forEach(dto -> dbClient.projectLinkDao().delete(session, dto.getUuid()));
}
use of org.sonar.db.component.ProjectLinkDto in project sonarqube by SonarSource.
the class DeleteActionTest method fail_if_anonymous.
@Test
public void fail_if_anonymous() {
ComponentDto project = db.components().insertPrivateProject();
ProjectLinkDto link = db.componentLinks().insertCustomLink(project);
userSession.anonymous();
assertThatThrownBy(() -> deleteLink(link)).isInstanceOf(ForbiddenException.class);
}
use of org.sonar.db.component.ProjectLinkDto in project sonarqube by SonarSource.
the class DeleteActionTest method no_response.
@Test
public void no_response() {
ComponentDto project = db.components().insertPrivateProject();
ProjectLinkDto link = db.componentLinks().insertCustomLink(project);
logInAsProjectAdministrator(project);
TestResponse response = deleteLink(link);
assertThat(response.getStatus()).isEqualTo(204);
assertThat(response.getInput()).isEmpty();
}
Aggregations