1
14
15 package com.liferay.portal.service;
16
17 import com.liferay.portal.kernel.exception.SystemException;
18 import com.liferay.portal.kernel.json.JSONObject;
19 import com.liferay.portal.kernel.util.LocaleUtil;
20 import com.liferay.portal.kernel.util.StringUtil;
21 import com.liferay.portal.model.PortletPreferencesIds;
22
23 import java.util.Locale;
24
25 import javax.portlet.PortletPreferences;
26
27
34 public class ServiceContextUtil {
35
36 public static Object deserialize(JSONObject jsonObject) {
37 ServiceContext serviceContext = new ServiceContext();
38
39
41 serviceContext.setCompanyId(jsonObject.getLong("companyId"));
42 serviceContext.setLayoutFullURL(jsonObject.getString("layoutFullURL"));
43 serviceContext.setLayoutURL(jsonObject.getString("layoutURL"));
44 serviceContext.setPathMain(jsonObject.getString("pathMain"));
45 serviceContext.setPlid(jsonObject.getLong("plid"));
46 serviceContext.setPortalURL(jsonObject.getString("portalURL"));
47 serviceContext.setScopeGroupId(jsonObject.getLong("scopeGroupId"));
48 serviceContext.setUserDisplayURL(
49 jsonObject.getString("userDisplayURL"));
50
51
53 String[] communityPermissions = StringUtil.split(
54 jsonObject.getString("communityPermissions"));
55 String[] guestPermissions = StringUtil.split(
56 jsonObject.getString("guestPermissions"));
57
58 serviceContext.setAddCommunityPermissions(
59 jsonObject.getBoolean("addCommunityPermissions"));
60 serviceContext.setAddGuestPermissions(
61 jsonObject.getBoolean("addGuestPermissions"));
62 serviceContext.setCommunityPermissions(communityPermissions);
63 serviceContext.setGuestPermissions(guestPermissions);
64
65
67 long[] assetCategoryIds = StringUtil.split(
68 jsonObject.getString("assetCategoryIds"), 0L);
69 String[] assetTagNames = StringUtil.split(
70 jsonObject.getString("assetTagNames"));
71
72 serviceContext.setAssetCategoryIds(assetCategoryIds);
73 serviceContext.setAssetTagNames(assetTagNames);
74
75
77 serviceContext.setStatus(jsonObject.getInt("status"));
78
79 return serviceContext;
80 }
81
82 public static Locale getLocale(ServiceContext serviceContext) {
83 return LocaleUtil.fromLanguageId(serviceContext.getLanguageId());
84 }
85
86 public static PortletPreferences getPortletPreferences(
87 ServiceContext serviceContext)
88 throws SystemException {
89
90 if (serviceContext == null) {
91 return null;
92 }
93
94 PortletPreferencesIds portletPreferencesIds =
95 serviceContext.getPortletPreferencesIds();
96
97 if (portletPreferencesIds == null) {
98 return null;
99 }
100 else {
101 return PortletPreferencesLocalServiceUtil.getPreferences(
102 portletPreferencesIds.getCompanyId(),
103 portletPreferencesIds.getOwnerId(),
104 portletPreferencesIds.getOwnerType(),
105 portletPreferencesIds.getPlid(),
106 portletPreferencesIds.getPortletId());
107 }
108 }
109
110 }