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.contact;
37 import java.util.List;
39 import javax.servlet.http.HttpServletRequest;
40 import javax.servlet.http.HttpServletResponse;
42 import org.apache.struts.action.Action;
43 import org.apache.struts.action.ActionForm;
44 import org.apache.struts.action.ActionForward;
45 import org.apache.struts.action.ActionMapping;
47 import com.liferay.portal.kernel.log.Log;
48 import com.liferay.portal.kernel.log.LogFactoryUtil;
49 import com.liferay.portal.kernel.util.ParamUtil;
50 import com.liferay.portal.model.Organization;
51 import com.liferay.portal.model.User;
52 import com.liferay.portal.service.UserLocalServiceUtil;
53 import com.liferay.portal.util.PortalUtil;
54 import com.pentila.entSavoie.ENTDisplayUtil;
55 import com.pentila.entSavoie.carnetDAdresses.FicheConstant;
56 import com.pentila.entSavoie.carnetDAdresses.model.Fiche;
57 import com.pentila.entSavoie.carnetDAdresses.service.FicheLocalServiceUtil;
60 public class AddToContact extends Action {
62 public ActionForward execute(ActionMapping mapping, ActionForm form,
63 HttpServletRequest request, HttpServletResponse response)
66 final User user = PortalUtil.getUser(request);
67 final String[] userIds = ParamUtil.getString(request, "userIds").split(",");
70 for (String id : userIds) {
71 final User assUser = UserLocalServiceUtil.getUser(Long.parseLong(id));
73 List<Fiche> relUserfiches = FicheLocalServiceUtil.findByRelUserIdGroupId(user.getGroup().getGroupId(), assUser.getUserId());
74 if (relUserfiches.size()==0) {
75 // on ajoute la fiche uniquement si aucune fiche ne concerne deja ce user
76 Fiche fiche = FicheLocalServiceUtil.addFiche(user.getGroup().getGroupId());
77 /*Enregistre l'utilisateur portail associe*/
78 fiche.setRelUserId(assUser.getUserId());
79 FicheLocalServiceUtil.updateFiche(fiche, false);
81 List<Organization> orgs = assUser.getOrganizations();
84 for (Organization o : orgs) {
85 listOrga += ENTDisplayUtil.formatSCONETName(user, o.getName());
92 FicheLocalServiceUtil.setFicheProperty(fiche.getFicheId(), FicheConstant.LASTNAME, assUser.getLastName());
93 FicheLocalServiceUtil.setFicheProperty(fiche.getFicheId(), FicheConstant.FIRSTNAME, assUser.getFirstName());
94 FicheLocalServiceUtil.setFicheProperty(fiche.getFicheId(), FicheConstant.EMAIL, assUser.getEmailAddress());
95 FicheLocalServiceUtil.setFicheProperty(fiche.getFicheId(), FicheConstant.ORGANIZATION, listOrga);
97 } catch (Exception e) {}
98 if (_log.isDebugEnabled()) {
104 } catch (Exception e) {
105 if (_log.isErrorEnabled()) {
109 return mapping.findForward("add_to_address_book");
112 final Log _log = LogFactoryUtil.getLog(this.getClass());