This is an automated email from the git hooks/post-receive script. New change to branch feature/9206-upload-validation-zip-documents in repository coselmar. See https://gitlab.nuiton.org/codelutin/coselmar.git from fdce731 refs-50 #9206 First draft for error management in Documents Zip import new 1f29db5 refs #9206 technical error management during zip import new 64faa45 refs-65 #9206 Start UI for documents zip file The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 64faa458eb0ff6864a34d108a4d0646acf69ce69 Author: Yannick Martel <martel@©odelutin.com> Date: Tue Jun 6 20:48:24 2017 +0200 refs-65 #9206 Start UI for documents zip file commit 1f29db59dd67a0ccd9b9f1aec9f015b4dd850a8a Author: Yannick Martel <martel@©odelutin.com> Date: Tue Jun 6 14:34:53 2017 +0200 refs #9206 technical error management during zip import Summary of changes: .../beans/MassiveDocumentsImportResult.java | 24 +++++---- .../coselmar/services/v1/DocumentsWebService.java | 17 ++++--- coselmar-rest/src/main/resources/mapping | 1 + .../src/test/resources/documents_errors.zip | Bin 87789 -> 87789 bytes coselmar-ui/src/main/webapp/i18n/en.js | 10 ++++ coselmar-ui/src/main/webapp/i18n/fr.js | 10 ++++ .../src/main/webapp/js/coselmar-admin-services.js | 18 +++++++ .../src/main/webapp/js/coselmar-controllers.js | 20 +++++++- .../src/main/webapp/views/admin/admintools.html | 54 +++++++++++++++++++++ 9 files changed, 135 insertions(+), 19 deletions(-) -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/9206-upload-validation-zip-documents in repository coselmar. See https://gitlab.nuiton.org/codelutin/coselmar.git commit 1f29db59dd67a0ccd9b9f1aec9f015b4dd850a8a Author: Yannick Martel <martel@©odelutin.com> Date: Tue Jun 6 14:34:53 2017 +0200 refs #9206 technical error management during zip import --- .../beans/MassiveDocumentsImportResult.java | 14 +++++++++++--- .../coselmar/services/v1/DocumentsWebService.java | 15 ++++++++------- .../src/test/resources/documents_errors.zip | Bin 87789 -> 87789 bytes 3 files changed, 19 insertions(+), 10 deletions(-) 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 fff4400..20495f4 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 @@ -1,6 +1,5 @@ package fr.ifremer.coselmar.beans; -import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -11,6 +10,7 @@ public class MassiveDocumentsImportResult { protected List<String> missingFiles; protected boolean errorSystem; + protected ImportSystemErrorType systemErrorType; protected boolean invalidFile; public MassiveDocumentsImportResult() { @@ -33,8 +33,9 @@ public class MassiveDocumentsImportResult { return errorSystem; } - public void setErrorSystem(boolean errorSystem) { - this.errorSystem = errorSystem; + public void setSystemErrorType(ImportSystemErrorType importSystemErrorType) { + this.systemErrorType = importSystemErrorType; + this.errorSystem = true; } public boolean isInvalidFile() { @@ -44,4 +45,11 @@ public class MassiveDocumentsImportResult { public void setInvalidFile(boolean invalidFile) { this.invalidFile = invalidFile; } + + public enum ImportSystemErrorType { + UNABLE_TO_READ_ZIP, + UNABLE_TO_READ_CSV, + UNABLE_TO_READ_ZIP_ENTRY, + ; + } } 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 6455deb..d54a7a0 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 @@ -975,7 +975,8 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { if (log.isErrorEnabled()) { log.error("error during ZipFile transfer", e); } - throw new CoselmarTechnicalException("Internal error during ZipFile transfer", e); + importResult.setSystemErrorType(MassiveDocumentsImportResult.ImportSystemErrorType.UNABLE_TO_READ_ZIP); + return importResult; } // Get descriptions.csv : it should contains all DocumentBean information @@ -1054,7 +1055,7 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { if (log.isErrorEnabled()) { log.error(message, e); } - importResult.setErrorSystem(true); + importResult.setSystemErrorType(MassiveDocumentsImportResult.ImportSystemErrorType.UNABLE_TO_READ_ZIP_ENTRY); importResult.addMissingFile(fileName); } } @@ -1064,8 +1065,8 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { if (log.isErrorEnabled()) { log.error("Error with CSV file", ire); } - importResult.setErrorSystem(true); - throw new CoselmarTechnicalException("Error with CSV file", ire); + importResult.setSystemErrorType(MassiveDocumentsImportResult.ImportSystemErrorType.UNABLE_TO_READ_CSV); + return importResult; } finally { // Close importer importer.close(); @@ -1086,11 +1087,11 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { commit(); } catch (IOException e) { // Big problem if we can't move files into real folder ! + String message = String.format("Unable to move files from temp folder '%s' to final folder", zipTempPath); if (log.isErrorEnabled()) { - log.error("Unable to move files from temp folder '%s' to final folder", e); + log.error(message, e); } - importResult.setErrorSystem(true); - rollback(); + throw new CoselmarTechnicalException(message, e); } } else { diff --git a/coselmar-rest/src/test/resources/documents_errors.zip b/coselmar-rest/src/test/resources/documents_errors.zip index 836cde6..a6e53df 100644 Binary files a/coselmar-rest/src/test/resources/documents_errors.zip and b/coselmar-rest/src/test/resources/documents_errors.zip differ -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/9206-upload-validation-zip-documents in repository coselmar. See https://gitlab.nuiton.org/codelutin/coselmar.git commit 64faa458eb0ff6864a34d108a4d0646acf69ce69 Author: Yannick Martel <martel@©odelutin.com> Date: Tue Jun 6 20:48:24 2017 +0200 refs-65 #9206 Start UI for documents zip file --- .../beans/MassiveDocumentsImportResult.java | 14 ++---- .../coselmar/services/v1/DocumentsWebService.java | 2 +- coselmar-rest/src/main/resources/mapping | 1 + coselmar-ui/src/main/webapp/i18n/en.js | 10 ++++ coselmar-ui/src/main/webapp/i18n/fr.js | 10 ++++ .../src/main/webapp/js/coselmar-admin-services.js | 18 ++++++++ .../src/main/webapp/js/coselmar-controllers.js | 20 +++++++- .../src/main/webapp/views/admin/admintools.html | 54 ++++++++++++++++++++++ 8 files changed, 118 insertions(+), 11 deletions(-) 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 20495f4..3f8f4ab 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,15 +8,19 @@ import java.util.List; */ public class MassiveDocumentsImportResult { + protected boolean success; protected List<String> missingFiles; protected boolean errorSystem; protected ImportSystemErrorType systemErrorType; - protected boolean invalidFile; public MassiveDocumentsImportResult() { this.missingFiles = new ArrayList<>(); } + public boolean isSuccess() { + return missingFiles.isEmpty() && !errorSystem; + } + public List<String> getMissingFiles() { return missingFiles; } @@ -38,14 +42,6 @@ public class MassiveDocumentsImportResult { this.errorSystem = true; } - public boolean isInvalidFile() { - return invalidFile; - } - - public void setInvalidFile(boolean invalidFile) { - this.invalidFile = invalidFile; - } - public enum ImportSystemErrorType { UNABLE_TO_READ_ZIP, UNABLE_TO_READ_CSV, 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 d54a7a0..d3b676a 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 @@ -989,8 +989,8 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { if (log.isErrorEnabled()) { log.error(message, e); } - importResult.setInvalidFile(true); importResult.addMissingFile(DESCRIPTION_CSV_FILE_NAME); + importResult.setSystemErrorType(MassiveDocumentsImportResult.ImportSystemErrorType.UNABLE_TO_READ_CSV); return importResult; // Direct break : cannot continue without this file } diff --git a/coselmar-rest/src/main/resources/mapping b/coselmar-rest/src/main/resources/mapping index b498a97..154cae2 100644 --- a/coselmar-rest/src/main/resources/mapping +++ b/coselmar-rest/src/main/resources/mapping @@ -78,6 +78,7 @@ GET /v1/general/topwords GeneralWebService.getTopWords # Admin API POST /v1/admin/lucene/index AdminWebService.refreshLuceneIndex +POST /v1/admin/documents/zip DocumentsWebService.uploadZipDocuments # Export diff --git a/coselmar-ui/src/main/webapp/i18n/en.js b/coselmar-ui/src/main/webapp/i18n/en.js index 54eee19..e6b38f5 100644 --- a/coselmar-ui/src/main/webapp/i18n/en.js +++ b/coselmar-ui/src/main/webapp/i18n/en.js @@ -318,6 +318,16 @@ var translateEN = { "admin.tools.message.refresh.inprogress" : "Refresh in progress.", "admin.tools.message.refresh.done" : "Search index has been well refreshed !", "admin.tools.message.refresh.errors" : "Error during search index refresh. Please try again. If problem persist, see server administrator.", +"admin.tools.label.documentsImport" : "Import Documents Zip file", +"admin.tools.button.documentsimport" : "Import !", +"admin.tools.message.massimport.inprogress" : "Import in progress.", +"admin.tools.message.massimport.done" : "Documents have been well imported !", +"admin.tools.message.massimport.errors" : "Error during documents import. Please try again. If problem persist, see server administrator.", +"admin.tools.message.massimport.fail" : "Some error occur during import.", +"admin.tools.message.massimport.zipReadFail" : "Unable to open zipfile, maybe it is corrupt ?", +"admin.tools.message.massimport.csvReadFail" : "Unable to read 'description.csv' file, please verify file format.", +"admin.tools.message.massimport.fileReadFail" : "Unable to read some files from zip.", +"admin.tools.message.massimport.missingFiles" : "Files not found from zip : ", //Common part diff --git a/coselmar-ui/src/main/webapp/i18n/fr.js b/coselmar-ui/src/main/webapp/i18n/fr.js index b4b398b..14f0d06 100644 --- a/coselmar-ui/src/main/webapp/i18n/fr.js +++ b/coselmar-ui/src/main/webapp/i18n/fr.js @@ -318,6 +318,16 @@ var translateFR = { "admin.tools.message.refresh.inprogress" : "Mise à jour en cours.", "admin.tools.message.refresh.done" : "L'index de recherche à bien été raffraichi !", "admin.tools.message.refresh.errors" : "Une erreur est survenue durant la mise à jour de l'index de recherche. Veuillez contacter l'administrateur serveur.", +"admin.tools.label.documentsImport" : "Importer un Zip de Documents", +"admin.tools.button.documentsimport" : "Importer !", +"admin.tools.message.massimport.inprogress" : "Import en cours.", +"admin.tools.message.massimport.done" : "Les documents ont bien été importés !", +"admin.tools.message.massimport.errors" : "Des erreurs sont survenues durant l'import. Veuillez contacter l'administrateur serveur.", +"admin.tools.message.massimport.fail" : "Des erreurs sont survenues durant le traitement des fichiers.", +"admin.tools.message.massimport.zipReadFail" : "Impossible de lire le fichier zip, peut-être est-il corrompu ?", +"admin.tools.message.massimport.csvReadFail" : "Erreur dans le traitement du fichier 'description.csv'. Veuillez vérifier le format des données.", +"admin.tools.message.massimport.fileReadFail" : "Erreur dans le traitement de fichiers contenus dans le zip.", +"admin.tools.message.massimport.missingFiles" : "Fichiers non retrouvés dans le zip : ", //Common part diff --git a/coselmar-ui/src/main/webapp/js/coselmar-admin-services.js b/coselmar-ui/src/main/webapp/js/coselmar-admin-services.js index 9a2da38..430fae4 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-admin-services.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-admin-services.js @@ -47,4 +47,22 @@ function Admin(resource, config){ adminResource.save(null, successFunction, failFunction); } + this.importDocumentsZip = function(file, successFunction, failFunction){ + + var formData = new FormData(); + formData.append("uploadFile", file); + + var serviceURL = baseURL + "/documents/zip"; + + // Launch import ! + var adminResource = resource(serviceURL, null, { + 'upload': { + method:'POST', + transformRequest: angular.identity, + headers: {'Content-Type': undefined, 'Content-Transfer-Encoding': 'utf-8'} + } + }); + adminResource.upload(null, formData, successFunction, failFunction); + } + }; \ No newline at end of file diff --git a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js index d0110e1..4db9a5b 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js @@ -2164,7 +2164,8 @@ coselmarControllers.controller("ReferentialCtrl", ['$scope', '$routeParams', '$l coselmarControllers.controller("AdminCtrl", ['$scope', '$routeParams', '$location', 'adminService', function($scope, $routeParams, $location, adminService){ - $scope.status = { 'indexRefresh' : 'none'}; + $scope.status = { 'indexRefresh' : 'none', 'massimport' : 'none', 'importResult' : undefined }; + $scope.importResult = undefined; $scope.refreshIndex = function() { $scope.status.indexRefresh = "inprogress"; @@ -2178,6 +2179,23 @@ coselmarControllers.controller("AdminCtrl", ['$scope', '$routeParams', '$locatio }; + $scope.importDocumentsZip = function() { + $scope.status.massimport = "inprogress"; + + adminService.importDocumentsZip($scope.uploadFile, function(importResult) { + if (importResult.isSuccess) { + $scope.status.massimport = "finish"; + } else { + $scope.status.massimport = "fail"; + $scope.status.importResult = importResult; + } + + },function(error) { + $scope.status.massimport = "error"; + }); + + }; + }]); /** diff --git a/coselmar-ui/src/main/webapp/views/admin/admintools.html b/coselmar-ui/src/main/webapp/views/admin/admintools.html index b337f8f..bdb9f25 100644 --- a/coselmar-ui/src/main/webapp/views/admin/admintools.html +++ b/coselmar-ui/src/main/webapp/views/admin/admintools.html @@ -52,4 +52,58 @@ </div> <br/> </div> + + <div class="form-group"> + <div class="form-group"> + + <label class="col-md-5 control-label">{{ 'admin.tools.label.documentsImport' | translate }}</label> + + <div class="col-md-7 "> + + <input class="col-md-8" type="file" class="form-control" name="uploadFile" ng-file-model="uploadFile" accept=".zip"/> + + <a class="form-inline btn btn-primary col-md-4" + ng-click="importDocumentsZip()" + ng-disabled="!uploadFile">{{ 'admin.tools.button.documentsimport' | translate }}</a> + </div> + </div> + + <div ng-show="status.massImport != 'none'" > + <div ng-show="status.massimport === 'inprogress'"> + {{ 'admin.tools.message.massimport.inprogress' | translate }} + </div> + <div ng-show="status.massimport === 'finish'"> + {{ 'admin.tools.message.massimport.done' | translate }} + </div> + <div ng-show="status.massimport === 'error'"> + {{ 'admin.tools.message.massimport.error' | translate }} + </div> + + <div ng-show="status.massimport === 'fail'"> + {{ 'admin.tools.message.massimport.fail' | translate }} + <!-- Unable to read Zip --> + <div ng-show="status.importResult && status.importResult.errorSystem && status.importResult.systemErrorType == 'UNABLE_TO_READ_ZIP'"> + {{ 'admin.tools.message.massimport.zipReadFail' | translate }} + </div> + <!-- Unable to read CSV data --> + <div ng-show="status.importResult && status.importResult.errorSystem && status.importResult.systemErrorType == 'UNABLE_TO_READ_CSV'"> + {{ 'admin.tools.message.massimport.csvReadFail' | translate }} + </div> + <!-- Unable to read a file entry in Zip --> + <div ng-show="status.importResult && status.importResult.errorSystem && status.importResult.systemErrorType == 'UNABLE_TO_READ_ZIP_ENTRY'"> + {{ 'admin.tools.message.massimport.fileReadFail' | translate }} + </div> + <!-- Missing files in Zip --> + <div ng-show="status.importResult && status.importResult.missingFiles && status.importResult.missingFiles.length > 0"> + {{ 'admin.tools.message.massimport.missingFiles' | translate }} + <ul> + <li ng-repeat="missingFile in status.importResult.missingFiles">{{missingFile}}</li> + </ul> + </div> + </div> + + + </div> + <br/> + </div> </div> \ No newline at end of file -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm