--- /dev/null
+/*******************************************************************************
+ * Copyright � Igor Barma, Alexandre Desoubeaux, Christian Martel, Eric Brun, Mathieu Amblard, Gwenael Gevet, Pierre Guillot, 2012
+ * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Alexandre Lefevre, Marc Salvat 2014-2016
+ * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Marc Salvat, Marc Suarez, Harifetra Ramamonjy 2017
+ *
+ * This file is part of the work and learning management system Pentila Nero.
+ *
+ * Pentila Nero is free software. You can redistribute it and/or modify since
+ * you respect the terms of either (at least one of the both license) :
+ * - under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ * - the CeCILL-C as published by CeCILL-C; either version 1 of the
+ * License, or any later version
+ * - the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the license,
+ * or (at your option) any later version.
+ *
+ * There are special exceptions to the terms and conditions of the
+ * licenses as they are applied to this software. View the full text of
+ * the exception in file LICENSE-PROJECT.txt in the directory of this software
+ * distribution.
+ *
+ * Pentila Nero 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
+ * Licenses for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * and the CeCILL-C and the GNU Lesser General Public License along with
+ * Pentila Nero. If not, see :
+ * <http://www.gnu.org/licenses/> and
+ * <http://www.cecill.info/licences.fr.html>.
+ ******************************************************************************/
+package com.pentila.entSavoie.listeners;
+
+import com.liferay.portal.ModelListenerException;
+import com.liferay.portal.NoSuchLayoutSetException;
+import com.liferay.portal.kernel.exception.SystemException;
+import com.liferay.portal.kernel.log.Log;
+import com.liferay.portal.kernel.log.LogFactoryUtil;
+import com.liferay.portal.kernel.util.StringPool;
+import com.liferay.portal.model.Group;
+import com.liferay.portal.model.LayoutConstants;
+import com.liferay.portal.model.LayoutSet;
+import com.liferay.portal.model.ModelListener;
+import com.liferay.portal.model.Theme;
+import com.liferay.portal.model.User;
+import com.liferay.portal.service.LayoutLocalServiceUtil;
+import com.liferay.portal.service.LayoutSetLocalServiceUtil;
+import com.liferay.portal.service.ServiceContext;
+import com.liferay.portal.service.ThemeLocalServiceUtil;
+import com.liferay.portal.service.UserLocalServiceUtil;
+import com.pentila.entSavoie.communityInfos.model.CommunityInfos;
+import com.pentila.entSavoie.communityInfos.service.CommunityInfosLocalServiceUtil;
+import com.pentila.entSavoie.communityInfos.service.GroupInfosLocalServiceUtil;
+
+/**
+ * Ce hook permet la creation automatique de page a la creation d'une community. <br/>
+ * <i>Créé le 11 sept. 2009.</i>
+ *
+ */
+public class CommunityListener implements ModelListener<Group> {
+
+ public void onAfterAddAssociation(Object classPK,
+ String associationClassName, Object associationClassPK)
+ throws ModelListenerException {}
+
+ public void onAfterCreate(Group group) {
+
+ //cas particuliers
+ if (group.getName().equals("Control Panel") || group.getName().equals("Guest") || (!group.isOrganization() && !group.isRegularSite()))
+ return;
+
+ long userId = group.getCreatorUserId();
+
+ // on cree le communityInfo
+ try {
+ CommunityInfosLocalServiceUtil.createCommunity(group.getCompanyId(), group.getGroupId(), userId);
+ } catch (SystemException e1) {
+ _log.error("ERROR IN CREATE CI FROM GRP LISTENER");
+ _log.error(e1);
+ }
+
+ try {
+ if (group.isOrganization()) {
+ userId = UserLocalServiceUtil.getDefaultUserId(group.getCompanyId());
+ }
+
+ User user = UserLocalServiceUtil.getUser(userId);
+ Theme defaultTheme = ThemeLocalServiceUtil.getTheme(user.getCompanyId(), "", false);
+
+ //Creation de la page prive du groupe
+ // on cree la page atelier privee
+ String fUrl = "/atelier";
+ LayoutSet set = null;
+ try {
+ set = LayoutSetLocalServiceUtil.getLayoutSet(group.getGroupId(), true);
+ } catch (NoSuchLayoutSetException e) {
+ set = LayoutSetLocalServiceUtil.addLayoutSet(group.getGroupId(), true);
+ }
+
+ //Initialise le layout set.
+ set.setThemeId(defaultTheme.getThemeId());
+ LayoutSetLocalServiceUtil.updateLayoutSet(set, true);
+ LayoutLocalServiceUtil.addLayout(
+ user.getUserId(),
+ set.getGroupId(),
+ set.getPrivateLayout(),
+ LayoutConstants.DEFAULT_PLID,
+ "Atelier",
+ "Atelier",
+ StringPool.BLANK,
+ LayoutConstants.TYPE_PANEL,
+ false,
+ fUrl,
+ new ServiceContext());
+
+ } catch (Exception e) {
+ if (_log.isErrorEnabled()) {
+ _log.error(e);
+ }
+ }
+
+
+
+ }
+
+ public void onAfterRemove(Group model) throws ModelListenerException {}
+
+ public void onAfterRemoveAssociation(Object classPK,
+ String associationClassName, Object associationClassPK)
+ throws ModelListenerException {}
+
+ public void onAfterUpdate(Group model) throws ModelListenerException {}
+
+ public void onBeforeAddAssociation(Object classPK,
+ String associationClassName, Object associationClassPK)
+ throws ModelListenerException {}
+
+ public void onBeforeCreate(Group model) throws ModelListenerException {
+ }
+
+ public void onBeforeRemove(Group group) throws ModelListenerException {
+
+ if (group.getName().equals("Control Panel") || group.getName().equals("Guest") || (!group.isOrganization() && !group.isRegularSite()))
+ return;
+
+ // on remove le CI
+ try {
+ CommunityInfos ci = CommunityInfosLocalServiceUtil.getCommunityInfosByGroupId(group.getGroupId());
+ CommunityInfosLocalServiceUtil.deleteCommunityInfos(ci);
+
+ } catch (Exception e) {
+ _log.error("ERROR IN CI REMOVE FROM GRP LISTENER");
+ }
+
+ // on remove le GrpInfo
+ try {
+ GroupInfosLocalServiceUtil.deleteGroupInfos(group.getGroupId());
+ } catch (Exception e) {
+ _log.error("ERROR IN GrpInfos REMOVE FROM GRP LISTENER");
+ }
+ _log.info("About to delete group "+group.getName()+" (id="+group.getGroupId()+")");
+ }
+
+ public void onBeforeRemoveAssociation(Object classPK,
+ String associationClassName, Object associationClassPK)
+ throws ModelListenerException {}
+
+ public void onBeforeUpdate(Group model) throws ModelListenerException {}
+
+ private Log _log = LogFactoryUtil.getLog(this.getClass());
+
+}