Search in sources :

Example 1 with BdioUploadService

use of com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadService in project blackduck-common by blackducksoftware.

the class CreateProjectWithBdioAndVerifyBOMTest method uploadAndVerifyBdio.

private void uploadAndVerifyBdio(UploadBatch uploadBatch, Set<String> expectedCodeLocationNames) throws IntegrationException, InterruptedException {
    Date startDate = blackDuckServices.notificationService.getLatestUserNotificationDate(currentUser);
    System.out.println("start date: ");
    System.out.println(RestConstants.formatDate(startDate));
    BdioUploadService bdioUploadService = blackDuckServices.blackDuckServicesFactory.createBdioUploadService();
    CodeLocationCreationData<UploadBatchOutput> creationData = bdioUploadService.uploadBdio(uploadBatch);
    Date endDate = Date.from(new Date().toInstant().plus(7, ChronoUnit.DAYS));
    assertCodeLocationsAddedToBOM(expectedCodeLocationNames, startDate, endDate);
}
Also used : UploadBatchOutput(com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput) BdioUploadService(com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadService) Date(java.util.Date)

Example 2 with BdioUploadService

use of com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadService in project blackduck-common by blackducksoftware.

the class ComprehensiveCookbookTestIT method testPolicyStatusFromBdioImport.

@Test
public void testPolicyStatusFromBdioImport() throws Exception {
    String projectName = "ek_mtglist";
    String projectVersionName = "0.0.1";
    String codeLocationName = "ek_mtglist Black Duck I/O Export";
    String policyRuleName = "Test Rule for comprehensive policy status/bdio";
    String componentName = "Apache POI";
    String componentVersion = "3.9";
    String groupId = "org.apache.poi";
    String artifact = "poi";
    CheckPolicyData checkPolicyData = new CheckPolicyData(projectName, projectVersionName, codeLocationName, policyRuleName, componentName, componentVersion, groupId, artifact);
    BlackDuckServices blackDuckServices = new BlackDuckServices(intHttpClientTestHelper);
    setupPolicyCheck(blackDuckServices, checkPolicyData);
    UserView currentUser = blackDuckServices.userService.findCurrentUser();
    Date userStartDate = blackDuckServices.notificationService.getLatestUserNotificationDate(currentUser);
    Date systemStartDate = blackDuckServices.notificationService.getLatestNotificationDate();
    // import the bdio
    File file = intHttpClientTestHelper.getFile("bdio/mtglist_bdio.jsonld");
    UploadBatch uploadBatch = new UploadBatch(UploadTarget.createDefault(new NameVersion(projectName, projectVersionName), codeLocationName, file));
    BdioUploadService bdioUploadService = blackDuckServices.blackDuckServicesFactory.createBdioUploadService();
    UploadBatchOutput uploadBatchOutput = bdioUploadService.uploadBdioAndWait(uploadBatch, 15 * 60);
    for (UploadOutput uploadOutput : uploadBatchOutput) {
        assertEquals(Result.SUCCESS, uploadOutput.getResult());
    }
    VerifyNotifications.verify(currentUser, blackDuckServices.blackDuckRegistrationService, blackDuckServices.notificationService, userStartDate, systemStartDate);
    completePolicyCheck(blackDuckServices, checkPolicyData);
}
Also used : UploadBatchOutput(com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput) NameVersion(com.synopsys.integration.util.NameVersion) BdioUploadService(com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadService) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) UploadBatch(com.synopsys.integration.blackduck.codelocation.upload.UploadBatch) UploadOutput(com.synopsys.integration.blackduck.codelocation.upload.UploadOutput) File(java.io.File) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 3 with BdioUploadService

use of com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadService in project blackduck-common by blackducksoftware.

the class CodeLocationServiceTestIT method createAndUploadSimpleBdioObject.

