use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey in project hub-alert by blackducksoftware.
the class DescriptorMapTest method getDescriptorKeyTest.
@Test
public void getDescriptorKeyTest() {
String expectedKeyValue = "expected_key";
MockDescriptorKey key1 = new MockDescriptorKey("bad key 01");
MockDescriptorKey key2 = new MockDescriptorKey(expectedKeyValue);
MockDescriptorKey key3 = new MockDescriptorKey("bad key z");
MockDescriptorKey key4 = new MockDescriptorKey("bad key x");
DescriptorMap descriptorMap = new DescriptorMap(List.of(key1, key2, key3, key4), List.of());
Optional<DescriptorKey> optionalFoundKey = descriptorMap.getDescriptorKey(expectedKeyValue);
assertTrue(optionalFoundKey.isPresent(), "Missing expected descriptor key");
DescriptorKey foundKey = optionalFoundKey.get();
assertEquals(expectedKeyValue, foundKey.getUniversalKey());
Optional<DescriptorKey> optionalMissingKey = descriptorMap.getDescriptorKey("a key that shouldn't be in there");
assertTrue(optionalMissingKey.isEmpty(), "Did not expect to find a descriptor key");
}
use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey in project hub-alert by blackducksoftware.
the class AzureBoardsGlobalApiAction method beforeSaveAction.
@Override
public FieldModel beforeSaveAction(FieldModel fieldModel) throws AlertException {
FieldModel updatedFieldModel = super.beforeSaveAction(fieldModel);
Optional<DescriptorKey> descriptorKey = descriptorMap.getDescriptorKey(fieldModel.getDescriptorName());
if (!descriptorKey.isPresent()) {
return updatedFieldModel;
}
ConfigContextEnum context = ConfigContextEnum.valueOf(fieldModel.getContext());
List<ConfigurationModel> existingConfig = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(descriptorKey.get(), context);
Optional<ConfigurationModel> configurationModel = existingConfig.stream().findFirst();
return configurationModel.map(config -> updateTokenFields(updatedFieldModel, config)).orElse(updatedFieldModel);
}
use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey in project hub-alert by blackducksoftware.
the class EmailConfigActionTestIT method createEmailAuthorizationManager.
private AuthorizationManager createEmailAuthorizationManager() {
AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
DescriptorKey descriptorKey = ChannelKeys.EMAIL;
PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.FULL_PERMISSIONS);
return authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
}
use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey 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");
}
use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey in project hub-alert by blackducksoftware.
the class ProviderConfigSelectCustomFunctionAction method createActionResponse.
@Override
public ActionResponse<LabelValueSelectOptions> createActionResponse(FieldModel fieldModel, HttpServletContentWrapper servletContentWrapper) {
String providerName = fieldModel.getDescriptorName();
Optional<DescriptorKey> descriptorKey = descriptorMap.getDescriptorKey(providerName);
List<LabelValueSelectOption> options = List.of();
if (descriptorKey.isPresent()) {
List<ConfigurationModel> configurationModels = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(descriptorKey.get(), ConfigContextEnum.GLOBAL);
options = configurationModels.stream().map(this::createNameToIdOption).flatMap(Optional::stream).collect(Collectors.toList());
}
LabelValueSelectOptions optionList = new LabelValueSelectOptions(options);
return new ActionResponse<>(HttpStatus.OK, optionList);
}
Aggregations