Search in sources :

Example 71 with DescriptorKey

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");
}
Also used : DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) Test(org.junit.jupiter.api.Test)

Example 72 with DescriptorKey

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);
}
Also used : ApiAction(com.synopsys.integration.alert.common.action.ApiAction) OAuthRequestValidator(com.synopsys.integration.alert.channel.azure.boards.oauth.OAuthRequestValidator) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) DescriptorMap(com.synopsys.integration.alert.common.descriptor.DescriptorMap) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) List(java.util.List) Component(org.springframework.stereotype.Component) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) Map(java.util.Map) AzureBoardsDescriptor(com.synopsys.integration.alert.channel.azure.boards.descriptor.AzureBoardsDescriptor) Optional(java.util.Optional) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)

Example 73 with DescriptorKey

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));
}
Also used : PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) AuthenticationTestUtils(com.synopsys.integration.alert.test.common.AuthenticationTestUtils) SettingsDescriptorKey(com.synopsys.integration.alert.component.settings.descriptor.SettingsDescriptorKey) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)

Example 74 with DescriptorKey

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");
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) SettingsDescriptorKey(com.synopsys.integration.alert.component.settings.descriptor.SettingsDescriptorKey) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) MultiFieldModel(com.synopsys.integration.alert.common.rest.model.MultiFieldModel) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 75 with DescriptorKey

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);
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) LabelValueSelectOption(com.synopsys.integration.alert.common.descriptor.config.field.LabelValueSelectOption) Optional(java.util.Optional) LabelValueSelectOptions(com.synopsys.integration.alert.common.descriptor.config.field.LabelValueSelectOptions) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Aggregations

DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)91 Test (org.junit.jupiter.api.Test)72 PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)42 PermissionMatrixModel (com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel)42 AuthenticationTestUtils (com.synopsys.integration.alert.test.common.AuthenticationTestUtils)41 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)39 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)29 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)28 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)23 ConfigurationFieldModelConverter (com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter)23 ChannelKey (com.synopsys.integration.alert.descriptor.api.model.ChannelKey)23 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)21 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)18 DescriptorAccessor (com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor)17 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)17 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)13 EmailGlobalConfigurationValidator (com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator)12 DefinedFieldModel (com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel)12 EncryptionUtility (com.synopsys.integration.alert.common.security.EncryptionUtility)12 EmailGlobalConfigModel (com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)12