/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library 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 Lesser General Public License for more * details. */ package com.liferay.opensocial.admin.exportimport.data.handler; import com.liferay.exportimport.kernel.lar.BasePortletDataHandler; import com.liferay.exportimport.kernel.lar.DataLevel; import com.liferay.exportimport.kernel.lar.PortletDataContext; import com.liferay.exportimport.kernel.lar.StagedModelDataHandlerUtil; import com.liferay.exportimport.kernel.lar.StagedModelType; import com.liferay.exportimport.kernel.xstream.XStreamAliasRegistryUtil; import com.liferay.opensocial.model.Gadget; import com.liferay.opensocial.model.impl.GadgetImpl; import com.liferay.opensocial.service.GadgetLocalServiceUtil; import com.liferay.opensocial.service.permission.GadgetPermission; import com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery; import com.liferay.portal.kernel.xml.Element; import java.util.List; import javax.portlet.PortletPreferences; /** * @author Michael C. Han */ public class AdminPortletDataHandler extends BasePortletDataHandler { public AdminPortletDataHandler() { setDataLevel(DataLevel.PORTAL); setDeletionSystemEventStagedModelTypes( new StagedModelType(Gadget.class)); setPublishToLiveByDefault(true); XStreamAliasRegistryUtil.register(GadgetImpl.class, "Gadget"); } @Override protected PortletPreferences doDeleteData( PortletDataContext portletDataContext, String portletId, PortletPreferences portletPreferences) throws Exception { if (portletDataContext.addPrimaryKey( AdminPortletDataHandler.class, "deleteData")) { return portletPreferences; } GadgetLocalServiceUtil.deleteGadgets(portletDataContext.getCompanyId()); return portletPreferences; } @Override protected String doExportData( final PortletDataContext portletDataContext, String portletId, PortletPreferences portletPreferences) throws Exception { Element rootElement = addExportDataRootElement(portletDataContext); portletDataContext.addPortletPermissions( GadgetPermission.RESOURCE_NAME); rootElement.addAttribute( "group-id", String.valueOf(portletDataContext.getScopeGroupId())); ActionableDynamicQuery actionableDynamicQuery = GadgetLocalServiceUtil.getExportActionableDynamicQuery( portletDataContext); actionableDynamicQuery.performActions(); return getExportDataRootElementString(rootElement); } @Override protected PortletPreferences doImportData( PortletDataContext portletDataContext, String portletId, PortletPreferences portletPreferences, String data) throws Exception { portletDataContext.importPortletPermissions( GadgetPermission.RESOURCE_NAME); Element gadgetsElement = portletDataContext.getImportDataGroupElement( Gadget.class); List<Element> gadgetElements = gadgetsElement.elements(); for (Element gadgetElement : gadgetElements) { StagedModelDataHandlerUtil.importStagedModel( portletDataContext, gadgetElement); } return null; } @Override protected void doPrepareManifestSummary( PortletDataContext portletDataContext, PortletPreferences portletPreferences) throws Exception { ActionableDynamicQuery actionableDynamicQuery = GadgetLocalServiceUtil.getExportActionableDynamicQuery( portletDataContext); actionableDynamicQuery.performCount(); } }