Search in sources :

Example 96 with ConfigurationFieldModel

use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.

the class ConfigurationModelMutable method put.

public void put(ConfigurationFieldModel configFieldModel) {
    Objects.requireNonNull(configFieldModel);
    String fieldKey = configFieldModel.getFieldKey();
    Objects.requireNonNull(fieldKey);
    if (getConfiguredFields().containsKey(fieldKey)) {
        ConfigurationFieldModel oldConfigField = getConfiguredFields().get(fieldKey);
        List<String> values = combine(oldConfigField, configFieldModel);
        oldConfigField.setFieldValues(values);
    } else {
        getConfiguredFields().put(fieldKey, configFieldModel);
    }
}
Also used : ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)

Example 97 with ConfigurationFieldModel

use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.

the class ProxyConfigurationModelSaveActionsTest method createDefaultConfigurationModel.

private ConfigurationModel createDefaultConfigurationModel() {
    Map<String, ConfigurationFieldModel> fieldValuesMap = new HashMap<>();
    ConfigurationFieldModel hostField = ConfigurationFieldModel.create(ProxyConfigurationModelConverter.FIELD_KEY_HOST);
    ConfigurationFieldModel portField = ConfigurationFieldModel.create(ProxyConfigurationModelConverter.FIELD_KEY_PORT);
    ConfigurationFieldModel usernameField = ConfigurationFieldModel.create(ProxyConfigurationModelConverter.FIELD_KEY_USERNAME);
    ConfigurationFieldModel passwordField = ConfigurationFieldModel.create(ProxyConfigurationModelConverter.FIELD_KEY_PASSWORD);
    ConfigurationFieldModel nonProxyHostField = ConfigurationFieldModel.create(ProxyConfigurationModelConverter.FIELD_KEY_NON_PROXY_HOSTS);
    hostField.setFieldValue(TEST_PROXY_HOST);
    portField.setFieldValue(TEST_PROXY_PORT);
    usernameField.setFieldValue(TEST_PROXY_USERNAME);
    passwordField.setFieldValue(TEST_PROXY_PASSWORD);
    nonProxyHostField.setFieldValue(TEST_PROXY_NON_PROXY_HOST);
    fieldValuesMap.put(ProxyConfigurationModelConverter.FIELD_KEY_HOST, hostField);
    fieldValuesMap.put(ProxyConfigurationModelConverter.FIELD_KEY_PORT, portField);
    fieldValuesMap.put(ProxyConfigurationModelConverter.FIELD_KEY_USERNAME, usernameField);
    fieldValuesMap.put(ProxyConfigurationModelConverter.FIELD_KEY_PASSWORD, passwordField);
    fieldValuesMap.put(ProxyConfigurationModelConverter.FIELD_KEY_NON_PROXY_HOSTS, nonProxyHostField);
    return new ConfigurationModel(1L, 1L, "", "", ConfigContextEnum.GLOBAL, fieldValuesMap);
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) HashMap(java.util.HashMap)

Example 98 with ConfigurationFieldModel

use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.

the class DailyTaskTest method cronExpressionNotDefault.

@Test
void cronExpressionNotDefault() {
    final String notDefaultValue = "44";
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    ConfigurationModelMutable configurationModel = new ConfigurationModelMutable(1L, 1L, null, null, ConfigContextEnum.GLOBAL);
    ConfigurationFieldModel configurationFieldModel = ConfigurationFieldModel.create(SchedulingDescriptor.KEY_DAILY_PROCESSOR_HOUR_OF_DAY);
    configurationFieldModel.setFieldValue(notDefaultValue);
    configurationModel.put(configurationFieldModel);
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(Mockito.any(DescriptorKey.class))).thenReturn(List.of(configurationModel));
    StaticJobAccessor jobAccessor = Mockito.mock(StaticJobAccessor.class);
    Mockito.when(jobAccessor.hasJobsByFrequency(Mockito.any())).thenReturn(true);
    DailyTask task = new DailyTask(SCHEDULING_DESCRIPTOR_KEY, null, null, null, null, configurationModelConfigurationAccessor, jobAccessor);
    String cronWithNotDefault = task.scheduleCronExpression();
    String expectedCron = String.format(DailyTask.CRON_FORMAT, notDefaultValue);
    assertEquals(expectedCron, cronWithNotDefault);
}
Also used : ConfigurationModelMutable(com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DailyTask(com.synopsys.integration.alert.component.scheduling.workflow.DailyTask) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) SchedulingDescriptorKey(com.synopsys.integration.alert.component.scheduling.descriptor.SchedulingDescriptorKey) StaticJobAccessor(com.synopsys.integration.alert.database.api.StaticJobAccessor) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) Test(org.junit.jupiter.api.Test)

