Search in sources :

Example 11 with IntegrationException

use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class BlackDuckProviderIssueHandler method retrieveExistingIssue.

private Optional<ProjectVersionIssuesView> retrieveExistingIssue(String projectVersionUrl, String blackDuckIssueId) throws IntegrationException {
    HttpUrl projectVersionHttpUrl = new HttpUrl(projectVersionUrl);
    ProjectVersionView projectVersion = blackDuckApiClient.getResponse(projectVersionHttpUrl, ProjectVersionView.class);
    List<ProjectVersionIssuesView> bomComponentIssues = issueService.getIssuesForProjectVersion(projectVersion);
    return bomComponentIssues.stream().filter(issue -> issue.getIssueId().equals(blackDuckIssueId)).findAny();
}
Also used : IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder) IssueRequest(com.synopsys.integration.blackduck.api.manual.temporary.component.IssueRequest) Date(java.util.Date) StringBodyContent(com.synopsys.integration.rest.body.StringBodyContent) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) Instant(java.time.Instant) HttpUrl(com.synopsys.integration.rest.HttpUrl) Nullable(org.jetbrains.annotations.Nullable) ProjectVersionIssuesView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionIssuesView) List(java.util.List) HttpMethod(com.synopsys.integration.rest.HttpMethod) Gson(com.google.gson.Gson) Optional(java.util.Optional) IssueService(com.synopsys.integration.blackduck.service.dataservice.IssueService) BlackDuckResponseRequest(com.synopsys.integration.blackduck.service.request.BlackDuckResponseRequest) BodyContentConverter(com.synopsys.integration.rest.body.BodyContentConverter) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) ProjectVersionIssuesView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionIssuesView) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Example 12 with IntegrationException

use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class AbstractBlackDuckComponentConcernMessageExtractor method extract.

@Override
protected final ProviderMessageHolder extract(NotificationContentWrapper notificationContentWrapper, T notificationContent) {
    AlertNotificationModel notificationModel = notificationContentWrapper.getAlertNotificationModel();
    Long providerConfigId = notificationModel.getProviderConfigId();
    String providerUrl;
    List<BomComponentDetails> bomComponentDetails;
    try {
        BlackDuckServicesFactory blackDuckServicesFactory = servicesFactoryCache.retrieveBlackDuckServicesFactory(providerConfigId);
        providerUrl = blackDuckServicesFactory.getBlackDuckHttpClient().getBlackDuckUrl().string();
        bomComponentDetails = createBomComponentDetails(notificationContent, blackDuckServicesFactory);
    } catch (AlertConfigurationException e) {
        logger.warn("Invalid BlackDuck configuration for notification. ID: {}. Name: {}", providerConfigId, notificationModel.getProviderConfigName(), e);
        return ProviderMessageHolder.empty();
    } catch (IntegrationException e) {
        logger.warn("Failed to retrieve BOM Component(s) from BlackDuck", e);
        return ProviderMessageHolder.empty();
    }
    LinkableItem providerItem = new LinkableItem(blackDuckProviderKey.getDisplayName(), notificationModel.getProviderConfigName(), providerUrl);
    ProviderDetails providerDetails = new ProviderDetails(notificationModel.getProviderConfigId(), providerItem);
    Optional<String> projectUrl = extractProjectUrl(notificationContent.getProjectVersionUrl());
    LinkableItem project = new LinkableItem(BlackDuckMessageLabels.LABEL_PROJECT, notificationContent.getProjectName(), projectUrl.orElse(null));
    LinkableItem projectVersion = new LinkableItem(BlackDuckMessageLabels.LABEL_PROJECT_VERSION, notificationContent.getProjectVersionName(), notificationContent.getProjectVersionUrl());
    // FIXME this is where I should put the additional info
    ProjectMessage projectMessage = createProjectMessage(providerDetails, project, projectVersion, bomComponentDetails);
    return new ProviderMessageHolder(List.of(projectMessage), List.of());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IntegrationException(com.synopsys.integration.exception.IntegrationException) ProviderDetails(com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Example 13 with IntegrationException

use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class BlackDuckSystemValidator method validate.

public boolean validate(BlackDuckProperties blackDuckProperties) {
    boolean valid = true;
    String configName = blackDuckProperties.getConfigName();
    logger.info("Validating Black Duck configuration '{}'...", configName);
    try {
        Optional<String> blackDuckUrlOptional = blackDuckProperties.getBlackDuckUrl();
        removeOldConfigMessages(blackDuckProperties, SystemMessageType.BLACKDUCK_PROVIDER_CONNECTIVITY, SystemMessageType.BLACKDUCK_PROVIDER_LOCALHOST, SystemMessageType.BLACKDUCK_PROVIDER_URL_MISSING);
        String errorMessage = String.format(MISSING_BLACKDUCK_URL_ERROR_W_CONFIG_FORMAT, configName);
        String urlMissingType = createProviderSystemMessageType(blackDuckProperties, SystemMessageType.BLACKDUCK_PROVIDER_URL_MISSING);
        boolean missingUrl = addSystemMessageForError(errorMessage, SystemMessageSeverity.WARNING, urlMissingType, blackDuckUrlOptional.isEmpty());
        if (missingUrl) {
            logger.error("  -> {}", String.format(MISSING_BLACKDUCK_CONFIG_ERROR_FORMAT, configName));
            valid = false;
        }
        if (blackDuckUrlOptional.isPresent()) {
            String blackDuckUrlString = blackDuckUrlOptional.get();
            Integer timeout = blackDuckProperties.getBlackDuckTimeout();
            logger.debug("  -> Black Duck configuration '{}' URL found validating: {}", configName, blackDuckUrlString);
            logger.debug("  -> Black Duck configuration '{}' Timeout: {}", configName, timeout);
            URL blackDuckUrl = new URL(blackDuckUrlString);
            String localhostMissingType = createProviderSystemMessageType(blackDuckProperties, SystemMessageType.BLACKDUCK_PROVIDER_LOCALHOST);
            boolean localHostError = addSystemMessageForError(String.format(BLACKDUCK_LOCALHOST_ERROR_FORMAT, configName), SystemMessageSeverity.WARNING, localhostMissingType, "localhost".equals(blackDuckUrl.getHost()));
            if (localHostError) {
                logger.warn("  -> {}", String.format(BLACKDUCK_LOCALHOST_ERROR_FORMAT, configName));
            }
            IntLogger intLogger = new Slf4jIntLogger(logger);
            BlackDuckServerConfig blackDuckServerConfig = blackDuckProperties.createBlackDuckServerConfig(intLogger);
            boolean canConnect = blackDuckServerConfig.canConnect(intLogger);
            if (canConnect) {
                logger.info("  -> Black Duck configuration '{}' is Valid!", configName);
            } else {
                String message = String.format("Can not connect to the Black Duck server with the configuration '%s'.", configName);
                connectivityWarning(blackDuckProperties, message);
                valid = false;
            }
        } else {
            String message = String.format("The Black Duck configuration '%s' is not valid.", configName);
            connectivityWarning(blackDuckProperties, message);
            valid = false;
        }
        BlackDuckApiTokenValidator blackDuckAPITokenValidator = new BlackDuckApiTokenValidator(blackDuckProperties);
        if (!blackDuckAPITokenValidator.isApiTokenValid()) {
            connectivityWarning(blackDuckProperties, BLACKDUCK_API_PERMISSION_FORMAT);
            valid = false;
        }
    } catch (MalformedURLException | IntegrationException | AlertRuntimeException ex) {
        logger.error("  -> Black Duck configuration '{}' is invalid; cause: {}", configName, ex.getMessage());
        logger.debug(String.format("  -> Black Duck configuration '%s' Stack Trace: ", configName), ex);
        valid = false;
    }
    return valid;
}
Also used : MalformedURLException(java.net.MalformedURLException) IntegrationException(com.synopsys.integration.exception.IntegrationException) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) IntLogger(com.synopsys.integration.log.IntLogger) URL(java.net.URL) BlackDuckServerConfig(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)

Example 14 with IntegrationException

use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class BlackDuckSSOConfigRetriever method retrieve.

public BlackDuckSSOConfigView retrieve() throws AlertException {
    BlackDuckRequestBuilder requestBuilder = new BlackDuckRequestBuilder().acceptMimeType(SSO_CONFIGURATION_MIME_TYPE);
    UrlSingleResponse<BlackDuckSSOConfigView> ssoConfigurationSingleResponse = apiDiscovery.metaSingleResponse(SSO_CONFIGURATION_PATH);
    BlackDuckRequest<BlackDuckSSOConfigView, UrlSingleResponse<BlackDuckSSOConfigView>> ssoConfigurationRequest = new BlackDuckRequest<>(requestBuilder, ssoConfigurationSingleResponse);
    try {
        return blackDuckApiClient.getResponse(ssoConfigurationRequest);
    } catch (IntegrationException e) {
        String errorMessage = String.format("Unable to retrieve SSO configuration from Black Duck: %s", e.getMessage());
        throw new AlertException(errorMessage, e);
    }
}
Also used : UrlSingleResponse(com.synopsys.integration.blackduck.api.core.response.UrlSingleResponse) IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder) BlackDuckRequest(com.synopsys.integration.blackduck.service.request.BlackDuckRequest) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 15 with IntegrationException

