Search in sources :

Example 46 with ActionResponse

use of com.synopsys.integration.alert.common.action.ActionResponse in project blackduck-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 47 with ActionResponse

use of com.synopsys.integration.alert.common.action.ActionResponse in project blackduck-alert by blackducksoftware.

the class ProcessingSelectCustomFunctionAction method createActionResponse.

@Override
public ActionResponse<LabelValueSelectOptions> createActionResponse(FieldModel fieldModel, HttpServletContentWrapper servletContentWrapper) {
    String channelName = fieldModel.getFieldValue(ChannelDescriptor.KEY_CHANNEL_NAME).orElse("");
    List<LabelValueSelectOption> options = Arrays.stream(ProcessingType.values()).filter(processingType -> this.shouldInclude(processingType, channelName)).map(processingType -> new LabelValueSelectOption(processingType.getLabel(), processingType.name())).collect(Collectors.toList());
    LabelValueSelectOptions optionList = new LabelValueSelectOptions(options);
    return new ActionResponse<>(HttpStatus.OK, optionList);
}
Also used : AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) Arrays(java.util.Arrays) LabelValueSelectOptions(com.synopsys.integration.alert.common.descriptor.config.field.LabelValueSelectOptions) AlertFieldStatus(com.synopsys.integration.alert.api.common.model.errors.AlertFieldStatus) Collection(java.util.Collection) ChannelDescriptor(com.synopsys.integration.alert.common.descriptor.ChannelDescriptor) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) CustomFunctionAction(com.synopsys.integration.alert.common.action.CustomFunctionAction) Collectors(java.util.stream.Collectors) HttpServletContentWrapper(com.synopsys.integration.alert.common.rest.HttpServletContentWrapper) HttpStatus(org.springframework.http.HttpStatus) LabelValueSelectOption(com.synopsys.integration.alert.common.descriptor.config.field.LabelValueSelectOption) List(java.util.List) Component(org.springframework.stereotype.Component) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) ProcessingType(com.synopsys.integration.alert.common.enumeration.ProcessingType) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) IssueTrackerChannelKey(com.synopsys.integration.alert.descriptor.api.model.IssueTrackerChannelKey) LabelValueSelectOption(com.synopsys.integration.alert.common.descriptor.config.field.LabelValueSelectOption) LabelValueSelectOptions(com.synopsys.integration.alert.common.descriptor.config.field.LabelValueSelectOptions) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 48 with ActionResponse

use of com.synopsys.integration.alert.common.action.ActionResponse in project blackduck-alert by blackducksoftware.

the class SystemActions method getSystemMessagesBefore.

private ActionResponse<MultiSystemMessageModel> getSystemMessagesBefore(String endDate) throws ParseException {
    OffsetDateTime date = DateUtils.parseDateFromJsonString(endDate);
    List<SystemMessageModel> messages = systemMessageAccessor.getSystemMessagesBefore(date);
    return new ActionResponse<>(HttpStatus.OK, new MultiSystemMessageModel(messages));
}
Also used : OffsetDateTime(java.time.OffsetDateTime) SystemMessageModel(com.synopsys.integration.alert.common.persistence.model.SystemMessageModel) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 49 with ActionResponse

use of com.synopsys.integration.alert.common.action.ActionResponse in project blackduck-alert by blackducksoftware.

the class SystemActions method getSystemMessagesBetween.

private ActionResponse<MultiSystemMessageModel> getSystemMessagesBetween(String startDate, String endDate) throws ParseException {
    DateRange dateRange = DateRange.of(startDate, endDate);
    List<SystemMessageModel> messages = systemMessageAccessor.findBetween(dateRange);
    return new ActionResponse<>(HttpStatus.OK, new MultiSystemMessageModel(messages));
}
Also used : DateRange(com.synopsys.integration.alert.common.message.model.DateRange) SystemMessageModel(com.synopsys.integration.alert.common.persistence.model.SystemMessageModel) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 50 with ActionResponse

use of com.synopsys.integration.alert.common.action.ActionResponse in project blackduck-alert by blackducksoftware.

the class DescriptorMetadataActions method getDescriptorsByPermissions.

public ActionResponse<DescriptorsResponseModel> getDescriptorsByPermissions(@Nullable String name, @Nullable String type, @Nullable String context) {
    Predicate<Descriptor> descriptorFilter = ignored -> true;
    Set<ConfigContextEnum> requestedContexts = Set.of(ConfigContextEnum.GLOBAL, ConfigContextEnum.DISTRIBUTION);
    if (StringUtils.isNotBlank(name)) {
        descriptorFilter = descriptorFilter.and(descriptor -> name.equals(descriptor.getDescriptorKey().getUniversalKey()));
    }
    if (StringUtils.isNotBlank(type)) {
        descriptorFilter = descriptorFilter.and(descriptor -> type.equals(descriptor.getType().name()));
    }
    if (StringUtils.isNotBlank(context)) {
        ConfigContextEnum requestedContext = EnumUtils.getEnum(ConfigContextEnum.class, context);
        if (null != requestedContext) {
            requestedContexts = Set.of(requestedContext);
        } else {
            requestedContexts = Set.of();
        }
    }
    return createDescriptorResponse(descriptorFilter, requestedContexts);
}
Also used : Descriptor(com.synopsys.integration.alert.common.descriptor.Descriptor) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) DescriptorMetadata(com.synopsys.integration.alert.common.descriptor.config.ui.DescriptorMetadata) Predicate(java.util.function.Predicate) AccessOperation(com.synopsys.integration.alert.common.enumeration.AccessOperation) Collection(java.util.Collection) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) HashSet(java.util.HashSet) Nullable(org.jetbrains.annotations.Nullable) HttpStatus(org.springframework.http.HttpStatus) Component(org.springframework.stereotype.Component) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) EnumUtils(org.apache.commons.lang3.EnumUtils) Optional(java.util.Optional) DescriptorType(com.synopsys.integration.alert.common.enumeration.DescriptorType) DescriptorsResponseModel(com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel) Descriptor(com.synopsys.integration.alert.common.descriptor.Descriptor) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)

Aggregations

ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)132 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)46 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)40 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)38 PermissionMatrixModel (com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel)34 PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)32 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)30 ChannelKey (com.synopsys.integration.alert.descriptor.api.model.ChannelKey)30 AuthenticationTestUtils (com.synopsys.integration.alert.test.common.AuthenticationTestUtils)30 Test (org.junit.jupiter.api.Test)30 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)24 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)16 JobFieldModel (com.synopsys.integration.alert.common.rest.model.JobFieldModel)16 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)12 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)10 Collection (java.util.Collection)10 Optional (java.util.Optional)10 Set (java.util.Set)10 Collectors (java.util.stream.Collectors)10 Autowired (org.springframework.beans.factory.annotation.Autowired)10