Search in sources :

Example 51 with ActionResponse

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

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

the class AbstractConfigResourceActions method update.

@Override
public final ActionResponse<FieldModel> update(Long id, FieldModel resource) {
    if (!authorizationManager.hasWritePermission(resource.getContext(), resource.getDescriptorName())) {
        return ActionResponse.createForbiddenResponse();
    }
    Optional<FieldModel> existingModel = findFieldModel(id);
    if (existingModel.isEmpty()) {
        return new ActionResponse<>(HttpStatus.NOT_FOUND);
    }
    ValidationActionResponse validationResponse = validateWithoutChecks(resource);
    if (validationResponse.isError()) {
        return new ActionResponse<>(validationResponse.getHttpStatus(), validationResponse.getMessage().orElse(null));
    }
    return updateWithoutChecks(id, resource);
}
Also used : ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) MultiFieldModel(com.synopsys.integration.alert.common.rest.model.MultiFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 53 with ActionResponse

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

the class AbstractJobResourceActions method update.

public final ActionResponse<JobFieldModel> update(UUID id, JobFieldModel resource) {
    boolean hasPermissions = hasRequiredPermissions(resource.getFieldModels(), authorizationManager::hasWritePermission);
    if (!hasPermissions) {
        return ActionResponse.createForbiddenResponse();
    }
    Optional<JobFieldModel> existingJob = findJobFieldModel(id);
    if (existingJob.isEmpty()) {
        return new ActionResponse<>(HttpStatus.NOT_FOUND);
    }
    // Clean input
    correctProjectsField(resource);
    ValidationActionResponse validationResponse = validateWithoutChecks(resource);
    if (validationResponse.isError()) {
        return new ActionResponse<>(validationResponse.getHttpStatus(), validationResponse.getMessage().orElse(null));
    }
    return updateWithoutChecks(id, resource);
}
Also used : ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) MultiJobFieldModel(com.synopsys.integration.alert.common.rest.model.MultiJobFieldModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 54 with ActionResponse

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

the class AbstractResourceActions method update.

public final ActionResponse<T> update(Long id, T resource) {
    if (!authorizationManager.hasWritePermission(context, descriptorKey)) {
        logger.debug(String.format(FORBIDDEN_ACTION_FORMAT, "Update"));
        return ActionResponse.createForbiddenResponse();
    }
    Optional<T> existingItem = findExisting(id);
    if (existingItem.isEmpty()) {
        return new ActionResponse<>(HttpStatus.NOT_FOUND);
    }
    ValidationActionResponse validationResponse = validateWithoutChecks(resource);
    if (validationResponse.isError()) {
        return new ActionResponse<>(validationResponse.getHttpStatus(), validationResponse.getMessage().orElse(null));
    }
    return updateWithoutChecks(id, resource);
}
Also used : ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 55 with ActionResponse

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

the class AbstractUploadAction method uploadFileExists.

public ActionResponse<ExistenceModel> uploadFileExists() {
    if (isTargetUndefined()) {
        return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, META_DATA_MISSING);
    }
    if (!authorizationManager.hasUploadReadPermission(target.getContext(), target.getDescriptorKey())) {
        return new ActionResponse<>(HttpStatus.FORBIDDEN, ActionResponse.FORBIDDEN_MESSAGE);
    }
    String targetFilename = target.getFilename();
    Boolean exists = filePersistenceUtil.uploadFileExists(targetFilename);
    ExistenceModel content = new ExistenceModel(exists);
    return new ActionResponse<>(HttpStatus.OK, content);
}
Also used : ExistenceModel(com.synopsys.integration.alert.common.rest.model.ExistenceModel) 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