1
14
15 package com.liferay.portal.service;
16
17 import com.liferay.portal.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 String[] tagsCategories = StringUtil.split(
68 jsonObject.getString("tagsCategories"));
69 String[] tagsEntries = StringUtil.split(
70 jsonObject.getString("tagsEntries"));
71
72 serviceContext.setTagsCategories(tagsCategories);
73 serviceContext.setTagsEntries(tagsEntries);
74
75 return serviceContext;
76 }
77
78 public static Locale getLocale(ServiceContext serviceContext) {
79 return LocaleUtil.fromLanguageId(serviceContext.getLanguageId());
80 }
81
82 public static PortletPreferences getPortletPreferences(
83 ServiceContext serviceContext)
84 throws SystemException {
85
86 if (serviceContext == null) {
87 return null;
88 }
89
90 PortletPreferencesIds portletPreferencesIds =
91 serviceContext.getPortletPreferencesIds();
92
93 if (portletPreferencesIds == null) {
94 return null;
95 }
96 else {
97 return PortletPreferencesLocalServiceUtil.getPreferences(
98 portletPreferencesIds.getCompanyId(),
99 portletPreferencesIds.getOwnerId(),
100 portletPreferencesIds.getOwnerType(),
101 portletPreferencesIds.getPlid(),
102 portletPreferencesIds.getPortletId());
103 }
104 }
105
106 }