private void createAndUploadSimpleBdioObject(List<String> codeLocationNames) throws IOException, IntegrationException {
    UploadBatch uploadBatch = new UploadBatch();
    for (String codeLocationName : codeLocationNames) {
        File bdioFile = File.createTempFile("bdio", "jsonld");
        bdioFile.deleteOnExit();
        ProjectDependencyGraph dependencyGraph = new ProjectDependencyGraph(Dependency.FACTORY.createMavenDependency(GROUP, PROJECT_NAME, VERSION));
        Dependency bdioTestDependency = Dependency.FACTORY.createMavenDependency(GROUP, COMPONENT_NAME, VERSION);
        dependencyGraph.addChildrenToRoot(bdioTestDependency);
        SimpleBdioDocument simpleBdioDocument = simpleBdioFactory.createPopulatedBdioDocument(codeLocationName, dependencyGraph);
        simpleBdioFactory.writeSimpleBdioDocumentToFile(bdioFile, simpleBdioDocument);
        uploadBatch.addUploadTarget(UploadTarget.createDefault(new NameVersion(PROJECT_NAME, VERSION), codeLocationName, bdioFile));
    }
    BdioUploadService bdioUploadService = blackDuckServices.blackDuckServicesFactory.createBdioUploadService();
    BdioUploadCodeLocationCreationRequest uploadRequest = bdioUploadService.createUploadRequest(uploadBatch);
    UploadBatchOutput uploadBatchOutput = bdioUploadService.uploadBdio(uploadRequest).getOutput();
    for (UploadOutput uploadOutput : uploadBatchOutput) {
        assertEquals(Result.SUCCESS, uploadOutput.getResult(), String.format("Upload result for %s was not successful", uploadOutput.getCodeLocationName()));
    }
}
Also used : UploadBatchOutput(com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput) NameVersion(com.synopsys.integration.util.NameVersion) BdioUploadService(com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadService) BdioUploadCodeLocationCreationRequest(com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadCodeLocationCreationRequest) UploadBatch(com.synopsys.integration.blackduck.codelocation.upload.UploadBatch) ProjectDependencyGraph(com.synopsys.integration.bdio.graph.ProjectDependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) UploadOutput(com.synopsys.integration.blackduck.codelocation.upload.UploadOutput) File(java.io.File) SimpleBdioDocument(com.synopsys.integration.bdio.model.SimpleBdioDocument)

Example 4 with BdioUploadService

use of com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadService in project blackduck-common by blackducksoftware.

the class CodeLocationServiceTestIT method testMappingWithProjectCodeCreator.

@Test
@Disabled
// ejk 2020-09-17 disabling this until I can figure out a better way to create the required elements for the test to pass
void testMappingWithProjectCodeCreator() throws IntegrationException, InterruptedException {
    /*
        This test requires a project/version: code_location_mapping_test_donotdelete/code_location_mapping_test_donotdelete
        Also, it requires a user, project_code_scanner, with the Project Code Scanner role on the above project.
         */
    String codeLocationName = "bdio to be mapped";
    File bdioFile = new File(getClass().getResource("/bdio/bdio_without_project.jsonld").getFile());
    UploadTarget uploadTarget = UploadTarget.createDefault(new NameVersion("inaccurate", "inaccurate"), codeLocationName, bdioFile);
    BdioUploadService bdioUploadService = blackDuckServices.blackDuckServicesFactory.createBdioUploadService();
    bdioUploadService.uploadBdio(uploadTarget);
    UserView projectCodeScanner = blackDuckServices.blackDuckServicesFactory.createUserGroupService().getUserByUsername("project_code_scanner").get();
    Optional<CodeLocationView> codeLocationView = blackDuckServices.codeLocationService.getCodeLocationByName(codeLocationName);
    int attempts = 0;
    while (!codeLocationView.isPresent()) {
        attempts++;
        if (attempts > 15) {
            fail("code location not created fast enough");
        }
        Thread.sleep(5000);
        codeLocationView = blackDuckServices.codeLocationService.getCodeLocationByName(codeLocationName);
    }
    assertTrue(StringUtils.isBlank(codeLocationView.get().getMappedProjectVersion()));
    HttpUrl codeLocationUrl = codeLocationView.get().getHref();
    // now use the project code scanner user
    BufferedIntLogger logger = new BufferedIntLogger();
    BlackDuckServerConfigBuilder projectCodeScannerBuilder = BlackDuckServerConfig.newBuilder();
    projectCodeScannerBuilder.setUrl(intHttpClientTestHelper.getProperty(TestingPropertyKey.TEST_BLACK_DUCK_SERVER_URL));
    projectCodeScannerBuilder.setUsername("project_code_scanner");
    projectCodeScannerBuilder.setPassword("super_secure_password");
    projectCodeScannerBuilder.setTrustCert(true);
    BlackDuckServicesFactory specialFactory = projectCodeScannerBuilder.build().createBlackDuckServicesFactory(logger);
    Optional<ProjectVersionWrapper> projectVersionWrapper = specialFactory.createProjectService().getProjectVersion(new NameVersion("code_location_mapping_test_donotdelete", "code_location_mapping_test_donotdelete"));
    assertTrue(projectVersionWrapper.isPresent());
    CodeLocationService specialCodeLocationService = specialFactory.createCodeLocationService();
    specialCodeLocationService.mapCodeLocation(codeLocationUrl, projectVersionWrapper.get().getProjectVersionView());
    codeLocationView = blackDuckServices.codeLocationService.getCodeLocationByName(codeLocationName);
    assertTrue(codeLocationView.isPresent());
    assertEquals(projectVersionWrapper.get().getProjectVersionView().getHref().string(), codeLocationView.get().getMappedProjectVersion());
    blackDuckServices.blackDuckApiClient.delete(codeLocationView.get());
}
Also used : BlackDuckServerConfigBuilder(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfigBuilder) UploadTarget(com.synopsys.integration.blackduck.codelocation.upload.UploadTarget) NameVersion(com.synopsys.integration.util.NameVersion) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) HttpUrl(com.synopsys.integration.rest.HttpUrl) CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) BdioUploadService(com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadService) File(java.io.File) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 5 with BdioUploadService

