001
014
015 package com.liferay.portal.service;
016
017 import com.liferay.portal.kernel.exception.SystemException;
018 import com.liferay.portal.kernel.json.JSONObject;
019 import com.liferay.portal.kernel.util.StringUtil;
020 import com.liferay.portal.model.PortletPreferencesIds;
021
022 import javax.portlet.PortletPreferences;
023
024
029 public class ServiceContextUtil {
030
031 public static Object deserialize(JSONObject jsonObject) {
032 ServiceContext serviceContext = new ServiceContext();
033
034
035
036 serviceContext.setCompanyId(jsonObject.getLong("companyId"));
037 serviceContext.setLayoutFullURL(jsonObject.getString("layoutFullURL"));
038 serviceContext.setLayoutURL(jsonObject.getString("layoutURL"));
039 serviceContext.setPathMain(jsonObject.getString("pathMain"));
040 serviceContext.setPlid(jsonObject.getLong("plid"));
041 serviceContext.setPortalURL(jsonObject.getString("portalURL"));
042 serviceContext.setScopeGroupId(jsonObject.getLong("scopeGroupId"));
043 serviceContext.setUserDisplayURL(
044 jsonObject.getString("userDisplayURL"));
045 serviceContext.setUserId(jsonObject.getLong("userId"));
046
047
048
049 String[] groupPermissions = StringUtil.split(
050 jsonObject.getString("groupPermissions"));
051 String[] guestPermissions = StringUtil.split(
052 jsonObject.getString("guestPermissions"));
053
054 serviceContext.setAddGroupPermissions(
055 jsonObject.getBoolean("addGroupPermissions"));
056 serviceContext.setAddGuestPermissions(
057 jsonObject.getBoolean("addGuestPermissions"));
058 serviceContext.setGroupPermissions(groupPermissions);
059 serviceContext.setGuestPermissions(guestPermissions);
060
061
062
063 long[] assetCategoryIds = StringUtil.split(
064 jsonObject.getString("assetCategoryIds"), 0L);
065 String[] assetTagNames = StringUtil.split(
066 jsonObject.getString("assetTagNames"));
067
068 serviceContext.setAssetCategoryIds(assetCategoryIds);
069 serviceContext.setAssetTagNames(assetTagNames);
070
071
072
073 serviceContext.setWorkflowAction(jsonObject.getInt("workflowAction"));
074
075 return serviceContext;
076 }
077
078 public static PortletPreferences getPortletPreferences(
079 ServiceContext serviceContext)
080 throws SystemException {
081
082 if (serviceContext == null) {
083 return null;
084 }
085
086 PortletPreferencesIds portletPreferencesIds =
087 serviceContext.getPortletPreferencesIds();
088
089 if (portletPreferencesIds == null) {
090 return null;
091 }
092 else {
093 return PortletPreferencesLocalServiceUtil.getPreferences(
094 portletPreferencesIds.getCompanyId(),
095 portletPreferencesIds.getOwnerId(),
096 portletPreferencesIds.getOwnerType(),
097 portletPreferencesIds.getPlid(),
098 portletPreferencesIds.getPortletId());
099 }
100 }
101
102 }