diff --git a/Dockerfile b/Dockerfile index 6006c6d1..7c8a6453 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,10 @@ -FROM sismics/jetty:9.2.20-jdk7 +FROM sismics/ubuntu-jetty:9.3.11 MAINTAINER b.gamard@sismics.com -RUN echo "deb http://http.debian.net/debian jessie-backports main contrib non-free" | tee /etc/apt/sources.list.d/backports.list RUN apt-get update && apt-get -y -q install ffmpeg mediainfo tesseract-ocr tesseract-ocr-fra tesseract-ocr-ita tesseract-ocr-kor tesseract-ocr-rus tesseract-ocr-ukr tesseract-ocr-spa tesseract-ocr-ara tesseract-ocr-hin tesseract-ocr-deu tesseract-ocr-pol tesseract-ocr-jpn tesseract-ocr-por tesseract-ocr-tha tesseract-ocr-jpn tesseract-ocr-chi-sim tesseract-ocr-chi-tra && \ apt-get clean && rm -rf /var/lib/apt/lists/* -ENV TESSDATA_PREFIX /usr/share/tesseract-ocr +ENV TESSDATA_PREFIX /usr/share/tesseract-ocr/4.00/ ENV LC_NUMERIC C # Remove the embedded javax.mail jar from Jetty diff --git a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/dto/TagStatDto.java b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/dto/TagStatDto.java deleted file mode 100644 index 03b0e76c..00000000 --- a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/dto/TagStatDto.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.sismics.docs.core.dao.jpa.dto; - - -/** - * Tag stat DTO. - * - * @author bgamard - */ -public class TagStatDto extends TagDto { - - private int count; - - /** - * Getter of count. - * - * @return the count - */ - public int getCount() { - return count; - } - - /** - * Setter of count. - * - * @param count count - */ - public void setCount(int count) { - this.count = count; - } -} diff --git a/docs-core/src/main/java/com/sismics/docs/core/listener/async/DocumentCreatedAsyncListener.java b/docs-core/src/main/java/com/sismics/docs/core/listener/async/DocumentCreatedAsyncListener.java index ace94c35..8aff6907 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/listener/async/DocumentCreatedAsyncListener.java +++ b/docs-core/src/main/java/com/sismics/docs/core/listener/async/DocumentCreatedAsyncListener.java @@ -31,16 +31,13 @@ public class DocumentCreatedAsyncListener { log.info("Document created event: " + event.toString()); } - TransactionUtil.handle(new Runnable() { - @Override - public void run() { - // Add the first contributor (the creator of the document) - ContributorDao contributorDao = new ContributorDao(); - Contributor contributor = new Contributor(); - contributor.setDocumentId(event.getDocument().getId()); - contributor.setUserId(event.getUserId()); - contributorDao.create(contributor); - } + TransactionUtil.handle(() -> { + // Add the first contributor (the creator of the document) + ContributorDao contributorDao = new ContributorDao(); + Contributor contributor = new Contributor(); + contributor.setDocumentId(event.getDocument().getId()); + contributor.setUserId(event.getUserId()); + contributorDao.create(contributor); }); // Update Lucene index diff --git a/docs-core/src/main/java/com/sismics/docs/core/listener/async/DocumentUpdatedAsyncListener.java b/docs-core/src/main/java/com/sismics/docs/core/listener/async/DocumentUpdatedAsyncListener.java index a3cdfcf5..99417a66 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/listener/async/DocumentUpdatedAsyncListener.java +++ b/docs-core/src/main/java/com/sismics/docs/core/listener/async/DocumentUpdatedAsyncListener.java @@ -34,32 +34,29 @@ public class DocumentUpdatedAsyncListener { log.info("Document updated event: " + event.toString()); } - TransactionUtil.handle(new Runnable() { - @Override - public void run() { - // Update Lucene index - DocumentDao documentDao = new DocumentDao(); - LuceneDao luceneDao = new LuceneDao(); - luceneDao.updateDocument(documentDao.getById(event.getDocumentId())); - - // Update contributors list - ContributorDao contributorDao = new ContributorDao(); - List contributorList = contributorDao.findByDocumentId(event.getDocumentId()); - - // Check if the user firing this event is not already a contributor - for (Contributor contributor : contributorList) { - if (contributor.getUserId().equals(event.getUserId())) { - // The current user is already a contributor on this document, don't do anything - return; - } + TransactionUtil.handle(() -> { + // Update Lucene index + DocumentDao documentDao = new DocumentDao(); + LuceneDao luceneDao = new LuceneDao(); + luceneDao.updateDocument(documentDao.getById(event.getDocumentId())); + + // Update contributors list + ContributorDao contributorDao = new ContributorDao(); + List contributorList = contributorDao.findByDocumentId(event.getDocumentId()); + + // Check if the user firing this event is not already a contributor + for (Contributor contributor : contributorList) { + if (contributor.getUserId().equals(event.getUserId())) { + // The current user is already a contributor on this document, don't do anything + return; } - - // Add a new contributor - Contributor contributor = new Contributor(); - contributor.setDocumentId(event.getDocumentId()); - contributor.setUserId(event.getUserId()); - contributorDao.create(contributor); } + + // Add a new contributor + Contributor contributor = new Contributor(); + contributor.setDocumentId(event.getDocumentId()); + contributor.setUserId(event.getUserId()); + contributorDao.create(contributor); }); } } diff --git a/docs-core/src/main/java/com/sismics/docs/core/listener/async/FileCreatedAsyncListener.java b/docs-core/src/main/java/com/sismics/docs/core/listener/async/FileCreatedAsyncListener.java index c0e7e890..6d63bff3 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/listener/async/FileCreatedAsyncListener.java +++ b/docs-core/src/main/java/com/sismics/docs/core/listener/async/FileCreatedAsyncListener.java @@ -59,12 +59,9 @@ public class FileCreatedAsyncListener { // Get the user from the database final AtomicReference user = new AtomicReference<>(); - TransactionUtil.handle(new Runnable() { - @Override - public void run() { - UserDao userDao = new UserDao(); - user.set(userDao.getById(event.getUserId())); - } + TransactionUtil.handle(() -> { + UserDao userDao = new UserDao(); + user.set(userDao.getById(event.getUserId())); }); if (user.get() == null) { // The user has been deleted meanwhile @@ -108,18 +105,15 @@ public class FileCreatedAsyncListener { log.info(MessageFormat.format("File content extracted in {0}ms", System.currentTimeMillis() - startTime)); // Save the file to database - TransactionUtil.handle(new Runnable() { - @Override - public void run() { - FileDao fileDao = new FileDao(); - if (fileDao.getActiveById(file.getId()) == null) { - // The file has been deleted since the text extraction started, ignore the result - return; - } - - file.setContent(content.get()); - fileDao.update(file); + TransactionUtil.handle(() -> { + FileDao fileDao = new FileDao(); + if (fileDao.getActiveById(file.getId()) == null) { + // The file has been deleted since the text extraction started, ignore the result + return; } + + file.setContent(content.get()); + fileDao.update(file); }); if (file.getDocumentId() != null) { diff --git a/docs-core/src/main/java/com/sismics/docs/core/listener/async/PasswordLostAsyncListener.java b/docs-core/src/main/java/com/sismics/docs/core/listener/async/PasswordLostAsyncListener.java index a8b02cf4..8ba75028 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/listener/async/PasswordLostAsyncListener.java +++ b/docs-core/src/main/java/com/sismics/docs/core/listener/async/PasswordLostAsyncListener.java @@ -35,19 +35,16 @@ public class PasswordLostAsyncListener { log.info("Password lost event: " + passwordLostEvent.toString()); } - TransactionUtil.handle(new Runnable() { - @Override - public void run() { - final UserDto user = passwordLostEvent.getUser(); - final PasswordRecovery passwordRecovery = passwordLostEvent.getPasswordRecovery(); - - // Send the password recovery email - Map paramRootMap = new HashMap<>(); - paramRootMap.put("user_name", user.getUsername()); - paramRootMap.put("password_recovery_key", passwordRecovery.getId()); - - EmailUtil.sendEmail(Constants.EMAIL_TEMPLATE_PASSWORD_RECOVERY, user, paramRootMap); - } + TransactionUtil.handle(() -> { + final UserDto user = passwordLostEvent.getUser(); + final PasswordRecovery passwordRecovery = passwordLostEvent.getPasswordRecovery(); + + // Send the password recovery email + Map paramRootMap = new HashMap<>(); + paramRootMap.put("user_name", user.getUsername()); + paramRootMap.put("password_recovery_key", passwordRecovery.getId()); + + EmailUtil.sendEmail(Constants.EMAIL_TEMPLATE_PASSWORD_RECOVERY, user, paramRootMap); }); } } diff --git a/docs-core/src/main/java/com/sismics/docs/core/listener/async/RebuildIndexAsyncListener.java b/docs-core/src/main/java/com/sismics/docs/core/listener/async/RebuildIndexAsyncListener.java index 9a7f4a53..5d1eac4f 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/listener/async/RebuildIndexAsyncListener.java +++ b/docs-core/src/main/java/com/sismics/docs/core/listener/async/RebuildIndexAsyncListener.java @@ -1,10 +1,5 @@ package com.sismics.docs.core.listener.async; -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.google.common.eventbus.Subscribe; import com.sismics.docs.core.dao.jpa.DocumentDao; import com.sismics.docs.core.dao.jpa.FileDao; @@ -13,6 +8,10 @@ import com.sismics.docs.core.event.RebuildIndexAsyncEvent; import com.sismics.docs.core.model.jpa.Document; import com.sismics.docs.core.model.jpa.File; import com.sismics.docs.core.util.TransactionUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; /** * Listener on rebuild index. @@ -29,30 +28,26 @@ public class RebuildIndexAsyncListener { * Rebuild Lucene index. * * @param rebuildIndexAsyncEvent Index rebuild event - * @throws Exception */ @Subscribe - public void on(final RebuildIndexAsyncEvent rebuildIndexAsyncEvent) throws Exception { + public void on(final RebuildIndexAsyncEvent rebuildIndexAsyncEvent) { if (log.isInfoEnabled()) { log.info("Rebuild index event: " + rebuildIndexAsyncEvent.toString()); } // Fetch all documents and files - TransactionUtil.handle(new Runnable() { - @Override - public void run() { - // Fetch all documents - DocumentDao documentDao = new DocumentDao(); - List documentList = documentDao.findAll(); - - // Fetch all files - FileDao fileDao = new FileDao(); - List fileList = fileDao.findAll(); - - // Rebuild index - LuceneDao luceneDao = new LuceneDao(); - luceneDao.rebuildIndex(documentList, fileList); - } + TransactionUtil.handle(() -> { + // Fetch all documents + DocumentDao documentDao = new DocumentDao(); + List documentList = documentDao.findAll(); + + // Fetch all files + FileDao fileDao = new FileDao(); + List fileList = fileDao.findAll(); + + // Rebuild index + LuceneDao luceneDao = new LuceneDao(); + luceneDao.rebuildIndex(documentList, fileList); }); } } diff --git a/docs-core/src/main/java/com/sismics/docs/core/listener/async/RouteStepValidateAsyncListener.java b/docs-core/src/main/java/com/sismics/docs/core/listener/async/RouteStepValidateAsyncListener.java index ce8b729b..a8e269a2 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/listener/async/RouteStepValidateAsyncListener.java +++ b/docs-core/src/main/java/com/sismics/docs/core/listener/async/RouteStepValidateAsyncListener.java @@ -34,19 +34,16 @@ public class RouteStepValidateAsyncListener { log.info("Route step validate event: " + routeStepValidateEvent.toString()); } - TransactionUtil.handle(new Runnable() { - @Override - public void run() { - final UserDto user = routeStepValidateEvent.getUser(); + TransactionUtil.handle(() -> { + final UserDto user = routeStepValidateEvent.getUser(); - // Send route step validated email - Map paramRootMap = new HashMap<>(); - paramRootMap.put("user_name", user.getUsername()); - paramRootMap.put("document_id", routeStepValidateEvent.getDocument().getId()); - paramRootMap.put("document_title", routeStepValidateEvent.getDocument().getTitle()); + // Send route step validated email + Map paramRootMap = new HashMap<>(); + paramRootMap.put("user_name", user.getUsername()); + paramRootMap.put("document_id", routeStepValidateEvent.getDocument().getId()); + paramRootMap.put("document_title", routeStepValidateEvent.getDocument().getTitle()); - EmailUtil.sendEmail(Constants.EMAIL_TEMPLATE_ROUTE_STEP_VALIDATE, user, paramRootMap); - } + EmailUtil.sendEmail(Constants.EMAIL_TEMPLATE_ROUTE_STEP_VALIDATE, user, paramRootMap); }); } } diff --git a/docs-core/src/main/java/com/sismics/docs/core/service/InboxService.java b/docs-core/src/main/java/com/sismics/docs/core/service/InboxService.java index fe576c54..5dbda09a 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/service/InboxService.java +++ b/docs-core/src/main/java/com/sismics/docs/core/service/InboxService.java @@ -67,41 +67,38 @@ public class InboxService extends AbstractScheduledService { * Synchronize the inbox. */ public void syncInbox() { - TransactionUtil.handle(new Runnable() { - @Override - public void run() { - Boolean enabled = ConfigUtil.getConfigBooleanValue(ConfigType.INBOX_ENABLED); - if (!enabled) { - return; - } + TransactionUtil.handle(() -> { + Boolean enabled = ConfigUtil.getConfigBooleanValue(ConfigType.INBOX_ENABLED); + if (!enabled) { + return; + } - log.info("Synchronizing IMAP inbox..."); - Folder inbox = null; - lastSyncError = null; - lastSyncDate = new Date(); - lastSyncMessageCount = 0; + log.info("Synchronizing IMAP inbox..."); + Folder inbox = null; + lastSyncError = null; + lastSyncDate = new Date(); + lastSyncMessageCount = 0; + try { + inbox = openInbox(); + Message[] messages = inbox.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false)); + log.info(messages.length + " messages found"); + for (Message message : messages) { + importMessage(message); + lastSyncMessageCount++; + } + } catch (FolderClosedException e) { + // Ignore this, we will just continue importing on the next cycle + } catch (Exception e) { + log.error("Error synching the inbox", e); + lastSyncError = e.getMessage(); + } finally { try { - inbox = openInbox(); - Message[] messages = inbox.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false)); - log.info(messages.length + " messages found"); - for (Message message : messages) { - importMessage(message); - lastSyncMessageCount++; + if (inbox != null) { + inbox.close(false); + inbox.getStore().close(); } - } catch (FolderClosedException e) { - // Ignore this, we will just continue importing on the next cycle } catch (Exception e) { - log.error("Error synching the inbox", e); - lastSyncError = e.getMessage(); - } finally { - try { - if (inbox != null) { - inbox.close(false); - inbox.getStore().close(); - } - } catch (Exception e) { - // NOP - } + // NOP } } }); diff --git a/docs-core/src/main/java/com/sismics/docs/core/service/IndexingService.java b/docs-core/src/main/java/com/sismics/docs/core/service/IndexingService.java index 5800464b..7e70402e 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/service/IndexingService.java +++ b/docs-core/src/main/java/com/sismics/docs/core/service/IndexingService.java @@ -115,11 +115,8 @@ public class IndexingService extends AbstractScheduledService { @Override protected void runOneIteration() { - TransactionUtil.handle(new Runnable() { - @Override - public void run() { - // NOP - } + TransactionUtil.handle(() -> { + // NOP }); } diff --git a/docs-web-common/src/main/java/com/sismics/util/filter/RequestContextFilter.java b/docs-web-common/src/main/java/com/sismics/util/filter/RequestContextFilter.java index d5367f71..bd7b0fe5 100644 --- a/docs-web-common/src/main/java/com/sismics/util/filter/RequestContextFilter.java +++ b/docs-web-common/src/main/java/com/sismics/util/filter/RequestContextFilter.java @@ -59,12 +59,7 @@ public class RequestContextFilter implements Filter { org.apache.log4j.Logger.getRootLogger().addAppender(fileAppender); // Initialize the application context - TransactionUtil.handle(new Runnable() { - @Override - public void run() { - AppContext.getInstance(); - } - }); + TransactionUtil.handle(AppContext::getInstance); } @Override diff --git a/docs-web/src/main/java/com/sismics/docs/rest/resource/DocumentResource.java b/docs-web/src/main/java/com/sismics/docs/rest/resource/DocumentResource.java index 91785ef2..dc086fa4 100644 --- a/docs-web/src/main/java/com/sismics/docs/rest/resource/DocumentResource.java +++ b/docs-web/src/main/java/com/sismics/docs/rest/resource/DocumentResource.java @@ -51,7 +51,6 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.StreamingOutput; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.StandardCopyOption; import java.text.MessageFormat; @@ -296,14 +295,11 @@ public class DocumentResource extends BaseResource { } // Convert to PDF - StreamingOutput stream = new StreamingOutput() { - @Override - public void write(OutputStream outputStream) throws IOException, WebApplicationException { - try { - PdfUtil.convertToPdf(documentDto, fileList, fitImageToPage, metadata, margin, outputStream); - } catch (Exception e) { - throw new IOException(e); - } + StreamingOutput stream = outputStream -> { + try { + PdfUtil.convertToPdf(documentDto, fileList, fitImageToPage, metadata, margin, outputStream); + } catch (Exception e) { + throw new IOException(e); } }; @@ -452,7 +448,7 @@ public class DocumentResource extends BaseResource { // New tag criteria List tagDtoList = TagUtil.findByName(params[1], allTagDtoList); if (documentCriteria.getTagIdList() == null) { - documentCriteria.setTagIdList(new ArrayList()); + documentCriteria.setTagIdList(new ArrayList<>()); } if (tagDtoList.isEmpty()) { // No tag found, the request must returns nothing @@ -492,32 +488,39 @@ public class DocumentResource extends BaseResource { // New specific date criteria try { boolean isUpdated = params[0].startsWith("u"); - if (params[1].length() == 10) { - DateTime date = dayFormatter.parseDateTime(params[1]); - if (isUpdated) { - documentCriteria.setUpdateDateMin(date.toDate()); - documentCriteria.setUpdateDateMax(date.plusDays(1).minusSeconds(1).toDate()); - } else { - documentCriteria.setCreateDateMin(date.toDate()); - documentCriteria.setCreateDateMax(date.plusDays(1).minusSeconds(1).toDate()); + switch (params[1].length()) { + case 10: { + DateTime date = dayFormatter.parseDateTime(params[1]); + if (isUpdated) { + documentCriteria.setUpdateDateMin(date.toDate()); + documentCriteria.setUpdateDateMax(date.plusDays(1).minusSeconds(1).toDate()); + } else { + documentCriteria.setCreateDateMin(date.toDate()); + documentCriteria.setCreateDateMax(date.plusDays(1).minusSeconds(1).toDate()); + } + break; } - } else if (params[1].length() == 7) { - DateTime date = monthFormatter.parseDateTime(params[1]); - if (isUpdated) { - documentCriteria.setUpdateDateMin(date.toDate()); - documentCriteria.setUpdateDateMax(date.plusMonths(1).minusSeconds(1).toDate()); - } else { - documentCriteria.setCreateDateMin(date.toDate()); - documentCriteria.setCreateDateMax(date.plusMonths(1).minusSeconds(1).toDate()); + case 7: { + DateTime date = monthFormatter.parseDateTime(params[1]); + if (isUpdated) { + documentCriteria.setUpdateDateMin(date.toDate()); + documentCriteria.setUpdateDateMax(date.plusMonths(1).minusSeconds(1).toDate()); + } else { + documentCriteria.setCreateDateMin(date.toDate()); + documentCriteria.setCreateDateMax(date.plusMonths(1).minusSeconds(1).toDate()); + } + break; } - } else if (params[1].length() == 4) { - DateTime date = yearFormatter.parseDateTime(params[1]); - if (isUpdated) { - documentCriteria.setUpdateDateMin(date.toDate()); - documentCriteria.setUpdateDateMax(date.plusYears(1).minusSeconds(1).toDate()); - } else { - documentCriteria.setCreateDateMin(date.toDate()); - documentCriteria.setCreateDateMax(date.plusYears(1).minusSeconds(1).toDate()); + case 4: { + DateTime date = yearFormatter.parseDateTime(params[1]); + if (isUpdated) { + documentCriteria.setUpdateDateMin(date.toDate()); + documentCriteria.setUpdateDateMax(date.plusYears(1).minusSeconds(1).toDate()); + } else { + documentCriteria.setCreateDateMin(date.toDate()); + documentCriteria.setCreateDateMax(date.plusYears(1).minusSeconds(1).toDate()); + } + break; } } } catch (IllegalArgumentException e) { diff --git a/docs-web/src/main/java/com/sismics/docs/rest/resource/FileResource.java b/docs-web/src/main/java/com/sismics/docs/rest/resource/FileResource.java index 993b4225..33860c5e 100644 --- a/docs-web/src/main/java/com/sismics/docs/rest/resource/FileResource.java +++ b/docs-web/src/main/java/com/sismics/docs/rest/resource/FileResource.java @@ -39,7 +39,6 @@ import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.StreamingOutput; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Paths; @@ -506,18 +505,15 @@ public class FileResource extends BaseResource { final InputStream responseInputStream = decrypt ? EncryptionUtil.decryptInputStream(fileInputStream, user.getPrivateKey()) : fileInputStream; - stream = new StreamingOutput() { - @Override - public void write(OutputStream outputStream) throws IOException, WebApplicationException { + stream = outputStream -> { + try { + ByteStreams.copy(responseInputStream, outputStream); + } finally { try { - ByteStreams.copy(responseInputStream, outputStream); - } finally { - try { - responseInputStream.close(); - outputStream.close(); - } catch (IOException e) { - // Ignore - } + responseInputStream.close(); + outputStream.close(); + } catch (IOException e) { + // Ignore } } }; @@ -578,32 +574,29 @@ public class FileResource extends BaseResource { final List fileList = fileDao.getByDocumentId(principal.getId(), documentId); // Create the ZIP stream - StreamingOutput stream = new StreamingOutput() { - @Override - public void write(OutputStream outputStream) throws IOException, WebApplicationException { - try (ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream)) { - // Add each file to the ZIP stream - int index = 0; - for (File file : fileList) { - java.nio.file.Path storedfile = DirectoryUtil.getStorageDirectory().resolve(file.getId()); - InputStream fileInputStream = Files.newInputStream(storedfile); - - // Add the decrypted file to the ZIP stream - // Files are encrypted by the creator of them - User user = userDao.getById(file.getUserId()); - try (InputStream decryptedStream = EncryptionUtil.decryptInputStream(fileInputStream, user.getPrivateKey())) { - ZipEntry zipEntry = new ZipEntry(index + "-" + file.getFullName(Integer.toString(index))); - zipOutputStream.putNextEntry(zipEntry); - ByteStreams.copy(decryptedStream, zipOutputStream); - zipOutputStream.closeEntry(); - } catch (Exception e) { - throw new WebApplicationException(e); - } - index++; + StreamingOutput stream = outputStream -> { + try (ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream)) { + // Add each file to the ZIP stream + int index = 0; + for (File file : fileList) { + java.nio.file.Path storedfile = DirectoryUtil.getStorageDirectory().resolve(file.getId()); + InputStream fileInputStream = Files.newInputStream(storedfile); + + // Add the decrypted file to the ZIP stream + // Files are encrypted by the creator of them + User user = userDao.getById(file.getUserId()); + try (InputStream decryptedStream = EncryptionUtil.decryptInputStream(fileInputStream, user.getPrivateKey())) { + ZipEntry zipEntry = new ZipEntry(index + "-" + file.getFullName(Integer.toString(index))); + zipOutputStream.putNextEntry(zipEntry); + ByteStreams.copy(decryptedStream, zipOutputStream); + zipOutputStream.closeEntry(); + } catch (Exception e) { + throw new WebApplicationException(e); } + index++; } - outputStream.close(); } + outputStream.close(); }; // Write to the output diff --git a/pom.xml b/pom.xml index e7a2b538..d533f1c2 100644 --- a/pom.xml +++ b/pom.xml @@ -11,8 +11,8 @@ Docs Parent - 1.7 - 1.7 + 1.8 + 1.8 UTF-8 @@ -49,10 +49,9 @@ 1.11.2 1.3.0 - - 9.2.13.v20150730 - 9.2.13.v20150730 - 9.2.13.v20150730 + 9.3.11.v20160721 + 9.3.11.v20160721 + 9.3.11.v20160721 1.8 @@ -61,7 +60,7 @@ 2.7 2.6 2.19.1 - 9.2.13.v20150730 + 9.3.11.v20160721