Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EPMRPP-87421 fixed attachments handling #1871

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import java.time.ZoneOffset;
import java.util.concurrent.CompletableFuture;
import javax.annotation.Nonnull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Primary;
Expand All @@ -60,6 +62,8 @@
@Transactional
public class CreateLogHandlerImpl implements CreateLogHandler {

private final Logger LOGGER = LoggerFactory.getLogger(CreateLogHandlerImpl.class);
grabsefx marked this conversation as resolved.
Show resolved Hide resolved
grabsefx marked this conversation as resolved.
Show resolved Hide resolved

@Autowired
TestItemRepository testItemRepository;

Expand Down Expand Up @@ -103,15 +107,19 @@ public EntryCreatedAsyncRS createLog(@Nonnull SaveLogRQ request, MultipartFile f

final LogFull logFull = logFullBuilder.get();
final Log log = LOG_FULL_TO_LOG.apply(logFull);
CompletableFuture<Log> saveLogFuture =
CompletableFuture.supplyAsync(() -> logRepository.saveAndFlush(log));
logFull.setId(log.getId());
logService.saveLogMessage(logFull, launch.getId());

if (file != null) {
saveLogFuture.thenAcceptAsync(
savedLog -> saveBinaryData(file, launch, savedLog), taskExecutor);
}
CompletableFuture.supplyAsync(() -> logRepository.saveAndFlush(log))
.thenAcceptAsync(savedLog -> {
logFull.setId(savedLog.getId());
logService.saveLogMessage(logFull, launch.getId());
if (file != null) {
saveBinaryData(file, launch, savedLog);
}
}, taskExecutor)
.exceptionally(e -> {
LOGGER.error("Failed to save log with attachments", e);
return null;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [reviewdog] <com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck> reported by reviewdog 🐶
'block rcurly' has incorrect indentation level 12, expected level should be one of the following: 8, 14, 16.

);

return new EntryCreatedAsyncRS(log.getUuid());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
import com.epam.ta.reportportal.exception.ReportPortalException;
import com.epam.ta.reportportal.ws.model.ErrorType;
import com.epam.ta.reportportal.ws.model.log.SaveLogRQ;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.validation.ConstraintViolation;
import javax.validation.Path;
import javax.validation.Validator;
import org.apache.commons.collections4.MultiValuedMap;
import org.apache.commons.collections4.multimap.ArrayListValuedHashMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
Expand All @@ -44,10 +44,14 @@ public class ControllerUtils {
* @param files Files map
* @return Found file
*/
public static MultipartFile findByFileName(String filename, Map<String, MultipartFile> files) {
public static MultipartFile findByFileName(String filename, MultiValuedMap<String, MultipartFile> files) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [reviewdog] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 100 characters (found 108).

/* Request part name? */
if (files.containsKey(filename)) {
return files.get(filename);
var multipartFile = files.get(filename).stream()
.findFirst()
.get();
files.get(filename).remove(multipartFile);
return multipartFile;
}
/* Filename? */
for (MultipartFile file : files.values()) {
Expand Down Expand Up @@ -93,8 +97,8 @@ public static void validateSaveRQ(Validator validator, SaveLogRQ saveLogRQ) {
}
}

public static Map<String, MultipartFile> getUploadedFiles(HttpServletRequest request) {
Map<String, MultipartFile> uploadedFiles = new HashMap<>();
public static MultiValuedMap<String, MultipartFile> getUploadedFiles(HttpServletRequest request) {
grabsefx marked this conversation as resolved.
Show resolved Hide resolved
MultiValuedMap<String, MultipartFile> uploadedFiles = new ArrayListValuedHashMap<>();
if (request instanceof MultipartHttpServletRequest) {
MultiValueMap<String, MultipartFile> multiFileMap = (((MultipartHttpServletRequest) request)).getMultiFileMap();
for (List<MultipartFile> multipartFiles : multiFileMap.values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
import com.epam.ta.reportportal.ws.model.ErrorType;
import com.epam.ta.reportportal.ws.model.log.SaveLogRQ;
import io.swagger.annotations.ApiOperation;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Validator;
import org.apache.commons.collections4.MultiValuedMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -127,7 +127,7 @@ public ResponseEntity<BatchSaveOperatingRS> createLog(@PathVariable String proje
* Since this is multipart request we can retrieve list of uploaded
* attachments
*/
Map<String, MultipartFile> uploadedFiles = getUploadedFiles(request);
MultiValuedMap<String, MultipartFile> uploadedFiles = getUploadedFiles(request);
BatchSaveOperatingRS response = new BatchSaveOperatingRS();
EntryCreatedAsyncRS responseItem;
/* Go through all provided save log request items */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Validator;
import org.apache.commons.collections4.MultiValuedMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -158,7 +159,7 @@ public ResponseEntity<BatchSaveOperatingRS> createLog(@PathVariable String proje
* Since this is multipart request we can retrieve list of uploaded
* attachments
*/
Map<String, MultipartFile> uploadedFiles = getUploadedFiles(request);
MultiValuedMap<String, MultipartFile> uploadedFiles = getUploadedFiles(request);
BatchSaveOperatingRS response = new BatchSaveOperatingRS();
EntryCreatedAsyncRS responseItem;
/* Go through all provided save log request items */
Expand Down
Loading