Search in sources :

Example 1 with EmailConfigurationEntity

use of com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationEntity in project hub-alert by blackducksoftware.

the class EmailGlobalConfigAccessor method populateConfiguration.

private EmailGlobalConfigModel populateConfiguration(UUID configurationId, EmailGlobalConfigModel configuration, OffsetDateTime createdAt) {
    OffsetDateTime currentTime = DateUtils.createCurrentDateTimestamp();
    EmailConfigurationEntity configurationToSave = toEntity(configurationId, configuration, createdAt, currentTime);
    EmailConfigurationEntity savedEmailConfig = emailConfigurationRepository.save(configurationToSave);
    emailConfigurationPropertiesRepository.bulkDeleteByConfigurationId(savedEmailConfig.getConfigurationId());
    List<EmailConfigurationsPropertyEntity> emailProperties = toPropertyEntityList(configurationId, configuration);
    emailConfigurationPropertiesRepository.saveAll(emailProperties);
    savedEmailConfig = emailConfigurationRepository.getOne(savedEmailConfig.getConfigurationId());
    return createConfigModel(savedEmailConfig);
}
Also used : OffsetDateTime(java.time.OffsetDateTime) EmailConfigurationEntity(com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationEntity) EmailConfigurationsPropertyEntity(com.synopsys.integration.alert.channel.email.database.configuration.properties.EmailConfigurationsPropertyEntity)

Example 2 with EmailConfigurationEntity

use of com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationEntity in project hub-alert by blackducksoftware.

the class EmailGlobalConfigAccessor method updateConfiguration.

@Override
@Transactional(propagation = Propagation.REQUIRED)
public EmailGlobalConfigModel updateConfiguration(EmailGlobalConfigModel configuration) throws AlertConfigurationException {
    EmailConfigurationEntity configurationEntity = emailConfigurationRepository.findByName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME).orElseThrow(() -> new AlertConfigurationException(String.format("Config with name '%s' did not exist", AlertRestConstants.DEFAULT_CONFIGURATION_NAME)));
    if (BooleanUtils.toBoolean(configuration.getIsSmtpPasswordSet()) && configuration.getSmtpPassword().isEmpty()) {
        String decryptedPassword = encryptionUtility.decrypt(configurationEntity.getAuthPassword());
        configuration.setSmtpPassword(decryptedPassword);
    }
    return populateConfiguration(configurationEntity.getConfigurationId(), configuration, configurationEntity.getCreatedAt());
}
Also used : EmailConfigurationEntity(com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationEntity) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with EmailConfigurationEntity

use of com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationEntity in project hub-alert by blackducksoftware.

the class EmailGlobalConfigurationModelSaveActionsTest method updateTest.

@Test
void updateTest() {
    AtomicReference<EmailConfigurationEntity> savedEntity = new AtomicReference<>();
    AtomicReference<EmailConfigurationsPropertyEntity> savedProperty = new AtomicReference<>();
    EmailConfigurationRepository emailConfigurationRepository = Mockito.mock(EmailConfigurationRepository.class);
    EmailConfigurationPropertiesRepository emailConfigurationPropertiesRepository = Mockito.mock(EmailConfigurationPropertiesRepository.class);
    Mockito.when(emailConfigurationRepository.save(Mockito.any(EmailConfigurationEntity.class))).thenAnswer(invocation -> {
        savedEntity.set(invocation.getArgument(0));
        return savedEntity.get();
    });
    Mockito.when(emailConfigurationRepository.findByName(Mockito.anyString())).thenAnswer(invocation -> Optional.ofNullable(savedEntity.get()));
    Mockito.when(emailConfigurationRepository.findById(Mockito.any())).thenAnswer(invocation -> Optional.ofNullable(savedEntity.get()));
    Mockito.when(emailConfigurationRepository.existsByName(Mockito.any())).thenAnswer(invocation -> savedEntity.get() != null);
    // Mockito.when(emailConfigurationRepository.existsByName(Mockito.anyString())).thenReturn(true);
    Mockito.when(emailConfigurationPropertiesRepository.saveAll(Mockito.any(List.class))).thenAnswer(invocation -> {
        Iterable<EmailConfigurationsPropertyEntity> iterable = invocation.getArgument(0);
        for (EmailConfigurationsPropertyEntity entity : iterable) {
            savedProperty.set(entity);
        }
        return List.of(savedProperty.get());
    });
    EmailGlobalConfigAccessor configurationAccessor = new EmailGlobalConfigAccessor(encryptionUtility, emailConfigurationRepository, emailConfigurationPropertiesRepository);
    EmailGlobalCrudActions crudActions = new EmailGlobalCrudActions(authorizationManager, configurationAccessor, validator);
    EmailGlobalConfigurationModelSaveActions saveActions = new EmailGlobalConfigurationModelSaveActions(converter, crudActions, configurationAccessor);
    String newPassword = "updatedPassword";
    String newHost = "updated." + TEST_SMTP_HOST;
    ConfigurationModel configurationModel = createDefaultConfigurationModel();
    saveActions.createConcreteModel(configurationModel);
    updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_HOST_KEY.getPropertyKey(), newHost);
    updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_PASSWORD_KEY.getPropertyKey(), newPassword);
    updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_EHLO_KEY.getPropertyKey(), "false");
    saveActions.updateConcreteModel(configurationModel);
    EmailConfigurationEntity actualEntity = savedEntity.get();
    assertEquals(ChannelKeys.EMAIL, saveActions.getDescriptorKey());
    assertEquals(Boolean.TRUE, actualEntity.getAuthRequired());
    assertEquals(TEST_AUTH_USER, actualEntity.getAuthUsername());
    assertEquals(newPassword, encryptionUtility.decrypt(actualEntity.getAuthPassword()));
    assertEquals(newHost, actualEntity.getSmtpHost());
    assertEquals(Integer.valueOf(TEST_SMTP_PORT), actualEntity.getSmtpPort());
    assertEquals(TEST_FROM, actualEntity.getSmtpFrom());
    EmailConfigurationsPropertyEntity emailProperty = savedProperty.get();
    assertNotNull(emailProperty);
    assertEquals(EmailPropertyKeys.JAVAMAIL_EHLO_KEY.getPropertyKey(), emailProperty.getPropertyKey());
    assertEquals("false", emailProperty.getPropertyValue());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) EmailConfigurationRepository(com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationRepository) EmailConfigurationEntity(com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationEntity) EmailConfigurationPropertiesRepository(com.synopsys.integration.alert.channel.email.database.configuration.properties.EmailConfigurationPropertiesRepository) AtomicReference(java.util.concurrent.atomic.AtomicReference) EmailGlobalConfigAccessor(com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor) EmailGlobalCrudActions(com.synopsys.integration.alert.channel.email.action.EmailGlobalCrudActions) EmailConfigurationsPropertyEntity(com.synopsys.integration.alert.channel.email.database.configuration.properties.EmailConfigurationsPropertyEntity) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 4 with EmailConfigurationEntity

