use of com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectVersionRequest in project hub-alert by blackducksoftware.
the class BlackDuckProviderService method deleteBlackDuckProjectAndVersion.
public void deleteBlackDuckProjectAndVersion(String projectName, String projectVersionName) throws IntegrationException {
setupBlackDuckServicesFactory();
ProjectService projectService = blackDuckServicesFactory.createProjectService();
ProjectRequest projectRequest = new ProjectRequest();
projectRequest.setName(projectName);
ProjectVersionRequest projectVersionRequest = new ProjectVersionRequest();
projectVersionRequest.setVersionName(projectVersionName);
projectVersionRequest.setPhase(ProjectVersionPhaseType.DEVELOPMENT);
projectVersionRequest.setDistribution(ProjectVersionDistributionType.OPENSOURCE);
projectRequest.setVersionRequest(projectVersionRequest);
Optional<ProjectVersionWrapper> existingProjectVersion = projectService.getProjectVersion(projectRequest.getName(), projectVersionRequest.getVersionName());
if (existingProjectVersion.isPresent()) {
intLogger.info(String.format("Project: %s Version %s already exists", projectName, projectVersionName));
BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
blackDuckApiClient.delete(existingProjectVersion.get().getProjectVersionView());
blackDuckApiClient.delete(existingProjectVersion.get().getProjectView());
intLogger.info(String.format("Deleting project: %s", projectName));
}
}
use of com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectVersionRequest in project hub-alert by blackducksoftware.
the class BlackDuckProviderService method findOrCreateBlackDuckProjectAndVersion.
public ProjectVersionWrapper findOrCreateBlackDuckProjectAndVersion(String projectName, String projectVersionName) throws IntegrationException {
setupBlackDuckServicesFactory();
ProjectService projectService = blackDuckServicesFactory.createProjectService();
ProjectRequest projectRequest = new ProjectRequest();
projectRequest.setName(projectName);
ProjectVersionRequest projectVersionRequest = new ProjectVersionRequest();
projectVersionRequest.setVersionName(projectVersionName);
projectVersionRequest.setPhase(ProjectVersionPhaseType.DEVELOPMENT);
projectVersionRequest.setDistribution(ProjectVersionDistributionType.OPENSOURCE);
projectRequest.setVersionRequest(projectVersionRequest);
Optional<ProjectVersionWrapper> existingProjectVersion = projectService.getProjectVersion(projectRequest.getName(), projectVersionRequest.getVersionName());
if (existingProjectVersion.isPresent()) {
intLogger.info(String.format("Project: %s Version %s already exists", projectName, projectVersionName));
return existingProjectVersion.get();
}
intLogger.info(String.format("Creating project: %s", projectName));
return projectService.createProject(projectRequest);
}
use of com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectVersionRequest in project blackduck-common by blackducksoftware.
the class ComprehensiveCookbookTestIT method createProjectVersion.
@Test
public void createProjectVersion() throws Exception {
String testProjectName = intHttpClientTestHelper.getProperty("TEST_CREATE_PROJECT");
ProjectService projectService = blackDuckServicesFactory.createProjectService();
BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
IntLogger logger = blackDuckServicesFactory.getLogger();
// delete the project, if it exists
intHttpClientTestHelper.deleteIfProjectExists(logger, projectService, blackDuckApiClient, testProjectName);
// get the count of all projects now
int projectCount = blackDuckApiClient.getAllResponses(apiDiscovery.metaProjectsLink()).size();
// create the project
ProjectRequest projectRequest = new ProjectRequest();
projectRequest.setName(testProjectName);
ProjectVersionWrapper projectVersionWrapper = projectService.createProject(projectRequest);
ProjectView projectItem = projectVersionWrapper.getProjectView();
Optional<ProjectView> projectItemFromName = projectService.getProjectByName(testProjectName);
// should return the same project
assertTrue(projectItemFromName.isPresent());
assertEquals(projectItem.toString(), projectItemFromName.get().toString());
int projectCountAfterCreate = blackDuckApiClient.getAllResponses(apiDiscovery.metaProjectsLink()).size();
assertTrue(projectCountAfterCreate > projectCount);
int projectVersionCount = blackDuckApiClient.getAllResponses(projectItem.metaVersionsLink()).size();
ProjectVersionRequest projectVersionRequest = new ProjectVersionRequest();
projectVersionRequest.setDistribution(ProjectVersionDistributionType.INTERNAL);
projectVersionRequest.setPhase(ProjectVersionPhaseType.DEVELOPMENT);
projectVersionRequest.setVersionName("RestConnectionTest");
ProjectVersionView projectVersionItem = projectService.createProjectVersion(projectItem, projectVersionRequest);
Optional<ProjectVersionView> projectVersionItemFromName = projectService.getProjectVersion(projectItem, "RestConnectionTest");
// should return the same project version
assertTrue(projectVersionItemFromName.isPresent());
assertEquals(projectVersionItem.toString(), projectVersionItemFromName.get().toString());
assertTrue(blackDuckApiClient.getAllResponses(projectItem.metaVersionsLink()).size() > projectVersionCount);
}
use of com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectVersionRequest in project blackduck-common by blackducksoftware.
the class ProjectServiceTestIT method testCreateDeleteWithNickname.
@Test
public void testCreateDeleteWithNickname() throws IllegalArgumentException, IntegrationException {
Long timestamp = (new Date()).getTime();
String testProjectName = "hub-common-it-ProjectServiceTest-" + timestamp;
String testProjectVersion1Name = "1";
String testProjectVersion2Name = "2";
String testProjectVersion3Name = "3";
ProjectRequest projectRequest = new ProjectRequest();
projectRequest.setName(testProjectName);
ProjectVersionWrapper projectVersionWrapper = ProjectServiceTestIT.projectService.createProject(projectRequest);
ProjectServiceTestIT.project = projectVersionWrapper.getProjectView();
HttpUrl projectUrl = ProjectServiceTestIT.project.getHref();
System.out.println("projectUrl: " + projectUrl);
ProjectVersionRequest projectVersionRequest1 = new ProjectVersionRequest();
projectVersionRequest1.setDistribution(ProjectVersionDistributionType.INTERNAL);
projectVersionRequest1.setPhase(ProjectVersionPhaseType.DEVELOPMENT);
projectVersionRequest1.setVersionName(testProjectVersion1Name);
ProjectVersionRequest projectVersionRequest2 = new ProjectVersionRequest();
projectVersionRequest2.setDistribution(ProjectVersionDistributionType.INTERNAL);
projectVersionRequest2.setPhase(ProjectVersionPhaseType.DEVELOPMENT);
projectVersionRequest2.setVersionName(testProjectVersion2Name);
ProjectVersionRequest projectVersionRequest3 = new ProjectVersionRequest();
projectVersionRequest3.setDistribution(ProjectVersionDistributionType.INTERNAL);
projectVersionRequest3.setPhase(ProjectVersionPhaseType.DEVELOPMENT);
projectVersionRequest3.setVersionName(testProjectVersion3Name);
ProjectServiceTestIT.projectService.createProjectVersion(ProjectServiceTestIT.project, projectVersionRequest1);
ProjectServiceTestIT.projectService.createProjectVersion(ProjectServiceTestIT.project, projectVersionRequest2);
ProjectServiceTestIT.projectService.createProjectVersion(ProjectServiceTestIT.project, projectVersionRequest3);
Optional<ProjectVersionView> projectVersion1 = ProjectServiceTestIT.projectService.getProjectVersion(ProjectServiceTestIT.project, testProjectVersion1Name);
assertEquals(testProjectVersion1Name, projectVersion1.get().getVersionName());
Optional<ProjectVersionView> projectVersion2 = ProjectServiceTestIT.projectService.getProjectVersion(ProjectServiceTestIT.project, testProjectVersion2Name);
assertEquals(testProjectVersion2Name, projectVersion2.get().getVersionName());
Optional<ProjectVersionView> projectVersion3 = ProjectServiceTestIT.projectService.getProjectVersion(ProjectServiceTestIT.project, testProjectVersion3Name);
assertEquals(testProjectVersion3Name, projectVersion3.get().getVersionName());
ProjectServiceTestIT.blackDuckApiClient.delete(ProjectServiceTestIT.project);
ProjectServiceTestIT.project = null;
try {
ProjectServiceTestIT.blackDuckApiClient.getResponse(projectUrl, ProjectView.class);
fail("This project should have been deleted");
} catch (Exception e) {
assertTrue(e instanceof BlackDuckApiException);
assertTrue(RestConstants.NOT_FOUND_404 == ((BlackDuckApiException) e).getOriginalIntegrationRestException().getHttpStatusCode());
}
}
use of com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectVersionRequest in project blackduck-common by blackducksoftware.
the class ProjectServiceTestIT method testCreateUpdateProjectVersion.
@Test
public void testCreateUpdateProjectVersion() throws IllegalArgumentException, IntegrationException {
String projectName = "InitialName";
deleteProjectIfExists(projectName);
ProjectRequest projectRequest = new ProjectRequest();
projectRequest.setName(projectName);
projectRequest.setProjectTier(2);
projectRequest.setDescription("Initial Description");
ProjectVersionRequest projectVersionRequest = new ProjectVersionRequest();
projectVersionRequest.setVersionName("Initial VersionName");
projectVersionRequest.setPhase(ProjectVersionPhaseType.PLANNING);
projectVersionRequest.setDistribution(ProjectVersionDistributionType.EXTERNAL);
projectRequest.setVersionRequest(projectVersionRequest);
ProjectVersionWrapper projectVersionWrapper = ProjectServiceTestIT.projectService.createProject(projectRequest);
ProjectServiceTestIT.project = projectVersionWrapper.getProjectView();
ProjectVersionView projectVersionView = projectVersionWrapper.getProjectVersionView();
assertEquals("Initial VersionName", projectVersionView.getVersionName());
assertEquals(ProjectVersionPhaseType.PLANNING, projectVersionView.getPhase());
assertEquals(ProjectVersionDistributionType.EXTERNAL, projectVersionView.getDistribution());
projectVersionView.setVersionName("New VersionName");
projectVersionView.setPhase(ProjectVersionPhaseType.DEPRECATED);
projectVersionView.setDistribution(ProjectVersionDistributionType.INTERNAL);
ProjectServiceTestIT.blackDuckApiClient.put(projectVersionView);
projectVersionView = ProjectServiceTestIT.blackDuckApiClient.getResponse(projectVersionView.getHref(), ProjectVersionView.class);
assertEquals("New VersionName", projectVersionView.getVersionName());
assertEquals(ProjectVersionPhaseType.DEPRECATED, projectVersionView.getPhase());
assertEquals(ProjectVersionDistributionType.INTERNAL, projectVersionView.getDistribution());
}
Aggregations