use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class FieldModelUtils method createConfigurationFieldModel.
public static ConfigurationFieldModel createConfigurationFieldModel(String key, String value) {
ConfigurationFieldModel field = ConfigurationFieldModel.create(key);
field.setFieldValue(value);
return field;
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class ConfigActions method updateWithoutChecks.
@Override
protected ActionResponse<FieldModel> updateWithoutChecks(Long id, FieldModel resource) {
Optional<ConfigurationModel> optionalPreviousConfig = configurationModelConfigurationAccessor.getConfigurationById(id);
FieldModel previousFieldModel = optionalPreviousConfig.isPresent() ? modelConverter.convertToFieldModel(optionalPreviousConfig.get()) : null;
try {
FieldModel updatedFieldModel = fieldModelProcessor.performBeforeUpdateAction(resource);
Collection<ConfigurationFieldModel> updatedFields = fieldModelProcessor.fillFieldModelWithExistingData(id, updatedFieldModel);
ConfigurationModel configurationModel = configurationModelConfigurationAccessor.updateConfiguration(id, updatedFields);
globalConfigurationModelToConcreteConversionService.updateDefaultConcreteModel(updatedFieldModel.getDescriptorName(), configurationModel);
FieldModel dbSavedModel = modelConverter.convertToFieldModel(configurationModel);
FieldModel afterUpdateAction = fieldModelProcessor.performAfterUpdateAction(previousFieldModel, dbSavedModel);
FieldModel responseModel = dbSavedModel.fill(afterUpdateAction);
return new ActionResponse<>(HttpStatus.OK, responseModel);
} catch (AlertException ex) {
logger.error("Error creating configuration", ex);
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, String.format("Error creating config: %s", ex.getMessage()));
}
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class ConfigActions method findFieldModel.
@Override
protected Optional<FieldModel> findFieldModel(Long id) {
Optional<FieldModel> optionalModel = Optional.empty();
Optional<ConfigurationModel> configurationModel = configurationModelConfigurationAccessor.getConfigurationById(id);
if (configurationModel.isPresent()) {
try {
FieldModel configurationFieldModel = modelConverter.convertToFieldModel(configurationModel.get());
FieldModel fieldModel = fieldModelProcessor.performAfterReadAction(configurationFieldModel);
optionalModel = Optional.of(fieldModel);
} catch (AlertException ex) {
logger.error(String.format("Error finding configuration for id: %d", id), ex);
}
}
return optionalModel;
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class ConfigActions method createWithoutChecks.
@Override
protected ActionResponse<FieldModel> createWithoutChecks(FieldModel resource) {
Optional<DescriptorKey> descriptorKey = descriptorMap.getDescriptorKey(resource.getDescriptorName());
if (descriptorKey.isPresent()) {
try {
FieldModel modifiedFieldModel = fieldModelProcessor.performBeforeSaveAction(resource);
String context = modifiedFieldModel.getContext();
Map<String, ConfigurationFieldModel> configurationFieldModelMap = modelConverter.convertToConfigurationFieldModelMap(modifiedFieldModel);
ConfigurationModel configuration = configurationModelConfigurationAccessor.createConfiguration(descriptorKey.get(), EnumUtils.getEnum(ConfigContextEnum.class, context), configurationFieldModelMap.values());
globalConfigurationModelToConcreteConversionService.createDefaultConcreteModel(modifiedFieldModel.getDescriptorName(), configuration);
FieldModel dbSavedModel = modelConverter.convertToFieldModel(configuration);
FieldModel afterSaveAction = fieldModelProcessor.performAfterSaveAction(dbSavedModel);
FieldModel responseModel = dbSavedModel.fill(afterSaveAction);
return new ActionResponse<>(HttpStatus.OK, responseModel);
} catch (AlertException ex) {
logger.error("Error creating configuration", ex);
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, String.format("Error creating config: %s", ex.getMessage()));
}
}
return new ActionResponse<>(HttpStatus.BAD_REQUEST, "descriptorName is missing or invalid");
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationModelConverterTest method invalidEmailPropertyKeysTest.
@Test
void invalidEmailPropertyKeysTest() {
String invalidFieldKey = "invalid.email.field";
ConfigurationFieldModel invalidField = ConfigurationFieldModel.create(invalidFieldKey);
Map<String, ConfigurationFieldModel> fieldValues = Map.of(invalidFieldKey, invalidField);
ConfigurationModel configurationModel = new ConfigurationModel(1L, 1L, "", "", ConfigContextEnum.GLOBAL, fieldValues);
EmailGlobalConfigurationModelConverter converter = new EmailGlobalConfigurationModelConverter();
Optional<EmailGlobalConfigModel> model = converter.convert(configurationModel);
assertTrue(model.isPresent());
EmailGlobalConfigModel emailModel = model.get();
Map<String, String> additionalProperties = emailModel.getAdditionalJavaMailProperties().orElse(Map.of());
assertEquals(0, additionalProperties.size());
}
Aggregations