Search in sources :

Example 1 with ProjectRequest

use of com.blackducksoftware.integration.hub.api.generated.component.ProjectRequest in project hub-alert by blackducksoftware.

the class AccumulatorProcessorTestIT method testProcess.

@Test
public void testProcess() throws Exception {
    final Long timestamp = (new Date()).getTime();
    final String testProjectName = "hub-Alert-NotificationAccumulatorTest-" + timestamp;
    final String testProjectVersionName = "1.0.0";
    final ProjectRequest projectRequest = new ProjectRequest();
    projectRequest.name = testProjectName;
    final String projectUrl = projectService.createHubProject(projectRequest);
    final ProjectView projectItem = hubService.getResponse(projectUrl, ProjectView.class);
    System.out.println("projectUrl: " + projectUrl);
    final ProjectVersionRequest projectVersionRequest = new ProjectVersionRequest();
    projectVersionRequest.distribution = ProjectVersionDistributionType.INTERNAL;
    projectVersionRequest.phase = ProjectVersionPhaseType.DEVELOPMENT;
    projectVersionRequest.versionName = testProjectVersionName;
    projectService.createHubVersion(projectItem, projectVersionRequest);
    uploadBdio("bdio/component-bdio.jsonld");
    TimeUnit.SECONDS.sleep(60);
    final NotificationResults notificationData = notificationDataService.getAllNotificationResults(new Date(System.currentTimeMillis() - 100000), new Date());
    final AccumulatorProcessor accumulatorProcessor = new AccumulatorProcessor(globalProperties);
    final DBStoreEvent storeEvent = accumulatorProcessor.process(notificationData);
    assertNotNull(storeEvent);
    final List<NotificationEvent> notificationEvents = storeEvent.getNotificationList();
    assertFalse(notificationEvents.isEmpty());
    assertEquals(storeEvent.getEventId().length(), 36);
    NotificationEvent apacheEvent = null;
    for (final NotificationEvent event : notificationEvents) {
        System.out.println(event);
        if ("Apache Commons FileUpload".equals(event.getDataSet().get("COMPONENT"))) {
            apacheEvent = event;
        }
    }
    assertNotNull(apacheEvent);
    final AccumulatorProcessor accumulatorProcessorNull = new AccumulatorProcessor(null);
    final DBStoreEvent storeEventNull = accumulatorProcessorNull.process(notificationData);
    assertNull(storeEventNull);
}
Also used : NotificationResults(com.blackducksoftware.integration.hub.notification.NotificationResults) ProjectRequest(com.blackducksoftware.integration.hub.api.generated.component.ProjectRequest) DBStoreEvent(com.blackducksoftware.integration.hub.alert.event.DBStoreEvent) NotificationEvent(com.blackducksoftware.integration.hub.notification.NotificationEvent) ProjectView(com.blackducksoftware.integration.hub.api.generated.view.ProjectView) Date(java.util.Date) ProjectVersionRequest(com.blackducksoftware.integration.hub.api.generated.component.ProjectVersionRequest) Test(org.junit.Test) HubConnectionTest(com.blackducksoftware.integration.test.annotation.HubConnectionTest)

Example 2 with ProjectRequest

use of com.blackducksoftware.integration.hub.api.generated.component.ProjectRequest in project hub-detect by blackducksoftware.

the class HubManager method ensureProjectVersionExists.

public ProjectVersionView ensureProjectVersionExists(final DetectProject detectProject, final ProjectService projectService) throws IntegrationException {
    final ProjectRequestBuilder builder = new ProjectRequestBuilder();
    builder.setProjectName(detectProject.getProjectName());
    builder.setVersionName(detectProject.getProjectVersionName());
    builder.setProjectLevelAdjustments(detectConfiguration.getProjectLevelMatchAdjustments());
    builder.setPhase(detectConfiguration.getProjectVersionPhase());
    builder.setDistribution(detectConfiguration.getProjectVersionDistribution());
    builder.setProjectTier(detectConfiguration.getProjectTier());
    builder.setReleaseComments(detectConfiguration.getProjectVersionNotes());
    final ProjectRequest projectRequest = builder.build();
    final ProjectVersionWrapper projectVersionWrapper = projectService.getProjectVersionAndCreateIfNeeded(projectRequest);
    return projectVersionWrapper.getProjectVersionView();
}
Also used : ProjectRequestBuilder(com.blackducksoftware.integration.hub.service.model.ProjectRequestBuilder) ProjectRequest(com.blackducksoftware.integration.hub.api.generated.component.ProjectRequest) ProjectVersionWrapper(com.blackducksoftware.integration.hub.service.model.ProjectVersionWrapper)

Example 3 with ProjectRequest

use of com.blackducksoftware.integration.hub.api.generated.component.ProjectRequest in project hub-detect by blackducksoftware.

the class HubSignatureScanner method scanPaths.

public ProjectVersionView scanPaths(final HubServerConfig hubServerConfig, final SignatureScannerService signatureScannerService, final DetectProject detectProject) throws IntegrationException {
    ProjectVersionView projectVersionView = null;
    final ProjectRequest projectRequest = createProjectRequest(detectProject);
    Set<String> canonicalPathsToScan = registeredPaths;
    if (null != detectProject.getProjectName() && null != detectProject.getProjectVersionName() && null != detectConfiguration.getHubSignatureScannerPaths() && detectConfiguration.getHubSignatureScannerPaths().length > 0) {
        canonicalPathsToScan = new HashSet<>();
        for (final String path : detectConfiguration.getHubSignatureScannerPaths()) {
            try {
                canonicalPathsToScan.add(new File(path).getCanonicalPath());
            } catch (final IOException e) {
                throw new IntegrationException(e.getMessage(), e);
            }
        }
    }
    final List<ScanPathCallable> scanPathCallables = new ArrayList<>();
    for (final String canonicalPath : canonicalPathsToScan) {
        final HubScanConfigBuilder hubScanConfigBuilder = createScanConfigBuilder(detectProject, canonicalPath);
        final HubScanConfig hubScanConfig = hubScanConfigBuilder.build();
        final ScanPathCallable scanPathCallable = new ScanPathCallable(signatureScannerService, hubServerConfig, hubScanConfig, projectRequest, canonicalPath, scanSummaryResults);
        scanPathCallables.add(scanPathCallable);
    }
    final ExecutorService pool = Executors.newFixedThreadPool(detectConfiguration.getHubSignatureScannerParallelProcessors());
    try {
        for (final ScanPathCallable scanPathCallable : scanPathCallables) {
            pool.submit(scanPathCallable);
        }
        for (final ScanPathCallable scanPathCallable : scanPathCallables) {
            final ProjectVersionWrapper projectVersionWrapperFromScan = scanPathCallable.call();
            if (projectVersionWrapperFromScan != null) {
                projectVersionView = projectVersionWrapperFromScan.getProjectVersionView();
            }
        }
    } finally {
        // get() was called on every java.util.concurrent.Future, no need to wait any longer
        pool.shutdownNow();
    }
    return projectVersionView;
}
Also used : HubScanConfigBuilder(com.blackducksoftware.integration.hub.configuration.HubScanConfigBuilder) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) HubScanConfig(com.blackducksoftware.integration.hub.configuration.HubScanConfig) ProjectRequest(com.blackducksoftware.integration.hub.api.generated.component.ProjectRequest) ProjectVersionView(com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView) ExecutorService(java.util.concurrent.ExecutorService) File(java.io.File) ProjectVersionWrapper(com.blackducksoftware.integration.hub.service.model.ProjectVersionWrapper)

Aggregations

ProjectRequest (com.blackducksoftware.integration.hub.api.generated.component.ProjectRequest)3 ProjectVersionWrapper (com.blackducksoftware.integration.hub.service.model.ProjectVersionWrapper)2 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)1 DBStoreEvent (com.blackducksoftware.integration.hub.alert.event.DBStoreEvent)1 ProjectVersionRequest (com.blackducksoftware.integration.hub.api.generated.component.ProjectVersionRequest)1 ProjectVersionView (com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView)1 ProjectView (com.blackducksoftware.integration.hub.api.generated.view.ProjectView)1 HubScanConfig (com.blackducksoftware.integration.hub.configuration.HubScanConfig)1 HubScanConfigBuilder (com.blackducksoftware.integration.hub.configuration.HubScanConfigBuilder)1 NotificationEvent (com.blackducksoftware.integration.hub.notification.NotificationEvent)1 NotificationResults (com.blackducksoftware.integration.hub.notification.NotificationResults)1 ProjectRequestBuilder (com.blackducksoftware.integration.hub.service.model.ProjectRequestBuilder)1 HubConnectionTest (com.blackducksoftware.integration.test.annotation.HubConnectionTest)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 ExecutorService (java.util.concurrent.ExecutorService)1 Test (org.junit.Test)1