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));
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations