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