Search in sources :

Example 26 with AlertConfigurationException

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));
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Example 27 with AlertConfigurationException

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));
}
Also used : JiraServerGlobalConfigModel(com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel) JiraServerConfigurationEntity(com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationEntity) UUID(java.util.UUID) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Test(org.junit.jupiter.api.Test)

Example 28 with AlertConfigurationException

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));
}
Also used : JiraServerGlobalConfigModel(com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel) JiraServerConfigurationEntity(com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationEntity) UUID(java.util.UUID) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Test(org.junit.jupiter.api.Test)

Example 29 with AlertConfigurationException

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
    }
}
Also used : JiraServerGlobalConfigModel(com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel) JiraServerConfigurationEntity(com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationEntity) UUID(java.util.UUID) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Test(org.junit.jupiter.api.Test)

Example 30 with AlertConfigurationException

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;
}
Also used : JiraServerGlobalConfigModel(com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel) EnvironmentProcessingResult(com.synopsys.integration.alert.environment.EnvironmentProcessingResult) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Aggregations

AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)54 Test (org.junit.jupiter.api.Test)20 Transactional (org.springframework.transaction.annotation.Transactional)10 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)8 UUID (java.util.UUID)8 EmailGlobalConfigModel (com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)5 Map (java.util.Map)5 JiraServerConfigurationEntity (com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationEntity)4 JiraServerGlobalConfigModel (com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel)4 AlertForbiddenOperationException (com.synopsys.integration.alert.common.exception.AlertForbiddenOperationException)4 UserModel (com.synopsys.integration.alert.common.persistence.model.UserModel)4 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)4 HashMap (java.util.HashMap)4 EmailGlobalCrudActions (com.synopsys.integration.alert.channel.email.action.EmailGlobalCrudActions)3 AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)3 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)3 UserRoleModel (com.synopsys.integration.alert.common.persistence.model.UserRoleModel)3 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)3 UserEntity (com.synopsys.integration.alert.database.user.UserEntity)3 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)3