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.model.Company;
023 import com.liferay.portal.model.Group;
024 import com.liferay.portal.model.Organization;
025 import com.liferay.portal.model.Portlet;
026 import com.liferay.portal.service.CompanyLocalServiceUtil;
027 import com.liferay.portal.service.PortletLocalServiceUtil;
028
029 import javax.portlet.PortletPreferences;
030
031
034 public class BlogsAggregatorPortletDataHandler
035 extends DefaultConfigurationPortletDataHandler {
036
037 public BlogsAggregatorPortletDataHandler() {
038 setDataLevel(DataLevel.PORTLET_INSTANCE);
039 setPublishToLiveByDefault(true);
040 }
041
042 @Override
043 protected PortletPreferences doProcessExportPortletPreferences(
044 PortletDataContext portletDataContext, String portletId,
045 PortletPreferences portletPreferences)
046 throws Exception {
047
048 return updateExportPortletPreferences(
049 portletDataContext, portletId, portletPreferences);
050 }
051
052 @Override
053 protected PortletPreferences doProcessImportPortletPreferences(
054 PortletDataContext portletDataContext, String portletId,
055 PortletPreferences portletPreferences)
056 throws Exception {
057
058 return updateImportPortletPreferences(
059 portletDataContext, portletId, portletPreferences);
060 }
061
062 protected PortletPreferences updateExportPortletPreferences(
063 PortletDataContext portletDataContext, String portletId,
064 PortletPreferences portletPreferences)
065 throws Exception {
066
067 long organizationId = GetterUtil.getLong(
068 portletPreferences.getValue("organizationId", null));
069
070 if (organizationId > 0) {
071 Portlet portlet = PortletLocalServiceUtil.getPortletById(
072 portletDataContext.getCompanyId(), portletId);
073
074 ExportImportHelperUtil.updateExportPortletPreferencesClassPKs(
075 portletDataContext, portlet, portletPreferences,
076 "organizationId", Organization.class.getName(),
077 portletDataContext.getExportDataRootElement());
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 }