Search in sources :

Example 6 with ProjectSyncModel

use of com.synopsys.integration.blackduck.service.model.ProjectSyncModel in project blackduck-common by blackducksoftware.

the class UserServiceTestIT method createProjectView.

private ProjectView createProjectView() throws IntegrationException {
    String projectName = "user-group-project" + System.currentTimeMillis();
    ProjectSyncModel projectSyncModel = ProjectSyncModel.createWithDefaults(projectName, "test");
    projectService.syncProjectAndVersion(projectSyncModel);
    return projectService.getProjectByName(projectName).orElse(null);
}
Also used : ProjectSyncModel(com.synopsys.integration.blackduck.service.model.ProjectSyncModel)

Example 7 with ProjectSyncModel

use of com.synopsys.integration.blackduck.service.model.ProjectSyncModel in project blackduck-common by blackducksoftware.

the class NotificationsTestIT method testProjectNotifications.

@Test
public void testProjectNotifications() throws IntegrationException, InterruptedException {
    BlackDuckServicesFactory blackDuckServicesFactory = intHttpClientTestHelper.createBlackDuckServicesFactory();
    String projectName = "notifications_test_" + System.currentTimeMillis();
    String projectVersionName = "notifications_test_version_" + System.currentTimeMillis();
    String projectVersion2Name = "notifications_test_version2_" + System.currentTimeMillis();
    BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
    ProjectService projectService = blackDuckServicesFactory.createProjectService();
    NotificationService notificationService = blackDuckServicesFactory.createNotificationService();
    UserService userService = blackDuckServicesFactory.createUserService();
    ProjectSyncModel projectSyncModel = ProjectSyncModel.createWithDefaults(projectName, projectVersionName);
    ProjectSyncModel projectSyncModel2 = ProjectSyncModel.createWithDefaults(projectName, projectVersion2Name);
    UserView currentUser = userService.findCurrentUser();
    Date startDate = notificationService.getLatestUserNotificationDate(currentUser);
    Date endDate = Date.from(startDate.toInstant().plus(1, ChronoUnit.DAYS));
    List<String> notificationTypes = new ArrayList<>();
    notificationTypes.add(NotificationType.PROJECT.name());
    notificationTypes.add(NotificationType.PROJECT_VERSION.name());
    // CREATE
    ProjectVersionWrapper projectVersionWrapper = projectService.syncProjectAndVersion(projectSyncModel);
    ProjectVersionWrapper projectVersionWrapper2 = projectService.syncProjectAndVersion(projectSyncModel2, true);
    // DELETE
    blackDuckApiClient.delete(projectVersionWrapper2.getProjectVersionView());
    blackDuckApiClient.delete(projectVersionWrapper.getProjectView());
    // two project version create
    // one project version delete, one project delete
    Set<String> expectedKeys = new HashSet(Arrays.asList("CREATE" + projectVersionName, "CREATE" + projectVersion2Name, "DELETE" + projectName, "DELETE" + projectVersion2Name));
    Set<String> foundKeys = new HashSet<>();
    long start = System.currentTimeMillis();
    long duration = 0;
    while ((foundKeys.size() < expectedKeys.size()) && duration < FIVE_MINUTES) {
        NotificationEditor notificationEditor = new NotificationEditor(startDate, endDate, notificationTypes);
        List<NotificationUserView> notifications = notificationService.getAllUserNotifications(currentUser, notificationEditor);
        for (NotificationUserView notificationUserView : notifications) {
            if (notificationUserView instanceof ProjectNotificationUserView) {
                ProjectNotificationContent content = ((ProjectNotificationUserView) notificationUserView).getContent();
                if (projectName.equals(content.getProjectName())) {
                    foundKeys.add(content.getOperationType() + content.getProjectName());
                }
            } else if (notificationUserView instanceof ProjectVersionNotificationUserView) {
                ProjectVersionNotificationContent content = ((ProjectVersionNotificationUserView) notificationUserView).getContent();
                if (projectName.equals(content.getProjectName())) {
                    foundKeys.add(content.getOperationType() + content.getProjectVersionName());
                }
            }
        }
        Thread.sleep(2000);
        duration = System.currentTimeMillis() - start;
    }
    assertEquals(expectedKeys, foundKeys);
}
Also used : ProjectNotificationContent(com.synopsys.integration.blackduck.api.manual.component.ProjectNotificationContent) UserService(com.synopsys.integration.blackduck.service.dataservice.UserService) ProjectSyncModel(com.synopsys.integration.blackduck.service.model.ProjectSyncModel) ArrayList(java.util.ArrayList) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) ProjectService(com.synopsys.integration.blackduck.service.dataservice.ProjectService) ProjectNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.ProjectNotificationUserView) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView) ProjectVersionNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.ProjectVersionNotificationUserView) NotificationService(com.synopsys.integration.blackduck.service.dataservice.NotificationService) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) Date(java.util.Date) ProjectVersionNotificationContent(com.synopsys.integration.blackduck.api.manual.component.ProjectVersionNotificationContent) ProjectVersionNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.ProjectVersionNotificationUserView) NotificationEditor(com.synopsys.integration.blackduck.service.request.NotificationEditor) ProjectNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.ProjectNotificationUserView) NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView) ProjectVersionNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.ProjectVersionNotificationUserView) ProjectNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.ProjectNotificationUserView) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 8 with ProjectSyncModel

