use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.
the class JiraCloudProcessorFactory method createJiraCloudProperties.
private JiraCloudProperties createJiraCloudProperties() throws AlertConfigurationException {
ConfigurationModel jiraCloudGlobalConfig = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(jiraCloudChannelKey, ConfigContextEnum.GLOBAL).stream().findAny().orElseThrow(() -> new AlertConfigurationException("Missing Jira Cloud global configuration"));
String jiraUrl = jiraCloudGlobalConfig.getField(JiraCloudDescriptor.KEY_JIRA_URL).flatMap(ConfigurationFieldModel::getFieldValue).orElse("");
return JiraCloudProperties.fromConfig(jiraCloudGlobalConfig, proxyManager.createProxyInfoForHost(jiraUrl));
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.
the class JiraServerGlobalConfigAccessorTest method getByConfigurationNameTest.
@Test
void getByConfigurationNameTest() throws AlertConfigurationException {
UUID id = UUID.randomUUID();
JiraServerConfigurationEntity entity = createEntity(id);
Mockito.when(jiraServerConfigurationRepository.findByName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME)).thenReturn(Optional.of(entity));
JiraServerGlobalConfigModel configModel = jiraServerGlobalConfigAccessor.getConfigurationByName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME).orElseThrow(() -> new AlertConfigurationException("Cannot find expected configuration"));
assertEquals(id.toString(), configModel.getId());
assertEquals(TEST_URL, configModel.getUrl());
assertEquals(TEST_USERNAME, configModel.getUserName());
assertTrue(configModel.getIsPasswordSet().orElse(Boolean.FALSE));
assertEquals(TEST_PASSWORD, configModel.getPassword().orElse(null));
assertTrue(configModel.getDisablePluginCheck().orElse(Boolean.FALSE));
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.
the class JiraServerGlobalConfigAccessorTest method getByConfigurationIdTest.
@Test
void getByConfigurationIdTest() throws AlertConfigurationException {
UUID id = UUID.randomUUID();
JiraServerConfigurationEntity entity = createEntity(id);
Mockito.when(jiraServerConfigurationRepository.findById(id)).thenReturn(Optional.of(entity));
JiraServerGlobalConfigModel configModel = jiraServerGlobalConfigAccessor.getConfiguration(id).orElseThrow(() -> new AlertConfigurationException("Cannot find expected configuration"));
assertEquals(id.toString(), configModel.getId());
assertEquals(TEST_URL, configModel.getUrl());
assertEquals(TEST_USERNAME, configModel.getUserName());
assertTrue(configModel.getIsPasswordSet().orElse(Boolean.FALSE));
assertEquals(TEST_PASSWORD, configModel.getPassword().orElse(null));
assertTrue(configModel.getDisablePluginCheck().orElse(Boolean.FALSE));
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.
the class JiraServerGlobalConfigAccessorTest method updateConfigurationNotFoundTest.
@Test
void updateConfigurationNotFoundTest() {
UUID id = UUID.randomUUID();
String updatedName = "updatedName";
String newUrl = "https://updated.example.com";
JiraServerConfigurationEntity entity = createEntity(id, OffsetDateTime.now(), OffsetDateTime.now());
JiraServerGlobalConfigModel model = new JiraServerGlobalConfigModel(null, AlertRestConstants.DEFAULT_CONFIGURATION_NAME, DateUtils.formatDate(entity.getCreatedAt(), DateUtils.UTC_DATE_FORMAT_TO_MINUTE), DateUtils.formatDate(entity.getLastUpdated(), DateUtils.UTC_DATE_FORMAT_TO_MINUTE), TEST_URL, TEST_USERNAME, TEST_PASSWORD, false, true);
Mockito.when(jiraServerConfigurationRepository.findById(id)).thenReturn(Optional.empty());
try {
jiraServerGlobalConfigAccessor.updateConfiguration(id, model);
fail("Exception expected because id not found");
} catch (AlertConfigurationException ex) {
// expected to get here
}
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.
the class JiraServerEnvironmentVariableHandlerFactory method updateConfiguration.
private EnvironmentProcessingResult updateConfiguration() {
EnvironmentProcessingResult.Builder builder = new EnvironmentProcessingResult.Builder(VARIABLE_NAMES);
String url = environmentVariableUtility.getEnvironmentValue(URL_KEY).orElse(null);
if (StringUtils.isBlank(url)) {
return EnvironmentProcessingResult.empty();
}
String name = AlertRestConstants.DEFAULT_CONFIGURATION_NAME;
String userName = environmentVariableUtility.getEnvironmentValue(USERNAME_KEY).orElse(null);
String password = environmentVariableUtility.getEnvironmentValue(PASSWORD_KEY).orElse(null);
String createdAt = DateUtils.formatDate(DateUtils.createCurrentDateTimestamp(), DateUtils.UTC_DATE_FORMAT_TO_MINUTE);
JiraServerGlobalConfigModel configModel = new JiraServerGlobalConfigModel(null, name, url, userName, password);
configModel.setCreatedAt(createdAt);
configModel.setLastUpdated(createdAt);
environmentVariableUtility.getEnvironmentValue(DISABLE_PLUGIN_KEY).map(Boolean::valueOf).ifPresent(configModel::setDisablePluginCheck);
JiraServerGlobalConfigModel obfuscatedModel = configModel.obfuscate();
if (StringUtils.isNotBlank(obfuscatedModel.getUrl())) {
builder.addVariableValue(URL_KEY, obfuscatedModel.getUrl());
}
if (StringUtils.isNotBlank(obfuscatedModel.getUserName())) {
builder.addVariableValue(USERNAME_KEY, obfuscatedModel.getUserName());
}
obfuscatedModel.getDisablePluginCheck().map(String::valueOf).ifPresent(value -> builder.addVariableValue(DISABLE_PLUGIN_KEY, value));
obfuscatedModel.getIsPasswordSet().filter(Boolean::booleanValue).ifPresent(ignored -> builder.addVariableValue(PASSWORD_KEY, AlertConstants.MASKED_VALUE));
EnvironmentProcessingResult result = builder.build();
if (result.hasValues() && configAccessor.getConfigurationByName(name).isEmpty()) {
try {
configAccessor.createConfiguration(configModel);
} catch (AlertConfigurationException ex) {
logger.error("Failed to create config: ", ex);
}
}
return result;
}
Aggregations