Example 99 with ConfigurationFieldModel

use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.

the class ProxyConfigurationModelConverter method convert.

@Override
public Optional<SettingsProxyModel> convert(ConfigurationModel globalConfigurationModel) {
    Optional<SettingsProxyModel> convertedModel = Optional.empty();
    SettingsProxyModel model = new SettingsProxyModel();
    try {
        globalConfigurationModel.getField(FIELD_KEY_HOST).flatMap(ConfigurationFieldModel::getFieldValue).ifPresent(model::setProxyHost);
        globalConfigurationModel.getField(FIELD_KEY_PORT).flatMap(ConfigurationFieldModel::getFieldValue).map(Integer::valueOf).ifPresent(model::setProxyPort);
        globalConfigurationModel.getField(FIELD_KEY_NON_PROXY_HOSTS).map(ConfigurationFieldModel::getFieldValues).map(ArrayList::new).ifPresent(model::setNonProxyHosts);
        globalConfigurationModel.getField(FIELD_KEY_USERNAME).flatMap(ConfigurationFieldModel::getFieldValue).ifPresent(model::setProxyUsername);
        globalConfigurationModel.getField(FIELD_KEY_PASSWORD).flatMap(ConfigurationFieldModel::getFieldValue).ifPresent(model::setProxyPassword);
        convertedModel = Optional.of(model);
    } catch (NumberFormatException ex) {
        logger.error("Error converting field model to concrete proxy configuration", ex);
    }
    return convertedModel;
}
Also used : ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel)

Example 100 with ConfigurationFieldModel

use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.

the class MockConfigurationModelFactory method createSlackDistributionFields.

public static List<ConfigurationFieldModel> createSlackDistributionFields() {
    List<ConfigurationFieldModel> fields = new ArrayList<>();
    ConfigurationFieldModel channel = createFieldModel(SlackDescriptor.KEY_CHANNEL_NAME, "Alert channel");
    ConfigurationFieldModel username = createFieldModel(SlackDescriptor.KEY_CHANNEL_USERNAME, "Alert unit test");
    ConfigurationFieldModel webhook = createFieldModel(SlackDescriptor.KEY_WEBHOOK, "Webhook");
    fields.add(channel);
    fields.add(username);
    fields.add(webhook);
    Collection<ConfigurationFieldModel> commonFields = createCommonDistributionFields("Slack Test Job", ChannelKeys.SLACK.getUniversalKey());
    fields.addAll(commonFields);
    return fields;
}
Also used : ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) ArrayList(java.util.ArrayList)

Aggregations

ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)105 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)47 Test (org.junit.jupiter.api.Test)32 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)27 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)23 HashMap (java.util.HashMap)20 ConfigurationFieldModelConverter (com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter)14 ArrayList (java.util.ArrayList)13 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)12 FieldValueModel (com.synopsys.integration.alert.common.rest.model.FieldValueModel)12 DescriptorAccessor (com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor)11 DefinedFieldModel (com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel)11 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)10 BlackDuckProviderKey (com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey)10 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)9 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)9 ConfigurationModelMutable (com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable)8 EncryptionUtility (com.synopsys.integration.alert.common.security.EncryptionUtility)8 BeforeEach (org.junit.jupiter.api.BeforeEach)8 FieldUtility (com.synopsys.integration.alert.common.persistence.accessor.FieldUtility)7