Skip to content

Commit

Permalink
Java 8, Tesseract 4, Ubuntu (sismics#214)
Browse files Browse the repository at this point in the history
Java 8, Tesseract 4, Ubuntu 18.04
  • Loading branch information
jendib authored Mar 18, 2018
1 parent 7ea8d0c commit 5220b13
Show file tree
Hide file tree
Showing 14 changed files with 178 additions and 248 deletions.
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,13 @@ public void on(final DocumentCreatedAsyncEvent event) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,29 @@ public void on(final DocumentUpdatedAsyncEvent event) {
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<Contributor> 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<Contributor> 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);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,9 @@ public void on(final FileCreatedAsyncEvent event) {

// Get the user from the database
final AtomicReference<User> 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
Expand Down Expand Up @@ -108,18 +105,15 @@ public void run() {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,16 @@ public void onPasswordLost(final PasswordLostEvent passwordLostEvent) {
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<String, Object> 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<String, Object> 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);
});
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,6 +8,10 @@
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.
Expand All @@ -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<Document> documentList = documentDao.findAll();

// Fetch all files
FileDao fileDao = new FileDao();
List<File> fileList = fileDao.findAll();

// Rebuild index
LuceneDao luceneDao = new LuceneDao();
luceneDao.rebuildIndex(documentList, fileList);
}
TransactionUtil.handle(() -> {
// Fetch all documents
DocumentDao documentDao = new DocumentDao();
List<Document> documentList = documentDao.findAll();

// Fetch all files
FileDao fileDao = new FileDao();
List<File> fileList = fileDao.findAll();

// Rebuild index
LuceneDao luceneDao = new LuceneDao();
luceneDao.rebuildIndex(documentList, fileList);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,16 @@ public void onRouteStepValidate(final RouteStepValidateEvent routeStepValidateEv
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<String, Object> 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<String, Object> 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);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,41 +67,38 @@ protected void runOneIteration() {
* 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
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,8 @@ protected void shutDown() {

@Override
protected void runOneIteration() {
TransactionUtil.handle(new Runnable() {
@Override
public void run() {
// NOP
}
TransactionUtil.handle(() -> {
// NOP
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,7 @@ public void init(FilterConfig filterConfig) {
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
Expand Down
Loading

0 comments on commit 5220b13

Please sign in to comment.