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.LocaleUtil;
020 import com.liferay.portal.kernel.util.StringUtil;
021 import com.liferay.portal.model.PortletPreferencesIds;
022
023 import java.util.Locale;
024
025 import javax.portlet.PortletPreferences;
026
027
032 public class ServiceContextUtil {
033
034 public static Object deserialize(JSONObject jsonObject) {
035 ServiceContext serviceContext = new ServiceContext();
036
037
038
039 serviceContext.setCompanyId(jsonObject.getLong("companyId"));
040 serviceContext.setLayoutFullURL(jsonObject.getString("layoutFullURL"));
041 serviceContext.setLayoutURL(jsonObject.getString("layoutURL"));
042 serviceContext.setPathMain(jsonObject.getString("pathMain"));
043 serviceContext.setPlid(jsonObject.getLong("plid"));
044 serviceContext.setPortalURL(jsonObject.getString("portalURL"));
045 serviceContext.setScopeGroupId(jsonObject.getLong("scopeGroupId"));
046 serviceContext.setUserDisplayURL(
047 jsonObject.getString("userDisplayURL"));
048
049
050
051 String[] communityPermissions = StringUtil.split(
052 jsonObject.getString("communityPermissions"));
053 String[] guestPermissions = StringUtil.split(
054 jsonObject.getString("guestPermissions"));
055
056 serviceContext.setAddCommunityPermissions(
057 jsonObject.getBoolean("addCommunityPermissions"));
058 serviceContext.setAddGuestPermissions(
059 jsonObject.getBoolean("addGuestPermissions"));
060 serviceContext.setCommunityPermissions(communityPermissions);
061 serviceContext.setGuestPermissions(guestPermissions);
062
063
064
065 long[] assetCategoryIds = StringUtil.split(
066 jsonObject.getString("assetCategoryIds"), 0L);
067 String[] assetTagNames = StringUtil.split(
068 jsonObject.getString("assetTagNames"));
069
070 serviceContext.setAssetCategoryIds(assetCategoryIds);
071 serviceContext.setAssetTagNames(assetTagNames);
072
073
074
075 serviceContext.setWorkflowAction(jsonObject.getInt("workflowAction"));
076
077 return serviceContext;
078 }
079
080 public static Locale getLocale(ServiceContext serviceContext) {
081 return LocaleUtil.fromLanguageId(serviceContext.getLanguageId());
082 }
083
084 public static PortletPreferences getPortletPreferences(
085 ServiceContext serviceContext)
086 throws SystemException {
087
088 if (serviceContext == null) {
089 return null;
090 }
091
092 PortletPreferencesIds portletPreferencesIds =
093 serviceContext.getPortletPreferencesIds();
094
095 if (portletPreferencesIds == null) {
096 return null;
097 }
098 else {
099 return PortletPreferencesLocalServiceUtil.getPreferences(
100 portletPreferencesIds.getCompanyId(),
101 portletPreferencesIds.getOwnerId(),
102 portletPreferencesIds.getOwnerType(),
103 portletPreferencesIds.getPlid(),
104 portletPreferencesIds.getPortletId());
105 }
106 }
107
108 }