use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class BlackDuckDataSyncTask method getEmailsPerProject.

private Map<ProviderProject, Set<String>> getEmailsPerProject(Map<ProjectView, ProviderProject> blackDuckToAlertProjects, ProjectUsersService projectUsersService) {
    Map<ProviderProject, Set<String>> projectToEmailAddresses = new ConcurrentHashMap<>();
    blackDuckToAlertProjects.entrySet().parallelStream().forEach(entry -> {
        try {
            ProjectView blackDuckProjectView = entry.getKey();
            ProviderProject alertProject = entry.getValue();
            Set<String> projectUserEmailAddresses = projectUsersService.getAllActiveUsersForProject(blackDuckProjectView).stream().filter(UserView::getActive).map(UserView::getEmail).filter(StringUtils::isNotBlank).collect(Collectors.toSet());
            if (StringUtils.isNotBlank(alertProject.getProjectOwnerEmail())) {
                projectUserEmailAddresses.add(alertProject.getProjectOwnerEmail());
            }
            projectToEmailAddresses.put(alertProject, projectUserEmailAddresses);
        } catch (IntegrationException e) {
            // We do this to break out of the stream
            throw new AlertRuntimeException(e.getMessage(), e);
        }
    });
    return projectToEmailAddresses;
}
Also used : Set(java.util.Set) IntegrationException(com.synopsys.integration.exception.IntegrationException) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

IntegrationException (com.synopsys.integration.exception.IntegrationException)53 HttpUrl (com.synopsys.integration.rest.HttpUrl)19 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)14 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)13 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)12 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)11 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)10 UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)9 ArrayList (java.util.ArrayList)9 ProviderProject (com.synopsys.integration.alert.common.persistence.model.ProviderProject)8 Slf4jIntLogger (com.synopsys.integration.log.Slf4jIntLogger)8 Set (java.util.Set)8 Test (org.junit.jupiter.api.Test)8 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)7 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)7 List (java.util.List)7 Optional (java.util.Optional)7 AlertFieldException (com.synopsys.integration.alert.common.exception.AlertFieldException)6 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)6 AlertPagedModel (com.synopsys.integration.alert.common.rest.model.AlertPagedModel)6