001
014
015 package com.liferay.portlet.assetpublisher;
016
017 import com.liferay.portal.kernel.portlet.PortletLayoutListener;
018 import com.liferay.portal.kernel.portlet.PortletLayoutListenerException;
019 import com.liferay.portal.kernel.util.StringPool;
020 import com.liferay.portal.model.Layout;
021 import com.liferay.portal.model.PortletConstants;
022 import com.liferay.portal.model.PortletPreferences;
023 import com.liferay.portal.service.LayoutLocalServiceUtil;
024 import com.liferay.portal.service.SubscriptionLocalServiceUtil;
025 import com.liferay.portal.util.PortletKeys;
026 import com.liferay.portlet.asset.util.AssetUtil;
027 import com.liferay.portlet.assetpublisher.util.AssetPublisherUtil;
028 import com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil;
029
030
033 public class AssetPublisherPortletLayoutListener
034 implements PortletLayoutListener {
035
036 @Override
037 public void onAddToLayout(String portletId, long plid) {
038 }
039
040 @Override
041 public void onMoveInLayout(String portletId, long plid) {
042 }
043
044 @Override
045 public void onRemoveFromLayout(String portletId, long plid)
046 throws PortletLayoutListenerException {
047
048 try {
049 Layout layout = LayoutLocalServiceUtil.getLayout(plid);
050
051 if (AssetUtil.isDefaultAssetPublisher(
052 layout, portletId, StringPool.BLANK)) {
053
054 JournalArticleLocalServiceUtil.deleteLayoutArticleReferences(
055 layout.getGroupId(), layout.getUuid());
056 }
057
058 long ownerId = PortletKeys.PREFS_OWNER_ID_DEFAULT;
059 int ownerType = PortletKeys.PREFS_OWNER_TYPE_LAYOUT;
060
061 if (PortletConstants.hasUserId(portletId)) {
062 ownerType = PortletKeys.PREFS_OWNER_TYPE_USER;
063 ownerId = PortletConstants.getUserId(portletId);
064 }
065
066 SubscriptionLocalServiceUtil.deleteSubscriptions(
067 layout.getCompanyId(), PortletPreferences.class.getName(),
068 AssetPublisherUtil.getSubscriptionClassPK(
069 ownerId, ownerType, plid, portletId));
070 }
071 catch (Exception e) {
072 throw new PortletLayoutListenerException(e);
073 }
074 }
075
076 }