Search in sources :

Example 86 with ActionResponse

use of com.synopsys.integration.alert.common.action.ActionResponse 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)

Example 87 with ActionResponse

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

the class AuditEntryActions method queryForAuditInfoInJobs.

public ActionResponse<AuditJobStatusesModel> queryForAuditInfoInJobs(JobIdsRequestModel queryRequestModel) {
    if (!authorizationManager.hasReadPermission(ConfigContextEnum.GLOBAL, descriptorKey)) {
        return new ActionResponse<>(HttpStatus.FORBIDDEN, ActionResponse.FORBIDDEN_MESSAGE);
    }
    List<UUID> jobIds = queryRequestModel.getJobIds();
    for (UUID jobId : jobIds) {
        if (null == jobId) {
            return new ActionResponse<>(HttpStatus.BAD_REQUEST, "The field 'jobIds' cannot contain null values");
        }
    }
    List<AuditJobStatusModel> auditJobStatusModels = auditAccessor.findByJobIds(jobIds);
    return new ActionResponse<>(HttpStatus.OK, new AuditJobStatusesModel(auditJobStatusModels));
}
Also used : AuditJobStatusModel(com.synopsys.integration.alert.common.persistence.model.AuditJobStatusModel) UUID(java.util.UUID) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) AuditJobStatusesModel(com.synopsys.integration.alert.common.rest.model.AuditJobStatusesModel)

Example 88 with ActionResponse

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

the class AuditEntryActions method resendNotification.

public ActionResponse<AuditEntryPageModel> resendNotification(Long notificationId, @Nullable UUID requestedJobId) {
    if (!authorizationManager.hasExecutePermission(ConfigContextEnum.GLOBAL, descriptorKey)) {
        return new ActionResponse<>(HttpStatus.FORBIDDEN, ActionResponse.FORBIDDEN_MESSAGE);
    }
    Optional<AlertNotificationModel> notification = notificationAccessor.findById(notificationId);
    if (notification.isEmpty()) {
        return new ActionResponse<>(HttpStatus.GONE, "No notification with this id exists.");
    }
    AlertNotificationModel notificationContent = notification.get();
    if (null != requestedJobId) {
        Optional<DistributionJobModel> optionalDistributionJob = jobAccessor.getJobById(requestedJobId);
        if (optionalDistributionJob.isEmpty()) {
            String message = String.format("The Distribution Job with this id could not be found. %s", requestedJobId.toString());
            return new ActionResponse<>(HttpStatus.GONE, message);
        }
        DistributionJobModel distributionJob = optionalDistributionJob.get();
        if (distributionJob.isEnabled()) {
            ProcessedNotificationDetails processedNotificationDetails = ProcessedNotificationDetails.fromDistributionJob(distributionJob);
            jobNotificationProcessor.processNotificationForJob(processedNotificationDetails, distributionJob.getProcessingType(), List.of(notificationContent));
        } else {
            UUID jobConfigId = distributionJob.getJobId();
            logger.warn("The Distribution Job with Id {} was disabled. This notification could not be sent", jobConfigId);
            String message = String.format("The Distribution Job is currently disabled. %s", jobConfigId);
            return new ActionResponse<>(HttpStatus.BAD_REQUEST, message);
        }
    } else {
        notificationProcessor.processNotifications(List.of(notificationContent), List.of(FrequencyType.DAILY, FrequencyType.REAL_TIME));
    }
    return get();
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) ProcessedNotificationDetails(com.synopsys.integration.alert.processor.api.distribute.ProcessedNotificationDetails) UUID(java.util.UUID) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)

Example 89 with ActionResponse

use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-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.common.descriptor.config.field.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 90 with ActionResponse

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

the class SystemActions method getSystemMessagesAfter.

private ActionResponse<MultiSystemMessageModel> getSystemMessagesAfter(String startDate) throws ParseException {
    OffsetDateTime date = DateUtils.parseDateFromJsonString(startDate);
    List<SystemMessageModel> messages = systemMessageAccessor.getSystemMessagesAfter(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)

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