Search in sources :

Example 11 with Attachment

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");
    }
}
Also used : ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Attachment(com.epam.ta.reportportal.entity.attachment.Attachment) BinaryData(com.epam.ta.reportportal.entity.attachment.BinaryData)

Aggregations

Attachment (com.epam.ta.reportportal.entity.attachment.Attachment)11 Test (org.junit.jupiter.api.Test)8 BaseTest (com.epam.ta.reportportal.BaseTest)7 Duration (java.time.Duration)4 LocalDateTime (java.time.LocalDateTime)4 Sql (org.springframework.test.context.jdbc.Sql)4 Log (com.epam.ta.reportportal.entity.log.Log)3 Lists (com.google.common.collect.Lists)3 ZoneOffset (java.time.ZoneOffset)3 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 CollectionUtils (org.apache.commons.collections4.CollectionUtils)3 Assertions (org.junit.jupiter.api.Assertions)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 PageRequest (org.springframework.data.domain.PageRequest)3 Filter (com.epam.ta.reportportal.commons.querygen.Filter)2 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)2 IndexLog (com.epam.ta.reportportal.ws.model.analyzer.IndexLog)2