001
014
015 package com.liferay.portlet.blogsaggregator.lar;
016
017 import com.liferay.portal.kernel.lar.DataLevel;
018 import com.liferay.portal.kernel.lar.DefaultConfigurationPortletDataHandler;
019 import com.liferay.portal.kernel.lar.ExportImportHelperUtil;
020 import com.liferay.portal.kernel.lar.PortletDataContext;
021 import com.liferay.portal.kernel.util.GetterUtil;
022 import com.liferay.portal.kernel.xml.Element;
023 import com.liferay.portal.model.Company;
024 import com.liferay.portal.model.Group;
025 import com.liferay.portal.model.Organization;
026 import com.liferay.portal.model.Portlet;
027 import com.liferay.portal.service.CompanyLocalServiceUtil;
028 import com.liferay.portal.service.PortletLocalServiceUtil;
029
030 import javax.portlet.PortletPreferences;
031
032
035 public class BlogsAggregatorPortletDataHandler
036 extends DefaultConfigurationPortletDataHandler {
037
038 public BlogsAggregatorPortletDataHandler() {
039 setDataLevel(DataLevel.PORTLET_INSTANCE);
040 setPublishToLiveByDefault(true);
041 }
042
043 @Override
044 protected PortletPreferences doProcessExportPortletPreferences(
045 PortletDataContext portletDataContext, String portletId,
046 PortletPreferences portletPreferences, Element rootElement)
047 throws Exception {
048
049 return updateExportPortletPreferences(
050 portletDataContext, portletId, portletPreferences, rootElement);
051 }
052
053 @Override
054 protected PortletPreferences doProcessImportPortletPreferences(
055 PortletDataContext portletDataContext, String portletId,
056 PortletPreferences portletPreferences)
057 throws Exception {
058
059 return updateImportPortletPreferences(
060 portletDataContext, portletId, portletPreferences);
061 }
062
063 protected PortletPreferences updateExportPortletPreferences(
064 PortletDataContext portletDataContext, String portletId,
065 PortletPreferences portletPreferences, Element rootElement)
066 throws Exception {
067
068 long organizationId = GetterUtil.getLong(
069 portletPreferences.getValue("organizationId", null));
070
071 if (organizationId > 0) {
072 Portlet portlet = PortletLocalServiceUtil.getPortletById(
073 portletDataContext.getCompanyId(), portletId);
074
075 ExportImportHelperUtil.updateExportPortletPreferencesClassPKs(
076 portletDataContext, portlet, portletPreferences,
077 "organizationId", Organization.class.getName(), rootElement);
078 }
079
080 return portletPreferences;
081 }
082
083 protected PortletPreferences updateImportPortletPreferences(
084 PortletDataContext portletDataContext, String portletId,
085 PortletPreferences portletPreferences)
086 throws Exception {
087
088 long organizationId = GetterUtil.getLong(
089 portletPreferences.getValue("organizationId", null));
090
091 if (organizationId > 0) {
092 Company company = CompanyLocalServiceUtil.getCompanyById(
093 portletDataContext.getCompanyId());
094
095 Group companyGroup = company.getGroup();
096
097 ExportImportHelperUtil.updateImportPortletPreferencesClassPKs(
098 portletDataContext, portletPreferences, "organizationId",
099 Organization.class, companyGroup.getGroupId());
100 }
101
102 return portletPreferences;
103 }
104
105 }