Search in sources :

Example 41 with AlertConfigurationException

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

the class EmailConfigActionTestIT method deleteEmailGlobalConfigTest.

@Test
void deleteEmailGlobalConfigTest() throws AlertConfigurationException {
    AuthorizationManager authorizationManager = createEmailAuthorizationManager();
    EmailGlobalCrudActions emailGlobalCrudActions = createEmailCrudActions(authorizationManager);
    GlobalConfigurationModelToConcreteConversionService globalConfigurationModelToConcreteConversionService = createConversionService(emailGlobalCrudActions);
    ConfigActions configActions = new ConfigActions(authorizationManager, descriptorAccessor, configurationModelConfigurationAccessor, fieldModelProcessor, descriptorProcessor, configurationFieldModelConverter, descriptorMap, pkixErrorResponseFactory, encryptionUtility, settingsDescriptorKey, globalConfigurationModelToConcreteConversionService);
    FieldModel fieldModel = createEmailFieldModel();
    fieldModel = configActions.create(fieldModel).getContent().orElseThrow(() -> new AlertConfigurationException("Couldn't create configuration"));
    configActions.delete(Long.valueOf(fieldModel.getId()));
    Optional<EmailGlobalConfigModel> staticEmailConfig = emailGlobalConfigAccessor.getConfiguration();
    assertTrue(staticEmailConfig.isEmpty());
}
Also used : EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) EmailGlobalCrudActions(com.synopsys.integration.alert.channel.email.action.EmailGlobalCrudActions) GlobalConfigurationModelToConcreteConversionService(com.synopsys.integration.alert.web.api.config.GlobalConfigurationModelToConcreteConversionService) ConfigActions(com.synopsys.integration.alert.web.api.config.ConfigActions) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 42 with AlertConfigurationException

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

the class MockRoleAccessor method updatePermissionsForRole.

@Override
public PermissionMatrixModel updatePermissionsForRole(String roleName, PermissionMatrixModel permissionMatrix) throws AlertConfigurationException {
    Long roleId = roleMap.entrySet().stream().filter(entry -> entry.getValue().getName().equals(roleName)).map(Map.Entry::getKey).findFirst().orElseThrow(() -> new AlertConfigurationException(String.format("role with name %s not found", roleName)));
    roleMap.computeIfPresent(roleId, (ignored, role) -> new UserRoleModel(role.getId(), role.getName(), role.isCustom(), permissionMatrix));
    return permissionMatrix;
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) RoleAccessor(com.synopsys.integration.alert.common.descriptor.accessor.RoleAccessor) AlertForbiddenOperationException(com.synopsys.integration.alert.common.exception.AlertForbiddenOperationException) Collection(java.util.Collection) Map(java.util.Map) Set(java.util.Set) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) HashMap(java.util.HashMap) UserRoleModel(com.synopsys.integration.alert.common.persistence.model.UserRoleModel) PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) Collectors(java.util.stream.Collectors) AtomicLong(java.util.concurrent.atomic.AtomicLong) UserRoleModel(com.synopsys.integration.alert.common.persistence.model.UserRoleModel) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Example 43 with AlertConfigurationException

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

the class EmailChannelMessageSender method sendMessages.

