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
|
||||
|
||||
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
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
TransactionUtil.handle(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
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
|
||||
|
@ -34,9 +34,7 @@ public class DocumentUpdatedAsyncListener {
|
||||
log.info("Document updated event: " + event.toString());
|
||||
}
|
||||
|
||||
TransactionUtil.handle(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TransactionUtil.handle(() -> {
|
||||
// Update Lucene index
|
||||
DocumentDao documentDao = new DocumentDao();
|
||||
LuceneDao luceneDao = new LuceneDao();
|
||||
@ -59,7 +57,6 @@ public class DocumentUpdatedAsyncListener {
|
||||
contributor.setDocumentId(event.getDocumentId());
|
||||
contributor.setUserId(event.getUserId());
|
||||
contributorDao.create(contributor);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -59,12 +59,9 @@ public class FileCreatedAsyncListener {
|
||||
|
||||
// Get the user from the database
|
||||
final AtomicReference<User> user = new AtomicReference<>();
|
||||
TransactionUtil.handle(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TransactionUtil.handle(() -> {
|
||||
UserDao userDao = new UserDao();
|
||||
user.set(userDao.getById(event.getUserId()));
|
||||
}
|
||||
});
|
||||
if (user.get() == null) {
|
||||
// The user has been deleted meanwhile
|
||||
@ -108,9 +105,7 @@ 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() {
|
||||
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
|
||||
@ -119,7 +114,6 @@ public class FileCreatedAsyncListener {
|
||||
|
||||
file.setContent(content.get());
|
||||
fileDao.update(file);
|
||||
}
|
||||
});
|
||||
|
||||
if (file.getDocumentId() != null) {
|
||||
|
@ -35,9 +35,7 @@ public class PasswordLostAsyncListener {
|
||||
log.info("Password lost event: " + passwordLostEvent.toString());
|
||||
}
|
||||
|
||||
TransactionUtil.handle(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TransactionUtil.handle(() -> {
|
||||
final UserDto user = passwordLostEvent.getUser();
|
||||
final PasswordRecovery passwordRecovery = passwordLostEvent.getPasswordRecovery();
|
||||
|
||||
@ -47,7 +45,6 @@ public class PasswordLostAsyncListener {
|
||||
paramRootMap.put("password_recovery_key", passwordRecovery.getId());
|
||||
|
||||
EmailUtil.sendEmail(Constants.EMAIL_TEMPLATE_PASSWORD_RECOVERY, user, paramRootMap);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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,18 +28,15 @@ 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() {
|
||||
TransactionUtil.handle(() -> {
|
||||
// Fetch all documents
|
||||
DocumentDao documentDao = new DocumentDao();
|
||||
List<Document> documentList = documentDao.findAll();
|
||||
@ -52,7 +48,6 @@ public class RebuildIndexAsyncListener {
|
||||
// Rebuild index
|
||||
LuceneDao luceneDao = new LuceneDao();
|
||||
luceneDao.rebuildIndex(documentList, fileList);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -34,9 +34,7 @@ public class RouteStepValidateAsyncListener {
|
||||
log.info("Route step validate event: " + routeStepValidateEvent.toString());
|
||||
}
|
||||
|
||||
TransactionUtil.handle(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TransactionUtil.handle(() -> {
|
||||
final UserDto user = routeStepValidateEvent.getUser();
|
||||
|
||||
// Send route step validated email
|
||||
@ -46,7 +44,6 @@ public class RouteStepValidateAsyncListener {
|
||||
paramRootMap.put("document_title", routeStepValidateEvent.getDocument().getTitle());
|
||||
|
||||
EmailUtil.sendEmail(Constants.EMAIL_TEMPLATE_ROUTE_STEP_VALIDATE, user, paramRootMap);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -67,9 +67,7 @@ public class InboxService extends AbstractScheduledService {
|
||||
* Synchronize the inbox.
|
||||
*/
|
||||
public void syncInbox() {
|
||||
TransactionUtil.handle(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TransactionUtil.handle(() -> {
|
||||
Boolean enabled = ConfigUtil.getConfigBooleanValue(ConfigType.INBOX_ENABLED);
|
||||
if (!enabled) {
|
||||
return;
|
||||
@ -103,7 +101,6 @@ public class InboxService extends AbstractScheduledService {
|
||||
// NOP
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -115,11 +115,8 @@ public class IndexingService extends AbstractScheduledService {
|
||||
|
||||
@Override
|
||||
protected void runOneIteration() {
|
||||
TransactionUtil.handle(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TransactionUtil.handle(() -> {
|
||||
// NOP
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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,15 +295,12 @@ public class DocumentResource extends BaseResource {
|
||||
}
|
||||
|
||||
// Convert to PDF
|
||||
StreamingOutput stream = new StreamingOutput() {
|
||||
@Override
|
||||
public void write(OutputStream outputStream) throws IOException, WebApplicationException {
|
||||
StreamingOutput stream = outputStream -> {
|
||||
try {
|
||||
PdfUtil.convertToPdf(documentDto, fileList, fitImageToPage, metadata, margin, outputStream);
|
||||
} catch (Exception e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return Response.ok(stream)
|
||||
@ -452,7 +448,7 @@ public class DocumentResource extends BaseResource {
|
||||
// New tag criteria
|
||||
List<TagDto> tagDtoList = TagUtil.findByName(params[1], allTagDtoList);
|
||||
if (documentCriteria.getTagIdList() == null) {
|
||||
documentCriteria.setTagIdList(new ArrayList<String>());
|
||||
documentCriteria.setTagIdList(new ArrayList<>());
|
||||
}
|
||||
if (tagDtoList.isEmpty()) {
|
||||
// No tag found, the request must returns nothing
|
||||
@ -492,7 +488,8 @@ public class DocumentResource extends BaseResource {
|
||||
// New specific date criteria
|
||||
try {
|
||||
boolean isUpdated = params[0].startsWith("u");
|
||||
if (params[1].length() == 10) {
|
||||
switch (params[1].length()) {
|
||||
case 10: {
|
||||
DateTime date = dayFormatter.parseDateTime(params[1]);
|
||||
if (isUpdated) {
|
||||
documentCriteria.setUpdateDateMin(date.toDate());
|
||||
@ -501,7 +498,9 @@ public class DocumentResource extends BaseResource {
|
||||
documentCriteria.setCreateDateMin(date.toDate());
|
||||
documentCriteria.setCreateDateMax(date.plusDays(1).minusSeconds(1).toDate());
|
||||
}
|
||||
} else if (params[1].length() == 7) {
|
||||
break;
|
||||
}
|
||||
case 7: {
|
||||
DateTime date = monthFormatter.parseDateTime(params[1]);
|
||||
if (isUpdated) {
|
||||
documentCriteria.setUpdateDateMin(date.toDate());
|
||||
@ -510,7 +509,9 @@ public class DocumentResource extends BaseResource {
|
||||
documentCriteria.setCreateDateMin(date.toDate());
|
||||
documentCriteria.setCreateDateMax(date.plusMonths(1).minusSeconds(1).toDate());
|
||||
}
|
||||
} else if (params[1].length() == 4) {
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
DateTime date = yearFormatter.parseDateTime(params[1]);
|
||||
if (isUpdated) {
|
||||
documentCriteria.setUpdateDateMin(date.toDate());
|
||||
@ -519,6 +520,8 @@ public class DocumentResource extends BaseResource {
|
||||
documentCriteria.setCreateDateMin(date.toDate());
|
||||
documentCriteria.setCreateDateMax(date.plusYears(1).minusSeconds(1).toDate());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Invalid date, returns no documents
|
||||
|
@ -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,9 +505,7 @@ 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 {
|
||||
@ -519,7 +516,6 @@ public class FileResource extends BaseResource {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
} catch (Exception e) {
|
||||
return Response.status(Status.SERVICE_UNAVAILABLE).build();
|
||||
@ -578,9 +574,7 @@ public class FileResource extends BaseResource {
|
||||
final List<File> fileList = fileDao.getByDocumentId(principal.getId(), documentId);
|
||||
|
||||
// Create the ZIP stream
|
||||
StreamingOutput stream = new StreamingOutput() {
|
||||
@Override
|
||||
public void write(OutputStream outputStream) throws IOException, WebApplicationException {
|
||||
StreamingOutput stream = outputStream -> {
|
||||
try (ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream)) {
|
||||
// Add each file to the ZIP stream
|
||||
int index = 0;
|
||||
@ -603,7 +597,6 @@ public class FileResource extends BaseResource {
|
||||
}
|
||||
}
|
||||
outputStream.close();
|
||||
}
|
||||
};
|
||||
|
||||
// Write to the output
|
||||
|
13
pom.xml
13
pom.xml
@ -11,8 +11,8 @@
|
||||
<name>Docs Parent</name>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.7</maven.compiler.source>
|
||||
<maven.compiler.target>1.7</maven.compiler.target>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
<!-- Dependencies version (external) -->
|
||||
@ -49,10 +49,9 @@
|
||||
<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>
|
||||
|
||||
<!-- Migrate to Java 8 before upgrading this -->
|
||||
<org.eclipse.jetty.jetty-server.version>9.2.13.v20150730</org.eclipse.jetty.jetty-server.version>
|
||||
<org.eclipse.jetty.jetty-webapp.version>9.2.13.v20150730</org.eclipse.jetty.jetty-webapp.version>
|
||||
<org.eclipse.jetty.jetty-servlet.version>9.2.13.v20150730</org.eclipse.jetty.jetty-servlet.version>
|
||||
<org.eclipse.jetty.jetty-server.version>9.3.11.v20160721</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-servlet.version>9.3.11.v20160721</org.eclipse.jetty.jetty-servlet.version>
|
||||
|
||||
<!-- Plugins 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-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.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>
|
||||
|
||||
<scm>
|
||||
|
Loading…
Reference in New Issue
Block a user