Search in sources :

Example 71 with ConfigurationFieldModel

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

the class ConfigurationModelMutableTest method putTest.

@Test
public void putTest() {
    final String fieldValue2 = "fieldValue-2";
    ConfigurationFieldModel configurationFieldModel2 = ConfigurationFieldModel.create(fieldKey);
    configurationFieldModel2.setFieldValue(fieldValue2);
    ConfigurationModelMutable configurationModelMutable = createConfigurationModelMutable();
    configurationModelMutable.put(configurationFieldModel);
    configurationModelMutable.put(configurationFieldModel2);
    Optional<ConfigurationFieldModel> testConfigurationFieldModelOptional = configurationModelMutable.getField(fieldKey);
    assertTrue(testConfigurationFieldModelOptional.isPresent());
    ArrayList<String> fieldValues = new ArrayList<>(testConfigurationFieldModelOptional.get().getFieldValues());
    assertEquals(2, fieldValues.size());
    assertTrue(fieldValues.contains(fieldValue));
    assertTrue(fieldValues.contains(fieldValue2));
}
Also used : ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 72 with ConfigurationFieldModel

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

the class ConfigurationTest method getFieldAccessorTest.

@Test
public void getFieldAccessorTest() {
    String fieldKey = "Key1";
    ConfigurationFieldModel testConfigurationFieldModel = Mockito.mock(ConfigurationFieldModel.class);
    Map<String, ConfigurationFieldModel> keyToFieldMapTest = new HashMap<>();
    keyToFieldMapTest.put(fieldKey, testConfigurationFieldModel);
    Configuration testConfig = new Configuration(keyToFieldMapTest);
    FieldUtility testFieldUtility = testConfig.getFieldUtility();
    Optional<ConfigurationFieldModel> newConfigurationFieldModel = testFieldUtility.getField(fieldKey);
    assertTrue(newConfigurationFieldModel.isPresent());
    assertEquals(testConfigurationFieldModel, newConfigurationFieldModel.get());
}
Also used : ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) HashMap(java.util.HashMap) FieldUtility(com.synopsys.integration.alert.common.persistence.accessor.FieldUtility) Test(org.junit.jupiter.api.Test)

Example 73 with ConfigurationFieldModel

use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel 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 74 with ConfigurationFieldModel

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

the class ConfigurationFieldModelConverter method convertToFieldValuesMap.

public Map<String, FieldValueModel> convertToFieldValuesMap(Collection<ConfigurationFieldModel> configurationFieldModels) {
    Map<String, FieldValueModel> fields = new HashMap<>();
    for (ConfigurationFieldModel fieldModel : configurationFieldModels) {
        String key = fieldModel.getFieldKey();
        Collection<String> values = fieldModel.getFieldValues();
        FieldValueModel fieldValueModel = new FieldValueModel(values, fieldModel.isSet());
        fields.put(key, fieldValueModel);
    }
    return fields;
}
Also used : ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) HashMap(java.util.HashMap) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel)

Example 75 with ConfigurationFieldModel

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

the class FieldModelProcessor method updateConfigurationWithSavedConfiguration.

private Map<String, FieldValueModel> updateConfigurationWithSavedConfiguration(Map<String, FieldValueModel> newConfiguration, Collection<ConfigurationFieldModel> savedConfiguration) {
    Collection<ConfigurationFieldModel> sensitiveFields = savedConfiguration.stream().filter(ConfigurationFieldModel::isSensitive).collect(Collectors.toSet());
    for (ConfigurationFieldModel sensitiveConfigurationFieldModel : sensitiveFields) {
        String key = sensitiveConfigurationFieldModel.getFieldKey();
        if (newConfiguration.containsKey(key)) {
            FieldValueModel sensitiveFieldValueModel = newConfiguration.get(key);
            if (sensitiveFieldValueModel.getIsSet() && !sensitiveFieldValueModel.hasValues()) {
                FieldValueModel newFieldModel = newConfiguration.get(key);
                newFieldModel.setValues(sensitiveConfigurationFieldModel.getFieldValues());
            }
        }
    }
    return newConfiguration;
}
Also used : ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel)

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