Search in sources :

Example 26 with FieldValueModel

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

the class EmailGlobalConfigurationFieldModelValidatorTest method createDefaultKeyToValues.

private Map<String, FieldValueModel> createDefaultKeyToValues() {
    Map<String, FieldValueModel> keyToValues = new HashMap<>();
    FieldValueModel hostFieldValueModel = new FieldValueModel(List.of("hostName"), true);
    FieldValueModel fromFieldValueModel = new FieldValueModel(List.of("from"), true);
    keyToValues.put(EmailPropertyKeys.JAVAMAIL_HOST_KEY.getPropertyKey(), hostFieldValueModel);
    keyToValues.put(EmailPropertyKeys.JAVAMAIL_FROM_KEY.getPropertyKey(), fromFieldValueModel);
    return keyToValues;
}
Also used : HashMap(java.util.HashMap) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel)

Example 27 with FieldValueModel

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

the class JiraCloudGlobalConfigurationFieldModelValidatorTest method createValidKeyToValues.

private Map<String, FieldValueModel> createValidKeyToValues() {
    Map<String, FieldValueModel> keyToValues = new HashMap<>();
    FieldValueModel url = new FieldValueModel(List.of("http://url.com"), true);
    FieldValueModel email = new FieldValueModel(List.of("email"), true);
    FieldValueModel apiToken = new FieldValueModel(List.of("apiToken"), true);
    keyToValues.put(JiraCloudDescriptor.KEY_JIRA_URL, url);
    keyToValues.put(JiraCloudDescriptor.KEY_JIRA_ADMIN_EMAIL_ADDRESS, email);
    keyToValues.put(JiraCloudDescriptor.KEY_JIRA_ADMIN_API_TOKEN, apiToken);
    return keyToValues;
}
Also used : HashMap(java.util.HashMap) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel)

Example 28 with FieldValueModel

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

the class ScalingPerformanceTest method createSlackJobs.

private void createSlackJobs(ConfigurationManager configurationManager, LocalDateTime startingTime, List<String> jobIds, int numberOfJobsToCreate, int intervalToLog, String blackDuckProviderID, String blackDuckProviderKey, String blackDuckProjectName) throws Exception {
    int startingJobNum = jobIds.size();
    while (jobIds.size() < startingJobNum + numberOfJobsToCreate) {
        // Create a Slack Job with a unique name using the job number
        Integer jobNumber = jobIds.size();
        String jobName = String.format("%s #%s", SLACK_SCALING_PERFORMANCE_JOB_NAME, jobNumber);
        Map<String, FieldValueModel> slackKeyToValues = new HashMap<>();
        slackKeyToValues.put(ChannelDescriptor.KEY_ENABLED, new FieldValueModel(List.of("true"), true));
        slackKeyToValues.put(ChannelDescriptor.KEY_CHANNEL_NAME, new FieldValueModel(List.of(ChannelKeys.SLACK.getUniversalKey()), true));
        slackKeyToValues.put(ChannelDescriptor.KEY_NAME, new FieldValueModel(List.of(jobName), true));
        slackKeyToValues.put(ChannelDescriptor.KEY_FREQUENCY, new FieldValueModel(List.of(FrequencyType.REAL_TIME.name()), true));
        slackKeyToValues.put(ChannelDescriptor.KEY_PROVIDER_TYPE, new FieldValueModel(List.of(blackDuckProviderKey), true));
        slackKeyToValues.put(SlackDescriptor.KEY_WEBHOOK, new FieldValueModel(List.of(SLACK_CHANNEL_WEBHOOK), true));
        slackKeyToValues.put(SlackDescriptor.KEY_CHANNEL_NAME, new FieldValueModel(List.of(SLACK_CHANNEL_NAME), true));
        slackKeyToValues.put(SlackDescriptor.KEY_CHANNEL_USERNAME, new FieldValueModel(List.of(SLACK_CHANNEL_USERNAME), true));
        String jobId = configurationManager.createJob(slackKeyToValues, jobName, blackDuckProviderID, blackDuckProjectName);
        jobIds.add(jobId);
        if (jobIds.size() % intervalToLog == 0) {
            String message = String.format("Creating %s jobs took", jobIds.size() - startingJobNum);
            logTimeElapsedWithMessage(message + " %s", startingTime, LocalDateTime.now());
        }
    }
    intLogger.info(String.format("Finished creating %s jobs. Current Job number %s.", numberOfJobsToCreate, jobIds.size()));
}
Also used : HashMap(java.util.HashMap) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel)

Example 29 with FieldValueModel

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

the class JobConfigControllerTestIT method createTestJobFieldModel.