use of com.synopsys.integration.blackduck.service.model.ProjectSyncModel in project blackduck-common by blackducksoftware.

the class ProjectBomServiceTestIT method testAddingProjectVersionToBom.

@Test
public void testAddingProjectVersionToBom() throws Exception {
    String projectName = "adding_project_version_test";
    String projectVersionName = "1.0.0";
    String projectNameToAdd = "to_add_project";
    String projectVersionNameToAdd = "to_add_project_version";
    BlackDuckServicesFactory blackDuckServicesFactory = intHttpClientTestHelper.createBlackDuckServicesFactory();
    BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
    ProjectService projectService = blackDuckServicesFactory.createProjectService();
    ProjectBomService projectBomService = blackDuckServicesFactory.createProjectBomService();
    IntLogger logger = blackDuckServicesFactory.getLogger();
    // delete the projects, if they exist
    intHttpClientTestHelper.deleteIfProjectExists(logger, projectService, blackDuckApiClient, projectName);
    // as this might have been previously added to a bom, it might still register as in use - try a few times
    int count = 0;
    boolean succeeded = false;
    while (count < 10 && !succeeded) {
        try {
            intHttpClientTestHelper.deleteIfProjectExists(logger, projectService, blackDuckApiClient, projectNameToAdd);
            succeeded = true;
        } catch (Exception ignored) {
        // ignored
        }
        count++;
    }
    // create the projects
    ProjectSyncModel projectSyncModel = ProjectSyncModel.createWithDefaults(projectName, projectVersionName);
    ProjectVersionWrapper projectVersionWrapper = projectService.syncProjectAndVersion(projectSyncModel);
    ProjectSyncModel projectSyncModelToAdd = ProjectSyncModel.createWithDefaults(projectNameToAdd, projectVersionNameToAdd);
    ProjectVersionWrapper projectVersionWrapperToAdd = projectService.syncProjectAndVersion(projectSyncModelToAdd);
    // verify the boms
    List<ProjectVersionComponentVersionView> bomComponents = projectBomService.getComponentsForProjectVersion(projectVersionWrapper.getProjectVersionView());
    assertEquals(0, bomComponents.size());
    projectBomService.addProjectVersionToProjectVersion(projectVersionWrapperToAdd.getProjectVersionView(), projectVersionWrapper.getProjectVersionView());
    bomComponents = projectBomService.getComponentsForProjectVersion(projectVersionWrapper.getProjectVersionView());
    assertEquals(1, bomComponents.size());
}
Also used : ProjectSyncModel(com.synopsys.integration.blackduck.service.model.ProjectSyncModel) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) ProjectService(com.synopsys.integration.blackduck.service.dataservice.ProjectService) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) IntLogger(com.synopsys.integration.log.IntLogger) ProjectBomService(com.synopsys.integration.blackduck.service.dataservice.ProjectBomService) NoSuchElementException(java.util.NoSuchElementException) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) Test(org.junit.jupiter.api.Test)

