Search in sources :

Example 11 with ActionResponse

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

the class CertificateActions method createWithoutChecks.

@Override
protected ActionResponse<CertificateModel> createWithoutChecks(CertificateModel resource) {
    String loggableAlias = escapeUtil.replaceWithUnderscore(resource.getAlias());
    logger.info("Importing certificate with alias {}", loggableAlias);
    try {
        CertificateModel certificateModel = importCertificate(resource);
        return new ActionResponse<>(HttpStatus.CREATED, certificateModel);
    } catch (AlertException ex) {
        String message = ex.getMessage();
        logger.error("There was an issue importing the certificate. {}", message);
        logger.debug(message, ex);
        return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, String.format("There was an issue importing the certificate. %s", message));
    }
}
Also used : CustomCertificateModel(com.synopsys.integration.alert.common.persistence.model.CustomCertificateModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 12 with ActionResponse

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

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

the class AbstractUploadAction method writeFile.

private ActionResponse<Void> writeFile(Resource fileResource) {
    try {
        String targetFilename = target.getFilename();
        String tempFilename = "temp_" + targetFilename;
        Optional<UploadValidationFunction> validationFunction = target.getValidationFunction();
        if (validationFunction.isPresent()) {
            writeFile(tempFilename, fileResource);
            File tempFileToValidate = filePersistenceUtil.createUploadsFile(tempFilename);
            ValidationResult validationResult = validationFunction.get().apply(tempFileToValidate);
            filePersistenceUtil.delete(tempFileToValidate);
            if (validationResult.hasErrors()) {
                return new ActionResponse<>(HttpStatus.BAD_REQUEST, validationResult.combineErrorMessages());
            }
        }
        writeFile(targetFilename, fileResource);
    } catch (IOException ex) {
        logger.error("Error uploading file - file: {}, context: {}, descriptor: {} ", target.getFilename(), target.getContext(), target.getDescriptorKey().getUniversalKey());
        logger.error("Error uploading file caused by: ", ex);
        return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, "Error uploading file to server.");
    }
    return new ActionResponse<>(HttpStatus.NO_CONTENT);
}
Also used : UploadValidationFunction(com.synopsys.integration.alert.common.descriptor.config.field.validation.UploadValidationFunction) IOException(java.io.IOException) ValidationResult(com.synopsys.integration.alert.common.descriptor.config.field.validation.ValidationResult) File(java.io.File) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 14 with ActionResponse

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

the class JiraServerInstallPluginAction method createBadRequestIntegrationException.

private ActionResponse<ValidationResponseModel> createBadRequestIntegrationException(IntegrationException error) {
    logger.error("There was an issue connecting to Jira server", error);
    ValidationResponseModel validationResponseModel = ValidationResponseModel.generalError("The following error occurred when connecting to Jira server: " + error.getMessage());
    return new ActionResponse<>(HttpStatus.BAD_REQUEST, validationResponseModel);
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 15 with ActionResponse

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

the class AuditEntryActions method get.

public ActionResponse<AuditEntryPageModel> get(Integer pageNumber, Integer pageSize, String searchTerm, String sortField, String sortOrder, boolean onlyShowSentNotifications) {
    if (!authorizationManager.hasReadPermission(ConfigContextEnum.GLOBAL, descriptorKey)) {
        return new ActionResponse<>(HttpStatus.FORBIDDEN, ActionResponse.FORBIDDEN_MESSAGE);
    }
    Integer page = ObjectUtils.defaultIfNull(pageNumber, AlertPagedModel.DEFAULT_PAGE_NUMBER);
    Integer size = ObjectUtils.defaultIfNull(pageSize, AlertPagedModel.DEFAULT_PAGE_SIZE);
    AuditEntryPageModel pagedRestModel = auditAccessor.getPageOfAuditEntries(page, size, searchTerm, sortField, sortOrder, onlyShowSentNotifications, auditAccessor::convertToAuditEntryModelFromNotification);
    logger.debug("Paged Audit Entry Rest Model: {}", pagedRestModel);
    return new ActionResponse<>(HttpStatus.OK, pagedRestModel);
}
Also used : ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) AuditEntryPageModel(com.synopsys.integration.alert.common.persistence.model.AuditEntryPageModel)

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