use of com.epam.ta.reportportal.entity.attachment.Attachment in project commons-dao by reportportal.
the class AttachmentBinaryDataServiceImpl method load.
@Override
public BinaryData load(Long fileId, ReportPortalUser.ProjectDetails projectDetails) {
try {
Attachment attachment = attachmentRepository.findById(fileId).orElseThrow(() -> new ReportPortalException(ErrorType.ATTACHMENT_NOT_FOUND, fileId));
InputStream data = dataStoreService.load(attachment.getFileId()).orElseThrow(() -> new ReportPortalException(ErrorType.UNABLE_TO_LOAD_BINARY_DATA, fileId));
expect(attachment.getProjectId(), Predicate.isEqual(projectDetails.getProjectId())).verify(ErrorType.ACCESS_DENIED, formattedSupplier("You are not assigned to project '{}'", projectDetails.getProjectName()));
return new BinaryData(attachment.getContentType(), (long) data.available(), data);
} catch (IOException e) {
LOGGER.error("Unable to load binary data", e);
throw new ReportPortalException(ErrorType.UNCLASSIFIED_REPORT_PORTAL_ERROR, "Unable to load binary data");
}
}
Aggregations