Example 9 with ProjectSyncModel

use of com.synopsys.integration.blackduck.service.model.ProjectSyncModel in project blackduck-common by blackducksoftware.

the class BdioUploadRecipeTest method testBdioUploadAndMapToVersion.

@Test
public void testBdioUploadAndMapToVersion() throws InterruptedException, IntegrationException {
    assertCodeLocationDoesNotExist();
    File file = BasicRecipe.restConnectionTestHelper.getFile("bdio/hub_common_bdio_without_project_section.jsonld");
    // in this case we upload the bdio but we have to map it to a project and version ourselves since the Project information is missing in the bdio file
    IntLogger logger = new BufferedIntLogger();
    UploadBatchRunner uploadBatchRunner = new UploadBatchRunner(logger, blackDuckApiClient, apiDiscovery, BlackDuckServicesFactory.NO_THREAD_EXECUTOR_SERVICE);
    UploadBatch uploadBatch = new UploadBatch();
    uploadBatch.addUploadTarget(UploadTarget.createDefault(projectAndVersion, codeLocationName, file));
    BdioUploadCodeLocationCreationRequest scanRequest = new BdioUploadCodeLocationCreationRequest(uploadBatchRunner, uploadBatch);
    codeLocationCreationService.createCodeLocations(scanRequest);
    // now that the file is uploaded, we want to lookup the code location that was created by the upload. in this case we know the name of the code location that was specified in the bdio file
    Optional<CodeLocationView> optionalCodeLocationView = codeLocationService.getCodeLocationByName(codeLocationName);
    int maxAttempts = 6;
    int attempt = 0;
    while (!optionalCodeLocationView.isPresent() && attempt < maxAttempts) {
        // creating the code location can take a few seconds
        attempt++;
        Thread.sleep(5000);
        optionalCodeLocationView = codeLocationService.getCodeLocationByName(codeLocationName);
    }
    CodeLocationView codeLocationView = optionalCodeLocationView.get();
    // then we map the code location to a version
    String versionName = "27.0.0-SNAPSHOT";
    ProjectSyncModel projectSyncModel = ProjectSyncModel.createWithDefaults(projectAndVersion);
    projectService.createProject(projectSyncModel.createProjectRequest());
    projectVersionWrapper = projectService.getProjectVersion(projectAndVersion);
    List<CodeLocationView> versionCodeLocations = blackDuckApiClient.getAllResponses(projectVersionWrapper.get().getProjectVersionView().metaCodelocationsLink());
    assertTrue(versionCodeLocations.isEmpty());
    NotificationTaskRange notificationTaskRange = codeLocationCreationService.calculateCodeLocationRange();
    System.out.println(RestConstants.formatDate(notificationTaskRange.getStartDate()));
    System.out.println(RestConstants.formatDate(notificationTaskRange.getEndDate()));
    codeLocationService.mapCodeLocation(codeLocationView, projectVersionWrapper.get().getProjectVersionView());
    CodeLocationWaitResult waitResult = codeLocationCreationService.waitForCodeLocations(notificationTaskRange, projectAndVersion, new HashSet<>(Arrays.asList(codeLocationView.getName())), 1, 3 * 60);
    System.out.println("wait status: " + waitResult.getStatus());
    if (waitResult.getErrorMessage().isPresent()) {
        System.out.println(waitResult.getErrorMessage().get());
    }
    waitResult.getCodeLocationNames().stream().forEach(System.out::println);
    assertEquals(CodeLocationWaitResult.Status.COMPLETE, waitResult.getStatus());
    assertEquals(1, waitResult.getCodeLocationNames().size());
    assertTrue(waitResult.getCodeLocationNames().contains(codeLocationName));
    versionCodeLocations = blackDuckApiClient.getAllResponses(projectVersionWrapper.get().getProjectVersionView().metaCodelocationsLink());
    CodeLocationView versionCodeLocation = versionCodeLocations.get(0);
    assertEquals(codeLocationName, versionCodeLocation.getName());
}
Also used : ProjectSyncModel(com.synopsys.integration.blackduck.service.model.ProjectSyncModel) CodeLocationWaitResult(com.synopsys.integration.blackduck.codelocation.CodeLocationWaitResult) BdioUploadCodeLocationCreationRequest(com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadCodeLocationCreationRequest) NotificationTaskRange(com.synopsys.integration.blackduck.service.model.NotificationTaskRange) IntLogger(com.synopsys.integration.log.IntLogger) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) UploadBatch(com.synopsys.integration.blackduck.codelocation.upload.UploadBatch) File(java.io.File) UploadBatchRunner(com.synopsys.integration.blackduck.codelocation.bdiolegacy.UploadBatchRunner) Test(org.junit.jupiter.api.Test)

Example 10 with ProjectSyncModel

use of com.synopsys.integration.blackduck.service.model.ProjectSyncModel in project synopsys-detect by blackducksoftware.

the class BlackDuckAssertions method emptyOnBlackDuck.

public ProjectVersionWrapper emptyOnBlackDuck() throws IntegrationException {
    Optional<ProjectVersionWrapper> optionalProjectVersionWrapper = projectService.getProjectVersion(projectNameVersion);
    if (optionalProjectVersionWrapper.isPresent()) {
        blackDuckApiClient.delete(optionalProjectVersionWrapper.get().getProjectView());
    }
    ProjectSyncModel projectSyncModel = ProjectSyncModel.createWithDefaults(projectNameVersion);
    projectService.syncProjectAndVersion(projectSyncModel);
    optionalProjectVersionWrapper = projectService.getProjectVersion(projectNameVersion);
    assertTrue(optionalProjectVersionWrapper.isPresent());
    List<CodeLocationView> codeLocations = blackDuckApiClient.getAllResponses(optionalProjectVersionWrapper.get().getProjectVersionView().metaCodelocationsLink());
    assertEquals(0, codeLocations.size());
    List<ProjectVersionComponentVersionView> bomComponents = projectBomService.getComponentsForProjectVersion(optionalProjectVersionWrapper.get().getProjectVersionView());
    assertEquals(0, bomComponents.size());
    return optionalProjectVersionWrapper.get();
}
Also used : CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) ProjectSyncModel(com.synopsys.integration.blackduck.service.model.ProjectSyncModel) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)

Aggregations

ProjectSyncModel (com.synopsys.integration.blackduck.service.model.ProjectSyncModel)23 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)15 Test (org.junit.jupiter.api.Test)13 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)6 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)6 ProjectService (com.synopsys.integration.blackduck.service.dataservice.ProjectService)6 ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)5 ProjectRequest (com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectRequest)5 IntLogger (com.synopsys.integration.log.IntLogger)5 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)4 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)4 HttpUrl (com.synopsys.integration.rest.HttpUrl)4 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)3 ProjectBomService (com.synopsys.integration.blackduck.service.dataservice.ProjectBomService)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)2 CodeLocationView (com.synopsys.integration.blackduck.api.generated.view.CodeLocationView)2 PolicyRuleView (com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView)2 ProjectVersionRequest (com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectVersionRequest)2 BlackDuckApiException (com.synopsys.integration.blackduck.exception.BlackDuckApiException)2