private SearchWsResponse doHandle(SearchRequest searchWsRequest) { try (DbSession dbSession = dbClient.openSession(false)) { ComponentDto component = getComponentByUuidOrKey(dbSession, searchWsRequest); List<ProjectLinkDto> links = dbClient.projectLinkDao() .selectByProjectUuid(dbSession, component.uuid()); return buildResponse(links); } }
@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(); } }
@Test public void select_by_project_uuid() { ComponentDto project = db.components().insertPrivateProject(); ProjectLinkDto link1 = db.componentLinks().insertProvidedLink(project); ProjectLinkDto link2 = db.componentLinks().insertProvidedLink(project); ProjectLinkDto link3 = db.componentLinks().insertProvidedLink(project); ComponentDto otherProject = db.components().insertPrivateProject(); ProjectLinkDto otherLink = db.componentLinks().insertProvidedLink(otherProject); assertThat(underTest.selectByProjectUuid(db.getSession(), project.uuid())) .extracting(ProjectLinkDto::getUuid) .containsExactlyInAnyOrder(link1.getUuid(), link2.getUuid(), link3.getUuid()); assertThat(underTest.selectByProjectUuid(db.getSession(), otherProject.uuid())) .extracting(ProjectLinkDto::getUuid) .containsExactlyInAnyOrder(otherLink.getUuid()); assertThat(underTest.selectByProjectUuid(db.getSession(), "UNKNOWN")).isEmpty(); }
@Test public void update_link() { mockBranch(true); ComponentDto project = db.components().insertPrivateProject(p -> p.setUuid("ABCD")); db.componentLinks().insertProvidedLink(project, l -> l.setType("homepage").setName("Home").setHref("http://www.sonar.org")); treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").build()); reportReader.putComponent(ScannerReport.Component.newBuilder() .setRef(1) .setType(ComponentType.PROJECT) .addLink(ScannerReport.ComponentLink.newBuilder().setType(HOME).setHref("http://www.sonarqube.org").build()) .build()); underTest.execute(new TestComputationStepContext()); assertThat(db.getDbClient().projectLinkDao().selectByProjectUuid(db.getSession(), "ABCD")) .extracting(ProjectLinkDto::getType, ProjectLinkDto::getHref) .containsExactlyInAnyOrder(tuple("homepage", "http://www.sonarqube.org")); }
@Test public void nothing_to_do_when_link_already_exists() { mockBranch(true); ComponentDto project = db.components().insertPrivateProject(p -> p.setUuid("ABCD")); db.componentLinks().insertProvidedLink(project, l -> l.setType("homepage").setName("Home").setHref("http://www.sonarqube.org")); treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").build()); reportReader.putComponent(ScannerReport.Component.newBuilder() .setRef(1) .setType(ComponentType.PROJECT) .addLink(ScannerReport.ComponentLink.newBuilder().setType(HOME).setHref("http://www.sonarqube.org").build()) .build()); underTest.execute(new TestComputationStepContext()); assertThat(db.getDbClient().projectLinkDao().selectByProjectUuid(db.getSession(), "ABCD")) .extracting(ProjectLinkDto::getType, ProjectLinkDto::getHref) .containsExactlyInAnyOrder(tuple("homepage", "http://www.sonarqube.org")); }
@Test public void add_links_on_project() { mockBranch(true); treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").build()); // project reportReader.putComponent(ScannerReport.Component.newBuilder() .setRef(1) .setType(ComponentType.PROJECT) .addChildRef(2) .addLink(ScannerReport.ComponentLink.newBuilder().setType(HOME).setHref("http://www.sonarqube.org").build()) .addLink(ScannerReport.ComponentLink.newBuilder().setType(SCM).setHref("https://github.com/SonarSource/sonar").build()) .addLink(ScannerReport.ComponentLink.newBuilder().setType(ISSUE).setHref("http://jira.sonarsource.com/").build()) .addLink(ScannerReport.ComponentLink.newBuilder().setType(CI).setHref("http://bamboo.ci.codehaus.org/browse/SONAR").build()) .build()); underTest.execute(new TestComputationStepContext()); assertThat(db.getDbClient().projectLinkDao().selectByProjectUuid(db.getSession(), "ABCD")) .extracting(ProjectLinkDto::getType, ProjectLinkDto::getHref, ProjectLinkDto::getName) .containsExactlyInAnyOrder( tuple("homepage", "http://www.sonarqube.org", null), tuple("scm", "https://github.com/SonarSource/sonar", null), tuple("issue", "http://jira.sonarsource.com/", null), tuple("ci", "http://bamboo.ci.codehaus.org/browse/SONAR", null)); }
private SearchWsResponse doHandle(SearchRequest searchWsRequest) { try (DbSession dbSession = dbClient.openSession(false)) { ComponentDto component = getComponentByUuidOrKey(dbSession, searchWsRequest); List<ProjectLinkDto> links = dbClient.projectLinkDao() .selectByProjectUuid(dbSession, component.uuid()); return buildResponse(links); } }
@Override public void execute() { 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(); } }