@Override
public MessageResult sendMessages(EmailJobDetailsModel emailJobDetails, List<EmailChannelMessageModel> emailMessages) throws AlertException {
    // Validation
    ValidatedEmailAddresses validatedAdditionalEmailAddresses;
    UUID jobId = emailJobDetails.getJobId();
    if (null != jobId) {
        validatedAdditionalEmailAddresses = emailAddressValidator.validate(jobId, emailJobDetails.getAdditionalEmailAddresses());
    } else {
        validatedAdditionalEmailAddresses = new ValidatedEmailAddresses(new HashSet<>(emailJobDetails.getAdditionalEmailAddresses()), Set.of());
    }
    Set<String> invalidEmailAddresses = validatedAdditionalEmailAddresses.getInvalidEmailAddresses();
    if (!invalidEmailAddresses.isEmpty()) {
        emailJobDetails = new EmailJobDetailsModel(emailJobDetails.getJobId(), emailJobDetails.getSubjectLine().orElse(null), emailJobDetails.isProjectOwnerOnly(), emailJobDetails.isAdditionalEmailAddressesOnly(), emailJobDetails.getAttachmentFileType(), new ArrayList<>(validatedAdditionalEmailAddresses.getValidEmailAddresses()));
    }
    // Distribution
    EmailGlobalConfigModel emailServerConfiguration = emailGlobalConfigAccessor.getConfiguration().orElseThrow(() -> new AlertConfigurationException("ERROR: Missing Email global config."));
    SmtpConfig smtpConfig = SmtpConfig.builder().setJavamailProperties(javamailPropertiesFactory.createJavaMailProperties(emailServerConfiguration)).setSmtpFrom(emailServerConfiguration.getSmtpFrom().orElse(null)).setSmtpHost(emailServerConfiguration.getSmtpHost().orElse(null)).setSmtpPort(emailServerConfiguration.getSmtpPort().orElse(-1)).setSmtpAuth(emailServerConfiguration.getSmtpAuth().orElse(false)).setSmtpUsername(emailServerConfiguration.getSmtpUsername().orElse(null)).setSmtpPassword(emailServerConfiguration.getSmtpPassword().orElse(null)).build();
    int totalEmailsSent = 0;
    for (EmailChannelMessageModel message : emailMessages) {
        Set<String> projectHrefs = message.getSource().map(ProjectMessage::getProject).flatMap(LinkableItem::getUrl).map(Set::of).orElse(Set.of());
        Set<String> gatheredEmailAddresses = emailAddressGatherer.gatherEmailAddresses(emailJobDetails, projectHrefs);
        if (gatheredEmailAddresses.isEmpty()) {
            if (invalidEmailAddresses.isEmpty()) {
                throw new AlertException("Could not determine what email addresses to send this content to");
            } else {
                String invalidEmailAddressesString = StringUtils.join(invalidEmailAddresses, ", ");
                throw new AlertException(String.format("No valid email addresses to send this content to. The following email addresses were invalid: %s", invalidEmailAddressesString));
            }
        }
        EmailTarget emailTarget = emailChannelMessagingService.createTarget(message, gatheredEmailAddresses);
        Optional<ProjectMessage> optionalProjectMessage = message.getSource();
        if (optionalProjectMessage.isPresent()) {
            EmailAttachmentFormat attachmentFormat = EmailAttachmentFormat.getValueSafely(emailJobDetails.getAttachmentFileType());
            emailChannelMessagingService.sendMessageWithAttachedProjectMessage(smtpConfig, emailTarget, optionalProjectMessage.get(), attachmentFormat);
        } else {
            emailChannelMessagingService.sendMessage(smtpConfig, emailTarget);
        }
        totalEmailsSent += emailTarget.getEmailAddresses().size();
    }
    // Reporting
    if (!invalidEmailAddresses.isEmpty()) {
        String invalidEmailAddressesString = StringUtils.join(invalidEmailAddresses, ", ");
        String errorMessage = String.format("No emails were sent to the following recipients because they were invalid: %s", invalidEmailAddressesString);
        AlertFieldStatus errorStatus = new AlertFieldStatus(EmailDescriptor.KEY_EMAIL_ADDITIONAL_ADDRESSES, FieldStatusSeverity.ERROR, errorMessage);
        return new MessageResult(errorMessage, List.of(errorStatus));
    }
    return new MessageResult(String.format("Successfully sent %d email(s)", totalEmailsSent));
}
Also used : EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) SmtpConfig(com.synopsys.integration.alert.service.email.SmtpConfig) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ArrayList(java.util.ArrayList) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) EmailAttachmentFormat(com.synopsys.integration.alert.channel.email.attachment.EmailAttachmentFormat) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) EmailJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel) EmailTarget(com.synopsys.integration.alert.service.email.EmailTarget) UUID(java.util.UUID) ValidatedEmailAddresses(com.synopsys.integration.alert.channel.email.distribution.address.ValidatedEmailAddresses) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) HashSet(java.util.HashSet) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Example 44 with AlertConfigurationException

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

the class JiraCloudPropertiesFactory method createJiraProperties.

public JiraCloudProperties createJiraProperties() throws AlertConfigurationException {
    ConfigurationModel jiraServerGlobalConfig = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(channelKey, ConfigContextEnum.GLOBAL).stream().findAny().orElseThrow(() -> new AlertConfigurationException("Missing Jira Cloud global configuration"));
    FieldUtility fieldUtility = new FieldUtility(jiraServerGlobalConfig.getCopyOfKeyToFieldMap());
    return createJiraProperties(fieldUtility);
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) FieldUtility(com.synopsys.integration.alert.common.persistence.accessor.FieldUtility) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Example 45 with AlertConfigurationException

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

the class ProviderDataAccessorTest method getProviderConfigUserByIdNotFoundTest.

@Test
void getProviderConfigUserByIdNotFoundTest() throws IntegrationException {
    UserService userService = Mockito.mock(UserService.class);
    Mockito.when(blackDuckServicesFactory.createUserService()).thenReturn(userService);
    String emailAddress = "fake@email.address";
    UserView userView1 = new UserView();
    userView1.setActive(true);
    userView1.setEmail(emailAddress);
    Mockito.when(userService.findCurrentUser()).thenReturn(userView1);
    BlackDuckProviderDataAccessor blackDuckProviderDataAccessor = new BlackDuckProviderDataAccessor(configurationModelConfigurationAccessor, blackDuckPropertiesFactory);
    long nonExistentConfig = 999L;
    try {
        ProviderUserModel providerConfigUser = blackDuckProviderDataAccessor.getProviderConfigUserById(nonExistentConfig);
        fail();
    } catch (AlertConfigurationException exception) {
        assertTrue(exception.getMessage().contains(String.valueOf(nonExistentConfig)));
    }
}
Also used : UserService(com.synopsys.integration.blackduck.service.dataservice.UserService) ProviderUserModel(com.synopsys.integration.alert.common.persistence.model.ProviderUserModel) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Test(org.junit.jupiter.api.Test)

Aggregations

AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)54 Test (org.junit.jupiter.api.Test)20 Transactional (org.springframework.transaction.annotation.Transactional)10 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)8 UUID (java.util.UUID)8 EmailGlobalConfigModel (com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)5 Map (java.util.Map)5 JiraServerConfigurationEntity (com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationEntity)4 JiraServerGlobalConfigModel (com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel)4 AlertForbiddenOperationException (com.synopsys.integration.alert.common.exception.AlertForbiddenOperationException)4 UserModel (com.synopsys.integration.alert.common.persistence.model.UserModel)4 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)4 HashMap (java.util.HashMap)4 EmailGlobalCrudActions (com.synopsys.integration.alert.channel.email.action.EmailGlobalCrudActions)3 AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)3 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)3 UserRoleModel (com.synopsys.integration.alert.common.persistence.model.UserRoleModel)3 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)3 UserEntity (com.synopsys.integration.alert.database.user.UserEntity)3 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)3