1 /*******************************************************************************
2 * Copyright � Igor Barma, Alexandre Desoubeaux, Christian Martel, Eric Brun, Mathieu Amblard, Gwenael Gevet, Pierre Guillot, 2012
3 * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Alexandre Lefevre, Marc Salvat 2014-2016
4 * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Marc Salvat, Marc Suarez, Harifetra Ramamonjy 2017
6 * This file is part of the work and learning management system Pentila Nero.
8 * Pentila Nero is free software. You can redistribute it and/or modify since
9 * you respect the terms of either (at least one of the both license) :
10 * - under the terms of the GNU Affero General Public License as
11 * published by the Free Software Foundation, either version 3 of the
12 * License, or (at your option) any later version.
13 * - the CeCILL-C as published by CeCILL-C; either version 1 of the
14 * License, or any later version
15 * - the GNU Lesser General Public License as published by the
16 * Free Software Foundation, either version 3 of the license,
17 * or (at your option) any later version.
19 * There are special exceptions to the terms and conditions of the
20 * licenses as they are applied to this software. View the full text of
21 * the exception in file LICENSE-PROJECT.txt in the directory of this software
24 * Pentila Nero is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * Licenses for more details.
29 * You should have received a copy of the GNU Affero General Public License
30 * and the CeCILL-C and the GNU Lesser General Public License along with
31 * Pentila Nero. If not, see :
32 * <http://www.gnu.org/licenses/> and
33 * <http://www.cecill.info/licences.fr.html>.
34 ******************************************************************************/
35 package com.pentila.entSavoie.utils;
37 import com.liferay.portal.kernel.json.JSONFactoryUtil;
38 import com.liferay.portal.kernel.json.JSONObject;
39 import com.liferay.portal.kernel.log.Log;
40 import com.liferay.portal.kernel.log.LogFactoryUtil;
41 import com.liferay.portal.model.Organization;
42 import com.liferay.portal.model.User;
43 import com.pentila.entSavoie.ENTRolesConstants;
44 import com.pentila.entSavoie.carnetDAdresses.model.Fiche;
45 import com.pentila.entSavoie.directory.OrganizationFinderServiceUtil;
47 public class JsonUserFactory {
49 private static Log _log = LogFactoryUtil.getLog(JsonUserFactory.class);
51 public static JSONObject convertUserToJson (User user) {
53 JSONObject jsonUser = JSONFactoryUtil.createJSONObject();
55 jsonUser.put("userId", user.getUserId());
56 jsonUser.put("userFirstName", user.getFirstName());
57 jsonUser.put("userLastName", user.getLastName());
60 boolean isFemale = user.getJobTitle().equals("Mme") || user.getJobTitle().equals("Mlle");
61 jsonUser.put("isMale", !isFemale);
63 Organization school = OrganizationFinderServiceUtil.getEtabRatachement(user);
65 jsonUser.put("schoolId", school.getOrganizationId());
66 jsonUser.put("schoolName", school.getName());
70 if (ENTRolesConstants.isStudent(user)) {
71 jsonUser.put("role", "El\u00E8ve");
72 } else if (ENTRolesConstants.isParent(user)) {
73 jsonUser.put("role", "Parent");
74 } else if (ENTRolesConstants.isTeacher(user)) {
75 jsonUser.put("role", "Enseignant");
77 jsonUser.put("role", "Personnel");
80 // ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute("THEME_DISPLAY");
81 // if (contactUser.isFemale()) {
82 // url = themeDisplay.getPathImage() + "/user_female_portrait?img_id=";
84 // url = themeDisplay.getPathImage() + "/user_male_portrait?img_id=";
87 // boolean portraitVisible = true;
89 // UserProperties up = UserPropertiesLocalServiceUtil.getUserPropertiesByUserId(contactFiche.getRelUserId());
90 // portraitVisible = up.getPortraitVisible();
91 // } catch (Exception e) {
94 // String urlImg = "";
95 // if (portraitVisible) {
96 // urlImg = url + contactUser.getPortraitId() + "&t=" + WebServerServletTokenUtil.getToken(contactUser.getPortraitId());
98 // urlImg = url + "0";
101 } catch (Exception e) {
102 _log.error("Error when getting informations on user "+user.getUserId(), e);
107 public static JSONObject convertUserToJson(Fiche fiche) {
109 JSONObject jsonUser = JSONFactoryUtil.createJSONObject();
112 JSONObject properties = JSONFactoryUtil.createJSONObject(fiche.getProperties());
114 jsonUser.put("userId", 0);
115 jsonUser.put("userFirstName", properties.getString("prenom"));
116 jsonUser.put("userLastName", properties.getString("nom"));
118 jsonUser.put("isMale", properties.getBoolean("isMale", true));
120 if (!properties.getString("organisation").isEmpty()) {
121 jsonUser.put("schoolName", properties.getString("organisation"));
124 jsonUser.put("role", "Externe");
125 } catch (Exception e) {
126 _log.error("Error when getting informations on fiche "+fiche.getFicheId(), e);