001
014
015 package com.liferay.portlet.pageratings.lar;
016
017 import com.liferay.portal.kernel.lar.BasePortletDataHandler;
018 import com.liferay.portal.kernel.lar.PortletDataContext;
019 import com.liferay.portal.kernel.lar.PortletDataHandlerBoolean;
020 import com.liferay.portal.kernel.lar.PortletDataHandlerControl;
021 import com.liferay.portal.kernel.util.GetterUtil;
022 import com.liferay.portal.model.Layout;
023 import com.liferay.portlet.ratings.service.RatingsStatsLocalServiceUtil;
024
025 import javax.portlet.PortletPreferences;
026
027
030 public class PageRatingsPortletDataHandlerImpl extends BasePortletDataHandler {
031
032 @Override
033 public PortletDataHandlerControl[] getExportControls() {
034 return new PortletDataHandlerControl[] {_ratings};
035 }
036
037 @Override
038 public PortletDataHandlerControl[] getImportControls() {
039 return new PortletDataHandlerControl[] {_ratings};
040 }
041
042 @Override
043 protected PortletPreferences doDeleteData(
044 PortletDataContext portletDataContext, String portletId,
045 PortletPreferences portletPreferences)
046 throws Exception {
047
048 RatingsStatsLocalServiceUtil.deleteStats(
049 Layout.class.getName(), portletDataContext.getPlid());
050
051 return null;
052 }
053
054 @Override
055 protected String doExportData(
056 PortletDataContext portletDataContext, String portletId,
057 PortletPreferences portletPreferences)
058 throws Exception {
059
060 portletDataContext.addRatingsEntries(
061 Layout.class, portletDataContext.getPlid());
062
063 return String.valueOf(portletDataContext.getPlid());
064 }
065
066 @Override
067 protected PortletPreferences doImportData(
068 PortletDataContext portletDataContext, String portletId,
069 PortletPreferences portletPreferences, String data)
070 throws Exception {
071
072 portletDataContext.importRatingsEntries(
073 Layout.class, GetterUtil.getLong(data),
074 portletDataContext.getPlid());
075
076 return null;
077 }
078
079 private static final String _NAMESPACE = "page_ratings";
080
081 private static PortletDataHandlerBoolean _ratings =
082 new PortletDataHandlerBoolean(_NAMESPACE, "ratings", true, true);
083
084 }