use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class NotificationReceivedEventHandlerTestIT method init.
@BeforeEach
public void init() {
properties = new TestProperties();
ConfigurationFieldModel providerConfigEnabled = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROVIDER_CONFIG_ENABLED);
providerConfigEnabled.setFieldValue("TRUE");
ConfigurationFieldModel providerConfigName = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME);
providerConfigName.setFieldValue("blackduck-config");
ConfigurationFieldModel blackduckUrl = ConfigurationFieldModel.create(BlackDuckDescriptor.KEY_BLACKDUCK_URL);
blackduckUrl.setFieldValue(properties.getBlackDuckURL());
ConfigurationFieldModel blackduckApiKey = ConfigurationFieldModel.createSensitive(BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY);
blackduckApiKey.setFieldValue(properties.getBlackDuckAPIToken());
ConfigurationFieldModel blackduckTimeout = ConfigurationFieldModel.create(BlackDuckDescriptor.KEY_BLACKDUCK_TIMEOUT);
blackduckTimeout.setFieldValue(String.valueOf(BlackDuckProperties.DEFAULT_TIMEOUT));
ConfigurationModel blackduckConfigurationModel = defaultConfigurationAccessor.createConfiguration(blackDuckProviderKey, ConfigContextEnum.GLOBAL, List.of(providerConfigEnabled, providerConfigName, blackduckUrl, blackduckApiKey, blackduckTimeout));
blackDuckGlobalConfigId = blackduckConfigurationModel.getConfigurationId();
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class DefaultDescriptorGlobalConfigUtility method save.
public FieldModel save(FieldModel fieldModel) throws AlertException {
FieldModel beforeAction = apiAction.beforeSaveAction(fieldModel);
Collection<ConfigurationFieldModel> values = configurationFieldModelConverter.convertToConfigurationFieldModelMap(beforeAction).values();
ConfigurationModel configuration = configurationModelConfigurationAccessor.createConfiguration(key, context, values);
FieldModel convertedFieldModel = configurationFieldModelConverter.convertToFieldModel(configuration);
return apiAction.afterSaveAction(convertedFieldModel);
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class DefaultDescriptorGlobalConfigUtility method update.
public FieldModel update(Long id, FieldModel fieldModel) throws AlertException {
FieldModel beforeUpdateActionFieldModel = apiAction.beforeUpdateAction(fieldModel);
Map<String, ConfigurationFieldModel> valueMap = configurationFieldModelConverter.convertToConfigurationFieldModelMap(beforeUpdateActionFieldModel);
Optional<ConfigurationModel> existingConfig = configurationModelConfigurationAccessor.getConfigurationById(id);
ConfigurationModel configurationModel;
if (existingConfig.isPresent()) {
Map<String, ConfigurationFieldModel> updatedValues = updateSensitiveFields(valueMap, existingConfig.get());
configurationModel = configurationModelConfigurationAccessor.updateConfiguration(id, updatedValues.values());
} else {
configurationModel = configurationModelConfigurationAccessor.createConfiguration(key, context, valueMap.values());
}
FieldModel convertedFieldModel = configurationFieldModelConverter.convertToFieldModel(configurationModel);
return apiAction.afterUpdateAction(beforeUpdateActionFieldModel, convertedFieldModel);
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class DefaultConfigurationModelConfigurationAccessorTest method decryptTest.
@Test
public void decryptTest() {
final String decryptedString = "decryptedString";
final String providerConfigName = "provider-config-name-test";
final String emptyProviderConfigName = "bad-config-name";
final Long fieldId = 1L;
final Long descriptorId = 4L;
final Long configurationId = 6L;
DefinedFieldEntity definedFieldEntity = new DefinedFieldEntity(fieldKey, true);
definedFieldEntity.setId(fieldId);
FieldValueEntity fieldValueEntity = new FieldValueEntity(2L, 3L, fieldValue);
DescriptorConfigEntity descriptorConfigEntity = new DescriptorConfigEntity(descriptorId, 5L, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp());
descriptorConfigEntity.setId(configurationId);
ConfigContextEntity configContextEntity = new ConfigContextEntity(configContextEnum.name());
EncryptionUtility encryptionUtilityDecrypt = Mockito.mock(EncryptionUtility.class);
Mockito.when(definedFieldRepository.findFirstByKey(Mockito.any())).thenReturn(Optional.of(definedFieldEntity));
Mockito.when(fieldValueRepository.findAllByFieldIdAndValue(fieldId, providerConfigName)).thenReturn(List.of(fieldValueEntity));
Mockito.when(fieldValueRepository.findAllByFieldIdAndValue(fieldId, emptyProviderConfigName)).thenReturn(List.of());
setupGetJobMocks(descriptorConfigEntity, configContextEntity, fieldValueEntity, definedFieldEntity);
Mockito.when(encryptionUtilityDecrypt.decrypt(Mockito.any())).thenReturn(decryptedString);
DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = new DefaultConfigurationModelConfigurationAccessor(null, definedFieldRepository, descriptorConfigRepository, configContextRepository, fieldValueRepository, encryptionUtilityDecrypt);
Optional<ConfigurationModel> configurationModelOptional = configurationModelConfigurationAccessor.getProviderConfigurationByName(providerConfigName);
assertTrue(configurationModelOptional.isPresent());
ConfigurationModel configurationModel = configurationModelOptional.get();
testConfigurationModel(configurationId, descriptorId, configurationModel);
assertEquals(decryptedString, configurationModel.getField(fieldKey).get().getFieldValue().get());
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class DefaultConfigurationModelConfigurationAccessorTest method deleteConfigurationTest.
@Test
public void deleteConfigurationTest() {
ConfigurationModel configurationModel = new ConfigurationModel(1L, 2L, "dateCreated", "lastUpdated", configContextEnum);
DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = new DefaultConfigurationModelConfigurationAccessor(null, null, descriptorConfigRepository, null, null, null);
configurationModelConfigurationAccessor.deleteConfiguration(configurationModel);
Mockito.verify(descriptorConfigRepository).deleteById(Mockito.any());
}
Aggregations