use of com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationEntity in project hub-alert by blackducksoftware.

the class EmailGlobalConfigurationModelSaveActionsTest method updateInvalidConversionTest.

@Test
void updateInvalidConversionTest() {
    AtomicReference<EmailConfigurationEntity> savedEntity = new AtomicReference<>();
    AtomicReference<EmailConfigurationsPropertyEntity> savedProperty = new AtomicReference<>();
    EmailConfigurationRepository emailConfigurationRepository = Mockito.mock(EmailConfigurationRepository.class);
    EmailConfigurationPropertiesRepository emailConfigurationPropertiesRepository = Mockito.mock(EmailConfigurationPropertiesRepository.class);
    Mockito.when(emailConfigurationRepository.save(Mockito.any(EmailConfigurationEntity.class))).thenAnswer(invocation -> {
        savedEntity.set(invocation.getArgument(0));
        return savedEntity.get();
    });
    Mockito.when(emailConfigurationRepository.findByName(Mockito.anyString())).thenAnswer(invocation -> Optional.ofNullable(savedEntity.get()));
    Mockito.when(emailConfigurationRepository.findById(Mockito.any())).thenAnswer(invocation -> Optional.ofNullable(savedEntity.get()));
    Mockito.when(emailConfigurationPropertiesRepository.saveAll(Mockito.any(List.class))).thenAnswer(invocation -> {
        Iterable<EmailConfigurationsPropertyEntity> iterable = invocation.getArgument(0);
        for (EmailConfigurationsPropertyEntity entity : iterable) {
            savedProperty.set(entity);
        }
        return List.of(savedProperty.get());
    });
    EmailGlobalConfigAccessor configurationAccessor = new EmailGlobalConfigAccessor(encryptionUtility, emailConfigurationRepository, emailConfigurationPropertiesRepository);
    EmailGlobalCrudActions crudActions = new EmailGlobalCrudActions(authorizationManager, configurationAccessor, validator);
    EmailGlobalConfigurationModelSaveActions saveActions = new EmailGlobalConfigurationModelSaveActions(converter, crudActions, configurationAccessor);
    String newPassword = "updatedPassword";
    String newHost = "updated." + TEST_SMTP_HOST;
    ConfigurationModel configurationModel = createDefaultConfigurationModel();
    saveActions.createConcreteModel(configurationModel);
    updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_PORT_KEY.getPropertyKey(), "badport");
    updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_HOST_KEY.getPropertyKey(), newHost);
    updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_PORT_KEY.getPropertyKey(), newPassword);
    updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_EHLO_KEY.getPropertyKey(), "false");
    saveActions.updateConcreteModel(configurationModel);
    // make sure the values are not the updated values
    EmailConfigurationEntity actualEntity = savedEntity.get();
    assertEquals(TEST_AUTH_PASSWORD, encryptionUtility.decrypt(actualEntity.getAuthPassword()));
    assertEquals(TEST_SMTP_HOST, actualEntity.getSmtpHost());
    assertEquals(Integer.valueOf(TEST_SMTP_PORT), actualEntity.getSmtpPort());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) EmailConfigurationRepository(com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationRepository) EmailConfigurationEntity(com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationEntity) EmailConfigurationPropertiesRepository(com.synopsys.integration.alert.channel.email.database.configuration.properties.EmailConfigurationPropertiesRepository) AtomicReference(java.util.concurrent.atomic.AtomicReference) EmailGlobalConfigAccessor(com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor) EmailGlobalCrudActions(com.synopsys.integration.alert.channel.email.action.EmailGlobalCrudActions) EmailConfigurationsPropertyEntity(com.synopsys.integration.alert.channel.email.database.configuration.properties.EmailConfigurationsPropertyEntity) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 5 with EmailConfigurationEntity

