mirror of
https://github.com/sismics/docs.git
synced 2024-11-17 11:47:56 +01:00
parent
7ea8d0c0f7
commit
5220b13e7d
@ -1,11 +1,10 @@
|
|||||||
FROM sismics/jetty:9.2.20-jdk7
|
FROM sismics/ubuntu-jetty:9.3.11
|
||||||
MAINTAINER b.gamard@sismics.com
|
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 && \
|
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/*
|
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
|
ENV LC_NUMERIC C
|
||||||
|
|
||||||
# Remove the embedded javax.mail jar from Jetty
|
# Remove the embedded javax.mail jar from Jetty
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -31,16 +31,13 @@ public class DocumentCreatedAsyncListener {
|
|||||||
log.info("Document created event: " + event.toString());
|
log.info("Document created event: " + event.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
TransactionUtil.handle(new Runnable() {
|
TransactionUtil.handle(() -> {
|
||||||
@Override
|
// Add the first contributor (the creator of the document)
|
||||||
public void run() {
|
ContributorDao contributorDao = new ContributorDao();
|
||||||
// Add the first contributor (the creator of the document)
|
Contributor contributor = new Contributor();
|
||||||
ContributorDao contributorDao = new ContributorDao();
|
contributor.setDocumentId(event.getDocument().getId());
|
||||||
Contributor contributor = new Contributor();
|
contributor.setUserId(event.getUserId());
|
||||||
contributor.setDocumentId(event.getDocument().getId());
|
contributorDao.create(contributor);
|
||||||
contributor.setUserId(event.getUserId());
|
|
||||||
contributorDao.create(contributor);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update Lucene index
|
// Update Lucene index
|
||||||
|
@ -34,32 +34,29 @@ public class DocumentUpdatedAsyncListener {
|
|||||||
log.info("Document updated event: " + event.toString());
|
log.info("Document updated event: " + event.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
TransactionUtil.handle(new Runnable() {
|
TransactionUtil.handle(() -> {
|
||||||
@Override
|
// Update Lucene index
|
||||||
public void run() {
|
DocumentDao documentDao = new DocumentDao();
|
||||||
// Update Lucene index
|
LuceneDao luceneDao = new LuceneDao();
|
||||||
DocumentDao documentDao = new DocumentDao();
|
luceneDao.updateDocument(documentDao.getById(event.getDocumentId()));
|
||||||
LuceneDao luceneDao = new LuceneDao();
|
|
||||||
luceneDao.updateDocument(documentDao.getById(event.getDocumentId()));
|
|
||||||
|
|
||||||
// Update contributors list
|
// Update contributors list
|
||||||
ContributorDao contributorDao = new ContributorDao();
|
ContributorDao contributorDao = new ContributorDao();
|
||||||
List<Contributor> contributorList = contributorDao.findByDocumentId(event.getDocumentId());
|
List<Contributor> contributorList = contributorDao.findByDocumentId(event.getDocumentId());
|
||||||
|
|
||||||
// Check if the user firing this event is not already a contributor
|
// Check if the user firing this event is not already a contributor
|
||||||
for (Contributor contributor : contributorList) {
|
for (Contributor contributor : contributorList) {
|
||||||
if (contributor.getUserId().equals(event.getUserId())) {
|
if (contributor.getUserId().equals(event.getUserId())) {
|
||||||
// The current user is already a contributor on this document, don't do anything
|
// The current user is already a contributor on this document, don't do anything
|
||||||
return;
|
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);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,12 +59,9 @@ public class FileCreatedAsyncListener {
|
|||||||
|
|
||||||
// Get the user from the database
|
// Get the user from the database
|
||||||
final AtomicReference<User> user = new AtomicReference<>();
|
final AtomicReference<User> user = new AtomicReference<>();
|
||||||
TransactionUtil.handle(new Runnable() {
|
TransactionUtil.handle(() -> {
|
||||||
@Override
|
UserDao userDao = new UserDao();
|
||||||
public void run() {
|
user.set(userDao.getById(event.getUserId()));
|
||||||
UserDao userDao = new UserDao();
|
|
||||||
user.set(userDao.getById(event.getUserId()));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
if (user.get() == null) {
|
if (user.get() == null) {
|
||||||
// The user has been deleted meanwhile
|
// 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));
|
log.info(MessageFormat.format("File content extracted in {0}ms", System.currentTimeMillis() - startTime));
|
||||||
|
|
||||||
// Save the file to database
|
// Save the file to database
|
||||||
TransactionUtil.handle(new Runnable() {
|
TransactionUtil.handle(() -> {
|
||||||
@Override
|
FileDao fileDao = new FileDao();
|
||||||
public void run() {
|
if (fileDao.getActiveById(file.getId()) == null) {
|
||||||
FileDao fileDao = new FileDao();
|
// The file has been deleted since the text extraction started, ignore the result
|
||||||
if (fileDao.getActiveById(file.getId()) == null) {
|
return;
|
||||||
// The file has been deleted since the text extraction started, ignore the result
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
file.setContent(content.get());
|
|
||||||
fileDao.update(file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
file.setContent(content.get());
|
||||||
|
fileDao.update(file);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (file.getDocumentId() != null) {
|
if (file.getDocumentId() != null) {
|
||||||
|
@ -35,19 +35,16 @@ public class PasswordLostAsyncListener {
|
|||||||
log.info("Password lost event: " + passwordLostEvent.toString());
|
log.info("Password lost event: " + passwordLostEvent.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
TransactionUtil.handle(new Runnable() {
|
TransactionUtil.handle(() -> {
|
||||||
@Override
|
final UserDto user = passwordLostEvent.getUser();
|
||||||
public void run() {
|
final PasswordRecovery passwordRecovery = passwordLostEvent.getPasswordRecovery();
|
||||||
final UserDto user = passwordLostEvent.getUser();
|
|
||||||
final PasswordRecovery passwordRecovery = passwordLostEvent.getPasswordRecovery();
|
|
||||||
|
|
||||||
// Send the password recovery email
|
// Send the password recovery email
|
||||||
Map<String, Object> paramRootMap = new HashMap<>();
|
Map<String, Object> paramRootMap = new HashMap<>();
|
||||||
paramRootMap.put("user_name", user.getUsername());
|
paramRootMap.put("user_name", user.getUsername());
|
||||||
paramRootMap.put("password_recovery_key", passwordRecovery.getId());
|
paramRootMap.put("password_recovery_key", passwordRecovery.getId());
|
||||||
|
|
||||||
EmailUtil.sendEmail(Constants.EMAIL_TEMPLATE_PASSWORD_RECOVERY, user, paramRootMap);
|
EmailUtil.sendEmail(Constants.EMAIL_TEMPLATE_PASSWORD_RECOVERY, user, paramRootMap);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
package com.sismics.docs.core.listener.async;
|
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.google.common.eventbus.Subscribe;
|
||||||
import com.sismics.docs.core.dao.jpa.DocumentDao;
|
import com.sismics.docs.core.dao.jpa.DocumentDao;
|
||||||
import com.sismics.docs.core.dao.jpa.FileDao;
|
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.Document;
|
||||||
import com.sismics.docs.core.model.jpa.File;
|
import com.sismics.docs.core.model.jpa.File;
|
||||||
import com.sismics.docs.core.util.TransactionUtil;
|
import com.sismics.docs.core.util.TransactionUtil;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listener on rebuild index.
|
* Listener on rebuild index.
|
||||||
@ -29,30 +28,26 @@ public class RebuildIndexAsyncListener {
|
|||||||
* Rebuild Lucene index.
|
* Rebuild Lucene index.
|
||||||
*
|
*
|
||||||
* @param rebuildIndexAsyncEvent Index rebuild event
|
* @param rebuildIndexAsyncEvent Index rebuild event
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void on(final RebuildIndexAsyncEvent rebuildIndexAsyncEvent) throws Exception {
|
public void on(final RebuildIndexAsyncEvent rebuildIndexAsyncEvent) {
|
||||||
if (log.isInfoEnabled()) {
|
if (log.isInfoEnabled()) {
|
||||||
log.info("Rebuild index event: " + rebuildIndexAsyncEvent.toString());
|
log.info("Rebuild index event: " + rebuildIndexAsyncEvent.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch all documents and files
|
// Fetch all documents and files
|
||||||
TransactionUtil.handle(new Runnable() {
|
TransactionUtil.handle(() -> {
|
||||||
@Override
|
// Fetch all documents
|
||||||
public void run() {
|
DocumentDao documentDao = new DocumentDao();
|
||||||
// Fetch all documents
|
List<Document> documentList = documentDao.findAll();
|
||||||
DocumentDao documentDao = new DocumentDao();
|
|
||||||
List<Document> documentList = documentDao.findAll();
|
|
||||||
|
|
||||||
// Fetch all files
|
// Fetch all files
|
||||||
FileDao fileDao = new FileDao();
|
FileDao fileDao = new FileDao();
|
||||||
List<File> fileList = fileDao.findAll();
|
List<File> fileList = fileDao.findAll();
|
||||||
|
|
||||||
// Rebuild index
|
// Rebuild index
|
||||||
LuceneDao luceneDao = new LuceneDao();
|
LuceneDao luceneDao = new LuceneDao();
|
||||||
luceneDao.rebuildIndex(documentList, fileList);
|
luceneDao.rebuildIndex(documentList, fileList);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,19 +34,16 @@ public class RouteStepValidateAsyncListener {
|
|||||||
log.info("Route step validate event: " + routeStepValidateEvent.toString());
|
log.info("Route step validate event: " + routeStepValidateEvent.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
TransactionUtil.handle(new Runnable() {
|
TransactionUtil.handle(() -> {
|
||||||
@Override
|
final UserDto user = routeStepValidateEvent.getUser();
|
||||||
public void run() {
|
|
||||||
final UserDto user = routeStepValidateEvent.getUser();
|
|
||||||
|
|
||||||
// Send route step validated email
|
// Send route step validated email
|
||||||
Map<String, Object> paramRootMap = new HashMap<>();
|
Map<String, Object> paramRootMap = new HashMap<>();
|
||||||
paramRootMap.put("user_name", user.getUsername());
|
paramRootMap.put("user_name", user.getUsername());
|
||||||
paramRootMap.put("document_id", routeStepValidateEvent.getDocument().getId());
|
paramRootMap.put("document_id", routeStepValidateEvent.getDocument().getId());
|
||||||
paramRootMap.put("document_title", routeStepValidateEvent.getDocument().getTitle());
|
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);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,41 +67,38 @@ public class InboxService extends AbstractScheduledService {
|
|||||||
* Synchronize the inbox.
|
* Synchronize the inbox.
|
||||||
*/
|
*/
|
||||||
public void syncInbox() {
|
public void syncInbox() {
|
||||||
TransactionUtil.handle(new Runnable() {
|
TransactionUtil.handle(() -> {
|
||||||
@Override
|
Boolean enabled = ConfigUtil.getConfigBooleanValue(ConfigType.INBOX_ENABLED);
|
||||||
public void run() {
|
if (!enabled) {
|
||||||
Boolean enabled = ConfigUtil.getConfigBooleanValue(ConfigType.INBOX_ENABLED);
|
return;
|
||||||
if (!enabled) {
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("Synchronizing IMAP inbox...");
|
log.info("Synchronizing IMAP inbox...");
|
||||||
Folder inbox = null;
|
Folder inbox = null;
|
||||||
lastSyncError = null;
|
lastSyncError = null;
|
||||||
lastSyncDate = new Date();
|
lastSyncDate = new Date();
|
||||||
lastSyncMessageCount = 0;
|
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 {
|
try {
|
||||||
inbox = openInbox();
|
if (inbox != null) {
|
||||||
Message[] messages = inbox.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false));
|
inbox.close(false);
|
||||||
log.info(messages.length + " messages found");
|
inbox.getStore().close();
|
||||||
for (Message message : messages) {
|
|
||||||
importMessage(message);
|
|
||||||
lastSyncMessageCount++;
|
|
||||||
}
|
}
|
||||||
} catch (FolderClosedException e) {
|
|
||||||
// Ignore this, we will just continue importing on the next cycle
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Error synching the inbox", e);
|
// NOP
|
||||||
lastSyncError = e.getMessage();
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (inbox != null) {
|
|
||||||
inbox.close(false);
|
|
||||||
inbox.getStore().close();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
// NOP
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -115,11 +115,8 @@ public class IndexingService extends AbstractScheduledService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void runOneIteration() {
|
protected void runOneIteration() {
|
||||||
TransactionUtil.handle(new Runnable() {
|
TransactionUtil.handle(() -> {
|
||||||
@Override
|
// NOP
|
||||||
public void run() {
|
|
||||||
// NOP
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,12 +59,7 @@ public class RequestContextFilter implements Filter {
|
|||||||
org.apache.log4j.Logger.getRootLogger().addAppender(fileAppender);
|
org.apache.log4j.Logger.getRootLogger().addAppender(fileAppender);
|
||||||
|
|
||||||
// Initialize the application context
|
// Initialize the application context
|
||||||
TransactionUtil.handle(new Runnable() {
|
TransactionUtil.handle(AppContext::getInstance);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
AppContext.getInstance();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -51,7 +51,6 @@ import javax.ws.rs.core.Response;
|
|||||||
import javax.ws.rs.core.StreamingOutput;
|
import javax.ws.rs.core.StreamingOutput;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
@ -296,14 +295,11 @@ public class DocumentResource extends BaseResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Convert to PDF
|
// Convert to PDF
|
||||||
StreamingOutput stream = new StreamingOutput() {
|
StreamingOutput stream = outputStream -> {
|
||||||
@Override
|
try {
|
||||||
public void write(OutputStream outputStream) throws IOException, WebApplicationException {
|
PdfUtil.convertToPdf(documentDto, fileList, fitImageToPage, metadata, margin, outputStream);
|
||||||
try {
|
} catch (Exception e) {
|
||||||
PdfUtil.convertToPdf(documentDto, fileList, fitImageToPage, metadata, margin, outputStream);
|
throw new IOException(e);
|
||||||
} catch (Exception e) {
|
|
||||||
throw new IOException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -452,7 +448,7 @@ public class DocumentResource extends BaseResource {
|
|||||||
// New tag criteria
|
// New tag criteria
|
||||||
List<TagDto> tagDtoList = TagUtil.findByName(params[1], allTagDtoList);
|
List<TagDto> tagDtoList = TagUtil.findByName(params[1], allTagDtoList);
|
||||||
if (documentCriteria.getTagIdList() == null) {
|
if (documentCriteria.getTagIdList() == null) {
|
||||||
documentCriteria.setTagIdList(new ArrayList<String>());
|
documentCriteria.setTagIdList(new ArrayList<>());
|
||||||
}
|
}
|
||||||
if (tagDtoList.isEmpty()) {
|
if (tagDtoList.isEmpty()) {
|
||||||
// No tag found, the request must returns nothing
|
// No tag found, the request must returns nothing
|
||||||
@ -492,32 +488,39 @@ public class DocumentResource extends BaseResource {
|
|||||||
// New specific date criteria
|
// New specific date criteria
|
||||||
try {
|
try {
|
||||||
boolean isUpdated = params[0].startsWith("u");
|
boolean isUpdated = params[0].startsWith("u");
|
||||||
if (params[1].length() == 10) {
|
switch (params[1].length()) {
|
||||||
DateTime date = dayFormatter.parseDateTime(params[1]);
|
case 10: {
|
||||||
if (isUpdated) {
|
DateTime date = dayFormatter.parseDateTime(params[1]);
|
||||||
documentCriteria.setUpdateDateMin(date.toDate());
|
if (isUpdated) {
|
||||||
documentCriteria.setUpdateDateMax(date.plusDays(1).minusSeconds(1).toDate());
|
documentCriteria.setUpdateDateMin(date.toDate());
|
||||||
} else {
|
documentCriteria.setUpdateDateMax(date.plusDays(1).minusSeconds(1).toDate());
|
||||||
documentCriteria.setCreateDateMin(date.toDate());
|
} else {
|
||||||
documentCriteria.setCreateDateMax(date.plusDays(1).minusSeconds(1).toDate());
|
documentCriteria.setCreateDateMin(date.toDate());
|
||||||
|
documentCriteria.setCreateDateMax(date.plusDays(1).minusSeconds(1).toDate());
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else if (params[1].length() == 7) {
|
case 7: {
|
||||||
DateTime date = monthFormatter.parseDateTime(params[1]);
|
DateTime date = monthFormatter.parseDateTime(params[1]);
|
||||||
if (isUpdated) {
|
if (isUpdated) {
|
||||||
documentCriteria.setUpdateDateMin(date.toDate());
|
documentCriteria.setUpdateDateMin(date.toDate());
|
||||||
documentCriteria.setUpdateDateMax(date.plusMonths(1).minusSeconds(1).toDate());
|
documentCriteria.setUpdateDateMax(date.plusMonths(1).minusSeconds(1).toDate());
|
||||||
} else {
|
} else {
|
||||||
documentCriteria.setCreateDateMin(date.toDate());
|
documentCriteria.setCreateDateMin(date.toDate());
|
||||||
documentCriteria.setCreateDateMax(date.plusMonths(1).minusSeconds(1).toDate());
|
documentCriteria.setCreateDateMax(date.plusMonths(1).minusSeconds(1).toDate());
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else if (params[1].length() == 4) {
|
case 4: {
|
||||||
DateTime date = yearFormatter.parseDateTime(params[1]);
|
DateTime date = yearFormatter.parseDateTime(params[1]);
|
||||||
if (isUpdated) {
|
if (isUpdated) {
|
||||||
documentCriteria.setUpdateDateMin(date.toDate());
|
documentCriteria.setUpdateDateMin(date.toDate());
|
||||||
documentCriteria.setUpdateDateMax(date.plusYears(1).minusSeconds(1).toDate());
|
documentCriteria.setUpdateDateMax(date.plusYears(1).minusSeconds(1).toDate());
|
||||||
} else {
|
} else {
|
||||||
documentCriteria.setCreateDateMin(date.toDate());
|
documentCriteria.setCreateDateMin(date.toDate());
|
||||||
documentCriteria.setCreateDateMax(date.plusYears(1).minusSeconds(1).toDate());
|
documentCriteria.setCreateDateMax(date.plusYears(1).minusSeconds(1).toDate());
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
@ -39,7 +39,6 @@ import javax.ws.rs.core.Response.Status;
|
|||||||
import javax.ws.rs.core.StreamingOutput;
|
import javax.ws.rs.core.StreamingOutput;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
@ -506,18 +505,15 @@ public class FileResource extends BaseResource {
|
|||||||
final InputStream responseInputStream = decrypt ?
|
final InputStream responseInputStream = decrypt ?
|
||||||
EncryptionUtil.decryptInputStream(fileInputStream, user.getPrivateKey()) : fileInputStream;
|
EncryptionUtil.decryptInputStream(fileInputStream, user.getPrivateKey()) : fileInputStream;
|
||||||
|
|
||||||
stream = new StreamingOutput() {
|
stream = outputStream -> {
|
||||||
@Override
|
try {
|
||||||
public void write(OutputStream outputStream) throws IOException, WebApplicationException {
|
ByteStreams.copy(responseInputStream, outputStream);
|
||||||
|
} finally {
|
||||||
try {
|
try {
|
||||||
ByteStreams.copy(responseInputStream, outputStream);
|
responseInputStream.close();
|
||||||
} finally {
|
outputStream.close();
|
||||||
try {
|
} catch (IOException e) {
|
||||||
responseInputStream.close();
|
// Ignore
|
||||||
outputStream.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
// Ignore
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -578,32 +574,29 @@ public class FileResource extends BaseResource {
|
|||||||
final List<File> fileList = fileDao.getByDocumentId(principal.getId(), documentId);
|
final List<File> fileList = fileDao.getByDocumentId(principal.getId(), documentId);
|
||||||
|
|
||||||
// Create the ZIP stream
|
// Create the ZIP stream
|
||||||
StreamingOutput stream = new StreamingOutput() {
|
StreamingOutput stream = outputStream -> {
|
||||||
@Override
|
try (ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream)) {
|
||||||
public void write(OutputStream outputStream) throws IOException, WebApplicationException {
|
// Add each file to the ZIP stream
|
||||||
try (ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream)) {
|
int index = 0;
|
||||||
// Add each file to the ZIP stream
|
for (File file : fileList) {
|
||||||
int index = 0;
|
java.nio.file.Path storedfile = DirectoryUtil.getStorageDirectory().resolve(file.getId());
|
||||||
for (File file : fileList) {
|
InputStream fileInputStream = Files.newInputStream(storedfile);
|
||||||
java.nio.file.Path storedfile = DirectoryUtil.getStorageDirectory().resolve(file.getId());
|
|
||||||
InputStream fileInputStream = Files.newInputStream(storedfile);
|
|
||||||
|
|
||||||
// Add the decrypted file to the ZIP stream
|
// Add the decrypted file to the ZIP stream
|
||||||
// Files are encrypted by the creator of them
|
// Files are encrypted by the creator of them
|
||||||
User user = userDao.getById(file.getUserId());
|
User user = userDao.getById(file.getUserId());
|
||||||
try (InputStream decryptedStream = EncryptionUtil.decryptInputStream(fileInputStream, user.getPrivateKey())) {
|
try (InputStream decryptedStream = EncryptionUtil.decryptInputStream(fileInputStream, user.getPrivateKey())) {
|
||||||
ZipEntry zipEntry = new ZipEntry(index + "-" + file.getFullName(Integer.toString(index)));
|
ZipEntry zipEntry = new ZipEntry(index + "-" + file.getFullName(Integer.toString(index)));
|
||||||
zipOutputStream.putNextEntry(zipEntry);
|
zipOutputStream.putNextEntry(zipEntry);
|
||||||
ByteStreams.copy(decryptedStream, zipOutputStream);
|
ByteStreams.copy(decryptedStream, zipOutputStream);
|
||||||
zipOutputStream.closeEntry();
|
zipOutputStream.closeEntry();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new WebApplicationException(e);
|
throw new WebApplicationException(e);
|
||||||
}
|
|
||||||
index++;
|
|
||||||
}
|
}
|
||||||
|
index++;
|
||||||
}
|
}
|
||||||
outputStream.close();
|
|
||||||
}
|
}
|
||||||
|
outputStream.close();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Write to the output
|
// Write to the output
|
||||||
|
13
pom.xml
13
pom.xml
@ -11,8 +11,8 @@
|
|||||||
<name>Docs Parent</name>
|
<name>Docs Parent</name>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>1.7</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>1.7</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
|
||||||
<!-- Dependencies version (external) -->
|
<!-- Dependencies version (external) -->
|
||||||
@ -49,10 +49,9 @@
|
|||||||
<org.jsoup.jsoup.version>1.11.2</org.jsoup.jsoup.version>
|
<org.jsoup.jsoup.version>1.11.2</org.jsoup.jsoup.version>
|
||||||
<com.github.jai-imageio.jai-imageio-jpeg2000.version>1.3.0</com.github.jai-imageio.jai-imageio-jpeg2000.version>
|
<com.github.jai-imageio.jai-imageio-jpeg2000.version>1.3.0</com.github.jai-imageio.jai-imageio-jpeg2000.version>
|
||||||
|
|
||||||
<!-- Migrate to Java 8 before upgrading this -->
|
<org.eclipse.jetty.jetty-server.version>9.3.11.v20160721</org.eclipse.jetty.jetty-server.version>
|
||||||
<org.eclipse.jetty.jetty-server.version>9.2.13.v20150730</org.eclipse.jetty.jetty-server.version>
|
<org.eclipse.jetty.jetty-webapp.version>9.3.11.v20160721</org.eclipse.jetty.jetty-webapp.version>
|
||||||
<org.eclipse.jetty.jetty-webapp.version>9.2.13.v20150730</org.eclipse.jetty.jetty-webapp.version>
|
<org.eclipse.jetty.jetty-servlet.version>9.3.11.v20160721</org.eclipse.jetty.jetty-servlet.version>
|
||||||
<org.eclipse.jetty.jetty-servlet.version>9.2.13.v20150730</org.eclipse.jetty.jetty-servlet.version>
|
|
||||||
|
|
||||||
<!-- Plugins version -->
|
<!-- Plugins version -->
|
||||||
<org.apache.maven.plugins.maven-antrun-plugin.version>1.8</org.apache.maven.plugins.maven-antrun-plugin.version>
|
<org.apache.maven.plugins.maven-antrun-plugin.version>1.8</org.apache.maven.plugins.maven-antrun-plugin.version>
|
||||||
@ -61,7 +60,7 @@
|
|||||||
<org.apache.maven.plugins.maven-resources-plugin.version>2.7</org.apache.maven.plugins.maven-resources-plugin.version>
|
<org.apache.maven.plugins.maven-resources-plugin.version>2.7</org.apache.maven.plugins.maven-resources-plugin.version>
|
||||||
<org.apache.maven.plugins.maven-war-plugin.version>2.6</org.apache.maven.plugins.maven-war-plugin.version>
|
<org.apache.maven.plugins.maven-war-plugin.version>2.6</org.apache.maven.plugins.maven-war-plugin.version>
|
||||||
<org.apache.maven.plugins.maven-surefire-plugin.version>2.19.1</org.apache.maven.plugins.maven-surefire-plugin.version>
|
<org.apache.maven.plugins.maven-surefire-plugin.version>2.19.1</org.apache.maven.plugins.maven-surefire-plugin.version>
|
||||||
<org.eclipse.jetty.jetty-maven-plugin.version>9.2.13.v20150730</org.eclipse.jetty.jetty-maven-plugin.version>
|
<org.eclipse.jetty.jetty-maven-plugin.version>9.3.11.v20160721</org.eclipse.jetty.jetty-maven-plugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<scm>
|
<scm>
|
||||||
|
Loading…
Reference in New Issue
Block a user