private JobFieldModel createTestJobFieldModel(String channelId, String providerId, ConfigurationModel providerGlobalConfig) {
    String descriptorName = ChannelKeys.SLACK.getUniversalKey();
    String context = ConfigContextEnum.DISTRIBUTION.name();
    FieldValueModel providerConfigField = new FieldValueModel(List.of(providerGlobalConfig.getConfigurationId().toString()), true);
    FieldValueModel slackChannelName = new FieldValueModel(List.of("channelName"), true);
    FieldValueModel frequency = new FieldValueModel(List.of(FrequencyType.DAILY.name()), true);
    FieldValueModel name = new FieldValueModel(List.of("name"), true);
    FieldValueModel provider = new FieldValueModel(List.of(blackDuckProviderKey.getUniversalKey()), true);
    FieldValueModel channel = new FieldValueModel(List.of("channel_slack"), true);
    FieldValueModel webhook = new FieldValueModel(List.of("http://slack_webhook_url"), true);
    Map<String, FieldValueModel> fields = Map.of(SlackDescriptor.KEY_CHANNEL_NAME, slackChannelName, SlackDescriptor.KEY_WEBHOOK, webhook, ChannelDescriptor.KEY_NAME, name, ChannelDescriptor.KEY_PROVIDER_TYPE, provider, ProviderDescriptor.KEY_PROVIDER_CONFIG_ID, providerConfigField, ChannelDescriptor.KEY_CHANNEL_NAME, channel, ChannelDescriptor.KEY_FREQUENCY, frequency);
    FieldModel fieldModel = new FieldModel(descriptorName, context, fields);
    if (StringUtils.isNotBlank(channelId)) {
        fieldModel.setId(channelId);
    }
    String bdDescriptorName = blackDuckProviderKey.getUniversalKey();
    String bdContext = ConfigContextEnum.DISTRIBUTION.name();
    FieldValueModel notificationType = new FieldValueModel(List.of("vulnerability"), true);
    FieldValueModel formatType = new FieldValueModel(List.of(ProcessingType.DEFAULT.name()), true);
    FieldValueModel filterByProject = new FieldValueModel(List.of("false"), true);
    FieldValueModel projectNames = new FieldValueModel(List.of("project"), true);
    Map<String, FieldValueModel> bdFields = Map.of(ProviderDescriptor.KEY_NOTIFICATION_TYPES, notificationType, ProviderDescriptor.KEY_PROVIDER_CONFIG_ID, providerConfigField, ProviderDescriptor.KEY_PROCESSING_TYPE, formatType, ProviderDescriptor.KEY_FILTER_BY_PROJECT, filterByProject, ProviderDescriptor.KEY_CONFIGURED_PROJECT, projectNames);
    FieldModel bdFieldModel = new FieldModel(bdDescriptorName, bdContext, bdFields);
    if (StringUtils.isNotBlank(providerId)) {
        bdFieldModel.setId(providerId);
    }
    return new JobFieldModel(UUID.randomUUID().toString(), Set.of(fieldModel, bdFieldModel), List.of(new JobProviderProjectFieldModel("project", "href", false)));
}
Also used : JobProviderProjectFieldModel(com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) JobProviderProjectFieldModel(com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel)

Example 30 with FieldValueModel

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

the class EmailConfigActionTestIT method updatePasswordEmailGlobalConfigTest.

@Test
void updatePasswordEmailGlobalConfigTest() 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;
    String updatedPassword = "updatedPassword";
    fieldModel.putField(EmailPropertyKeys.JAVAMAIL_HOST_KEY.getPropertyKey(), new FieldValueModel(List.of(updatedHost), false));
    fieldModel.putField(EmailPropertyKeys.JAVAMAIL_PASSWORD_KEY.getPropertyKey(), new FieldValueModel(List.of(updatedPassword), 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(updatedPassword, 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)

Aggregations

FieldValueModel (com.synopsys.integration.alert.common.rest.model.FieldValueModel)58 HashMap (java.util.HashMap)27 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)24 Test (org.junit.jupiter.api.Test)18 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)12 AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)6 GlobalConfigurationValidatorAsserter (com.synopsys.integration.alert.test.common.channel.GlobalConfigurationValidatorAsserter)6 JobFieldModel (com.synopsys.integration.alert.common.rest.model.JobFieldModel)5 JobProviderProjectFieldModel (com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel)4 ConfigurationManager (com.synopsys.integration.alert.performance.utility.ConfigurationManager)4 IntegrationPerformanceTestRunner (com.synopsys.integration.alert.performance.utility.IntegrationPerformanceTestRunner)4 Disabled (org.junit.jupiter.api.Disabled)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)3 DescriptorAccessor (com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor)3 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)3 EncryptionUtility (com.synopsys.integration.alert.common.security.EncryptionUtility)3 AlertRequestUtility (com.synopsys.integration.alert.performance.utility.AlertRequestUtility)3 BlackDuckProviderService (com.synopsys.integration.alert.performance.utility.BlackDuckProviderService)3 List (java.util.List)3