use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class AzureBoardsGlobalFieldModelTestAction method testConfig.
@Override
public MessageResult testConfig(String configId, FieldModel fieldModel, FieldUtility registeredFieldValues) throws IntegrationException {
try {
Optional<ConfigurationFieldModel> configurationFieldModel = registeredFieldValues.getField(AzureBoardsDescriptor.KEY_ORGANIZATION_NAME);
String organizationName = configurationFieldModel.flatMap(ConfigurationFieldModel::getFieldValue).orElse(null);
AzureBoardsProperties azureBoardsProperties = AzureBoardsProperties.fromFieldAccessor(azureBoardsCredentialDataStoreFactory, azureRedirectUrlCreator.createOAuthRedirectUri(), registeredFieldValues);
AzureHttpService azureHttpService = createAzureHttpService(azureBoardsProperties);
AzureProjectService azureProjectService = new AzureProjectService(azureHttpService, new AzureApiVersionAppender());
azureProjectService.getProjects(organizationName);
return new MessageResult("Successfully connected to Azure instance.");
} catch (HttpServiceException ex) {
logger.error("Global Test Action failed testing Azure Boards connection.", ex);
throw (ex);
}
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel 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);
}
}
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class AlertStartupInitializer method createFieldModelsFromDefinedFields.
private Set<ConfigurationFieldModel> createFieldModelsFromDefinedFields(DescriptorKey descriptorKey, List<DefinedFieldModel> fieldsForDescriptor, Map<String, ConfigurationFieldModel> existingConfiguredFields) {
Set<ConfigurationFieldModel> configurationModels = new HashSet<>();
logger.info(" ### Environment Variables ### ");
for (DefinedFieldModel fieldModel : fieldsForDescriptor) {
String key = fieldModel.getKey();
String convertedKey = environmentUtility.convertKeyToProperty(descriptorKey, key);
boolean hasEnvironmentValue = environmentUtility.hasEnvironmentValue(convertedKey);
logger.info(" {}", convertedKey);
logger.debug(" Environment Variable Found - {}", hasEnvironmentValue);
String defaultValue = null;
if (existingConfiguredFields.containsKey(key)) {
Optional<String> fieldValue = existingConfiguredFields.get(key).getFieldValue();
if (fieldValue.isPresent()) {
defaultValue = fieldValue.get();
}
}
environmentUtility.getEnvironmentValue(convertedKey, defaultValue).flatMap(value -> modelConverter.convertFromDefinedFieldModel(fieldModel, value, StringUtils.isNotBlank(value))).ifPresent(configurationModels::add);
}
return configurationModels;
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class AlertStartupInitializer method saveAction.
private Collection<ConfigurationFieldModel> saveAction(DescriptorKey descriptorKey, Collection<ConfigurationFieldModel> configurationFieldModels) throws AlertException {
Map<String, FieldValueModel> fieldValueModelMap = modelConverter.convertToFieldValuesMap(configurationFieldModels);
FieldModel fieldModel = new FieldModel(descriptorKey.getUniversalKey(), ConfigContextEnum.GLOBAL.name(), fieldValueModelMap);
FieldModel savedFieldModel = fieldModelProcessor.performBeforeSaveAction(fieldModel);
return modelConverter.convertToConfigurationFieldModelMap(savedFieldModel).values();
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel 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());
}
Aggregations