From f44b4bb0e0f8acbc7e4cae88d23ad873d6ea35ea Mon Sep 17 00:00:00 2001 From: Benjamin Gamard Date: Tue, 13 Mar 2018 23:32:05 +0100 Subject: [PATCH] #201: file processing indicator --- .../core/event/FileCreatedAsyncEvent.java | 5 +-- .../async/FileCreatedAsyncListener.java | 2 + .../com/sismics/docs/core/util/FileUtil.java | 37 +++++++++++++++++++ .../docs/rest/resource/FileResource.java | 3 ++ docs-web/src/main/webapp/src/locale/en.json | 3 +- .../partial/docs/document.view.content.html | 5 +++ docs-web/src/main/webapp/src/style/main.less | 9 +++++ 7 files changed, 60 insertions(+), 4 deletions(-) diff --git a/docs-core/src/main/java/com/sismics/docs/core/event/FileCreatedAsyncEvent.java b/docs-core/src/main/java/com/sismics/docs/core/event/FileCreatedAsyncEvent.java index 17b4c460..5dca827e 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/event/FileCreatedAsyncEvent.java +++ b/docs-core/src/main/java/com/sismics/docs/core/event/FileCreatedAsyncEvent.java @@ -1,11 +1,10 @@ package com.sismics.docs.core.event; -import java.io.InputStream; -import java.nio.file.Path; - import com.google.common.base.MoreObjects; import com.sismics.docs.core.model.jpa.File; +import java.nio.file.Path; + /** * New file created event. * diff --git a/docs-core/src/main/java/com/sismics/docs/core/listener/async/FileCreatedAsyncListener.java b/docs-core/src/main/java/com/sismics/docs/core/listener/async/FileCreatedAsyncListener.java index eb5bf27e..59250bf4 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/listener/async/FileCreatedAsyncListener.java +++ b/docs-core/src/main/java/com/sismics/docs/core/listener/async/FileCreatedAsyncListener.java @@ -59,5 +59,7 @@ public class FileCreatedAsyncListener { // Update Lucene index LuceneDao luceneDao = new LuceneDao(); luceneDao.createFile(fileCreatedAsyncEvent.getFile()); + + FileUtil.endProcessingFile(file.getId()); } } diff --git a/docs-core/src/main/java/com/sismics/docs/core/util/FileUtil.java b/docs-core/src/main/java/com/sismics/docs/core/util/FileUtil.java index d821f3c5..9002ecbc 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/util/FileUtil.java +++ b/docs-core/src/main/java/com/sismics/docs/core/util/FileUtil.java @@ -29,6 +29,9 @@ import java.io.InputStream; import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; /** * File entity utilities. @@ -40,6 +43,11 @@ public class FileUtil { * Logger. */ private static final Logger log = LoggerFactory.getLogger(FileUtil.class); + + /** + * File ID of files currently being processed. + */ + private static Set processingFileSet = Collections.synchronizedSet(new HashSet()); /** * Extract content from a file. @@ -269,6 +277,7 @@ public class FileUtil { // Raise a new file created event and document updated event if we have a document if (documentId != null) { + startProcessingFile(fileId); FileCreatedAsyncEvent fileCreatedAsyncEvent = new FileCreatedAsyncEvent(); fileCreatedAsyncEvent.setUserId(userId); fileCreatedAsyncEvent.setLanguage(language); @@ -285,4 +294,32 @@ public class FileUtil { return fileId; } + + /** + * Start processing a file. + * + * @param fileId File ID + */ + public static void startProcessingFile(String fileId) { + processingFileSet.add(fileId); + } + + /** + * End processing a file. + * + * @param fileId File ID + */ + public static void endProcessingFile(String fileId) { + processingFileSet.remove(fileId); + } + + /** + * Return true if a file is currently processing. + * + * @param fileId File ID + * @return True if the file is processing + */ + public static boolean isProcessingFile(String fileId) { + return processingFileSet.contains(fileId); + } } diff --git a/docs-web/src/main/java/com/sismics/docs/rest/resource/FileResource.java b/docs-web/src/main/java/com/sismics/docs/rest/resource/FileResource.java index 84637018..21e04536 100644 --- a/docs-web/src/main/java/com/sismics/docs/rest/resource/FileResource.java +++ b/docs-web/src/main/java/com/sismics/docs/rest/resource/FileResource.java @@ -196,6 +196,7 @@ public class FileResource extends BaseResource { try { java.nio.file.Path storedFile = DirectoryUtil.getStorageDirectory().resolve(id); java.nio.file.Path unencryptedFile = EncryptionUtil.decryptFile(storedFile, user.getPrivateKey()); + FileUtil.startProcessingFile(id); FileCreatedAsyncEvent fileCreatedAsyncEvent = new FileCreatedAsyncEvent(); fileCreatedAsyncEvent.setUserId(principal.getId()); fileCreatedAsyncEvent.setLanguage(documentDto.getLanguage()); @@ -283,6 +284,7 @@ public class FileResource extends BaseResource { * @apiSuccess {String} files.id ID * @apiSuccess {String} files.mimetype MIME type * @apiSuccess {String} files.name File name + * @apiSuccess {String} files.processing True if the file is currently processing * @apiSuccess {String} files.document_id Document ID * @apiSuccess {String} files.create_date Create date (timestamp) * @apiSuccess {String} files.size File size (in bytes) @@ -321,6 +323,7 @@ public class FileResource extends BaseResource { try { files.add(Json.createObjectBuilder() .add("id", fileDb.getId()) + .add("processing", FileUtil.isProcessingFile(fileDb.getId())) .add("name", JsonUtil.nullable(fileDb.getName())) .add("mimetype", fileDb.getMimeType()) .add("document_id", JsonUtil.nullable(fileDb.getDocumentId())) diff --git a/docs-web/src/main/webapp/src/locale/en.json b/docs-web/src/main/webapp/src/locale/en.json index 538a036f..4b037c41 100644 --- a/docs-web/src/main/webapp/src/locale/en.json +++ b/docs-web/src/main/webapp/src/locale/en.json @@ -114,7 +114,8 @@ "upload_error": "Upload error", "upload_error_quota": "Quota reached", "drop_zone": "Drag & drop files here to upload", - "add_files": "Add files" + "add_files": "Add files", + "file_processing_indicator": "This file is being processed. Searching will not be available before it is complete." }, "workflow": { "workflow": "Workflow", diff --git a/docs-web/src/main/webapp/src/partial/docs/document.view.content.html b/docs-web/src/main/webapp/src/partial/docs/document.view.content.html index deb62018..de675d74 100644 --- a/docs-web/src/main/webapp/src/partial/docs/document.view.content.html +++ b/docs-web/src/main/webapp/src/partial/docs/document.view.content.html @@ -45,6 +45,11 @@
+
+ +
+ diff --git a/docs-web/src/main/webapp/src/style/main.less b/docs-web/src/main/webapp/src/style/main.less index b8208372..1b35671d 100644 --- a/docs-web/src/main/webapp/src/style/main.less +++ b/docs-web/src/main/webapp/src/style/main.less @@ -214,6 +214,15 @@ } } +// File processing indicator +.file-processing-indicator { + position: absolute; + z-index: 2; + margin-left: 8px; + margin-top: 8px; + color: #2ab2dc; +} + // File name .file-name { word-wrap: break-word;