Search in sources :

Example 21 with ActionResponse

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

the class ConfigActions method readAllByContextAndDescriptorWithoutChecks.

@Override
protected ActionResponse<MultiFieldModel> readAllByContextAndDescriptorWithoutChecks(String context, String descriptorName) {
    ConfigContextEnum configContext = ConfigContextEnum.valueOf(context);
    Optional<DescriptorKey> descriptorKey = descriptorMap.getDescriptorKey(descriptorName);
    if (!descriptorKey.isPresent()) {
        return new ActionResponse<>(HttpStatus.BAD_REQUEST, String.format("Unknown descriptor: %s", descriptorName));
    }
    List<ConfigurationModel> configurationModels = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(descriptorKey.get(), configContext);
    List<FieldModel> fieldModels = convertConfigurationModelList(descriptorName, context, configurationModels);
    return new ActionResponse<>(HttpStatus.OK, new MultiFieldModel(fieldModels));
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) SettingsDescriptorKey(com.synopsys.integration.alert.component.settings.descriptor.SettingsDescriptorKey) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) MultiFieldModel(com.synopsys.integration.alert.common.rest.model.MultiFieldModel) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) 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) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 22 with ActionResponse

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

the class DistributionActions method retrieveJobWithAuditInfo.

public ActionResponse<AlertPagedModel<DistributionWithAuditInfo>> retrieveJobWithAuditInfo(int page, int pageSize, @Nullable String sortName, @Nullable String sortOrder, @Nullable String searchTerm) {
    Set<String> authorizedChannelDescriptorNames = findAuthorizedChannelDescriptorNames();
    if (authorizedChannelDescriptorNames.isEmpty()) {
        return ActionResponse.createForbiddenResponse();
    }
    String applicableSortName = convertSortName(sortName);
    Direction validSortOrder = Direction.ASC;
    if (Direction.DESC.name().equalsIgnoreCase(sortOrder)) {
        validSortOrder = Direction.DESC;
    }
    AlertPagedModel<DistributionWithAuditInfo> distributionWithAuditInfo;
    if (searchTerm != null) {
        distributionWithAuditInfo = distributionAccessor.getDistributionWithAuditInfoWithSearch(page, pageSize, applicableSortName, validSortOrder, authorizedChannelDescriptorNames, searchTerm);
    } else {
        distributionWithAuditInfo = distributionAccessor.getDistributionWithAuditInfo(page, pageSize, applicableSortName, validSortOrder, authorizedChannelDescriptorNames);
    }
    AlertPagedModel<DistributionWithAuditInfo> sortedPagedModel = sortByChannelDisplayNameIfApplicable(distributionWithAuditInfo, applicableSortName, validSortOrder);
    return new ActionResponse(HttpStatus.OK, sortedPagedModel);
}
Also used : DistributionWithAuditInfo(com.synopsys.integration.alert.common.rest.model.DistributionWithAuditInfo) Direction(org.springframework.data.domain.Sort.Direction) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 23 with ActionResponse

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

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

the class JobConfigActions method updateWithoutChecks.

@Override
protected ActionResponse<JobFieldModel> updateWithoutChecks(UUID id, JobFieldModel resource) {
    try {
        Optional<DistributionJobModel> jobModel = jobAccessor.getJobById(id);
        if (jobModel.isPresent()) {
            DistributionJobModel previousJob = jobModel.get();
            JobFieldModel jobFieldModel = JobFieldModelPopulationUtils.createJobFieldModelWithDefaultProviderProjectState(previousJob);
            Map<String, FieldModel> descriptorAndContextToPreviousFieldModel = new HashMap<>();
            for (FieldModel previousJobFieldModel : jobFieldModel.getFieldModels()) {
                descriptorAndContextToPreviousFieldModel.put(previousJobFieldModel.getDescriptorName() + previousJobFieldModel.getContext(), previousJobFieldModel);
            }
            Set<ConfigurationFieldModel> configurationFieldModels = new HashSet<>();
            for (FieldModel fieldModel : resource.getFieldModels()) {
                FieldModel beforeUpdateEventFieldModel = fieldModelProcessor.performBeforeUpdateAction(fieldModel);
                String beforeFieldModelId = beforeUpdateEventFieldModel.getId();
                Long fieldModelId = (StringUtils.isNotBlank(beforeFieldModelId)) ? Long.parseLong(beforeFieldModelId) : null;
                Collection<ConfigurationFieldModel> updatedFieldModels = fieldModelProcessor.fillFieldModelWithExistingData(fieldModelId, beforeUpdateEventFieldModel);
                configurationFieldModels.addAll(updatedFieldModels);
            }
            List<JobProviderProjectFieldModel> configuredProviderProjects = Optional.ofNullable(resource.getConfiguredProviderProjects()).orElse(List.of());
            DistributionJobRequestModel jobRequestModel = createDistributionJobRequestModel(configurationFieldModels, configuredProviderProjects, previousJob.getCreatedAt(), DateUtils.createCurrentDateTimestamp());
            DistributionJobModel savedJob = jobAccessor.updateJob(previousJob.getJobId(), jobRequestModel);
            JobFieldModel savedJobFieldModel = JobFieldModelPopulationUtils.createJobFieldModel(savedJob, configuredProviderProjects);
            Set<FieldModel> updatedFieldModels = new HashSet<>();
            for (FieldModel fieldModel : savedJobFieldModel.getFieldModels()) {
                FieldModel previousFieldModel = descriptorAndContextToPreviousFieldModel.get(fieldModel.getDescriptorName() + fieldModel.getContext());
                FieldModel updatedModel = fieldModelProcessor.performAfterUpdateAction(previousFieldModel, fieldModel);
                updatedFieldModels.add(updatedModel);
            }
            savedJobFieldModel.setFieldModels(updatedFieldModels);
            return new ActionResponse<>(HttpStatus.OK, savedJobFieldModel);
        } else {
            return new ActionResponse<>(HttpStatus.NOT_FOUND);
        }
    } catch (AlertException ex) {
        logger.error("Error creating job", ex);
        return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) JobProviderProjectFieldModel(com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) JobProviderProjectFieldModel(com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) HashSet(java.util.HashSet)

Example 25 with ActionResponse

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

Aggregations

ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)66 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)23 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)20 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)19 PermissionMatrixModel (com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel)17 PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)16 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)15 ChannelKey (com.synopsys.integration.alert.descriptor.api.model.ChannelKey)15 AuthenticationTestUtils (com.synopsys.integration.alert.test.common.AuthenticationTestUtils)15 Test (org.junit.jupiter.api.Test)15 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)12 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)8 JobFieldModel (com.synopsys.integration.alert.common.rest.model.JobFieldModel)8 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)6 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)6 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)5 MultiFieldModel (com.synopsys.integration.alert.common.rest.model.MultiFieldModel)5 Collection (java.util.Collection)5 Optional (java.util.Optional)5 Set (java.util.Set)5