This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository coselmar. See https://gitlab.nuiton.org/codelutin/coselmar.git commit e5eac8c42e8ab38e9243db42b8c9cab8e60979a0 Author: Yannick Martel <martel@©odelutin.com> Date: Thu Jun 8 16:51:43 2017 +0200 refs #9206 So Tika-parsers is not an option, fix shame mistake on FileInfos attribtues, be able to manage temporary dir for file with FileInfos --- coselmar-rest/pom.xml | 4 +++ .../java/fr/ifremer/coselmar/beans/FileInfos.java | 31 ++++++++++++++-------- .../beans/MassiveDocumentsImportResult.java | 7 +++-- .../coselmar/services/v1/DocumentsWebService.java | 25 +++++++++-------- .../src/main/webapp/js/coselmar-controllers.js | 2 +- pom.xml | 7 +++++ 6 files changed, 51 insertions(+), 25 deletions(-) diff --git a/coselmar-rest/pom.xml b/coselmar-rest/pom.xml index f939eb8..245f80d 100644 --- a/coselmar-rest/pom.xml +++ b/coselmar-rest/pom.xml @@ -170,6 +170,10 @@ <groupId>org.apache.tika</groupId> <artifactId>tika-core</artifactId> </dependency> + <dependency> + <groupId>org.apache.tika</groupId> + <artifactId>tika-parsers</artifactId> + </dependency> <!-- Others --> <dependency> diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/FileInfos.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/FileInfos.java index 5bebc04..025cfa3 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/FileInfos.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/FileInfos.java @@ -5,31 +5,40 @@ package fr.ifremer.coselmar.beans; */ public class FileInfos { - protected String FileName; - protected String FilePath; - protected String MimeType; + protected String fileName; + protected String finalFilePath; + protected String actualFilePath; + protected String mimeType; public String getFileName() { - return FileName; + return fileName; } public void setFileName(String fileName) { - FileName = fileName; + this.fileName = fileName; } - public String getFilePath() { - return FilePath; + public String getFinalFilePath() { + return finalFilePath; } - public void setFilePath(String filePath) { - FilePath = filePath; + public void setFinalFilePath(String finalFilePath) { + this.finalFilePath = finalFilePath; + } + + public String getActualFilePath() { + return actualFilePath; + } + + public void setActualFilePath(String actualFilePath) { + this.actualFilePath = actualFilePath; } public String getMimeType() { - return MimeType; + return mimeType; } public void setMimeType(String mimeType) { - MimeType = mimeType; + this.mimeType = mimeType; } } diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/MassiveDocumentsImportResult.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/MassiveDocumentsImportResult.java index 6bb29ad..97b3b88 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/MassiveDocumentsImportResult.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/MassiveDocumentsImportResult.java @@ -8,7 +8,7 @@ import java.util.List; */ public class MassiveDocumentsImportResult { - protected boolean success; + protected boolean success = true; protected List<String> missingFiles; protected boolean errorSystem; protected ImportSystemErrorType systemErrorType; @@ -18,7 +18,7 @@ public class MassiveDocumentsImportResult { } public boolean isSuccess() { - return missingFiles != null && missingFiles.isEmpty() && !errorSystem; + return this.success; } public List<String> getMissingFiles() { @@ -26,11 +26,13 @@ public class MassiveDocumentsImportResult { } public void setMissingFiles(List<String> missingFiles) { + this.success = false; this.missingFiles = missingFiles; } public void addMissingFile(String missingFileName) { this.missingFiles.add(missingFileName); + this.success = false; } public boolean isErrorSystem() { @@ -40,6 +42,7 @@ public class MassiveDocumentsImportResult { public void setSystemErrorType(ImportSystemErrorType importSystemErrorType) { this.systemErrorType = importSystemErrorType; this.errorSystem = true; + this.success = false; } public enum ImportSystemErrorType { diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java index 951f67d..153af10 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java @@ -53,16 +53,13 @@ import fr.ifremer.coselmar.services.errors.NoResultException; import fr.ifremer.coselmar.services.errors.UnauthorizedException; import fr.ifremer.coselmar.services.indexation.DocumentsIndexationService; import fr.ifremer.coselmar.services.indexation.TikaUtils; -import fr.ifremer.coselmar.services.indexation.TransverseIndexationService; import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.lucene.queryparser.classic.ParseException; import org.debux.webmotion.server.call.UploadFile; import org.debux.webmotion.server.render.Render; import org.nuiton.csv.Import; -import org.nuiton.csv.ImportModel; import org.nuiton.csv.ImportRuntimeException; import org.nuiton.topia.persistence.TopiaNoResultException; import org.nuiton.util.DateUtil; @@ -71,7 +68,6 @@ import org.nuiton.util.pagination.PaginationResult; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; @@ -428,7 +424,7 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { // Get owner to place correctly the file CoselmarUser owner = documentEntity.getOwner(); FileInfos fileInfos = manageDocumentFile(uploadFile, owner); - String filePath = fileInfos.getFilePath(); + String filePath = fileInfos.getFinalFilePath(); String contentType = fileInfos.getMimeType(); // Read file content String fileContent = TikaUtils.getFileContent(filePath); @@ -726,9 +722,13 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { String fileContent = ""; if (fileInfos != null) { - String filePath = fileInfos.getFilePath(); + String filePath = fileInfos.getFinalFilePath(); String contentType = fileInfos.getMimeType(); - fileContent = TikaUtils.getFileContent(filePath); + if (StringUtils.isNotBlank(fileInfos.getActualFilePath())) { + fileContent = TikaUtils.getFileContent(fileInfos.getActualFilePath()); + } else { + fileContent = TikaUtils.getFileContent(filePath); + } documentEntity.setWithFile(true); documentEntity.setMimeType(contentType); @@ -851,7 +851,7 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { FileInfos fileInfos = new FileInfos(); fileInfos.setFileName(fileName); fileInfos.setMimeType(contentType); - fileInfos.setFilePath(destFile.getAbsolutePath()); + fileInfos.setFinalFilePath(destFile.getAbsolutePath()); return fileInfos; } @@ -1016,7 +1016,7 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { try { for (DocumentBean documentBean : importer) { FileInfos fileInfos = new FileInfos(); - String fileName = documentBean.getFileName(); + String fileName = StringUtils.strip(documentBean.getFileName()); // cf https://forge.codelutin.com/issues/9205?issue_count=18&issue_position=4&next_issue_id=9198&prev_issue_id=9206#note-2 documentBean.setPrivacy(Privacy.PUBLIC.name()); @@ -1040,7 +1040,8 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { // Create fileInfos fileInfos.setFileName(fileName); - fileInfos.setFilePath(futureFilePath); + fileInfos.setFinalFilePath(futureFilePath); + fileInfos.setActualFilePath(zipEntryFile.getAbsolutePath()); fileInfos.setMimeType(fileMimeType); // Create document @@ -1086,7 +1087,9 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { // All is ok ! try { // Ok, let move all files from temp storage to real one ! - FileUtils.moveDirectory(new File(zipTempPath), new File(getUserDocumentPath(currentUser))); + File tmpDir = new File(zipTempPath); + FileUtils.copyDirectory(tmpDir, new File(getUserDocumentPath(currentUser))); + FileUtils.deleteDirectory(tmpDir); commit(); } catch (IOException e) { // Big problem if we can't move files into real folder ! diff --git a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js index 4db9a5b..3f6536c 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js @@ -2183,7 +2183,7 @@ coselmarControllers.controller("AdminCtrl", ['$scope', '$routeParams', '$locatio $scope.status.massimport = "inprogress"; adminService.importDocumentsZip($scope.uploadFile, function(importResult) { - if (importResult.isSuccess) { + if (importResult.success) { $scope.status.massimport = "finish"; } else { $scope.status.massimport = "fail"; diff --git a/pom.xml b/pom.xml index 154caeb..5ca2379 100644 --- a/pom.xml +++ b/pom.xml @@ -333,6 +333,13 @@ <groupId>org.apache.tika</groupId> <artifactId>tika-core</artifactId> <version>${tikaVersion}</version> + </dependency> + + <dependency> + <groupId>org.apache.tika</groupId> + <artifactId>tika-parsers</artifactId> + <version>${tikaVersion}</version> + <scope>runtime</scope> <exclusions> <exclusion> <groupId>org.bouncycastle</groupId> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.