This is an automated email from the git hooks/post-receive script. New commit to branch feature/importFavoriteList in repository pollen. See http://git.chorem.org/pollen.git commit c721979157188c67b68464b1fe87e4637749528a Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Thu Aug 21 12:04:32 2014 +0200 add error when import favorite list from csv file --- .../org/chorem/pollen/rest/api/JsonHelper.java | 20 +++++++++++++++++++ .../org/chorem/pollen/rest/api/PollenRender.java | 3 ++- .../org/chorem/pollen/rest/api/v1/ErrorAction.java | 10 ++++++++++ .../i18n/pollen-services_en_GB.properties | 6 +++--- .../i18n/pollen-services_fr_FR.properties | 6 +++--- pollen-ui-angular/src/main/webapp/i18n/en.js | 2 ++ pollen-ui-angular/src/main/webapp/i18n/fr.js | 2 ++ pollen-ui-angular/src/main/webapp/js/directives.js | 23 ++++++++++++++++------ 8 files changed, 59 insertions(+), 13 deletions(-) diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/JsonHelper.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/JsonHelper.java index e30c5a4..dabbe1f 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/JsonHelper.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/JsonHelper.java @@ -37,6 +37,7 @@ import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; import org.chorem.pollen.services.bean.PollenEntityId; import org.chorem.pollen.services.bean.PollenEntityRef; +import org.chorem.pollen.services.service.FavoriteListImportException; import org.chorem.pollen.services.service.InvalidFormException; import org.nuiton.topia.persistence.TopiaIdFactory; @@ -170,6 +171,25 @@ public class JsonHelper { }); + gsonBuilder.registerTypeAdapter(FavoriteListImportException.class, new JsonSerializer<FavoriteListImportException>() { + + @Override + public JsonElement serialize(FavoriteListImportException src, Type typeOfSrc, JsonSerializationContext context) { + + + String error = src.getCauseMessage(); + + Map<String, Object> map = new HashMap<>(); + map.put("error", error); + + JsonElement result = context.serialize(map); + + return result; + + } + + }); + gsonBuilder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() { @Override diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java index 979f22b..d2ab840 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java @@ -23,6 +23,7 @@ package org.chorem.pollen.rest.api; * #L% */ +import org.chorem.pollen.services.service.FavoriteListImportException; import org.chorem.pollen.services.service.InvalidFormException; import org.debux.webmotion.server.call.Call; import org.debux.webmotion.server.call.HttpContext; @@ -59,7 +60,7 @@ public class PollenRender<T> extends Render { PollenRestApiApplicationContext applicationContext = PollenRestApiApplicationContext.getApplicationContext(context.getServletContext()); - if (model instanceof InvalidFormException) { + if (model instanceof InvalidFormException || model instanceof FavoriteListImportException) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ErrorAction.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ErrorAction.java index 281dd24..a5d6875 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ErrorAction.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ErrorAction.java @@ -24,6 +24,7 @@ package org.chorem.pollen.rest.api.v1; */ import org.chorem.pollen.rest.api.PollenRestApiUtil; +import org.chorem.pollen.services.service.FavoriteListImportException; import org.chorem.pollen.services.service.InvalidFormException; import org.debux.webmotion.server.WebMotionController; import org.debux.webmotion.server.call.HttpContext; @@ -48,6 +49,15 @@ public class ErrorAction extends WebMotionController { } + public FavoriteListImportException on400Form(HttpContext context, FavoriteListImportException e) { + + PollenRestApiUtil.prepareResponse(context); + + // just return the exception, + return e; + + } + public Render on404(HttpContext context, Exception e) { PollenRestApiUtil.prepareResponse(context); diff --git a/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties b/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties index b67777a..e1210d8 100644 --- a/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties +++ b/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties @@ -18,9 +18,9 @@ pollen.error.choice.choiceNameExist=choice name already used in this list pollen.error.choice.choiceTypeEmpty=choiceType can not be null pollen.error.comment.author.name.mandatory=author name can not be empty pollen.error.comment.text.mandatory=text can not be empty -pollen.error.favoriteList.import.csv.already.used.email= -pollen.error.favoriteList.import.csv.already.used.name= -pollen.error.favoriteList.import.csv.invalid.email= +pollen.error.favoriteList.import.csv.already.used.email=Line %s \: Email already used +pollen.error.favoriteList.import.csv.already.used.name=Line %s \: Name already used +pollen.error.favoriteList.import.csv.invalid.email=Line %s \: Invalid email pollen.error.favoriteList.import.ldap.already.used.email= pollen.error.favoriteList.import.ldap.already.used.name= pollen.error.favoriteList.import.ldap.invalid.email= diff --git a/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties b/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties index dc1adcb..a6353b6 100644 --- a/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties +++ b/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties @@ -18,9 +18,9 @@ pollen.error.choice.choiceNameExist=Le nom du choix est déjà utilisé sur ce s pollen.error.choice.choiceTypeEmpty=Le type du choix doit être défini pollen.error.comment.author.name.mandatory=Le nom est obligatoire pollen.error.comment.text.mandatory=le text est obligatoire -pollen.error.favoriteList.import.csv.already.used.email= -pollen.error.favoriteList.import.csv.already.used.name= -pollen.error.favoriteList.import.csv.invalid.email= +pollen.error.favoriteList.import.csv.already.used.email=Ligne %s \: Courriel déjà utilisé +pollen.error.favoriteList.import.csv.already.used.name=Ligne %s \: Nom déjà utilisé +pollen.error.favoriteList.import.csv.invalid.email=Ligne %s \: Courriel invalide pollen.error.favoriteList.import.ldap.already.used.email= pollen.error.favoriteList.import.ldap.already.used.name= pollen.error.favoriteList.import.ldap.invalid.email= diff --git a/pollen-ui-angular/src/main/webapp/i18n/en.js b/pollen-ui-angular/src/main/webapp/i18n/en.js index 5800ba0..3e37db5 100644 --- a/pollen-ui-angular/src/main/webapp/i18n/en.js +++ b/pollen-ui-angular/src/main/webapp/i18n/en.js @@ -165,6 +165,7 @@ var translateEN = { 'action.restricted.notify' : 'Notify', 'action.favoriteList.import.addGroup' : 'Import in new group', 'action.favoriteList.import.inGroup' : 'Import in this group', +'action.favoriteList.import.fromCSV' : 'Import this CSV file', 'action.favoriteList.add' : 'Add favorite list', 'action.favoriteList.delete' : 'Delete the favorite list', 'action.favoriteList.addMember' : 'Add a member', @@ -181,6 +182,7 @@ var translateEN = { 'error.forbidden' : 'Access forbidden', 'error.notFound' : 'Not found resource', 'error.noServer' : 'No connexion with the server', +'error.reader.noFile' : 'Error no file', 'info.load' : 'Loading' }; diff --git a/pollen-ui-angular/src/main/webapp/i18n/fr.js b/pollen-ui-angular/src/main/webapp/i18n/fr.js index 8a284d7..063843c 100644 --- a/pollen-ui-angular/src/main/webapp/i18n/fr.js +++ b/pollen-ui-angular/src/main/webapp/i18n/fr.js @@ -165,6 +165,7 @@ var translateFR = { 'action.restricted.notify' : 'Envoyer un mail', 'action.favoriteList.import.addGroup' : 'Importer dans un nouveau groupe', 'action.favoriteList.import.inGroup' : 'Importer dans ce groupe', +'action.favoriteList.import.fromCSV' : 'Importer ce fichier CSV', 'action.favoriteList.add' : 'Créer une nouvelle liste de diffusion', 'action.favoriteList.delete' : 'Supprimer la liste de diffusion', 'action.favoriteList.addMember' : 'Ajouter un membre', @@ -181,6 +182,7 @@ var translateFR = { 'error.forbidden' : 'Accès interdit', 'error.notFound' : 'Aucune ressource trouvée', 'error.noServer' : 'Erreur de connexion avec le serveur', +'error.reader.noFile' : 'Erreur aucun fichier', 'info.load' : 'Chargement en cours' }; diff --git a/pollen-ui-angular/src/main/webapp/js/directives.js b/pollen-ui-angular/src/main/webapp/js/directives.js index 2c14179..6507618 100644 --- a/pollen-ui-angular/src/main/webapp/js/directives.js +++ b/pollen-ui-angular/src/main/webapp/js/directives.js @@ -453,8 +453,13 @@ angular.module('pollenDirective', []) scope.ngModel.data = conf.restURL+'/resources/'+response.id; }); }; - console.log(changeEvent.target.files[0]); - reader.readAsDataURL( changeEvent.target.files[0] ); + try { + reader.readAsDataURL(changeEvent.target.files[0]); + } catch (e) { + scope.$apply(function () { + $rootScope.$broadcast('newError', 'error.reader.noFile'); + }); + } }); } @@ -465,7 +470,7 @@ angular.module('pollenDirective', []) ///// IMPORT CSV ///// ////////////////////////////////////// - .directive("importCsv", ['FavoriteList', '$route', function (FavoriteList, $route) { + .directive("importCsv", ['$rootScope', 'FavoriteList', '$route', function ($rootScope, FavoriteList, $route) { return { restrict : "E", scope: { @@ -474,7 +479,7 @@ angular.module('pollenDirective', []) template: '<form>' + '<input type="file" name="csvFile"/>' + - '<button class="btn btn-primary" type="submit"><span class="fa fa-download"></span> {{ \'action.favoriteList.importCSV\' | translate }}</button>' + + '<button class="btn btn-primary" type="submit"><span class="fa fa-download"></span> {{ \'action.favoriteList.import.fromCSV\' | translate }}</button>' + '</form>', link: function (scope, element) { element.find('button').bind("click", function (event) { @@ -484,10 +489,16 @@ angular.module('pollenDirective', []) FavoriteList.importcsv({favoriteListId: scope.fvId}, formData, function (data) { $route.reload(); }, function (error) { - console.log(error); + $rootScope.$broadcast('newError', error.data.error); }); }; - reader.readAsText(element.find('input[type=file]')[0].files[0]); + try { + reader.readAsText(element.find('input[type=file]')[0].files[0]); + } catch(e) { + scope.$apply(function () { + $rootScope.$broadcast('newError', 'error.reader.noFile'); + }); + } }); } } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.