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));
}
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());
}
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;
}
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;
}
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;
}
Aggregations