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;
}
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;
}
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;
}
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);
}
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());
}
Aggregations