/* * Copyright (C) 2003-2007 eXo Platform SAS. * * This program is free software; you can redistribute it and/or * modify it 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. * * 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. */ package org.exoplatform.portal.config; import java.util.Iterator; import java.util.List; import org.exoplatform.commons.utils.LazyPageList; import org.exoplatform.container.ExoContainer; import org.exoplatform.container.ExoContainerContext; import org.exoplatform.portal.application.PortletPreferences; import org.exoplatform.portal.config.model.Page; import org.exoplatform.portal.config.model.PageNavigation; import org.exoplatform.portal.config.model.PortalConfig; import org.exoplatform.services.organization.Group; import org.exoplatform.services.organization.GroupEventListener; /** * Created by The eXo Platform SARL * Author : Nhu Dinh Thuan * nhudinhthuan@exoplatform.com * May 29, 2007 */ public class GroupPortalConfigListener extends GroupEventListener { public void preDelete(Group group) throws Exception { ExoContainer container = ExoContainerContext.getCurrentContainer(); UserPortalConfigService portalConfigService = (UserPortalConfigService)container.getComponentInstanceOfType(UserPortalConfigService.class) ; DataStorage dataStorage = (DataStorage)container.getComponentInstanceOfType(DataStorage.class) ; String groupId = group.getId().trim(); if(groupId.charAt(0)=='/') groupId = groupId.substring(1); Query pageQuery = new Query(PortalConfig.GROUP_TYPE, groupId, Page.class) ; LazyPageList pageList = dataStorage.find(pageQuery) ; int i = 1 ; while(i <= pageList.getAvailablePage()) { List list = pageList.getPage(i) ; Iterator iterator = list.iterator() ; while(iterator.hasNext()){ portalConfigService.remove((Page)iterator.next() ) ; } i++ ; } Query portletPrefQuery = new Query(PortalConfig.GROUP_TYPE, groupId, PortletPreferences.class) ; pageList = dataStorage.find(portletPrefQuery) ; i = 1 ; while(i <= pageList.getAvailablePage()) { List list = pageList.getPage(i) ; Iterator iterator = list.iterator() ; while(iterator.hasNext()) dataStorage.remove((PortletPreferences)iterator.next()) ; i++ ; } PageNavigation navigation = dataStorage.getPageNavigation(PortalConfig.GROUP_TYPE, groupId) ; if (navigation != null) portalConfigService.remove(navigation) ; } }