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);
}
}
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);
}
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);
}
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;
}
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;
}
Aggregations