Search in sources :

Example 16 with ActionResponse

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

the class AbstractJobResourceActions method create.

public final ActionResponse<JobFieldModel> create(JobFieldModel resource) {
    boolean hasPermissions = hasRequiredPermissions(resource.getFieldModels(), authorizationManager::hasCreatePermission);
    if (!hasPermissions) {
        return ActionResponse.createForbiddenResponse();
    }
    // Clean input
    resource.setJobId(null);
    correctProjectsField(resource);
    ValidationActionResponse validationResponse = validateWithoutChecks(resource);
    if (validationResponse.isError()) {
        return new ActionResponse<>(validationResponse.getHttpStatus(), validationResponse.getMessage().orElse(null));
    }
    return createWithoutChecks(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 17 with ActionResponse

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

the class AzureBoardsCustomFunctionAction method createErrorResponse.

private ActionResponse<OAuthEndpointResponse> createErrorResponse(HttpStatus httpStatus, String errorMessage) {
    oAuthRequestValidator.removeAllRequests();
    OAuthEndpointResponse oAuthEndpointResponse = new OAuthEndpointResponse(false, "", errorMessage);
    return new ActionResponse<>(httpStatus, errorMessage, oAuthEndpointResponse);
}
Also used : OAuthEndpointResponse(com.synopsys.integration.alert.common.descriptor.config.field.endpoint.oauth.OAuthEndpointResponse) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 18 with ActionResponse

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

the class AzureBoardsCustomFunctionAction method createActionResponse.

@Override
public ActionResponse<OAuthEndpointResponse> createActionResponse(FieldModel fieldModel, HttpServletContentWrapper servletContentWrapper) {
    try {
        Optional<FieldModel> savedFieldModel = saveIfValid(fieldModel);
        if (!savedFieldModel.isPresent()) {
            return createErrorResponse("The configuration is invalid. Please test the configuration.");
        }
        FieldUtility fieldUtility = createFieldAccessor(savedFieldModel.get());
        Optional<String> clientId = fieldUtility.getString(AzureBoardsDescriptor.KEY_CLIENT_ID);
        if (!clientId.isPresent()) {
            return createErrorResponse("App ID not found.");
        }
        Optional<String> alertServerUrl = alertWebServerUrlManager.getServerUrl();
        if (!alertServerUrl.isPresent()) {
            return createErrorResponse("Could not determine the alert server url for the callback.");
        }
        String requestKey = oAuthRequestValidator.generateRequestKey();
        // since we have only one OAuth channel now remove any other requests.
        // if we have more OAuth clients then the "remove requests" will have to be removed from here.
        // beginning authentication process create the request id at the start.
        oAuthRequestValidator.removeRequestsOlderThan5MinutesAgo();
        oAuthRequestValidator.addAuthorizationRequest(requestKey);
        logger.info("OAuth authorization request created: {}", requestKey);
        String authUrl = createAuthURL(clientId.get(), requestKey);
        logger.debug("Authenticating Azure OAuth URL: {}", authUrl);
        return new ActionResponse<>(HttpStatus.OK, new OAuthEndpointResponse(isAuthenticated(fieldUtility), authUrl, "Authenticating..."));
    } catch (Exception ex) {
        logger.error("Error activating Azure Boards", ex);
        return createErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, "Error activating azure oauth.");
    }
}
Also used : OAuthEndpointResponse(com.synopsys.integration.alert.common.descriptor.config.field.endpoint.oauth.OAuthEndpointResponse) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) FieldUtility(com.synopsys.integration.alert.common.persistence.accessor.FieldUtility) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 19 with ActionResponse

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

the class JobConfigActions method createWithoutChecks.

@Override
protected ActionResponse<JobFieldModel> createWithoutChecks(JobFieldModel resource) {
    try {
        Set<ConfigurationFieldModel> configurationFieldModels = new HashSet<>();
        for (FieldModel fieldModel : resource.getFieldModels()) {
            FieldModel beforeSaveEventFieldModel = fieldModelProcessor.performBeforeSaveAction(fieldModel);
            Collection<ConfigurationFieldModel> savedFieldsModels = modelConverter.convertToConfigurationFieldModelMap(beforeSaveEventFieldModel).values();
            configurationFieldModels.addAll(savedFieldsModels);
        }
        List<JobProviderProjectFieldModel> configuredProviderProjects = Optional.ofNullable(resource.getConfiguredProviderProjects()).orElse(List.of());
        DistributionJobRequestModel jobRequestModel = createDistributionJobRequestModel(configurationFieldModels, configuredProviderProjects, DateUtils.createCurrentDateTimestamp(), null);
        DistributionJobModel savedJob = jobAccessor.createJob(jobRequestModel);
        JobFieldModel savedJobFieldModel = JobFieldModelPopulationUtils.createJobFieldModel(savedJob, configuredProviderProjects);
        Set<FieldModel> updatedFieldModels = new HashSet<>();
        for (FieldModel fieldModel : savedJobFieldModel.getFieldModels()) {
            FieldModel updatedModel = fieldModelProcessor.performAfterSaveAction(fieldModel);
            updatedFieldModels.add(updatedModel);
        }
        savedJobFieldModel.setFieldModels(updatedFieldModels);
        return new ActionResponse<>(HttpStatus.OK, savedJobFieldModel);
    } catch (AlertException ex) {
        logger.error("Error creating job", ex);
        return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
    }
}
Also used : 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 20 with ActionResponse

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

the class JobConfigActions method deleteWithoutChecks.

@Override
protected ActionResponse<JobFieldModel> deleteWithoutChecks(UUID id) {
    try {
        Optional<DistributionJobModel> job = jobAccessor.getJobById(id);
        if (job.isPresent()) {
            LinkedList<FieldModel> processedFieldModels = new LinkedList<>();
            DistributionJobModel distributionJobModel = job.get();
            JobFieldModel jobFieldModel = JobFieldModelPopulationUtils.createJobFieldModelWithDefaultProviderProjectState(distributionJobModel);
            for (FieldModel fieldModel : jobFieldModel.getFieldModels()) {
                FieldModel preProcessedFieldModel = fieldModelProcessor.performBeforeDeleteAction(fieldModel);
                processedFieldModels.add(preProcessedFieldModel);
            }
            jobAccessor.deleteJob(distributionJobModel.getJobId());
            for (FieldModel preProcessedFieldModel : processedFieldModels) {
                fieldModelProcessor.performAfterDeleteAction(preProcessedFieldModel);
            }
        } else {
            return new ActionResponse<>(HttpStatus.NOT_FOUND);
        }
    } catch (AlertException ex) {
        logger.error("Error reading job", ex);
        return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
    }
    return new ActionResponse<>(HttpStatus.NO_CONTENT);
}
Also used : JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) 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) LinkedList(java.util.LinkedList) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)

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