Search in sources :

Example 31 with ConfigurationModel

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

the class BlackDuckNotificationRetrieverFactoryTest method createBlackDuckProperties.

private BlackDuckProperties createBlackDuckProperties(String blackDuckUrl) {
    ConfigurationModel configurationModel = createConfigurationModel(blackDuckUrl);
    ProxyManager proxyManager = new ProxyManager(new MockSettingsUtility());
    return new BlackDuckProperties(1L, new Gson(), BlackDuckServicesFactory.createDefaultObjectMapper(), new MockAlertProperties(), proxyManager, configurationModel);
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager) MockAlertProperties(com.synopsys.integration.alert.test.common.MockAlertProperties) Gson(com.google.gson.Gson)

Example 32 with ConfigurationModel

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

the class AlertStartupInitializer method initializeConfiguration.

private void initializeConfiguration(Collection<DescriptorKey> descriptorKeys) {
    for (DescriptorKey descriptorKey : descriptorKeys) {
        logger.info(LINE_DIVIDER);
        logger.info("Descriptor: {}", descriptorKey.getUniversalKey());
        logger.info(LINE_DIVIDER);
        logger.info("  Starting Descriptor Initialization...");
        try {
            List<DefinedFieldModel> fieldsForDescriptor = descriptorAccessor.getFieldsForDescriptor(descriptorKey, ConfigContextEnum.GLOBAL).stream().sorted(Comparator.comparing(DefinedFieldModel::getKey)).collect(Collectors.toList());
            List<ConfigurationModel> foundConfigurationModels = fieldConfigurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(descriptorKey, ConfigContextEnum.GLOBAL);
            Map<String, ConfigurationFieldModel> existingConfiguredFields = new HashMap<>();
            foundConfigurationModels.forEach(config -> existingConfiguredFields.putAll(config.getCopyOfKeyToFieldMap()));
            Set<ConfigurationFieldModel> configurationModels = createFieldModelsFromDefinedFields(descriptorKey, fieldsForDescriptor, existingConfiguredFields);
            logConfiguration(configurationModels);
            updateConfigurationFields(descriptorKey, foundConfigurationModels, configurationModels);
        } catch (IllegalArgumentException | SecurityException | AlertException ex) {
            logger.error("error initializing descriptor", ex);
        } finally {
            logger.info("  Finished Descriptor Initialization...");
            logger.info(LINE_DIVIDER);
        }
    }
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) DefinedFieldModel(com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel) HashMap(java.util.HashMap) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 33 with ConfigurationModel

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

the class BlackDuckGlobalConfigurationFieldModelValidatorTest method nonUniqueName.

@Test
public void nonUniqueName() {
    String duplicateName = "duplicateName";
    Map<String, FieldValueModel> defaultKeyToValues = createDefaultKeyToValues();
    FieldValueModel apiKeyFieldValueModel = new FieldValueModel(List.of(duplicateName), true);
    defaultKeyToValues.put(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME, apiKeyFieldValueModel);
    FieldModel fieldModel = new FieldModel(new BlackDuckProviderKey().getUniversalKey(), ConfigContextEnum.GLOBAL.name(), defaultKeyToValues);
    ConfigurationFieldModel configurationFieldModel = Mockito.mock(ConfigurationFieldModel.class);
    Mockito.when(configurationFieldModel.getFieldValue()).thenReturn(Optional.of(duplicateName));
    ConfigurationModel configurationModel = Mockito.mock(ConfigurationModel.class);
    Mockito.when(configurationModel.getDescriptorContext()).thenReturn(ConfigContextEnum.GLOBAL);
    Mockito.when(configurationModel.getField(Mockito.any())).thenReturn(Optional.of(configurationFieldModel));
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorType(Mockito.any())).thenReturn(List.of(configurationModel));
    BlackDuckGlobalConfigurationFieldModelValidator blackDuckGlobalConfigurationValidator = new BlackDuckGlobalConfigurationFieldModelValidator(configurationModelConfigurationAccessor);
    Set<AlertFieldStatus> alertFieldStatuses = blackDuckGlobalConfigurationValidator.validate(fieldModel);
    assertEquals(1, alertFieldStatuses.size());
    AlertFieldStatus alertFieldStatus = alertFieldStatuses.stream().findFirst().orElse(null);
    assertNotNull(alertFieldStatus);
    assertEquals(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME, alertFieldStatus.getFieldName());
}
Also used : BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) Test(org.junit.jupiter.api.Test)

Example 34 with ConfigurationModel

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

the class NotificationExtractorBlackDuckServicesFactoryCacheTest method createConfigurationModel.

private ConfigurationModel createConfigurationModel() {
    Map<String, ConfigurationFieldModel> configuredFields = new HashMap<>();
    ConfigurationFieldModel apiKey = ConfigurationFieldModel.create(BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY);
    apiKey.setFieldValue("blackDuckApiKey");
    configuredFields.put(BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY, apiKey);
    ConfigurationFieldModel url = ConfigurationFieldModel.create(BlackDuckDescriptor.KEY_BLACKDUCK_URL);
    url.setFieldValue("http://blackDuckUrl");
    configuredFields.put(BlackDuckDescriptor.KEY_BLACKDUCK_URL, url);
    return new ConfigurationModel(1L, 2L, "createdAt", "lastUpdated", ConfigContextEnum.GLOBAL, configuredFields);
}
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 35 with ConfigurationModel

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

the class NotificationExtractorBlackDuckServicesFactoryCacheTest method invalidConfigurationTest.

@Test
public void invalidConfigurationTest() {
    ConfigurationModel configurationModel = new ConfigurationModel(1L, 2L, "createdAt", "lastUpdated", ConfigContextEnum.GLOBAL, Map.of());
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(Mockito.eq(blackDuckConfigId))).thenReturn(Optional.of(configurationModel));
    try {
        cache.retrieveBlackDuckServicesFactory(blackDuckConfigId);
        fail("Expected AlertConfigurationException to be thrown due to missing configuredFields in the ConfigurationModel.");
    } catch (AlertConfigurationException e) {
    // Pass
    }
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)140 Test (org.junit.jupiter.api.Test)89 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)49 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)33 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)31 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)22 List (java.util.List)15 AtomicReference (java.util.concurrent.atomic.AtomicReference)14 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)13 DescriptorMap (com.synopsys.integration.alert.common.descriptor.DescriptorMap)13 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)13 HashMap (java.util.HashMap)13 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)11 NotificationContentRepository (com.synopsys.integration.alert.database.notification.NotificationContentRepository)11 NotificationEntity (com.synopsys.integration.alert.database.notification.NotificationEntity)11 DescriptorConfigEntity (com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity)10 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)10 ArrayList (java.util.ArrayList)10 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)9 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)9