Search in sources :

Example 1 with BlackDuckRequestFilter

use of com.synopsys.integration.blackduck.http.BlackDuckRequestFilter in project blackduck-common by blackducksoftware.

the class NotificationEditor method edit.

@Override
public void edit(BlackDuckRequestBuilder blackDuckRequestBuilder) {
    SimpleDateFormat sdf = new SimpleDateFormat(RestConstants.JSON_DATE_FORMAT);
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    String startDateString = sdf.format(startDate);
    String endDateString = sdf.format(endDate);
    BlackDuckRequestFilter notificationTypeFilter = createFilterForNotificationsTypes(notificationTypesToInclude);
    blackDuckRequestBuilder.addQueryParameter("startDate", startDateString).addQueryParameter("endDate", endDateString).addBlackDuckFilter(notificationTypeFilter);
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) BlackDuckRequestFilter(com.synopsys.integration.blackduck.http.BlackDuckRequestFilter)

Example 2 with BlackDuckRequestFilter

use of com.synopsys.integration.blackduck.http.BlackDuckRequestFilter in project synopsys-detect by blackducksoftware.

the class MapToParentOperation method mapToParentProjectVersion.

public void mapToParentProjectVersion(String parentProjectName, String parentVersionName, ProjectVersionWrapper projectVersionWrapper) throws DetectUserFriendlyException {
    logger.debug("Will attempt to add this project to a parent.");
    String projectName = projectVersionWrapper.getProjectView().getName();
    String projectVersionName = projectVersionWrapper.getProjectVersionView().getVersionName();
    if (StringUtils.isBlank(parentProjectName) || StringUtils.isBlank(parentVersionName)) {
        String errorReason = "Both the parent project name and the parent project version name must be specified if either is specified.";
        throw new DetectUserFriendlyException(errorReason, ExitCodeType.FAILURE_CONFIGURATION);
    }
    try {
        Optional<ProjectVersionWrapper> parentWrapper = projectService.getProjectVersion(parentProjectName, parentVersionName);
        if (parentWrapper.isPresent()) {
            ProjectVersionView parentProjectVersionView = parentWrapper.get().getProjectVersionView();
            BlackDuckRequestFilter filter = BlackDuckRequestFilter.createFilterWithSingleValue("bomComponentSource", "custom_project");
            BlackDuckMultipleRequest<ProjectVersionComponentVersionView> spec = new BlackDuckRequestBuilder().commonGet().addBlackDuckFilter(filter).buildBlackDuckRequest(parentProjectVersionView.metaComponentsLink());
            List<ProjectVersionComponentVersionView> components = blackDuckService.getAllResponses(spec);
            Optional<ProjectVersionComponentVersionView> existingProjectComponent = components.stream().filter(component -> component.getComponentName().equals(projectName)).filter(component -> component.getComponentVersionName().equals(projectVersionName)).findFirst();
            if (existingProjectComponent.isPresent()) {
                logger.debug("This project already exists on the parent so it will not be added to the parent again.");
            } else {
                projectBomService.addProjectVersionToProjectVersion(projectVersionWrapper.getProjectVersionView(), parentWrapper.get().getProjectVersionView());
            }
        } else {
            throw new DetectUserFriendlyException("Unable to find parent project or parent project version on the server.", ExitCodeType.FAILURE_BLACKDUCK_FEATURE_ERROR);
        }
    } catch (IntegrationException e) {
        String errorReason = "Unable to add project to parent.";
        throw new DetectUserFriendlyException(errorReason, e, ExitCodeType.FAILURE_BLACKDUCK_FEATURE_ERROR);
    }
}
Also used : DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) ExitCodeType(com.synopsys.integration.detect.configuration.enumeration.ExitCodeType) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) IntegrationException(com.synopsys.integration.exception.IntegrationException) Logger(org.slf4j.Logger) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder) LoggerFactory(org.slf4j.LoggerFactory) ProjectBomService(com.synopsys.integration.blackduck.service.dataservice.ProjectBomService) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) StringUtils(org.apache.commons.lang3.StringUtils) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) BlackDuckMultipleRequest(com.synopsys.integration.blackduck.service.request.BlackDuckMultipleRequest) List(java.util.List) ProjectService(com.synopsys.integration.blackduck.service.dataservice.ProjectService) BlackDuckRequestFilter(com.synopsys.integration.blackduck.http.BlackDuckRequestFilter) Optional(java.util.Optional) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckRequestFilter(com.synopsys.integration.blackduck.http.BlackDuckRequestFilter) DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)

Aggregations

BlackDuckRequestFilter (com.synopsys.integration.blackduck.http.BlackDuckRequestFilter)2 ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)1 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)1 BlackDuckRequestBuilder (com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder)1 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)1 ProjectBomService (com.synopsys.integration.blackduck.service.dataservice.ProjectBomService)1 ProjectService (com.synopsys.integration.blackduck.service.dataservice.ProjectService)1 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)1 BlackDuckMultipleRequest (com.synopsys.integration.blackduck.service.request.BlackDuckMultipleRequest)1 DetectUserFriendlyException (com.synopsys.integration.detect.configuration.DetectUserFriendlyException)1 ExitCodeType (com.synopsys.integration.detect.configuration.enumeration.ExitCodeType)1 IntegrationException (com.synopsys.integration.exception.IntegrationException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 List (java.util.List)1 Optional (java.util.Optional)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1