Search in sources :

Example 51 with FieldModel

use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-alert by blackducksoftware.

the class AzureBoardsGlobalApiAction method beforeUpdateAction.

@Override
public FieldModel beforeUpdateAction(FieldModel fieldModel) throws AlertException {
    FieldModel updatedFieldModel = super.beforeUpdateAction(fieldModel);
    Optional<ConfigurationModel> existingConfig = configurationModelConfigurationAccessor.getConfigurationById(Long.valueOf(fieldModel.getId()));
    return existingConfig.map(config -> updateTokenFields(updatedFieldModel, config)).orElse(updatedFieldModel);
}
Also used : ApiAction(com.synopsys.integration.alert.common.action.ApiAction) OAuthRequestValidator(com.synopsys.integration.alert.channel.azure.boards.oauth.OAuthRequestValidator) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) DescriptorMap(com.synopsys.integration.alert.common.descriptor.DescriptorMap) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) List(java.util.List) Component(org.springframework.stereotype.Component) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) Map(java.util.Map) AzureBoardsDescriptor(com.synopsys.integration.alert.channel.azure.boards.descriptor.AzureBoardsDescriptor) Optional(java.util.Optional) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel)

Example 52 with FieldModel

use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-alert by blackducksoftware.

the class AzureBoardsGlobalApiAction method beforeSaveAction.

@Override
public FieldModel beforeSaveAction(FieldModel fieldModel) throws AlertException {
    FieldModel updatedFieldModel = super.beforeSaveAction(fieldModel);
    Optional<DescriptorKey> descriptorKey = descriptorMap.getDescriptorKey(fieldModel.getDescriptorName());
    if (!descriptorKey.isPresent()) {
        return updatedFieldModel;
    }
    ConfigContextEnum context = ConfigContextEnum.valueOf(fieldModel.getContext());
    List<ConfigurationModel> existingConfig = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(descriptorKey.get(), context);
    Optional<ConfigurationModel> configurationModel = existingConfig.stream().findFirst();
    return configurationModel.map(config -> updateTokenFields(updatedFieldModel, config)).orElse(updatedFieldModel);
}
Also used : ApiAction(com.synopsys.integration.alert.common.action.ApiAction) OAuthRequestValidator(com.synopsys.integration.alert.channel.azure.boards.oauth.OAuthRequestValidator) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) DescriptorMap(com.synopsys.integration.alert.common.descriptor.DescriptorMap) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) List(java.util.List) Component(org.springframework.stereotype.Component) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) Map(java.util.Map) AzureBoardsDescriptor(com.synopsys.integration.alert.channel.azure.boards.descriptor.AzureBoardsDescriptor) Optional(java.util.Optional) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)

Example 53 with FieldModel

use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-alert by blackducksoftware.

the class EmailConfigActionTestIT method updateReadExistingPasswordEmailGlobalConfigTest.

@Test
void updateReadExistingPasswordEmailGlobalConfigTest() 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"));
    String updatedHost = "updated." + TEST_SMTP_HOST;
    fieldModel.putField(EmailPropertyKeys.JAVAMAIL_HOST_KEY.getPropertyKey(), new FieldValueModel(List.of(updatedHost), false));
    configActions.update(Long.valueOf(fieldModel.getId()), fieldModel);
    Optional<EmailGlobalConfigModel> staticEmailConfig = emailGlobalConfigAccessor.getConfiguration();
    assertTrue(staticEmailConfig.isPresent());
    EmailGlobalConfigModel staticModel = staticEmailConfig.get();
    assertEquals(Boolean.TRUE, staticModel.getSmtpAuth().orElse(null));
    assertEquals(TEST_AUTH_USER, staticModel.getSmtpUsername().orElse(null));
    assertEquals(TEST_AUTH_PASSWORD, staticModel.getSmtpPassword().orElse(null));
    assertEquals(updatedHost, staticModel.getSmtpHost().orElse(null));
    assertEquals(Integer.valueOf(TEST_SMTP_PORT), staticModel.getSmtpPort().orElse(null));
    assertEquals(TEST_FROM, staticModel.getSmtpFrom().orElse(null));
    String propertyValue = staticModel.getAdditionalJavaMailProperties().map(map -> map.get(EmailPropertyKeys.JAVAMAIL_EHLO_KEY.getPropertyKey())).orElse(null);
    assertEquals("true", propertyValue);
}
Also used : EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) BeforeEach(org.junit.jupiter.api.BeforeEach) EmailGlobalConfigurationModelSaveActions(com.synopsys.integration.alert.channel.email.convert.EmailGlobalConfigurationModelSaveActions) DescriptorAccessor(com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) SettingsDescriptorKey(com.synopsys.integration.alert.component.settings.descriptor.SettingsDescriptorKey) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) PKIXErrorResponseFactory(com.synopsys.integration.alert.component.certificates.web.PKIXErrorResponseFactory) EmailPropertyKeys(com.synopsys.integration.alert.service.email.enumeration.EmailPropertyKeys) EmailGlobalCrudActions(com.synopsys.integration.alert.channel.email.action.EmailGlobalCrudActions) DescriptorMap(com.synopsys.integration.alert.common.descriptor.DescriptorMap) ConfigActions(com.synopsys.integration.alert.web.api.config.ConfigActions) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) Map(java.util.Map) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) EmailGlobalConfigAccessor(com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) AuthenticationTestUtils(com.synopsys.integration.alert.test.common.AuthenticationTestUtils) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) FieldModelProcessor(com.synopsys.integration.alert.common.rest.FieldModelProcessor) EmailGlobalConfigurationModelConverter(com.synopsys.integration.alert.channel.email.convert.EmailGlobalConfigurationModelConverter) EmailGlobalConfigurationValidator(com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator) Optional(java.util.Optional) EncryptionUtility(com.synopsys.integration.alert.common.security.EncryptionUtility) ChannelKeys(com.synopsys.integration.alert.descriptor.api.model.ChannelKeys) DescriptorProcessor(com.synopsys.integration.alert.common.descriptor.DescriptorProcessor) GlobalConfigurationModelToConcreteConversionService(com.synopsys.integration.alert.web.api.config.GlobalConfigurationModelToConcreteConversionService) GlobalConfigurationModelToConcreteSaveActions(com.synopsys.integration.alert.common.action.api.GlobalConfigurationModelToConcreteSaveActions) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) 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) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 54 with FieldModel

