use of com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable in project hub-alert by blackducksoftware.
the class ConfigurationModel method createMutableCopy.
public ConfigurationModelMutable createMutableCopy() {
ConfigurationModelMutable mutableCopy = new ConfigurationModelMutable(descriptorId, configurationId, createdAt, lastUpdated, context);
mutableCopy.getConfiguredFields().putAll(configuredFields);
return mutableCopy;
}
use of com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable in project hub-alert by blackducksoftware.
the class ConfigurationFieldModelConverter method convertToConfigurationModel.
public ConfigurationModel convertToConfigurationModel(FieldModel fieldModel) {
String descriptorName = fieldModel.getDescriptorName();
DescriptorKey descriptorKey = getDescriptorKey(descriptorName).orElseThrow(() -> new AlertRuntimeException("Could not find a Descriptor with the name: " + descriptorName));
long descriptorId = descriptorAccessor.getRegisteredDescriptorByKey(descriptorKey).map(RegisteredDescriptorModel::getId).orElse(0L);
long configId = Long.parseLong(fieldModel.getId());
ConfigurationModelMutable configurationModel = new ConfigurationModelMutable(configId, descriptorId, fieldModel.getCreatedAt(), fieldModel.getLastUpdated(), fieldModel.getContext());
convertToConfigurationFieldModelMap(fieldModel).values().forEach(configurationModel::put);
return configurationModel;
}
use of com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable in project hub-alert by blackducksoftware.
the class DefaultConfigurationModelConfigurationAccessor method createConfiguration.
private ConfigurationModel createConfiguration(String descriptorKey, ConfigContextEnum context, Collection<ConfigurationFieldModel> configuredFields) {
Long descriptorId = getDescriptorIdOrThrowException(descriptorKey);
Long configContextId = getConfigContextIdOrThrowException(context);
OffsetDateTime currentTime = DateUtils.createCurrentDateTimestamp();
DescriptorConfigEntity descriptorConfigToSave = new DescriptorConfigEntity(descriptorId, configContextId, currentTime, currentTime);
DescriptorConfigEntity savedDescriptorConfig = descriptorConfigsRepository.save(descriptorConfigToSave);
ConfigurationModelMutable createdConfig = createEmptyConfigModel(descriptorId, savedDescriptorConfig.getId(), savedDescriptorConfig.getCreatedAt(), savedDescriptorConfig.getLastUpdated(), context);
if (configuredFields != null && !configuredFields.isEmpty()) {
List<FieldValueEntity> fieldValuesToSave = new ArrayList<>(configuredFields.size());
for (ConfigurationFieldModel configuredField : configuredFields) {
String fieldKey = configuredField.getFieldKey();
if (configuredField.isSet()) {
DefinedFieldEntity associatedField = definedFieldRepository.findFirstByKey(fieldKey).orElseThrow(() -> new AlertRuntimeException(String.format("FATAL: Field with key '%s' did not exist", fieldKey)));
for (String value : configuredField.getFieldValues()) {
FieldValueEntity newFieldValueEntity = new FieldValueEntity(createdConfig.getConfigurationId(), associatedField.getId(), encrypt(value, configuredField.isSensitive()));
fieldValuesToSave.add(newFieldValueEntity);
}
}
createdConfig.put(configuredField);
}
fieldValueRepository.saveAll(fieldValuesToSave);
}
return createdConfig;
}
use of com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable in project hub-alert by blackducksoftware.
the class DefaultConfigurationModelConfigurationAccessor method updateConfiguration.
/**
* @return the config after update
*/
@Override
public ConfigurationModel updateConfiguration(Long descriptorConfigId, Collection<ConfigurationFieldModel> configuredFields) throws AlertConfigurationException {
DescriptorConfigEntity descriptorConfigEntity = descriptorConfigsRepository.findById(descriptorConfigId).orElseThrow(() -> new AlertConfigurationException(String.format("Config with id '%d' did not exist", descriptorConfigId)));
List<FieldValueEntity> oldValues = fieldValueRepository.findByConfigId(descriptorConfigId);
fieldValueRepository.deleteAll(oldValues);
fieldValueRepository.flush();
ConfigurationModelMutable updatedConfig = createEmptyConfigModel(descriptorConfigEntity.getDescriptorId(), descriptorConfigEntity.getId(), descriptorConfigEntity.getCreatedAt(), descriptorConfigEntity.getLastUpdated(), descriptorConfigEntity.getContextId());
if (configuredFields != null && !configuredFields.isEmpty()) {
List<FieldValueEntity> fieldValuesToSave = new ArrayList<>(configuredFields.size());
for (ConfigurationFieldModel configFieldModel : configuredFields) {
String fieldKey = configFieldModel.getFieldKey();
Long fieldId = getFieldIdOrThrowException(fieldKey);
boolean isSensitive = isFieldSensitive(fieldKey);
for (String value : configFieldModel.getFieldValues()) {
FieldValueEntity newFieldValue = new FieldValueEntity(descriptorConfigId, fieldId, encrypt(value, isSensitive));
fieldValuesToSave.add(newFieldValue);
}
updatedConfig.put(configFieldModel);
}
fieldValueRepository.saveAll(fieldValuesToSave);
fieldValueRepository.flush();
}
descriptorConfigEntity.setLastUpdated(DateUtils.createCurrentDateTimestamp());
descriptorConfigsRepository.save(descriptorConfigEntity);
return updatedConfig;
}
use of com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable in project hub-alert by blackducksoftware.
the class BlackDuckSSOConfigRetrieverTest method createBlackDuckProperties.
private BlackDuckProperties createBlackDuckProperties() {
TestProperties testProperties = new TestProperties();
String blackDuckUrl = testProperties.getBlackDuckURL();
String blackDuckApiKey = testProperties.getBlackDuckAPIToken();
String blackDuckTimeout = testProperties.getOptionalProperty(TestPropertyKey.TEST_BLACKDUCK_PROVIDER_TIMEOUT).orElse("300");
MockAlertProperties mockAlertProperties = new MockAlertProperties();
ProxyManager mockProxyManager = Mockito.mock(ProxyManager.class);
Mockito.when(mockProxyManager.createProxyInfoForHost(Mockito.anyString())).thenReturn(ProxyInfo.NO_PROXY_INFO);
ConfigurationModelMutable configurationModel = new ConfigurationModelMutable(0L, 0L, null, null, ConfigContextEnum.GLOBAL);
configurationModel.put(createConfigFieldModel(ProviderDescriptor.KEY_PROVIDER_CONFIG_ENABLED, Boolean.TRUE.toString()));
configurationModel.put(createConfigFieldModel(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME, BlackDuckSSOConfigRetrieverTest.class.getSimpleName()));
configurationModel.put(createConfigFieldModel(BlackDuckDescriptor.KEY_BLACKDUCK_URL, blackDuckUrl));
configurationModel.put(createConfigFieldModel(BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY, blackDuckApiKey));
configurationModel.put(createConfigFieldModel(BlackDuckDescriptor.KEY_BLACKDUCK_TIMEOUT, blackDuckTimeout));
return new BlackDuckProperties(0L, new Gson(), BlackDuckServicesFactory.createDefaultObjectMapper(), mockAlertProperties, mockProxyManager, configurationModel);
}
Aggregations