Search in sources :

Example 1 with ProjectVersionRequest

use of com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectVersionRequest in project blackduck-common by blackducksoftware.

the class ProjectServiceTestIT method testCreateProjectWithTwoVersions.

@Test
public void testCreateProjectWithTwoVersions() throws Exception {
    // first create a new project with a single version
    String projectName = "createWithTwo" + Instant.now().toString();
    String projectVersionName = "1.0.0";
    ProjectSyncModel projectSyncModel = ProjectSyncModel.createWithDefaults(projectName, projectVersionName);
    ProjectRequest projectRequest = projectSyncModel.createProjectRequest();
    ProjectServiceTestIT.projectService.createProject(projectRequest);
    Optional<ProjectVersionWrapper> projectVersionWrapper = ProjectServiceTestIT.projectService.getProjectVersion(projectName, projectVersionName);
    ProjectServiceTestIT.project = projectVersionWrapper.get().getProjectView();
    List<ProjectVersionView> projectVersionViews = ProjectServiceTestIT.blackDuckApiClient.getAllResponses(ProjectServiceTestIT.project.metaVersionsLink());
    assertEquals(1, projectVersionViews.size());
    Optional<ProjectVersionView> latestProjectVersionView = ProjectServiceTestIT.projectService.getNewestProjectVersion(ProjectServiceTestIT.project);
    assertTrue(latestProjectVersionView.isPresent());
    assertEquals("1.0.0", latestProjectVersionView.get().getVersionName());
    ProjectVersionRequest projectVersionRequest = projectRequest.getVersionRequest();
    projectVersionRequest.setVersionName("2.0.0");
    ProjectServiceTestIT.projectService.createProjectVersion(ProjectServiceTestIT.project, projectVersionRequest);
    List<ProjectVersionView> projectVersionViewsAfterUpdate = ProjectServiceTestIT.blackDuckApiClient.getAllResponses(ProjectServiceTestIT.project.metaVersionsLink());
    assertEquals(2, projectVersionViewsAfterUpdate.size());
    latestProjectVersionView = ProjectServiceTestIT.projectService.getNewestProjectVersion(ProjectServiceTestIT.project);
    assertTrue(latestProjectVersionView.isPresent());
    assertEquals("2.0.0", latestProjectVersionView.get().getVersionName());
}
Also used : ProjectSyncModel(com.synopsys.integration.blackduck.service.model.ProjectSyncModel) 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)

Example 2 with ProjectVersionRequest

use of com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectVersionRequest in project blackduck-common by blackducksoftware.

the class ProjectServiceTestIT method testCloning.

@Test
public void testCloning() throws Exception {
    // first create a new project with a single version
    String projectName = "create" + Instant.now().toString();
    String projectVersionName = "1.0.0";
    ProjectSyncModel projectSyncModel = ProjectSyncModel.createWithDefaults(projectName, projectVersionName);
    ProjectRequest projectRequest = projectSyncModel.createProjectRequest();
    ProjectServiceTestIT.projectService.createProject(projectRequest);
    Optional<ProjectVersionWrapper> projectVersionWrapper = ProjectServiceTestIT.projectService.getProjectVersion(projectName, projectVersionName);
    ProjectServiceTestIT.project = projectVersionWrapper.get().getProjectView();
    ProjectVersionView projectVersionView = projectVersionWrapper.get().getProjectVersionView();
    assertNotNull(ProjectServiceTestIT.project);
    assertNotNull(projectVersionView);
    HttpUrl projectUrl = ProjectServiceTestIT.project.getHref();
    HttpUrl projectVersionUrl = projectVersionView.getHref();
    List<ProjectVersionView> projectVersionViews = ProjectServiceTestIT.blackDuckApiClient.getAllResponses(ProjectServiceTestIT.project.metaVersionsLink());
    assertEquals(1, projectVersionViews.size());
    ProjectServiceTestIT.project.setCloneCategories(Arrays.asList(ProjectCloneCategoriesType.COMPONENT_DATA));
    ProjectServiceTestIT.blackDuckApiClient.put(ProjectServiceTestIT.project);
    ProjectVersionRequest projectVersionRequest = new ProjectVersionRequest();
    projectVersionRequest.setCloneFromReleaseUrl(projectVersionUrl.string());
    projectVersionRequest.setVersionName("1.0.0-clone");
    projectVersionRequest.setPhase(ProjectVersionPhaseType.DEVELOPMENT);
    projectVersionRequest.setDistribution(ProjectVersionDistributionType.OPENSOURCE);
    ProjectServiceTestIT.projectService.createProjectVersion(ProjectServiceTestIT.project, projectVersionRequest);
    projectVersionViews = ProjectServiceTestIT.blackDuckApiClient.getAllResponses(ProjectServiceTestIT.project.metaVersionsLink());
    assertEquals(2, projectVersionViews.size());
}
Also used : ProjectSyncModel(com.synopsys.integration.blackduck.service.model.ProjectSyncModel) 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) HttpUrl(com.synopsys.integration.rest.HttpUrl) ProjectVersionRequest(com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectVersionRequest) Test(org.junit.jupiter.api.Test)

