mirror of
https://github.com/sismics/docs.git
synced 2025-12-15 02:36:24 +00:00
@@ -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() {
|
||||
// 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
|
||||
|
||||
@@ -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<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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
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) {
|
||||
|
||||
@@ -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<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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user