Search in sources :

Example 6 with ProjectVersionRequest

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));
    }
}
Also used : ProjectRequest(com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectRequest) ProjectService(com.synopsys.integration.blackduck.service.dataservice.ProjectService) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) ProjectVersionRequest(com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectVersionRequest)

Example 7 with ProjectVersionRequest

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);
}
Also used : ProjectRequest(com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectRequest) ProjectService(com.synopsys.integration.blackduck.service.dataservice.ProjectService) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) ProjectVersionRequest(com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectVersionRequest)

Example 8 with ProjectVersionRequest

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);
}
Also used : ProjectRequest(com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectRequest) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) ProjectService(com.synopsys.integration.blackduck.service.dataservice.ProjectService) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) SilentIntLogger(com.synopsys.integration.log.SilentIntLogger) IntLogger(com.synopsys.integration.log.IntLogger) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) ProjectVersionRequest(com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectVersionRequest) Test(org.junit.jupiter.api.Test)

Example 9 with ProjectVersionRequest

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());
    }
}
Also used : BlackDuckApiException(com.synopsys.integration.blackduck.exception.BlackDuckApiException) ProjectRequest(com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectRequest) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) Date(java.util.Date) HttpUrl(com.synopsys.integration.rest.HttpUrl) IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckApiException(com.synopsys.integration.blackduck.exception.BlackDuckApiException) ProjectVersionRequest(com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectVersionRequest) Test(org.junit.jupiter.api.Test)

Example 10 with ProjectVersionRequest

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());
}
Also used : ProjectRequest(com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectRequest) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) ProjectVersionRequest(com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectVersionRequest) Test(org.junit.jupiter.api.Test)

Aggregations

ProjectVersionRequest (com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectVersionRequest)12 ProjectRequest (com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectRequest)11 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)11 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)7 Test (org.junit.jupiter.api.Test)6 ProjectService (com.synopsys.integration.blackduck.service.dataservice.ProjectService)5 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)3 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)2 ProjectSyncModel (com.synopsys.integration.blackduck.service.model.ProjectSyncModel)2 HttpUrl (com.synopsys.integration.rest.HttpUrl)2 ComplexLicenseRequest (com.synopsys.integration.blackduck.api.manual.temporary.component.ComplexLicenseRequest)1 BlackDuckApiException (com.synopsys.integration.blackduck.exception.BlackDuckApiException)1 IntegrationException (com.synopsys.integration.exception.IntegrationException)1 IntLogger (com.synopsys.integration.log.IntLogger)1 SilentIntLogger (com.synopsys.integration.log.SilentIntLogger)1 Date (java.util.Date)1