use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-alert by blackducksoftware.

the class EmailConfigActionTestIT method createEmailGlobalConfigTest.

@Test
void createEmailGlobalConfigTest() {
    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();
    configActions.create(fieldModel);
    Optional<EmailGlobalConfigModel> staticEmailConfig = emailGlobalConfigAccessor.getConfiguration();
    assertTrue(staticEmailConfig.isPresent());
    EmailGlobalConfigModel staticModel = staticEmailConfig.get();
    assertEquals(Boolean.TRUE, staticModel.getSmtpAuth().orElse(null));
    assertEquals(TEST_AUTH_USER, staticModel.getSmtpUsername().orElse(null));
    assertEquals(TEST_AUTH_PASSWORD, staticModel.getSmtpPassword().orElse(null));
    assertEquals(TEST_SMTP_HOST, staticModel.getSmtpHost().orElse(null));
    assertEquals(Integer.valueOf(TEST_SMTP_PORT), staticModel.getSmtpPort().orElse(null));
    assertEquals(TEST_FROM, staticModel.getSmtpFrom().orElse(null));
    String propertyValue = staticModel.getAdditionalJavaMailProperties().map(map -> map.get(EmailPropertyKeys.JAVAMAIL_EHLO_KEY.getPropertyKey())).orElse(null);
    assertEquals("true", propertyValue);
}
Also used : EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) BeforeEach(org.junit.jupiter.api.BeforeEach) EmailGlobalConfigurationModelSaveActions(com.synopsys.integration.alert.channel.email.convert.EmailGlobalConfigurationModelSaveActions) DescriptorAccessor(com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) SettingsDescriptorKey(com.synopsys.integration.alert.component.settings.descriptor.SettingsDescriptorKey) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) PKIXErrorResponseFactory(com.synopsys.integration.alert.component.certificates.web.PKIXErrorResponseFactory) EmailPropertyKeys(com.synopsys.integration.alert.service.email.enumeration.EmailPropertyKeys) EmailGlobalCrudActions(com.synopsys.integration.alert.channel.email.action.EmailGlobalCrudActions) DescriptorMap(com.synopsys.integration.alert.common.descriptor.DescriptorMap) ConfigActions(com.synopsys.integration.alert.web.api.config.ConfigActions) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) Map(java.util.Map) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) EmailGlobalConfigAccessor(com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) AuthenticationTestUtils(com.synopsys.integration.alert.test.common.AuthenticationTestUtils) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) FieldModelProcessor(com.synopsys.integration.alert.common.rest.FieldModelProcessor) EmailGlobalConfigurationModelConverter(com.synopsys.integration.alert.channel.email.convert.EmailGlobalConfigurationModelConverter) EmailGlobalConfigurationValidator(com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator) Optional(java.util.Optional) EncryptionUtility(com.synopsys.integration.alert.common.security.EncryptionUtility) ChannelKeys(com.synopsys.integration.alert.descriptor.api.model.ChannelKeys) DescriptorProcessor(com.synopsys.integration.alert.common.descriptor.DescriptorProcessor) GlobalConfigurationModelToConcreteConversionService(com.synopsys.integration.alert.web.api.config.GlobalConfigurationModelToConcreteConversionService) GlobalConfigurationModelToConcreteSaveActions(com.synopsys.integration.alert.common.action.api.GlobalConfigurationModelToConcreteSaveActions) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) 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) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 55 with FieldModel

use of com.synopsys.integration.alert.common.rest.model.FieldModel 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)

Aggregations

FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)73 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)43 FieldValueModel (com.synopsys.integration.alert.common.rest.model.FieldValueModel)31 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)28 Test (org.junit.jupiter.api.Test)26 HashMap (java.util.HashMap)25 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)21 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)21 ConfigurationFieldModelConverter (com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter)19 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)18 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)18 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)15 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)14 FieldUtility (com.synopsys.integration.alert.common.persistence.accessor.FieldUtility)13 JobFieldModel (com.synopsys.integration.alert.common.rest.model.JobFieldModel)13 List (java.util.List)13 Autowired (org.springframework.beans.factory.annotation.Autowired)13 DescriptorAccessor (com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor)12 JobProviderProjectFieldModel (com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel)12 MultiFieldModel (com.synopsys.integration.alert.common.rest.model.MultiFieldModel)12