diff --git a/src/main/java/net/gepafin/tendermanagement/dao/DocumentDao.java b/src/main/java/net/gepafin/tendermanagement/dao/DocumentDao.java index 4f87d2bc..597e3c4f 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/DocumentDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/DocumentDao.java @@ -99,19 +99,22 @@ public class DocumentDao { log.info("Uploading files userId={}, sourceType={}, fileType={}", userId,sourceType,fileType); List documentEntities = new ArrayList<>(); Long source = resolveSourceId(sourceId, sourceType); - for (MultipartFile file : files) { - log.info("Uploading file '{}'", file.getOriginalFilename()); - UploadFileOnAmazonS3Response uploadFileOnAmazonS3Response = uploadFileOnAmazonS3(file, sourceType, sourceId); - if (uploadFileOnAmazonS3Response != null) { - DocumentEntity documentEntity = new DocumentEntity(); - documentEntity.setFileName(uploadFileOnAmazonS3Response.getFileName()); - documentEntity.setSource(sourceType.getValue()); - documentEntity.setSourceId(source); - documentEntity.setType(fileType.getValue()); - documentEntity.setFilePath(uploadFileOnAmazonS3Response.getFilePath()); - documentEntity.setIsDeleted(false); - documentEntity.setUploadedBy(userId); - documentEntities.add(documentEntity); + + if(files!=null) { + for (MultipartFile file : files) { + log.info("Uploading file '{}'", file.getOriginalFilename()); + UploadFileOnAmazonS3Response uploadFileOnAmazonS3Response = uploadFileOnAmazonS3(file, sourceType, sourceId); + if (uploadFileOnAmazonS3Response != null) { + DocumentEntity documentEntity = new DocumentEntity(); + documentEntity.setFileName(uploadFileOnAmazonS3Response.getFileName()); + documentEntity.setSource(sourceType.getValue()); + documentEntity.setSourceId(source); + documentEntity.setType(fileType.getValue()); + documentEntity.setFilePath(uploadFileOnAmazonS3Response.getFilePath()); + documentEntity.setIsDeleted(false); + documentEntity.setUploadedBy(userId); + documentEntities.add(documentEntity); + } } } documentRepository.saveAll(documentEntities);