use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class JiraIssueCommenter method addComment.
@Override
protected final void addComment(String comment, ExistingIssueDetails<String> existingIssueDetails, @Nullable ProjectIssueModel source) throws AlertException {
try {
IssueCommentRequestModel issueCommentRequestModel = new IssueCommentRequestModel(existingIssueDetails.getIssueKey(), comment);
addComment(issueCommentRequestModel);
} catch (IntegrationException e) {
throw new AlertException(String.format("Failed to add a comment in Jira. Issue Key: %s", existingIssueDetails.getIssueKey()), e);
}
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class JiraExactIssueFinder method findExistingIssuesByProjectIssueModel.
@Override
public List<ExistingIssueDetails<String>> findExistingIssuesByProjectIssueModel(ProjectIssueModel projectIssueModel) throws AlertException {
LinkableItem provider = projectIssueModel.getProvider();
LinkableItem project = projectIssueModel.getProject();
IssueBomComponentDetails bomComponent = projectIssueModel.getBomComponentDetails();
ComponentConcernType concernType = ComponentConcernType.VULNERABILITY;
String policyName = null;
Optional<IssuePolicyDetails> policyDetails = projectIssueModel.getPolicyDetails();
Optional<String> optionalPolicyName = policyDetails.map(IssuePolicyDetails::getName);
if (optionalPolicyName.isPresent()) {
concernType = ComponentConcernType.POLICY;
policyName = optionalPolicyName.get();
}
if (projectIssueModel.getComponentUnknownVersionDetails().isPresent()) {
concernType = ComponentConcernType.UNKNOWN_VERSION;
}
String jqlString = JqlStringCreator.createBlackDuckComponentConcernIssuesSearchString(jiraProjectKey, provider, project, projectIssueModel.getProjectVersion().orElse(null), bomComponent.getComponent(), bomComponent.getComponentVersion().orElse(null), concernType, policyName);
logger.debug("Searching for Jira issues with this Query: {}", jqlString);
IssueCategory issueCategory = issueCategoryRetriever.retrieveIssueCategoryFromComponentConcernType(concernType);
return jqlQueryExecutor.executeQuery(jqlString).stream().map(jiraSearcherResponseModel -> searchResultCreator.createExistingIssueDetails(jiraSearcherResponseModel, issueCategory)).collect(Collectors.toList());
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class RestChannelUtilityTest method sendMessageRuntimeExceptionTest.
@Test
public void sendMessageRuntimeExceptionTest() throws IntegrationException {
IntHttpClient intHttpClient = Mockito.mock(IntHttpClient.class);
Mockito.when(intHttpClient.execute(Mockito.any(Request.class))).thenThrow(new IllegalStateException("Something is wrong"));
RestChannelUtility restChannelUtility = new RestChannelUtility(intHttpClient);
try {
restChannelUtility.sendMessage(List.of(TEST_REQUEST, TEST_REQUEST), CLASS_NAME);
fail("Expected an exception to be thrown");
} catch (AlertException e) {
// Pass
}
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class UserActions method updateWithoutChecks.
@Override
protected ActionResponse<UserConfig> updateWithoutChecks(Long id, UserConfig resource) {
Optional<UserModel> userModel = userAccessor.getUser(id);
if (userModel.isPresent()) {
UserModel existingUser = userModel.get();
boolean passwordMissing = StringUtils.isBlank(resource.getPassword());
String userName = resource.getUsername();
String password = passwordMissing ? existingUser.getPassword() : resource.getPassword();
String emailAddress = resource.getEmailAddress();
UserModel newUserModel = UserModel.existingUser(existingUser.getId(), userName, password, emailAddress, existingUser.getAuthenticationType(), existingUser.getRoles(), existingUser.isEnabled());
try {
logger.debug(actionMessageCreator.updateStartMessage("user", userName));
userAccessor.updateUser(newUserModel, passwordMissing);
Set<String> configuredRoleNames = resource.getRoleNames();
if (null != configuredRoleNames && !configuredRoleNames.isEmpty()) {
Collection<UserRoleModel> roleNames = roleAccessor.getRoles().stream().filter(role -> configuredRoleNames.contains(role.getName())).collect(Collectors.toList());
authorizationManager.updateUserRoles(existingUser.getId(), roleNames);
}
userSystemValidator.validateDefaultAdminUser(id);
UserConfig user = userAccessor.getUser(id).map(this::convertDatabaseModelToRestModel).orElse(resource);
logger.debug(actionMessageCreator.updateSuccessMessage("User", userName));
return new ActionResponse<>(HttpStatus.NO_CONTENT);
} catch (AlertException ex) {
logger.error(actionMessageCreator.updateErrorMessage("User", userName));
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
}
}
logger.warn(actionMessageCreator.updateNotFoundMessage("User", id));
return new ActionResponse<>(HttpStatus.NOT_FOUND);
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class UserActions method createWithoutChecks.
@Override
protected ActionResponse<UserConfig> createWithoutChecks(UserConfig resource) {
try {
String userName = resource.getUsername();
String password = resource.getPassword();
String emailAddress = resource.getEmailAddress();
logger.debug(actionMessageCreator.createStartMessage("user", userName));
UserModel userModel = userAccessor.addUser(userName, password, emailAddress);
Long userId = userModel.getId();
Set<String> configuredRoleNames = resource.getRoleNames();
if (null != configuredRoleNames && !configuredRoleNames.isEmpty()) {
Collection<UserRoleModel> roleNames = roleAccessor.getRoles().stream().filter(role -> configuredRoleNames.contains(role.getName())).collect(Collectors.toList());
authorizationManager.updateUserRoles(userId, roleNames);
}
userModel = userAccessor.getUser(userId).orElse(userModel);
logger.debug(actionMessageCreator.createSuccessMessage("User", userName));
return new ActionResponse<>(HttpStatus.CREATED, convertDatabaseModelToRestModel(userModel));
} catch (AlertException ex) {
logger.error(actionMessageCreator.createErrorMessage("user", resource.getUsername()));
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, String.format("There was an issue creating the user. %s", ex.getMessage()));
}
}
Aggregations