Search in sources :

Example 11 with DefinedFieldModel

use of com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel in project hub-alert by blackducksoftware.

the class ConfigurationFieldModelConverter method convertToConfigurationFieldModelMap.

public final Map<String, ConfigurationFieldModel> convertToConfigurationFieldModelMap(FieldModel fieldModel) {
    ConfigContextEnum context = EnumUtils.getEnum(ConfigContextEnum.class, fieldModel.getContext());
    String descriptorName = fieldModel.getDescriptorName();
    DescriptorKey descriptorKey = getDescriptorKey(descriptorName).orElseThrow(() -> new AlertRuntimeException("Could not find a Descriptor with the name: " + descriptorName));
    List<DefinedFieldModel> fieldsForContext = descriptorAccessor.getFieldsForDescriptor(descriptorKey, context);
    Map<String, ConfigurationFieldModel> configurationModels = new HashMap<>();
    for (DefinedFieldModel definedField : fieldsForContext) {
        fieldModel.getFieldValueModel(definedField.getKey()).flatMap(fieldValueModel -> convertFromDefinedFieldModel(definedField, fieldValueModel.getValues(), fieldValueModel.getIsSet())).ifPresent(configurationFieldModel -> configurationModels.put(configurationFieldModel.getFieldKey(), configurationFieldModel));
    }
    return configurationModels;
}
Also used : DefinedFieldModel(com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel) DescriptorAccessor(com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DataStructureUtils(com.synopsys.integration.alert.common.util.DataStructureUtils) Collection(java.util.Collection) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) BooleanUtils(org.apache.commons.lang3.BooleanUtils) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) StringUtils(org.apache.commons.lang3.StringUtils) ConfigurationModelMutable(com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) FieldUtility(com.synopsys.integration.alert.common.persistence.accessor.FieldUtility) RegisteredDescriptorModel(com.synopsys.integration.alert.common.persistence.model.RegisteredDescriptorModel) List(java.util.List) Component(org.springframework.stereotype.Component) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) EnumUtils(org.apache.commons.lang3.EnumUtils) Map(java.util.Map) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) Optional(java.util.Optional) EncryptionUtility(com.synopsys.integration.alert.common.security.EncryptionUtility) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DefinedFieldModel(com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel) HashMap(java.util.HashMap) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)

Example 12 with DefinedFieldModel

use of com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel in project hub-alert by blackducksoftware.

the class ConfigurationFieldModelTest method convertDefinedFieldModelWithValuesEmptyTest.

@Test
public void convertDefinedFieldModelWithValuesEmptyTest() throws Exception {
    List<DefinedFieldModel> configFields = createConfigFields();
    EncryptionUtility encryptionUtility = Mockito.mock(EncryptionUtility.class);
    DescriptorAccessor descriptorAccessor = new MockDescriptorAccessor(configFields);
    List<DescriptorKey> descriptorKeys = createDescriptorKeyList();
    ConfigurationFieldModelConverter modelConverter = new ConfigurationFieldModelConverter(encryptionUtility, descriptorAccessor, descriptorKeys);
    Optional<ConfigurationFieldModel> optionalModel = modelConverter.convertFromDefinedFieldModel(new DefinedFieldModel(KEY_FIELD_1, ConfigContextEnum.GLOBAL, true), List.of(VALUE_FIELD_1, VALUE_FIELD_2), true);
    assertTrue(optionalModel.isEmpty());
}
Also used : ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DefinedFieldModel(com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel) MockDescriptorAccessor(com.synopsys.integration.alert.mock.MockDescriptorAccessor) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) MockDescriptorAccessor(com.synopsys.integration.alert.mock.MockDescriptorAccessor) DescriptorAccessor(com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) EncryptionUtility(com.synopsys.integration.alert.common.security.EncryptionUtility) Test(org.junit.jupiter.api.Test)

Example 13 with DefinedFieldModel

use of com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel in project hub-alert by blackducksoftware.

the class ConfigurationFieldModelTest method convertDefinedFieldModelTest.

@Test
public void convertDefinedFieldModelTest() throws Exception {
    List<DefinedFieldModel> configFields = createConfigFields();
    EncryptionUtility encryptionUtility = Mockito.mock(EncryptionUtility.class);
    Mockito.when(encryptionUtility.isInitialized()).thenReturn(true);
    DescriptorAccessor descriptorAccessor = new MockDescriptorAccessor(configFields);
    List<DescriptorKey> descriptorKeys = createDescriptorKeyList();
    ConfigurationFieldModelConverter modelConverter = new ConfigurationFieldModelConverter(encryptionUtility, descriptorAccessor, descriptorKeys);
    Optional<ConfigurationFieldModel> optionalModel = modelConverter.convertFromDefinedFieldModel(new DefinedFieldModel(KEY_FIELD_1, ConfigContextEnum.GLOBAL, false), VALUE_FIELD_1, true);
    assertTrue(optionalModel.isPresent());
    ConfigurationFieldModel actualModel = optionalModel.get();
    assertEquals(VALUE_FIELD_1, actualModel.getFieldValue().orElseThrow(IllegalArgumentException::new));
    assertFalse(actualModel.isSensitive());
    assertEquals(KEY_FIELD_1, actualModel.getFieldKey());
    optionalModel = modelConverter.convertFromDefinedFieldModel(new DefinedFieldModel(KEY_FIELD_1, ConfigContextEnum.GLOBAL, true), VALUE_FIELD_1, true);
    assertTrue(optionalModel.isPresent());
    actualModel = optionalModel.get();
    assertEquals(VALUE_FIELD_1, actualModel.getFieldValue().orElseThrow(IllegalArgumentException::new));
    assertTrue(actualModel.isSensitive());
    assertEquals(KEY_FIELD_1, actualModel.getFieldKey());
}
Also used : ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DefinedFieldModel(com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel) MockDescriptorAccessor(com.synopsys.integration.alert.mock.MockDescriptorAccessor) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) MockDescriptorAccessor(com.synopsys.integration.alert.mock.MockDescriptorAccessor) DescriptorAccessor(com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) EncryptionUtility(com.synopsys.integration.alert.common.security.EncryptionUtility) Test(org.junit.jupiter.api.Test)

Aggregations

DefinedFieldModel (com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel)13 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)10 Test (org.junit.jupiter.api.Test)10 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)9 DescriptorAccessor (com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor)8 ConfigurationFieldModelConverter (com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter)7 EncryptionUtility (com.synopsys.integration.alert.common.security.EncryptionUtility)7 MockDescriptorAccessor (com.synopsys.integration.alert.mock.MockDescriptorAccessor)6 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)4 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)4 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)3 HashMap (java.util.HashMap)3 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)2 AlertRuntimeException (com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)2 FieldUtility (com.synopsys.integration.alert.common.persistence.accessor.FieldUtility)2 RegisteredDescriptorModel (com.synopsys.integration.alert.common.persistence.model.RegisteredDescriptorModel)2 FieldValueModel (com.synopsys.integration.alert.common.rest.model.FieldValueModel)2 ConfigContextEntity (com.synopsys.integration.alert.database.configuration.ConfigContextEntity)2 DefinedFieldEntity (com.synopsys.integration.alert.database.configuration.DefinedFieldEntity)2 RegisteredDescriptorEntity (com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity)2