use of com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationEntity in project hub-alert by blackducksoftware.

the class EmailGlobalConfigurationModelSaveActionsTest method updateItemNotFoundTest.

@Test
void updateItemNotFoundTest() {
    AtomicReference<EmailConfigurationEntity> savedEntity = new AtomicReference<>();
    AtomicReference<EmailConfigurationsPropertyEntity> savedProperty = new AtomicReference<>();
    EmailConfigurationRepository emailConfigurationRepository = Mockito.mock(EmailConfigurationRepository.class);
    EmailConfigurationPropertiesRepository emailConfigurationPropertiesRepository = Mockito.mock(EmailConfigurationPropertiesRepository.class);
    Mockito.when(emailConfigurationRepository.save(Mockito.any(EmailConfigurationEntity.class))).thenAnswer(invocation -> {
        savedEntity.set(invocation.getArgument(0));
        return savedEntity.get();
    });
    Mockito.when(emailConfigurationRepository.findByName(Mockito.anyString())).thenAnswer(invocation -> Optional.ofNullable(savedEntity.get()));
    Mockito.when(emailConfigurationRepository.findById(Mockito.any())).thenAnswer(invocation -> Optional.ofNullable(savedEntity.get()));
    Mockito.when(emailConfigurationPropertiesRepository.saveAll(Mockito.any(List.class))).thenAnswer(invocation -> {
        Iterable<EmailConfigurationsPropertyEntity> iterable = invocation.getArgument(0);
        for (EmailConfigurationsPropertyEntity entity : iterable) {
            savedProperty.set(entity);
        }
        return List.of(savedProperty.get());
    });
    EmailGlobalConfigAccessor configurationAccessor = new EmailGlobalConfigAccessor(encryptionUtility, emailConfigurationRepository, emailConfigurationPropertiesRepository);
    EmailGlobalCrudActions crudActions = new EmailGlobalCrudActions(authorizationManager, configurationAccessor, validator);
    EmailGlobalConfigurationModelSaveActions saveActions = new EmailGlobalConfigurationModelSaveActions(converter, crudActions, configurationAccessor);
    String newPassword = "updatedPassword";
    String newHost = "updated." + TEST_SMTP_HOST;
    ConfigurationModel configurationModel = createDefaultConfigurationModel();
    saveActions.createConcreteModel(configurationModel);
    updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_PORT_KEY.getPropertyKey(), "badport");
    updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_HOST_KEY.getPropertyKey(), newHost);
    updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_PORT_KEY.getPropertyKey(), newPassword);
    updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_EHLO_KEY.getPropertyKey(), "false");
    saveActions.updateConcreteModel(configurationModel);
    // make sure the values are not the updated values
    EmailConfigurationEntity actualEntity = savedEntity.get();
    assertEquals(TEST_AUTH_PASSWORD, encryptionUtility.decrypt(actualEntity.getAuthPassword()));
    assertEquals(TEST_SMTP_HOST, actualEntity.getSmtpHost());
    assertEquals(Integer.valueOf(TEST_SMTP_PORT), actualEntity.getSmtpPort());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) EmailConfigurationRepository(com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationRepository) EmailConfigurationEntity(com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationEntity) EmailConfigurationPropertiesRepository(com.synopsys.integration.alert.channel.email.database.configuration.properties.EmailConfigurationPropertiesRepository) AtomicReference(java.util.concurrent.atomic.AtomicReference) EmailGlobalConfigAccessor(com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor) EmailGlobalCrudActions(com.synopsys.integration.alert.channel.email.action.EmailGlobalCrudActions) EmailConfigurationsPropertyEntity(com.synopsys.integration.alert.channel.email.database.configuration.properties.EmailConfigurationsPropertyEntity) List(java.util.List) Test(org.junit.jupiter.api.Test)

Aggregations

EmailConfigurationEntity (com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationEntity)8 EmailConfigurationsPropertyEntity (com.synopsys.integration.alert.channel.email.database.configuration.properties.EmailConfigurationsPropertyEntity)7 EmailGlobalCrudActions (com.synopsys.integration.alert.channel.email.action.EmailGlobalCrudActions)6 EmailGlobalConfigAccessor (com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor)6 EmailConfigurationRepository (com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationRepository)6 EmailConfigurationPropertiesRepository (com.synopsys.integration.alert.channel.email.database.configuration.properties.EmailConfigurationPropertiesRepository)6 List (java.util.List)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 Test (org.junit.jupiter.api.Test)6 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)5 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)1 OffsetDateTime (java.time.OffsetDateTime)1 Transactional (org.springframework.transaction.annotation.Transactional)1