use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class DefaultDescriptorGlobalConfigUtilityTest method testGetFieldModel.
@Test
public void testGetFieldModel() throws Exception {
DescriptorKey descriptorKey = createDescriptorKey();
FieldModel fieldModel = new FieldModel(descriptorKey.getUniversalKey(), ConfigContextEnum.GLOBAL.name(), Map.of());
ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
ConfigurationFieldModelConverter converter = Mockito.mock(ConfigurationFieldModelConverter.class);
ConfigurationModel configurationModel = Mockito.mock(ConfigurationModel.class);
ApiAction apiAction = Mockito.mock(ApiAction.class);
Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class))).thenReturn(List.of(configurationModel));
Mockito.when(converter.convertToFieldModel(Mockito.any())).thenReturn(fieldModel);
Mockito.when(apiAction.afterGetAction(Mockito.eq(fieldModel))).thenReturn(fieldModel);
DefaultDescriptorGlobalConfigUtility configUtility = new DefaultDescriptorGlobalConfigUtility(descriptorKey, configurationModelConfigurationAccessor, apiAction, converter);
FieldModel actualFieldModel = configUtility.getFieldModel().orElse(null);
assertEquals(fieldModel, actualFieldModel);
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class AzureBoardsCredentialDataStore method set.
@Override
public AzureBoardsCredentialDataStore set(String key, StoredCredential value) throws IOException {
if (null != key && null != value) {
ConfigurationModel defaultConfig = retrieveConfiguration();
Map<String, ConfigurationFieldModel> keyToFieldMap = defaultConfig.getCopyOfKeyToFieldMap();
setFieldValue(keyToFieldMap, AzureBoardsDescriptor.KEY_OAUTH_USER_EMAIL, key);
setFieldValue(keyToFieldMap, AzureBoardsDescriptor.KEY_ACCESS_TOKEN, value.getAccessToken());
setFieldValue(keyToFieldMap, AzureBoardsDescriptor.KEY_REFRESH_TOKEN, value.getRefreshToken());
Long expTimeMillis = value.getExpirationTimeMilliseconds();
String expTimeMillisString = expTimeMillis != null ? expTimeMillis.toString() : null;
setFieldValue(keyToFieldMap, AzureBoardsDescriptor.KEY_TOKEN_EXPIRATION_MILLIS, expTimeMillisString);
try {
configurationModelConfigurationAccessor.updateConfiguration(defaultConfig.getConfigurationId(), keyToFieldMap.values());
} catch (AlertConfigurationException e) {
throw new IOException("Cannot update the Azure Boards global configuration", e);
}
}
return this;
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class AzureBoardsGlobalApiAction method beforeUpdateAction.
@Override
public FieldModel beforeUpdateAction(FieldModel fieldModel) throws AlertException {
FieldModel updatedFieldModel = super.beforeUpdateAction(fieldModel);
Optional<ConfigurationModel> existingConfig = configurationModelConfigurationAccessor.getConfigurationById(Long.valueOf(fieldModel.getId()));
return existingConfig.map(config -> updateTokenFields(updatedFieldModel, config)).orElse(updatedFieldModel);
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class AzureBoardsGlobalApiAction method beforeSaveAction.
@Override
public FieldModel beforeSaveAction(FieldModel fieldModel) throws AlertException {
FieldModel updatedFieldModel = super.beforeSaveAction(fieldModel);
Optional<DescriptorKey> descriptorKey = descriptorMap.getDescriptorKey(fieldModel.getDescriptorName());
if (!descriptorKey.isPresent()) {
return updatedFieldModel;
}
ConfigContextEnum context = ConfigContextEnum.valueOf(fieldModel.getContext());
List<ConfigurationModel> existingConfig = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(descriptorKey.get(), context);
Optional<ConfigurationModel> configurationModel = existingConfig.stream().findFirst();
return configurationModel.map(config -> updateTokenFields(updatedFieldModel, config)).orElse(updatedFieldModel);
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class BlackDuckProviderDataAccessor method getProviderConfigUserById.
@Override
public ProviderUserModel getProviderConfigUserById(Long providerConfigId) throws AlertConfigurationException {
try {
Optional<ConfigurationModel> providerConfigOptional = configurationModelConfigurationAccessor.getConfigurationById(providerConfigId);
if (providerConfigOptional.isPresent()) {
BlackDuckServicesFactory blackDuckServicesFactory = createBlackDuckServicesFactory(providerConfigOptional.get());
UserService userService = blackDuckServicesFactory.createUserService();
UserView providerConfigUser = userService.findCurrentUser();
return new ProviderUserModel(providerConfigUser.getEmail(), false);
}
} catch (IntegrationException e) {
throw new AlertConfigurationException(createUserNotFoundString(providerConfigId, e.getMessage()), e);
}
throw new AlertConfigurationException(String.format("The provider config with id '%s' is invalid", providerConfigId));
}
Aggregations