Search in sources :

Example 36 with AlertException

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);
    }
}
Also used : IntegrationException(com.synopsys.integration.exception.IntegrationException) IssueCommentRequestModel(com.synopsys.integration.jira.common.model.request.IssueCommentRequestModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 37 with AlertException

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());
}
Also used : Logger(org.slf4j.Logger) ExactIssueFinder(com.synopsys.integration.alert.api.channel.issue.search.ExactIssueFinder) ComponentConcernType(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType) LoggerFactory(org.slf4j.LoggerFactory) IssueCategory(com.synopsys.integration.alert.api.channel.issue.search.enumeration.IssueCategory) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ExistingIssueDetails(com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails) Collectors(java.util.stream.Collectors) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) List(java.util.List) Optional(java.util.Optional) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) IssueCategoryRetriever(com.synopsys.integration.alert.api.channel.issue.search.IssueCategoryRetriever) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ComponentConcernType(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType) IssueCategory(com.synopsys.integration.alert.api.channel.issue.search.enumeration.IssueCategory) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)

Example 38 with AlertException

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
    }
}
Also used : IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) Request(com.synopsys.integration.rest.request.Request) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test)

Example 39 with AlertException

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);
}
Also used : UserModel(com.synopsys.integration.alert.common.persistence.model.UserModel) UserManagementDescriptorKey(com.synopsys.integration.alert.component.users.UserManagementDescriptorKey) AbstractResourceActions(com.synopsys.integration.alert.common.action.api.AbstractResourceActions) StringUtils(org.apache.commons.lang.StringUtils) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) UserModel(com.synopsys.integration.alert.common.persistence.model.UserModel) Autowired(org.springframework.beans.factory.annotation.Autowired) DefaultUserRole(com.synopsys.integration.alert.common.enumeration.DefaultUserRole) UserSystemValidator(com.synopsys.integration.alert.component.users.UserSystemValidator) ArrayList(java.util.ArrayList) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) AlertLoggerFactory(com.synopsys.integration.alert.common.logging.AlertLoggerFactory) ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) ActionMessageCreator(com.synopsys.integration.alert.common.action.api.ActionMessageCreator) AuthenticationTypeDetails(com.synopsys.integration.alert.common.persistence.model.AuthenticationTypeDetails) UserAccessor(com.synopsys.integration.alert.common.persistence.accessor.UserAccessor) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) Logger(org.slf4j.Logger) Collection(java.util.Collection) Set(java.util.Set) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) Collectors(java.util.stream.Collectors) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) HttpStatus(org.springframework.http.HttpStatus) RoleAccessor(com.synopsys.integration.alert.common.descriptor.accessor.RoleAccessor) List(java.util.List) Component(org.springframework.stereotype.Component) AuthenticationTypeAccessor(com.synopsys.integration.alert.common.persistence.accessor.AuthenticationTypeAccessor) NumberUtils(org.apache.commons.lang3.math.NumberUtils) Optional(java.util.Optional) UserRoleModel(com.synopsys.integration.alert.common.persistence.model.UserRoleModel) Transactional(org.springframework.transaction.annotation.Transactional) UserRoleModel(com.synopsys.integration.alert.common.persistence.model.UserRoleModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 40 with AlertException

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()));
    }
}
Also used : UserModel(com.synopsys.integration.alert.common.persistence.model.UserModel) UserManagementDescriptorKey(com.synopsys.integration.alert.component.users.UserManagementDescriptorKey) AbstractResourceActions(com.synopsys.integration.alert.common.action.api.AbstractResourceActions) StringUtils(org.apache.commons.lang.StringUtils) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) UserModel(com.synopsys.integration.alert.common.persistence.model.UserModel) Autowired(org.springframework.beans.factory.annotation.Autowired) DefaultUserRole(com.synopsys.integration.alert.common.enumeration.DefaultUserRole) UserSystemValidator(com.synopsys.integration.alert.component.users.UserSystemValidator) ArrayList(java.util.ArrayList) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) AlertLoggerFactory(com.synopsys.integration.alert.common.logging.AlertLoggerFactory) ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) ActionMessageCreator(com.synopsys.integration.alert.common.action.api.ActionMessageCreator) AuthenticationTypeDetails(com.synopsys.integration.alert.common.persistence.model.AuthenticationTypeDetails) UserAccessor(com.synopsys.integration.alert.common.persistence.accessor.UserAccessor) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) Logger(org.slf4j.Logger) Collection(java.util.Collection) Set(java.util.Set) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) Collectors(java.util.stream.Collectors) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) HttpStatus(org.springframework.http.HttpStatus) RoleAccessor(com.synopsys.integration.alert.common.descriptor.accessor.RoleAccessor) List(java.util.List) Component(org.springframework.stereotype.Component) AuthenticationTypeAccessor(com.synopsys.integration.alert.common.persistence.accessor.AuthenticationTypeAccessor) NumberUtils(org.apache.commons.lang3.math.NumberUtils) Optional(java.util.Optional) UserRoleModel(com.synopsys.integration.alert.common.persistence.model.UserRoleModel) Transactional(org.springframework.transaction.annotation.Transactional) UserRoleModel(com.synopsys.integration.alert.common.persistence.model.UserRoleModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Aggregations

AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)101 Test (org.junit.jupiter.api.Test)35 MessageResult (com.synopsys.integration.alert.common.message.model.MessageResult)22 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)18 List (java.util.List)18 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)17 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)16 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)16 Optional (java.util.Optional)13 IssueTrackerModelHolder (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder)12 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)12 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)11 HashMap (java.util.HashMap)11 IntegrationException (com.synopsys.integration.exception.IntegrationException)10 ArrayList (java.util.ArrayList)9 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)8 DistributionJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel)8 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)8 UUID (java.util.UUID)8 IssueOperation (com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation)7