mirror of
https://github.com/sismics/docs.git
synced 2024-12-22 11:23:48 +01:00
#189: fire async event after transactionutil.handle
This commit is contained in:
parent
e540260377
commit
4f6de892b5
@ -23,7 +23,7 @@ public class TemporaryFileCleanupAsyncListener {
|
||||
* Cleanup temporary files.
|
||||
*
|
||||
* @param event Temporary file cleanup event
|
||||
* @throws Exception
|
||||
* @throws Exception e
|
||||
*/
|
||||
@Subscribe
|
||||
public void on(final TemporaryFileCleanupAsyncEvent event) throws Exception {
|
||||
|
@ -65,8 +65,6 @@ public class TransactionUtil {
|
||||
return;
|
||||
}
|
||||
|
||||
ThreadLocalContext.cleanup();
|
||||
|
||||
// No error in the current request : commit the transaction
|
||||
if (em.isOpen()) {
|
||||
if (em.getTransaction() != null && em.getTransaction().isActive()) {
|
||||
@ -79,6 +77,12 @@ public class TransactionUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fire all pending async events after request transaction commit.
|
||||
// This way, all modifications done during this request are available in the listeners.
|
||||
context.fireAllAsyncEvents();
|
||||
|
||||
ThreadLocalContext.cleanup();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -8,6 +8,7 @@ import javax.persistence.EntityManager;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -112,14 +113,19 @@ public class ThreadLocalContext {
|
||||
* Fire all pending async events.
|
||||
*/
|
||||
public void fireAllAsyncEvents() {
|
||||
for (Object asyncEvent : asyncEventList) {
|
||||
Iterator<Object> iterator = asyncEventList.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Object asyncEvent = iterator.next();
|
||||
iterator.remove();
|
||||
AppContext.getInstance().getAsyncEventBus().post(asyncEvent);
|
||||
}
|
||||
|
||||
if (!temporaryFileList.isEmpty()) {
|
||||
// Some files were created during this request, add a cleanup event to the queue
|
||||
// It works because we are using a one thread executor
|
||||
AppContext.getInstance().getAsyncEventBus().post(new TemporaryFileCleanupAsyncEvent(temporaryFileList));
|
||||
AppContext.getInstance().getAsyncEventBus().post(
|
||||
new TemporaryFileCleanupAsyncEvent(Lists.newArrayList(temporaryFileList)));
|
||||
temporaryFileList.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -188,14 +188,14 @@
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<a class="text-center"><span class="glyphicon glyphicon-plus"></span> Add this search query on the home</a>
|
||||
<!--<a class="text-center"><span class="glyphicon glyphicon-plus"></span> Add this search query on the home</a>-->
|
||||
|
||||
<div class="pull-left" title="{{ 'document.upgrade_quota' | translate }}"
|
||||
<div class="pull-left small text-muted" title="{{ 'document.upgrade_quota' | translate }}"
|
||||
translate="document.quota"
|
||||
translate-values="{ current: userInfo.storage_current / 1000000, percent: userInfo.storage_current / userInfo.storage_quota * 100, total: userInfo.storage_quota / 1000000 }">
|
||||
</div>
|
||||
|
||||
<div class="text-right" >
|
||||
<div class="text-right small text-muted">
|
||||
<span ng-if="totalDocuments" translate="document.count" translate-values="{ count: totalDocuments }"></span>
|
||||
<span ng-if="!totalDocuments"> </span>
|
||||
</div>
|
||||
|
@ -297,7 +297,7 @@ public class TestAppResource extends BaseJerseyTest {
|
||||
|
||||
// Search for added documents
|
||||
json = target().path("/document/list")
|
||||
.queryParam("search", "tag:Inbox")
|
||||
.queryParam("search", "tag:Inbox full:content")
|
||||
.request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||
.get(JsonObject.class);
|
||||
@ -317,7 +317,7 @@ public class TestAppResource extends BaseJerseyTest {
|
||||
|
||||
// Search for added documents
|
||||
json = target().path("/document/list")
|
||||
.queryParam("search", "tag:Inbox")
|
||||
.queryParam("search", "tag:Inbox full:content")
|
||||
.request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||
.get(JsonObject.class);
|
||||
|
Loading…
Reference in New Issue
Block a user