Example 3 with ProjectVersionRequest

use of com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectVersionRequest in project blackduck-common by blackducksoftware.

the class ProjectServiceTestIT method testSetLicenseForProjectVersion.

@Test
public void testSetLicenseForProjectVersion() throws 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("InitialVersion");
    projectVersionRequest.setPhase(ProjectVersionPhaseType.DEVELOPMENT);
    projectVersionRequest.setDistribution(ProjectVersionDistributionType.OPENSOURCE);
    ComplexLicenseRequest complexLicenseRequest = new ComplexLicenseRequest();
    String licenseName = ".NETZ GPL 2.0 With Exception License";
    complexLicenseRequest.setLicense(licenseService.getLicenseUrlByLicenseName(licenseName).get().string());
    projectVersionRequest.setLicense(complexLicenseRequest);
    projectRequest.setVersionRequest(projectVersionRequest);
    ProjectVersionWrapper projectVersionWrapper = ProjectServiceTestIT.projectService.createProject(projectRequest);
    ProjectVersionView projectVersion = projectVersionWrapper.getProjectVersionView();
    Assertions.assertEquals(licenseName, projectVersion.getLicense().getLicenseDisplay());
}
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) ComplexLicenseRequest(com.synopsys.integration.blackduck.api.manual.temporary.component.ComplexLicenseRequest) ProjectVersionRequest(com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectVersionRequest) Test(org.junit.jupiter.api.Test)

Example 4 with ProjectVersionRequest

use of com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectVersionRequest in project blackduck-common by blackducksoftware.

the class ProjectService method syncProjectAndVersion.

public ProjectVersionWrapper syncProjectAndVersion(ProjectSyncModel projectSyncModel, boolean performUpdate) throws IntegrationException {
    String projectName = projectSyncModel.getName();
    Optional<ProjectView> optionalProjectView = getProjectByName(projectName);
    if (!optionalProjectView.isPresent()) {
        logger.info(String.format("The %s project was not found, so it will be created - if a version was included, it will also be created.", projectName));
        ProjectRequest projectRequest = projectSyncModel.createProjectRequest();
        return createProject(projectRequest);
    }
    ProjectView projectView = optionalProjectView.get();
    if (performUpdate) {
        logger.info(String.format("The %s project was found and performUpdate=true, so it will be updated.", projectName));
        projectSyncModel.populateProjectView(projectView);
        blackDuckApiClient.put(projectView);
        projectView = blackDuckApiClient.getResponse(projectView.getHref(), ProjectView.class);
    }
    ProjectVersionView projectVersionView = null;
    if (projectSyncModel.shouldHandleProjectVersion()) {
        String projectVersionName = projectSyncModel.getVersionName();
        Optional<ProjectVersionView> optionalProjectVersionView = getProjectVersion(projectView, projectVersionName);
        if (optionalProjectVersionView.isPresent()) {
            projectVersionView = optionalProjectVersionView.get();
            if (performUpdate) {
                logger.info(String.format("The %s version was found and performUpdate=true, so the version will be updated.", projectVersionName));
                projectSyncModel.populateProjectVersionView(projectVersionView);
                blackDuckApiClient.put(projectVersionView);
                projectVersionView = blackDuckApiClient.getResponse(projectVersionView.getHref(), ProjectVersionView.class);
            }
        } else {
            logger.info(String.format("The %s version was not found, so it will be created under the %s project.", projectVersionName, projectName));
            ProjectVersionRequest projectVersionRequest = projectSyncModel.createProjectVersionRequest();
            projectVersionView = createProjectVersion(projectView, projectVersionRequest);
        }
    }
    return new ProjectVersionWrapper(projectView, projectVersionView);
}
Also used : ProjectRequest(com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectRequest) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) 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)

Example 5 with ProjectVersionRequest

use of com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectVersionRequest in project blackduck-common by blackducksoftware.

the class ProjectSyncModel method createProjectVersionRequest.

public ProjectVersionRequest createProjectVersionRequest() {
    ProjectVersionRequest projectVersionRequest = new ProjectVersionRequest();
    projectVersionRequest.setDistribution(distribution);
    projectVersionRequest.setPhase(phase);
    projectVersionRequest.setVersionName(versionName);
    projectVersionRequest.setReleaseComments(releaseComments);
    projectVersionRequest.setCloneFromReleaseUrl(cloneFromReleaseUrl);
    projectVersionRequest.setReleasedOn(releasedOn);
    projectVersionRequest.setNickname(nickname);
    if (fieldSet(ProjectSyncModel.VERSION_LICENSE_URL_FIELD)) {
        // A ProjectVersionRequest with a ComplexLicenseRequest that has a null license url triggers a failure
        projectVersionRequest.setLicense(createComplexLicenseRequest());
    }
    return projectVersionRequest;
}
Also used : ProjectVersionRequest(com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectVersionRequest)

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