Search in sources :

Example 76 with ActionResponse

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

the class ConfigurationCrudHelperTest method testDeleteModelNotFound.

@Test
public void testDeleteModelNotFound() {
    AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
    DescriptorKey descriptorKey = new ChannelKey("channel_key", "channel-display-name");
    PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
    Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.FULL_PERMISSIONS);
    AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
    ConfigurationCrudHelper configurationHelper = new ConfigurationCrudHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
    ActionResponse response = configurationHelper.delete(() -> false, () -> {
    });
    assertEquals(HttpStatus.NOT_FOUND, response.getHttpStatus());
}
Also used : PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) ChannelKey(com.synopsys.integration.alert.descriptor.api.model.ChannelKey) AuthenticationTestUtils(com.synopsys.integration.alert.test.common.AuthenticationTestUtils) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) Test(org.junit.jupiter.api.Test)

Example 77 with ActionResponse

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

the class ConfigurationCrudHelperTest method testCreateSuccess.

@Test
public void testCreateSuccess() {
    AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
    DescriptorKey descriptorKey = new ChannelKey("channel_key", "channel-display-name");
    PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
    Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.FULL_PERMISSIONS);
    AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
    ConfigurationCrudHelper configurationHelper = new ConfigurationCrudHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
    ActionResponse response = configurationHelper.create(() -> ValidationResponseModel.success(), () -> Boolean.FALSE, () -> createDefault());
    assertEquals(HttpStatus.OK, response.getHttpStatus());
}
Also used : PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) ChannelKey(com.synopsys.integration.alert.descriptor.api.model.ChannelKey) AuthenticationTestUtils(com.synopsys.integration.alert.test.common.AuthenticationTestUtils) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) Test(org.junit.jupiter.api.Test)

Example 78 with ActionResponse

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

the class JobConfigActions method readPageWithoutChecks.

@Override
public final ActionResponse<JobPagedModel> readPageWithoutChecks(Integer pageNumber, Integer pageSize, String searchTerm, Collection<String> permittedDescriptorsForSession) {
    AlertPagedModel<DistributionJobModel> pageOfJobs = jobAccessor.getPageOfJobs(pageNumber, pageSize, searchTerm, permittedDescriptorsForSession);
    List<DistributionJobModel> distributionJobModels = pageOfJobs.getModels();
    List<JobFieldModel> jobFieldModels = new ArrayList<>(distributionJobModels.size());
    for (DistributionJobModel distributionJobModel : distributionJobModels) {
        JobFieldModel jobFieldModel = JobFieldModelPopulationUtils.createJobFieldModelWithDefaultProviderProjectState(distributionJobModel);
        jobFieldModels.add(jobFieldModel);
    }
    JobPagedModel jobPagedModel = new JobPagedModel(pageOfJobs.getTotalPages(), pageOfJobs.getCurrentPage(), pageOfJobs.getPageSize(), jobFieldModels);
    return new ActionResponse<>(HttpStatus.OK, jobPagedModel);
}
Also used : ArrayList(java.util.ArrayList) JobPagedModel(com.synopsys.integration.alert.common.rest.model.JobPagedModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) 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)

Example 79 with ActionResponse

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

the class JobConfigActions method validateJobsById.

public ActionResponse<List<JobFieldStatuses>> validateJobsById(JobIdsRequestModel jobIdsValidationModel) {
    List<PermissionKey> keys = gatherPermissionKeys();
    if (!getAuthorizationManager().anyReadPermission(keys)) {
        return ActionResponse.createForbiddenResponse();
    }
    List<UUID> jobIdsToValidate = jobIdsValidationModel.getJobIds();
    if (null == jobIdsToValidate || jobIdsToValidate.isEmpty()) {
        return new ActionResponse<>(HttpStatus.OK, List.of());
    }
    List<DistributionJobModel> distributionJobModels = jobAccessor.getJobsById(jobIdsToValidate);
    List<JobFieldModel> jobFieldModels = new LinkedList<>();
    for (DistributionJobModel distributionJobModel : distributionJobModels) {
        JobFieldModel jobFieldModel = JobFieldModelPopulationUtils.createJobFieldModelWithDefaultProviderProjectState(distributionJobModel);
        jobFieldModels.add(jobFieldModel);
    }
    return validateJobFieldModels(jobFieldModels);
}
Also used : PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) UUID(java.util.UUID) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) LinkedList(java.util.LinkedList) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)

Example 80 with ActionResponse

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