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.listeners;
37 import com.liferay.portal.ModelListenerException;
38 import com.liferay.portal.NoSuchLayoutSetException;
39 import com.liferay.portal.kernel.exception.SystemException;
40 import com.liferay.portal.kernel.log.Log;
41 import com.liferay.portal.kernel.log.LogFactoryUtil;
42 import com.liferay.portal.kernel.util.StringPool;
43 import com.liferay.portal.model.Group;
44 import com.liferay.portal.model.LayoutConstants;
45 import com.liferay.portal.model.LayoutSet;
46 import com.liferay.portal.model.ModelListener;
47 import com.liferay.portal.model.Theme;
48 import com.liferay.portal.model.User;
49 import com.liferay.portal.service.LayoutLocalServiceUtil;
50 import com.liferay.portal.service.LayoutSetLocalServiceUtil;
51 import com.liferay.portal.service.ServiceContext;
52 import com.liferay.portal.service.ThemeLocalServiceUtil;
53 import com.liferay.portal.service.UserLocalServiceUtil;
54 import com.pentila.entSavoie.communityInfos.model.CommunityInfos;
55 import com.pentila.entSavoie.communityInfos.service.CommunityInfosLocalServiceUtil;
56 import com.pentila.entSavoie.communityInfos.service.GroupInfosLocalServiceUtil;
59 * Ce hook permet la creation automatique de page a la creation d'une community. <br/>
60 * <i>Créé le 11 sept. 2009.</i>
63 public class CommunityListener implements ModelListener<Group> {
65 public void onAfterAddAssociation(Object classPK,
66 String associationClassName, Object associationClassPK)
67 throws ModelListenerException {}
69 public void onAfterCreate(Group group) {
72 if (group.getName().equals("Control Panel") || group.getName().equals("Guest") || (!group.isOrganization() && !group.isRegularSite()))
75 long userId = group.getCreatorUserId();
77 // on cree le communityInfo
79 CommunityInfosLocalServiceUtil.createCommunity(group.getCompanyId(), group.getGroupId(), userId);
80 } catch (SystemException e1) {
81 _log.error("ERROR IN CREATE CI FROM GRP LISTENER");
86 if (group.isOrganization()) {
87 userId = UserLocalServiceUtil.getDefaultUserId(group.getCompanyId());
90 User user = UserLocalServiceUtil.getUser(userId);
91 Theme defaultTheme = ThemeLocalServiceUtil.getTheme(user.getCompanyId(), "", false);
93 //Creation de la page prive du groupe
94 // on cree la page atelier privee
95 String fUrl = "/atelier";
98 set = LayoutSetLocalServiceUtil.getLayoutSet(group.getGroupId(), true);
99 } catch (NoSuchLayoutSetException e) {
100 set = LayoutSetLocalServiceUtil.addLayoutSet(group.getGroupId(), true);
103 //Initialise le layout set.
104 set.setThemeId(defaultTheme.getThemeId());
105 LayoutSetLocalServiceUtil.updateLayoutSet(set, true);
106 LayoutLocalServiceUtil.addLayout(
109 set.getPrivateLayout(),
110 LayoutConstants.DEFAULT_PLID,
114 LayoutConstants.TYPE_PANEL,
117 new ServiceContext());
119 } catch (Exception e) {
120 if (_log.isErrorEnabled()) {
129 public void onAfterRemove(Group model) throws ModelListenerException {}
131 public void onAfterRemoveAssociation(Object classPK,
132 String associationClassName, Object associationClassPK)
133 throws ModelListenerException {}
135 public void onAfterUpdate(Group model) throws ModelListenerException {}
137 public void onBeforeAddAssociation(Object classPK,
138 String associationClassName, Object associationClassPK)
139 throws ModelListenerException {}
141 public void onBeforeCreate(Group model) throws ModelListenerException {
144 public void onBeforeRemove(Group group) throws ModelListenerException {
146 if (group.getName().equals("Control Panel") || group.getName().equals("Guest") || (!group.isOrganization() && !group.isRegularSite()))
151 CommunityInfos ci = CommunityInfosLocalServiceUtil.getCommunityInfosByGroupId(group.getGroupId());
152 CommunityInfosLocalServiceUtil.deleteCommunityInfos(ci);
154 } catch (Exception e) {
155 _log.error("ERROR IN CI REMOVE FROM GRP LISTENER");
158 // on remove le GrpInfo
160 GroupInfosLocalServiceUtil.deleteGroupInfos(group.getGroupId());
161 } catch (Exception e) {
162 _log.error("ERROR IN GrpInfos REMOVE FROM GRP LISTENER");
164 _log.info("About to delete group "+group.getName()+" (id="+group.getGroupId()+")");
167 public void onBeforeRemoveAssociation(Object classPK,
168 String associationClassName, Object associationClassPK)
169 throws ModelListenerException {}
171 public void onBeforeUpdate(Group model) throws ModelListenerException {}
173 private Log _log = LogFactoryUtil.getLog(this.getClass());