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.util.GetterUtil;
021 import com.liferay.portal.model.Layout;
022 import com.liferay.portlet.ratings.service.RatingsStatsLocalServiceUtil;
023
024 import javax.portlet.PortletPreferences;
025
026
029 public class PageRatingsPortletDataHandler extends BasePortletDataHandler {
030
031 public static final String NAMESPACE = "page_ratings";
032
033 public PageRatingsPortletDataHandler() {
034 setExportControls(
035 new PortletDataHandlerBoolean(NAMESPACE, "ratings", true, true));
036 }
037
038 @Override
039 protected PortletPreferences doDeleteData(
040 PortletDataContext portletDataContext, String portletId,
041 PortletPreferences portletPreferences)
042 throws Exception {
043
044 RatingsStatsLocalServiceUtil.deleteStats(
045 Layout.class.getName(), portletDataContext.getPlid());
046
047 return portletPreferences;
048 }
049
050 @Override
051 protected String doExportData(
052 PortletDataContext portletDataContext, String portletId,
053 PortletPreferences portletPreferences)
054 throws Exception {
055
056 portletDataContext.addRatingsEntries(
057 Layout.class, portletDataContext.getPlid());
058
059 return String.valueOf(portletDataContext.getPlid());
060 }
061
062 @Override
063 protected PortletPreferences doImportData(
064 PortletDataContext portletDataContext, String portletId,
065 PortletPreferences portletPreferences, String data)
066 throws Exception {
067
068 portletDataContext.importRatingsEntries(
069 Layout.class, GetterUtil.getLong(data),
070 portletDataContext.getPlid());
071
072 return null;
073 }
074
075 }