Search in sources :

Example 81 with ConfigurationFieldModel

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;
}
Also used : ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)

Example 82 with ConfigurationFieldModel

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()));
    }
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) MultiFieldModel(com.synopsys.integration.alert.common.rest.model.MultiFieldModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 83 with ConfigurationFieldModel

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;
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) MultiFieldModel(com.synopsys.integration.alert.common.rest.model.MultiFieldModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 84 with ConfigurationFieldModel

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");
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) SettingsDescriptorKey(com.synopsys.integration.alert.component.settings.descriptor.SettingsDescriptorKey) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) MultiFieldModel(com.synopsys.integration.alert.common.rest.model.MultiFieldModel) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 85 with ConfigurationFieldModel

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());
}
Also used : EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)105 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)47 Test (org.junit.jupiter.api.Test)32 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)27 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)23 HashMap (java.util.HashMap)20 ConfigurationFieldModelConverter (com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter)14 ArrayList (java.util.ArrayList)13 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)12 FieldValueModel (com.synopsys.integration.alert.common.rest.model.FieldValueModel)12 DescriptorAccessor (com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor)11 DefinedFieldModel (com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel)11 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)10 BlackDuckProviderKey (com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey)10 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)9 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)9 ConfigurationModelMutable (com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable)8 EncryptionUtility (com.synopsys.integration.alert.common.security.EncryptionUtility)8 BeforeEach (org.junit.jupiter.api.BeforeEach)8 FieldUtility (com.synopsys.integration.alert.common.persistence.accessor.FieldUtility)7