Search in sources :

Example 6 with AlertRuntimeException

use of com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException in project hub-alert by blackducksoftware.

the class IssueTrackerSearcher method findIssues.

public final List<ActionableIssueSearchResult<T>> findIssues(ProjectMessage projectMessage) throws AlertException {
    ProviderDetails providerDetails = projectMessage.getProviderDetails();
    LinkableItem project = projectMessage.getProject();
    MessageReason messageReason = projectMessage.getMessageReason();
    boolean isEntireBomDeleted = projectMessage.getOperation().filter(ProjectOperation.DELETE::equals).isPresent();
    if (MessageReason.PROJECT_STATUS.equals(messageReason)) {
        return findProjectIssues(isEntireBomDeleted, () -> projectIssueFinder.findProjectIssues(providerDetails, project));
    }
    LinkableItem projectVersion = projectMessage.getProjectVersion().orElseThrow(() -> new AlertRuntimeException("Missing project version"));
    if (MessageReason.PROJECT_VERSION_STATUS.equals(messageReason)) {
        return findProjectIssues(isEntireBomDeleted, () -> projectVersionIssueFinder.findProjectVersionIssues(providerDetails, project, projectVersion));
    }
    if (MessageReason.COMPONENT_UPDATE.equals(messageReason)) {
        return findIssuesByAllComponents(providerDetails, project, projectVersion, projectMessage.getBomComponents());
    }
    List<ProjectIssueModel> projectIssueModels = modelTransformer.convertToIssueModels(projectMessage);
    List<ActionableIssueSearchResult<T>> projectIssueSearchResults = new LinkedList<>();
    for (ProjectIssueModel projectIssueModel : projectIssueModels) {
        ActionableIssueSearchResult<T> searchResult = findIssueByProjectIssueModel(projectIssueModel);
        if (searchResult.getExistingIssueDetails().isEmpty() && isOnlyDeleteOperation(projectIssueModel)) {
            logger.debug("Ignoring component-level notification for issue-tracker because no matching issue(s) existed and it only contained DELETE operations");
        } else {
            projectIssueSearchResults.add(searchResult);
        }
    }
    return projectIssueSearchResults;
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ProviderDetails(com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails) MessageReason(com.synopsys.integration.alert.processor.api.extract.model.project.MessageReason) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) LinkedList(java.util.LinkedList) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) ProjectOperation(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectOperation)

Example 7 with AlertRuntimeException

use of com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException 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 8 with AlertRuntimeException

use of com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException 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)

Example 9 with AlertRuntimeException

use of com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException in project hub-alert by blackducksoftware.

the class JiraIssueCreator method createSearchProperties.

private JiraIssueSearchProperties createSearchProperties(ProjectIssueModel alertIssueSource) {
    LinkableItem provider = alertIssueSource.getProvider();
    LinkableItem project = alertIssueSource.getProject();
    LinkableItem projectVersion = alertIssueSource.getProjectVersion().orElseThrow(() -> new AlertRuntimeException("Missing project version"));
    IssueBomComponentDetails bomComponent = alertIssueSource.getBomComponentDetails();
    LinkableItem component = bomComponent.getComponent();
    String componentVersionLabel = bomComponent.getComponentVersion().map(LinkableItem::getLabel).orElse(null);
    String componentVersionName = bomComponent.getComponentVersion().map(LinkableItem::getValue).orElse(null);
    String additionalKey = null;
    ComponentConcernType concernType = ComponentConcernType.VULNERABILITY;
    Optional<String> optionalPolicyName = alertIssueSource.getPolicyDetails().map(IssuePolicyDetails::getName);
    if (optionalPolicyName.isPresent()) {
        concernType = ComponentConcernType.POLICY;
        additionalKey = JiraIssueSearchPropertyStringCompatibilityUtils.createPolicyAdditionalKey(optionalPolicyName.get());
    }
    if (alertIssueSource.getComponentUnknownVersionDetails().isPresent()) {
        concernType = ComponentConcernType.UNKNOWN_VERSION;
    }
    String category = JiraIssueSearchPropertyStringCompatibilityUtils.createCategory(concernType);
    return new JiraIssueSearchProperties(provider.getLabel(), provider.getUrl().flatMap(JiraIssueAlertPropertiesUrlCorrector::correctUrl).orElse(null), project.getLabel(), project.getValue(), projectVersion.getLabel(), projectVersion.getValue(), category, component.getLabel(), component.getValue(), componentVersionLabel, componentVersionName, additionalKey);
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ComponentConcernType(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) JiraIssueSearchProperties(com.synopsys.integration.alert.api.channel.jira.JiraIssueSearchProperties) JiraIssueAlertPropertiesUrlCorrector(com.synopsys.integration.alert.api.channel.jira.distribution.search.JiraIssueAlertPropertiesUrlCorrector) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)

Example 10 with AlertRuntimeException

use of com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException in project hub-alert by blackducksoftware.

the class JiraCustomFieldResolver method retrieveCustomFieldDefinition.

protected CustomFieldDefinitionModel retrieveCustomFieldDefinition(JiraCustomFieldConfig customFieldConfig) {
    String fieldName = customFieldConfig.getFieldName();
    CustomFieldCreationResponseModel fieldResponse = retrieveFieldDefinition(fieldName).orElseThrow(() -> new AlertRuntimeException(String.format("No custom field named '%s' existed", fieldName)));
    return new CustomFieldDefinitionModel(fieldResponse.getId(), fieldResponse.getSchema().getType(), fieldResponse.getSchema().getItems());
}
Also used : CustomFieldCreationResponseModel(com.synopsys.integration.jira.common.model.response.CustomFieldCreationResponseModel) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)

Aggregations

AlertRuntimeException (com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)22 ConfigurationModelMutable (com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable)4 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)3 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)3 RegisteredDescriptorModel (com.synopsys.integration.alert.common.persistence.model.RegisteredDescriptorModel)3 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)3 IntegrationException (com.synopsys.integration.exception.IntegrationException)3 ArrayList (java.util.ArrayList)3 IssueBomComponentDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails)2 IssuePolicyDetails (com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)2 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)2 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)2 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)2 DefinedFieldModel (com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel)2 ProviderProject (com.synopsys.integration.alert.common.persistence.model.ProviderProject)2 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)2 FieldValueModel (com.synopsys.integration.alert.common.rest.model.FieldValueModel)2 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)2 HashMap (java.util.HashMap)2 List (java.util.List)2