branch develop updated (f11feeb -> e91b089)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository coselmar. See http://git.codelutin.com/coselmar.git from f11feeb fixes #7774 revue de la gestion de l'export new f39137f refs-30 #7853 Prepare service for user search export new e91b089 fixes #7853 add users searched export on ui 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 e91b089acc6384ab7c8797abe7ed3bdfcccb2ab0 Author: Yannick Martel <martel@©odelutin.com> Date: Wed Dec 23 14:07:31 2015 +0100 fixes #7853 add users searched export on ui commit f39137fa5066e65ba7030746fdc900c31e737cbb Author: Yannick Martel <martel@©odelutin.com> Date: Tue Dec 22 18:03:53 2015 +0100 refs-30 #7853 Prepare service for user search export Summary of changes: .../java/fr/ifremer/coselmar/beans/UserBean.java | 9 +++ .../fr/ifremer/coselmar/beans/UserExportModel.java | 78 ++++++++++++++++++++++ .../coselmar/services/v1/UsersWebService.java | 58 ++++++++++++++++ .../i18n/coselmar-services_en_GB.properties | 16 +++++ .../i18n/coselmar-services_fr_FR.properties | 16 +++++ coselmar-rest/src/main/resources/mapping | 1 + .../src/main/webapp/js/coselmar-controllers.js | 12 +++- .../src/main/webapp/js/coselmar-user-services.js | 5 ++ .../src/main/webapp/views/users/searchPart.html | 2 +- coselmar-ui/src/main/webapp/views/users/users.html | 8 +++ 10 files changed, 201 insertions(+), 4 deletions(-) create mode 100644 coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/UserExportModel.java -- 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 develop in repository coselmar. See http://git.codelutin.com/coselmar.git commit f39137fa5066e65ba7030746fdc900c31e737cbb Author: Yannick Martel <martel@©odelutin.com> Date: Tue Dec 22 18:03:53 2015 +0100 refs-30 #7853 Prepare service for user search export --- .../java/fr/ifremer/coselmar/beans/UserBean.java | 9 +++ .../fr/ifremer/coselmar/beans/UserExportModel.java | 78 ++++++++++++++++++++++ .../coselmar/services/v1/UsersWebService.java | 58 ++++++++++++++++ .../i18n/coselmar-services_en_GB.properties | 16 +++++ .../i18n/coselmar-services_fr_FR.properties | 16 +++++ coselmar-rest/src/main/resources/mapping | 1 + 6 files changed, 178 insertions(+) diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/UserBean.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/UserBean.java index 7024c36..d4a2c7e 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/UserBean.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/UserBean.java @@ -31,6 +31,15 @@ import java.io.Serializable; */ public class UserBean implements Serializable { + public static final String PROPERTY_FIRST_NAME = "firstName"; + public static final String PROPERTY_NAME = "name"; + public static final String PROPERTY_MAIL = "mail"; + public static final String PROPERTY_ROLE = "role"; + public static final String PROPERTY_QUALIFICATION = "qualification"; + public static final String PROPERTY_ORGANIZATION = "organization"; + public static final String PROPERTY_PHONE_NUMBER = "phoneNumber"; + public static final String PROPERTY_ACTIVE = "active"; + protected String id; protected String firstName; protected String name; diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/UserExportModel.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/UserExportModel.java new file mode 100644 index 0000000..0fd91e9 --- /dev/null +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/UserExportModel.java @@ -0,0 +1,78 @@ +package fr.ifremer.coselmar.beans; + +/* + * #%L + * Coselmar :: Rest Services + * %% + * Copyright (C) 2014 - 2015 Ifremer, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.apache.commons.lang3.StringUtils; +import org.nuiton.csv.Common; +import org.nuiton.csv.ValueFormatter; +import org.nuiton.csv.ext.AbstractExportModel; +import org.nuiton.util.DateUtil; + +import static org.nuiton.i18n.I18n.t; + +/** + * @author ymartel (martel@codelutin.com) + */ +public class UserExportModel extends AbstractExportModel<UserBean> { + + protected static final ValueFormatter<Boolean> USER_ACTIVE_FORMATTER = new ValueFormatter<Boolean>() { + @Override + public String format(Boolean value) { + String result; + if (value) { + result = t("user.metadata.status.enable"); + + } else { + result = t("user.metadata.status.disable"); + } + return result; + } + }; + + protected static final ValueFormatter<String> USER_ROLE_FORMATTER = new ValueFormatter<String>() { + @Override + public String format(String value) { + String result = ""; + if (StringUtils.isNotBlank(value)) { + result = t("user.metadata.role." + value.toLowerCase()); + + } + return result; + } + }; + + protected static final Common.DateValue dateFormatter = new Common.DateValue(DateUtil.DEFAULT_PATTERN); + + public UserExportModel() { + super(';'); + + modelBuilder.newColumnForExport(t("user.metadata.firstName"), UserBean.PROPERTY_FIRST_NAME); + modelBuilder.newColumnForExport(t("user.metadata.name"), UserBean.PROPERTY_NAME); + modelBuilder.newColumnForExport(t("user.metadata.mail"), UserBean.PROPERTY_MAIL); + modelBuilder.newColumnForExport(t("user.metadata.qualification"), UserBean.PROPERTY_QUALIFICATION); + modelBuilder.newColumnForExport(t("user.metadata.organization"), UserBean.PROPERTY_ORGANIZATION); + modelBuilder.newColumnForExport(t("user.metadata.organization"), UserBean.PROPERTY_ROLE, USER_ROLE_FORMATTER); + modelBuilder.newColumnForExport(t("user.metadata.status"), UserBean.PROPERTY_ACTIVE,USER_ACTIVE_FORMATTER); + } + +} diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/UsersWebService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/UsersWebService.java index 63746ea..6d5ffd6 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/UsersWebService.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/UsersWebService.java @@ -42,6 +42,7 @@ import fr.ifremer.coselmar.beans.AbstractMail; import fr.ifremer.coselmar.beans.LostPasswordMail; import fr.ifremer.coselmar.beans.UserAccountCreatedMail; import fr.ifremer.coselmar.beans.UserBean; +import fr.ifremer.coselmar.beans.UserExportModel; import fr.ifremer.coselmar.beans.UserPasswordChangedMail; import fr.ifremer.coselmar.beans.UserSearchBean; import fr.ifremer.coselmar.beans.UserWebToken; @@ -56,12 +57,14 @@ import fr.ifremer.coselmar.services.errors.InvalidCredentialException; import fr.ifremer.coselmar.services.errors.MailAlreadyExistingException; import fr.ifremer.coselmar.services.errors.UnauthorizedException; import org.apache.commons.io.Charsets; +import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.mail.Email; import org.apache.commons.mail.EmailException; import org.apache.commons.mail.SimpleEmail; import org.debux.webmotion.server.render.Render; +import org.nuiton.csv.Export; import org.nuiton.topia.persistence.TopiaNoResultException; import org.nuiton.util.StringUtil; @@ -447,6 +450,61 @@ public class UsersWebService extends CoselmarWebServiceSupport { } + public Render exportSearchedUsers(String token, UserSearchBean searchOption) throws InvalidCredentialException, UnauthorizedException { + + CoselmarUser currentUser = checkUserAuthentication(token); + + // Who is allowed here ? Admin and user himself + if (currentUser.getRole() != CoselmarUserRole.ADMIN + && currentUser.getRole() != CoselmarUserRole.SUPERVISOR) { + if (log.isDebugEnabled()) { + String message = String.format("A non admin, non supervisor user is trying to access users list"); + log.debug(message); + } + throw new UnauthorizedException("Not allowed to see users"); + } + + List<CoselmarUser> userList; + if (searchOption != null) { + // Search default parameter if not given + SearchRequestBean requestBean = new SearchRequestBean(); + requestBean.setLimit(searchOption.getLimit()); + requestBean.setPage(searchOption.getPage()); + requestBean.setFullTextSearch(searchOption.getFullTextSearch()); + + CoselmarUser example = BeanEntityConverter.fromBean(searchOption); + + userList = getCoselmarUserDao().findAllByExample(example, searchOption.isActiveAndInactive(), requestBean); + + } else { + userList = getCoselmarUserDao().findAll(); + + } + + List<UserBean> users = new ArrayList<>(userList.size()); + + for (CoselmarUser user : userList) { + String userLightId = getPersistenceContext().getTopiaIdFactory().getRandomPart(user.getTopiaId()); + UserBean userBean = BeanEntityConverter.toBean(userLightId, user); + users.add(userBean); + } + + UserExportModel exportModel = new UserExportModel(); + + String exportData; + try { + exportData = Export.exportToString(exportModel, users); + } catch (Exception e) { + if (log.isErrorEnabled()) { + log.error("Error during export", e); + } + throw new CoselmarTechnicalException("Unable to export datas"); + } + + return renderDownload(IOUtils.toInputStream(exportData), "export-users-result.csv", "text/csv"); + + } + ///////////////////////////////////////////// ///////////// Internal Part ///////// ///////////////////////////////////////////// diff --git a/coselmar-rest/src/main/resources/i18n/coselmar-services_en_GB.properties b/coselmar-rest/src/main/resources/i18n/coselmar-services_en_GB.properties index 8068b56..49367d5 100644 --- a/coselmar-rest/src/main/resources/i18n/coselmar-services_en_GB.properties +++ b/coselmar-rest/src/main/resources/i18n/coselmar-services_en_GB.properties @@ -31,3 +31,19 @@ question.metadata.status=Status question.metadata.clients=Clients question.metadata.relatedDocuments=Related documents question.metadata.participants=Participants + +user.metadata.name=Name +user.metadata.firstName=First name +user.metadata.mail=Contact +user.metadata.phone=Phone number +user.metadata.qualification=Qualification +user.metadata.organization=Organization +user.metadata.role=role +user.metadata.status=Status +user.metadata.status.disable=Disable +user.metadata.status.enable=Active +user.metadata.role.admin=Admin +user.metadata.role.supervisor=Supervisor +user.metadata.role.expert=Expert +user.metadata.role.member=Member +user.metadata.role.client=Client \ No newline at end of file diff --git a/coselmar-rest/src/main/resources/i18n/coselmar-services_fr_FR.properties b/coselmar-rest/src/main/resources/i18n/coselmar-services_fr_FR.properties index 61d69b0..9fd8ca4 100644 --- a/coselmar-rest/src/main/resources/i18n/coselmar-services_fr_FR.properties +++ b/coselmar-rest/src/main/resources/i18n/coselmar-services_fr_FR.properties @@ -32,3 +32,19 @@ question.metadata.status=Status question.metadata.clients=Clients question.metadata.relatedDocuments=Documents associés question.metadata.participants=Participants + +user.metadata.name=Nom +user.metadata.firstName=Prénom +user.metadata.mail=Contact +user.metadata.phone=Numéro de téléphone +user.metadata.qualification=Profession +user.metadata.organization=Organisation +user.metadata.role=Rôle +user.metadata.status=Status +user.metadata.status.disable=Désactivé +user.metadata.status.enable=Activé +user.metadata.role.admin=Admin +user.metadata.role.supervisor=Superviseur +user.metadata.role.expert=Expert +user.metadata.role.member=Membre +user.metadata.role.client=Client \ No newline at end of file diff --git a/coselmar-rest/src/main/resources/mapping b/coselmar-rest/src/main/resources/mapping index 9a5eb16..a980514 100644 --- a/coselmar-rest/src/main/resources/mapping +++ b/coselmar-rest/src/main/resources/mapping @@ -74,6 +74,7 @@ POST /v1/admin/lucene/index AdminWebService.refreshLuceneInd # Export POST /v1/export/questions QuestionsWebService.exportSearchedQuestions +POST /v1/export/users UsersWebService.exportSearchedUsers # Health -- 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 develop in repository coselmar. See http://git.codelutin.com/coselmar.git commit e91b089acc6384ab7c8797abe7ed3bdfcccb2ab0 Author: Yannick Martel <martel@©odelutin.com> Date: Wed Dec 23 14:07:31 2015 +0100 fixes #7853 add users searched export on ui --- coselmar-ui/src/main/webapp/js/coselmar-controllers.js | 12 +++++++++--- coselmar-ui/src/main/webapp/js/coselmar-user-services.js | 5 +++++ coselmar-ui/src/main/webapp/views/users/searchPart.html | 2 +- coselmar-ui/src/main/webapp/views/users/users.html | 8 ++++++++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js index d432d51..e1afab7 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js @@ -548,7 +548,7 @@ coselmarControllers.controller("UsersCtrl", ['$scope', '$route', '$routeParams', //manage keywords if given $scope.search = { searchKeywords : []}; - $scope.example = { active : "true", role : 'ALL'}; + $scope.example = { active : "true", role : ''}; var keywords = $routeParams.keywords; if (Array.isArray(keywords)) { @@ -637,8 +637,6 @@ coselmarControllers.controller("UsersCtrl", ['$scope', '$route', '$routeParams', }; $scope.searchMode = function(type) { - console.log("pouet"); - console.log(type); if (type == 'advanced') { $location.search('advancedSearch'); $scope.advanced = true; @@ -647,6 +645,14 @@ coselmarControllers.controller("UsersCtrl", ['$scope', '$route', '$routeParams', $scope.advanced = false; } }; + + $scope.getExportUsersUrl = function() { + return userService.getExportUsersUrl(); + }; + + $scope.getToken = function() { + return localStorage.getItem('coselmar-jwt'); + } }]); // Controller for new user View diff --git a/coselmar-ui/src/main/webapp/js/coselmar-user-services.js b/coselmar-ui/src/main/webapp/js/coselmar-user-services.js index 81415fb..3f1e1d9 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-user-services.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-user-services.js @@ -31,6 +31,7 @@ function User(resource, config){ this.resource = resource; var baseURL = config.BASE_URL + "/users"; + var exportURL = config.BASE_URL + "/export/users"; this.saveUser = function(user, successFunction, failFunction){ @@ -106,4 +107,8 @@ function User(resource, config){ userResource.post(params, successFunction, failFunction); }; + this.getExportUsersUrl = function() { + return exportURL; + }; + }; \ No newline at end of file diff --git a/coselmar-ui/src/main/webapp/views/users/searchPart.html b/coselmar-ui/src/main/webapp/views/users/searchPart.html index 7ab1c84..16d7afd 100644 --- a/coselmar-ui/src/main/webapp/views/users/searchPart.html +++ b/coselmar-ui/src/main/webapp/views/users/searchPart.html @@ -82,7 +82,7 @@ <label class="col-md-1 control-label">{{ 'user.metadata.role' | translate }}</label> <div class="col-md-2"> <select class="form-control" name="role" ng-model="example.role" title="role" > - <option value="ALL">{{ 'user.metadata.role.all' | translate }}</option> + <option value="">{{ 'user.metadata.role.all' | translate }}</option> <option value="ADMIN">{{ 'user.metadata.role.admin' | translate }}</option> <option value="SUPERVISOR">{{ 'user.metadata.role.supervisor' | translate }}</option> <option value="EXPERT">{{ 'user.metadata.role.expert' | translate }}</option> diff --git a/coselmar-ui/src/main/webapp/views/users/users.html b/coselmar-ui/src/main/webapp/views/users/users.html index 5364160..2642793 100644 --- a/coselmar-ui/src/main/webapp/views/users/users.html +++ b/coselmar-ui/src/main/webapp/views/users/users.html @@ -32,5 +32,13 @@ <div ng-include="src='views/users/adminUsers.html'" ng-if="context.currentUser.role == 'ADMIN'"></div> <div ng-include="src='views/users/supervisorUsers.html'" ng-if="context.currentUser.role == 'SUPERVISOR'"></div> <p ng-if="users && users.length == 0" translate="common.search.noResult" class="info"/> + <div ng-if="users && users.length > 0" > + <form action="{{getExportUsersUrl()}}" method="post" target="_blank"> + <input type="hidden" name="searchOption" value="{{example}}" /> + <input type="hidden" name="token" value="{{getToken()}}" /> + <button type="submit" class="btn btn-primary"> + <span class="fa fa-download" aria-hidden="true"></span>{{ 'common.button.csvExport' | translate }}</button> + </form> + </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