Search in sources :

Example 16 with CodeLocationView

use of com.synopsys.integration.blackduck.api.generated.view.CodeLocationView in project synopsys-detect by blackducksoftware.

the class ImpactAnalysisMapCodeLocationsOperation method mapCodeLocation.

// TODO: Use the method provided in blackduck-common:49.2.0
private void mapCodeLocation(HttpUrl projectVersionUrl, HttpUrl codeLocationUrl) throws IntegrationException {
    // Retrieving a Code Location with just the Project Code Scanner role is not possible so we must construct it ourselves.
    CodeLocationView codeLocationView = new CodeLocationView();
    ResourceMetadata resourceMetadata = new ResourceMetadata();
    resourceMetadata.setHref(codeLocationUrl);
    codeLocationView.setMeta(resourceMetadata);
    NullNode pathJsonNode = new JsonNodeFactory(false).nullNode();
    codeLocationView.setPatch(pathJsonNode);
    codeLocationView.setMappedProjectVersion(projectVersionUrl.string());
    blackDuckService.put(codeLocationView);
}
Also used : CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) ResourceMetadata(com.synopsys.integration.blackduck.api.core.ResourceMetadata) NullNode(com.fasterxml.jackson.databind.node.NullNode) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory)

Example 17 with CodeLocationView

use of com.synopsys.integration.blackduck.api.generated.view.CodeLocationView in project synopsys-detect by blackducksoftware.

the class UnmapCodeLocationsOperation method unmapCodeLocations.

public void unmapCodeLocations(ProjectVersionView projectVersionView) throws DetectUserFriendlyException {
    try {
        List<CodeLocationView> codeLocationViews = blackDuckService.getAllResponses(projectVersionView.metaCodelocationsLink());
        for (CodeLocationView codeLocationView : codeLocationViews) {
            codeLocationService.unmapCodeLocation(codeLocationView);
        }
        logger.info("Successfully unmapped (" + codeLocationViews.size() + ") code locations.");
    } catch (IntegrationException e) {
        String errorMessage = String.format("There was a problem unmapping Code Locations: %s", e.getMessage());
        throw new DetectUserFriendlyException(errorMessage, e, ExitCodeType.FAILURE_GENERAL_ERROR);
    }
}
Also used : CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) IntegrationException(com.synopsys.integration.exception.IntegrationException)

Example 18 with CodeLocationView

use of com.synopsys.integration.blackduck.api.generated.view.CodeLocationView in project synopsys-detect by blackducksoftware.

the class BlackDuckAssertions method deleteProjectAndCodeLocations.

public void deleteProjectAndCodeLocations() throws IntegrationException {
    Optional<ProjectVersionWrapper> optionalProjectVersionWrapper = projectService.getProjectVersion(projectNameVersion);
    if (!optionalProjectVersionWrapper.isPresent()) {
        return;
    }
    ProjectVersionWrapper projectVersionWrapper = optionalProjectVersionWrapper.get();
    List<CodeLocationView> codeLocationsToDelete = blackDuckApiClient.getAllResponses(projectVersionWrapper.getProjectVersionView().metaCodelocationsLink());
    for (CodeLocationView toDelete : codeLocationsToDelete) {
        blackDuckApiClient.delete(toDelete);
    }
    blackDuckApiClient.delete(projectVersionWrapper.getProjectView());
}
Also used : CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)

Example 19 with CodeLocationView

use of com.synopsys.integration.blackduck.api.generated.view.CodeLocationView 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)

Example 20 with CodeLocationView

use of com.synopsys.integration.blackduck.api.generated.view.CodeLocationView in project synopsys-detect by blackducksoftware.

the class ReportService method getDateTimeOfLatestScanForProjectVersion.

private LocalDateTime getDateTimeOfLatestScanForProjectVersion(ProjectVersionView projectVersion, String projectName) throws IntegrationException {
    List<CodeLocationView> codeLocations = blackDuckApiClient.getAllResponses(projectVersion.metaCodelocationsLink());
    if (codeLocations.isEmpty()) {
        logger.info(String.format("Could not find any code locations for %s - %s", projectName, projectVersion.getVersionName()));
        return null;
    }
    Date dateOfLatestScan = Collections.max(codeLocations.stream().map(CodeLocationView::getUpdatedAt).collect(Collectors.toList()));
    return convertDateToLocalDateTime(dateOfLatestScan);
}
Also used : CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) Date(java.util.Date)

Aggregations

CodeLocationView (com.synopsys.integration.blackduck.api.generated.view.CodeLocationView)26 Test (org.junit.jupiter.api.Test)9 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)8 File (java.io.File)7 ResourceMetadata (com.synopsys.integration.blackduck.api.core.ResourceMetadata)6 IntegrationException (com.synopsys.integration.exception.IntegrationException)6 BufferedIntLogger (com.synopsys.integration.log.BufferedIntLogger)6 HttpUrl (com.synopsys.integration.rest.HttpUrl)6 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)5 IntLogger (com.synopsys.integration.log.IntLogger)5 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)4 UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)4 UploadBatch (com.synopsys.integration.blackduck.codelocation.upload.UploadBatch)4 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)4 NameVersion (com.synopsys.integration.util.NameVersion)4 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)3 NullNode (com.fasterxml.jackson.databind.node.NullNode)3 BdioUploadCodeLocationCreationRequest (com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadCodeLocationCreationRequest)3 BdioUploadService (com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadService)3 UploadTarget (com.synopsys.integration.blackduck.codelocation.upload.UploadTarget)3