001
014
015 package com.liferay.portlet.blogsaggregator.lar;
016
017 import com.liferay.portal.kernel.util.GetterUtil;
018 import com.liferay.portal.model.Company;
019 import com.liferay.portal.model.Group;
020 import com.liferay.portal.model.Organization;
021 import com.liferay.portal.model.Portlet;
022 import com.liferay.portal.service.CompanyLocalServiceUtil;
023 import com.liferay.portal.service.PortletLocalServiceUtil;
024 import com.liferay.portlet.exportimport.lar.DataLevel;
025 import com.liferay.portlet.exportimport.lar.DefaultConfigurationPortletDataHandler;
026 import com.liferay.portlet.exportimport.lar.ExportImportHelperUtil;
027 import com.liferay.portlet.exportimport.lar.PortletDataContext;
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 }
078
079 return portletPreferences;
080 }
081
082 protected PortletPreferences updateImportPortletPreferences(
083 PortletDataContext portletDataContext, String portletId,
084 PortletPreferences portletPreferences)
085 throws Exception {
086
087 long organizationId = GetterUtil.getLong(
088 portletPreferences.getValue("organizationId", null));
089
090 if (organizationId > 0) {
091 Company company = CompanyLocalServiceUtil.getCompanyById(
092 portletDataContext.getCompanyId());
093
094 Group companyGroup = company.getGroup();
095
096 ExportImportHelperUtil.updateImportPortletPreferencesClassPKs(
097 portletDataContext, portletPreferences, "organizationId",
098 Organization.class, companyGroup.getGroupId());
099 }
100
101 return portletPreferences;
102 }
103
104 }