use of com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadService in project blackduck-docker-inspector by blackducksoftware.

the class BlackDuckClient method uploadBdio.

public void uploadBdio(File bdioFile, String codeLocationName, NameVersion projectAndVersion) throws IntegrationException {
    if (config.isOfflineMode()) {
        logger.info("Upload of BDIO has been disabled by offline mode");
        return;
    }
    logger.info("Uploading BDIO files.");
    BlackDuckHttpClient httpConnection = createHttpConnection(intLogger);
    BlackDuckServicesFactory blackDuckServicesFactory = createBlackDuckServicesFactory(intLogger, httpConnection);
    BdioUploadService bdioUploadService = blackDuckServicesFactory.createBdioUploadService();
    UploadBatch uploadBatch = new UploadBatch();
    UploadTarget uploadTarget = UploadTarget.createDefault(projectAndVersion, codeLocationName, bdioFile);
    logger.info(String.format("uploading %s", uploadTarget.getUploadFile().getName()));
    uploadBatch.addUploadTarget(uploadTarget);
    BdioUploadCodeLocationCreationRequest uploadRequest = bdioUploadService.createUploadRequest(uploadBatch);
    CodeLocationCreationData<UploadBatchOutput> bdioUploadResults = bdioUploadService.uploadBdio(uploadRequest);
    bdioUploadResults.getOutput().getOutputs().stream().forEach(o -> logger.debug(String.format("\tUpload %s: output: %s%n", o.getCodeLocationName(), o.getResponse().orElse("unknown"))));
    logger.info(String.format("Uploaded bdio file %s to %s", bdioFile.getName(), config.getBlackDuckUrl()));
}
Also used : UploadBatchOutput(com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput) UploadTarget(com.synopsys.integration.blackduck.codelocation.upload.UploadTarget) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) BdioUploadService(com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadService) BdioUploadCodeLocationCreationRequest(com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadCodeLocationCreationRequest) UploadBatch(com.synopsys.integration.blackduck.codelocation.upload.UploadBatch) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)

Aggregations

BdioUploadService (com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadService)5 UploadBatchOutput (com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput)4 UploadBatch (com.synopsys.integration.blackduck.codelocation.upload.UploadBatch)3 NameVersion (com.synopsys.integration.util.NameVersion)3 File (java.io.File)3 UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)2 BdioUploadCodeLocationCreationRequest (com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadCodeLocationCreationRequest)2 UploadOutput (com.synopsys.integration.blackduck.codelocation.upload.UploadOutput)2 UploadTarget (com.synopsys.integration.blackduck.codelocation.upload.UploadTarget)2 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)2 Date (java.util.Date)2 Test (org.junit.jupiter.api.Test)2 ProjectDependencyGraph (com.synopsys.integration.bdio.graph.ProjectDependencyGraph)1 SimpleBdioDocument (com.synopsys.integration.bdio.model.SimpleBdioDocument)1 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)1 CodeLocationView (com.synopsys.integration.blackduck.api.generated.view.CodeLocationView)1 BlackDuckServerConfigBuilder (com.synopsys.integration.blackduck.configuration.BlackDuckServerConfigBuilder)1 BlackDuckHttpClient (com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient)1 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)1 BufferedIntLogger (com.synopsys.integration.log.BufferedIntLogger)1