[pollen] branch feature/importFavoriteList created (now c721979)
This is an automated email from the git hooks/post-receive script. New change to branch feature/importFavoriteList in repository pollen. See http://git.chorem.org/pollen.git at c721979 add error when import favorite list from csv file This branch includes the following new commits: new 95ccc62 add import favorite list from 'csv' file new c721979 add error when import favorite list from csv 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 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 commit 95ccc6238dae90d8ccf736b9d98cdac0ac9113f0 Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Wed Aug 20 12:33:00 2014 +0200 add import favorite list from 'csv' file -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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 95ccc6238dae90d8ccf736b9d98cdac0ac9113f0 Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Wed Aug 20 12:33:00 2014 +0200 add import favorite list from 'csv' file --- .../chorem/pollen/rest/api/v1/FavoriteListApi.java | 5 ++-- .../pollen/rest/api/v1/PollenResourceApi.java | 1 + pollen-rest-api/src/main/resources/mapping | 1 + pollen-ui-angular/src/main/webapp/js/directives.js | 33 ++++++++++++++++++++++ pollen-ui-angular/src/main/webapp/js/services.js | 8 ++++++ pollen-ui-angular/src/main/webapp/less/style.less | 4 +++ .../main/webapp/partials/favoriteList-edit.html | 6 ++++ 7 files changed, 56 insertions(+), 2 deletions(-) diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListApi.java index 8adb776..23e415d 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListApi.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListApi.java @@ -35,6 +35,7 @@ import org.chorem.pollen.services.service.FavoriteListImportException; import org.chorem.pollen.services.service.FavoriteListService; import org.chorem.pollen.services.service.InvalidFormException; import org.debux.webmotion.server.WebMotionController; +import org.debux.webmotion.server.call.UploadFile; import java.io.File; @@ -80,9 +81,9 @@ public class FavoriteListApi extends WebMotionController { } - public void importFavoriteListMembersFromCsv(FavoriteListService favoriteListService, PollenEntityId<FavoriteList> favoriteListId, File csvFile) throws FavoriteListImportException { + public void importFavoriteListMembersFromCsv(FavoriteListService favoriteListService, PollenEntityId<FavoriteList> favoriteListId, UploadFile csvFile) throws FavoriteListImportException { - favoriteListService.importFavoriteListMembersFromCsv(favoriteListId.getEntityId(), csvFile); + favoriteListService.importFavoriteListMembersFromCsv(favoriteListId.getEntityId(), csvFile.getFile()); } diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenResourceApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenResourceApi.java index db7dc0e..734b8de 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenResourceApi.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenResourceApi.java @@ -19,6 +19,7 @@ import java.io.IOException; * Created on 10/07/14. * * @author dralagen + * @since 2.0 */ public class PollenResourceApi extends WebMotionController { diff --git a/pollen-rest-api/src/main/resources/mapping b/pollen-rest-api/src/main/resources/mapping index d0dbfd1..c17b4c7 100644 --- a/pollen-rest-api/src/main/resources/mapping +++ b/pollen-rest-api/src/main/resources/mapping @@ -42,6 +42,7 @@ org.chorem.pollen.services.service.security.PollenInvalidPermissionException org.chorem.pollen.services.service.security.PollenInvalidEmailActivationTokenException ErrorAction.on403 org.chorem.pollen.services.service.security.PollenInvalidPasswordException ErrorAction.on400Form org.chorem.pollen.services.service.InvalidFormException ErrorAction.on400Form +org.chorem.pollen.services.service.FavoriteListImportException ErrorAction.on400Form org.nuiton.topia.persistence.TopiaNoResultException ErrorAction.on404 org.chorem.pollen.services.service.InvalidEntityLinkException ErrorAction.on404 diff --git a/pollen-ui-angular/src/main/webapp/js/directives.js b/pollen-ui-angular/src/main/webapp/js/directives.js index 1e7bfe1..2c14179 100644 --- a/pollen-ui-angular/src/main/webapp/js/directives.js +++ b/pollen-ui-angular/src/main/webapp/js/directives.js @@ -453,6 +453,7 @@ angular.module('pollenDirective', []) scope.ngModel.data = conf.restURL+'/resources/'+response.id; }); }; + console.log(changeEvent.target.files[0]); reader.readAsDataURL( changeEvent.target.files[0] ); }); @@ -461,6 +462,38 @@ angular.module('pollenDirective', []) }]) ////////////////////////////////////// +///// IMPORT CSV ///// +////////////////////////////////////// + + .directive("importCsv", ['FavoriteList', '$route', function (FavoriteList, $route) { + return { + restrict : "E", + scope: { + fvId: "=" + }, + 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>' + + '</form>', + link: function (scope, element) { + element.find('button').bind("click", function (event) { + var reader = new FileReader(); + reader.onload = function () { + var formData = new FormData(element[0].firstChild); + FavoriteList.importcsv({favoriteListId: scope.fvId}, formData, function (data) { + $route.reload(); + }, function (error) { + console.log(error); + }); + }; + reader.readAsText(element.find('input[type=file]')[0].files[0]); + }); + } + } + }]) + +////////////////////////////////////// ///// PRINT RESOURCE ///// ////////////////////////////////////// diff --git a/pollen-ui-angular/src/main/webapp/js/services.js b/pollen-ui-angular/src/main/webapp/js/services.js index de2714b..51d46ff 100644 --- a/pollen-ui-angular/src/main/webapp/js/services.js +++ b/pollen-ui-angular/src/main/webapp/js/services.js @@ -313,6 +313,14 @@ angular.module('pollenServices', ['ngResource']) transformRequest: function (data) { return transformParam(data); } + }, + 'importcsv': { + method:'POST', + url: conf.restURL + '/favoriteLists/:favoriteListId/importCsv', + transformRequest: angular.identity, + headers:{ + 'Content-Type':undefined + } } }) }]) diff --git a/pollen-ui-angular/src/main/webapp/less/style.less b/pollen-ui-angular/src/main/webapp/less/style.less index 666903c..bb8f3eb 100644 --- a/pollen-ui-angular/src/main/webapp/less/style.less +++ b/pollen-ui-angular/src/main/webapp/less/style.less @@ -485,6 +485,10 @@ a { &.action { width:@width-action; } + + input[type=file] { + display: inline-block; + } } } diff --git a/pollen-ui-angular/src/main/webapp/partials/favoriteList-edit.html b/pollen-ui-angular/src/main/webapp/partials/favoriteList-edit.html index d1b4d54..59b1b8b 100644 --- a/pollen-ui-angular/src/main/webapp/partials/favoriteList-edit.html +++ b/pollen-ui-angular/src/main/webapp/partials/favoriteList-edit.html @@ -70,6 +70,12 @@ <button class="btn btn-danger" ng-click="deleteFavoriteList();"><span class="fa fa-trash-o"></span> {{ 'action.favoriteList.delete' | translate }} </button> </th> </tr> + + <tr ng-if="data.favoriteList.id"> + <th colspan="3"> + <import-csv fv-id="data.favoriteList.id"></import-csv> + </th> + </tr> </table> <div class="text-right"> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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>.
participants (1)
-
chorem.org scm