use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey 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.descriptor.api.model.DescriptorKey in project hub-alert by blackducksoftware.
the class ConfigurationFieldModelConverter method convertToConfigurationModel.
public ConfigurationModel convertToConfigurationModel(FieldModel fieldModel) {
String descriptorName = fieldModel.getDescriptorName();
DescriptorKey descriptorKey = getDescriptorKey(descriptorName).orElseThrow(() -> new AlertRuntimeException("Could not find a Descriptor with the name: " + descriptorName));
long descriptorId = descriptorAccessor.getRegisteredDescriptorByKey(descriptorKey).map(RegisteredDescriptorModel::getId).orElse(0L);
long configId = Long.parseLong(fieldModel.getId());
ConfigurationModelMutable configurationModel = new ConfigurationModelMutable(configId, descriptorId, fieldModel.getCreatedAt(), fieldModel.getLastUpdated(), fieldModel.getContext());
convertToConfigurationFieldModelMap(fieldModel).values().forEach(configurationModel::put);
return configurationModel;
}
use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey in project hub-alert by blackducksoftware.
the class ConfigurationValidationHelperTest method testValidationWithError.
@Test
public void testValidationWithError() {
AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
DescriptorKey descriptorKey = new ChannelKey("channel_key", "channel-display-name");
PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.FULL_PERMISSIONS);
AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
ConfigurationValidationHelper validationHelper = new ConfigurationValidationHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
ValidationActionResponse response = validationHelper.validate(() -> ValidationResponseModel.generalError("generalError"));
ValidationResponseModel validationResponseModel = response.getContent().orElseThrow(() -> new IllegalStateException("Validation content missing"));
assertEquals(HttpStatus.OK, response.getHttpStatus());
assertTrue(validationResponseModel.hasErrors());
}
use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey 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());
}
use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey in project hub-alert by blackducksoftware.
the class DescriptorMapTest method createMockDescriptor.
private Descriptor createMockDescriptor(String descriptorName, DescriptorType descriptorType) {
Descriptor descriptor = Mockito.mock(Descriptor.class);
DescriptorKey descriptorKey = new MockDescriptorKey(descriptorName);
Mockito.when(descriptor.getDescriptorKey()).thenReturn(descriptorKey);
Mockito.when(descriptor.getType()).thenReturn(descriptorType);
return descriptor;
}
Aggregations