Search in sources :

Example 16 with FieldValueModel

use of com.synopsys.integration.alert.common.rest.model.FieldValueModel in project hub-alert by blackducksoftware.

the class JobConfigActionsTest method createFieldModel.

private FieldModel createFieldModel() {
    String value = "testValue";
    Map<String, FieldValueModel> keyToValues = new HashMap<>();
    keyToValues.put(FieldModelTestAction.KEY_CUSTOM_TOPIC, new FieldValueModel(List.of(value), false));
    keyToValues.put(ChannelDescriptor.KEY_NAME, new FieldValueModel(List.of(value), false));
    return new FieldModel(descriptorKey.getUniversalKey(), ConfigContextEnum.DISTRIBUTION.name(), keyToValues);
}
Also used : HashMap(java.util.HashMap) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel)

Example 17 with FieldValueModel

use of com.synopsys.integration.alert.common.rest.model.FieldValueModel in project hub-alert by blackducksoftware.

the class JobConfigActions method convertFieldToConfigurationField.

private Optional<ConfigurationFieldModel> convertFieldToConfigurationField(FieldModel fieldModel, String fieldKey) {
    Optional<FieldValueModel> fieldValueModel = fieldModel.getFieldValueModel(fieldKey);
    if (fieldValueModel.isPresent()) {
        ConfigurationFieldModel configurationFieldModel = ConfigurationFieldModel.create(fieldKey);
        configurationFieldModel.setFieldValues(fieldValueModel.get().getValues());
        return Optional.of(configurationFieldModel);
    }
    return Optional.empty();
}
Also used : ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel)

Example 18 with FieldValueModel

use of com.synopsys.integration.alert.common.rest.model.FieldValueModel in project hub-alert by blackducksoftware.

the class PolicyNotificationFilterCustomFunctionAction method createPagedActionResponse.

@Override
public ActionResponse<NotificationFilterModelOptions> createPagedActionResponse(FieldModel fieldModel, HttpServletContentWrapper servletContentWrapper, int pageNumber, int pageSize, String searchTerm) throws IntegrationException {
    Optional<FieldValueModel> fieldValueModel = fieldModel.getFieldValueModel(ProviderDescriptor.KEY_NOTIFICATION_TYPES);
    Collection<String> selectedNotificationTypes = fieldValueModel.map(FieldValueModel::getValues).orElse(List.of());
    int totalPages = 1;
    List<NotificationFilterModel> options = List.of();
    if (isJobFilterableByPolicy(selectedNotificationTypes)) {
        try {
            Optional<BlackDuckServicesFactory> blackDuckServicesFactory = createBlackDuckServicesFactory(fieldModel);
            if (blackDuckServicesFactory.isPresent()) {
                BlackDuckPageResponse<PolicyRuleView> policyRulesPage = retrievePolicyRules(blackDuckServicesFactory.get(), pageNumber, pageSize, searchTerm);
                totalPages = (policyRulesPage.getTotalCount() + (pageSize - 1)) / pageSize;
                options = convertToNotificationFilterModel(policyRulesPage.getItems());
            }
        } catch (IntegrationException e) {
            logger.errorAndDebug("There was an issue communicating with Black Duck. " + e.getMessage(), e);
            throw new AlertException("Unable to communicate with Black Duck.", e);
        }
    }
    NotificationFilterModelOptions notificationFilterModelOptions = new NotificationFilterModelOptions(totalPages, pageNumber, pageSize, options);
    return new ActionResponse<>(HttpStatus.OK, notificationFilterModelOptions);
}
Also used : IntegrationException(com.synopsys.integration.exception.IntegrationException) PolicyRuleView(com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 19 with FieldValueModel

use of com.synopsys.integration.alert.common.rest.model.FieldValueModel in project hub-alert by blackducksoftware.

the class VulnerabilityNotificationFilterCustomFunctionAction method createActionResponse.

@Override
public ActionResponse<LabelValueSelectOptions> createActionResponse(FieldModel fieldModel, HttpServletContentWrapper servletContentWrapper) {
    Optional<FieldValueModel> fieldValueModel = fieldModel.getFieldValueModel(ProviderDescriptor.KEY_NOTIFICATION_TYPES);
    Collection<String> selectedNotificationTypes = fieldValueModel.map(FieldValueModel::getValues).orElse(List.of());
    List<LabelValueSelectOption> options = List.of();
    if (isFilterableVulnerability(selectedNotificationTypes)) {
        options = retrieveBlackDuckVulnerabilityOptions();
    }
    LabelValueSelectOptions optionList = new LabelValueSelectOptions(options);
    return new ActionResponse<>(HttpStatus.OK, optionList);
}
Also used : LabelValueSelectOption(com.synopsys.integration.alert.common.descriptor.config.field.LabelValueSelectOption) LabelValueSelectOptions(com.synopsys.integration.alert.common.descriptor.config.field.LabelValueSelectOptions) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 20 with FieldValueModel

use of com.synopsys.integration.alert.common.rest.model.FieldValueModel in project hub-alert by blackducksoftware.

the class SettingsGlobalConfigurationFieldModelValidatorTest method createProxyKeyToValues.

private Map<String, FieldValueModel> createProxyKeyToValues() {
    Map<String, FieldValueModel> keyToValues = createKeyToValues();
    FieldValueModel proxyHost = new FieldValueModel(List.of("proxyHost"), true);
    FieldValueModel proxyPort = new FieldValueModel(List.of("99"), true);
    keyToValues.put(ProxyManager.KEY_PROXY_HOST, proxyHost);
    keyToValues.put(ProxyManager.KEY_PROXY_PORT, proxyPort);
    return keyToValues;
}
Also used : FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel)

Aggregations

FieldValueModel (com.synopsys.integration.alert.common.rest.model.FieldValueModel)58 HashMap (java.util.HashMap)27 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)24 Test (org.junit.jupiter.api.Test)18 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)12 AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)6 GlobalConfigurationValidatorAsserter (com.synopsys.integration.alert.test.common.channel.GlobalConfigurationValidatorAsserter)6 JobFieldModel (com.synopsys.integration.alert.common.rest.model.JobFieldModel)5 JobProviderProjectFieldModel (com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel)4 ConfigurationManager (com.synopsys.integration.alert.performance.utility.ConfigurationManager)4 IntegrationPerformanceTestRunner (com.synopsys.integration.alert.performance.utility.IntegrationPerformanceTestRunner)4 Disabled (org.junit.jupiter.api.Disabled)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)3 DescriptorAccessor (com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor)3 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)3 EncryptionUtility (com.synopsys.integration.alert.common.security.EncryptionUtility)3 AlertRequestUtility (com.synopsys.integration.alert.performance.utility.AlertRequestUtility)3 BlackDuckProviderService (com.synopsys.integration.alert.performance.utility.BlackDuckProviderService)3 List (java.util.List)3