1
19
20 package com.liferay.portal.service;
21
22 import com.liferay.portal.SystemException;
23 import com.liferay.portal.kernel.json.JSONObject;
24 import com.liferay.portal.kernel.util.LocaleUtil;
25 import com.liferay.portal.kernel.util.StringUtil;
26 import com.liferay.portal.model.PortletPreferencesIds;
27
28 import java.util.Locale;
29
30 import javax.portlet.PortletPreferences;
31
32
40 public class ServiceContextUtil {
41
42 public static Object deserialize(JSONObject jsonObject) {
43 ServiceContext serviceContext = new ServiceContext();
44
45
47 serviceContext.setCompanyId(jsonObject.getLong("companyId"));
48 serviceContext.setLayoutURL(jsonObject.getString("layoutURL"));
49 serviceContext.setPathMain(jsonObject.getString("pathMain"));
50 serviceContext.setPlid(jsonObject.getLong("plid"));
51 serviceContext.setPortalURL(jsonObject.getString("portalURL"));
52 serviceContext.setScopeGroupId(jsonObject.getLong("scopeGroupId"));
53 serviceContext.setUserDisplayURL(
54 jsonObject.getString("userDisplayURL"));
55
56
58 String[] communityPermissions = StringUtil.split(
59 jsonObject.getString("communityPermissions"));
60 String[] guestPermissions = StringUtil.split(
61 jsonObject.getString("guestPermissions"));
62
63 serviceContext.setAddCommunityPermissions(
64 jsonObject.getBoolean("addCommunityPermissions"));
65 serviceContext.setAddGuestPermissions(
66 jsonObject.getBoolean("addGuestPermissions"));
67 serviceContext.setCommunityPermissions(communityPermissions);
68 serviceContext.setGuestPermissions(guestPermissions);
69
70
72 String[] tagsCategories = StringUtil.split(
73 jsonObject.getString("tagsCategories"));
74 String[] tagsEntries = StringUtil.split(
75 jsonObject.getString("tagsEntries"));
76
77 serviceContext.setTagsCategories(tagsCategories);
78 serviceContext.setTagsEntries(tagsEntries);
79
80 return serviceContext;
81 }
82
83 public static Locale getLocale(ServiceContext serviceContext) {
84 return LocaleUtil.fromLanguageId(serviceContext.getLanguageId());
85 }
86
87 public static PortletPreferences getPortletPreferences(
88 ServiceContext serviceContext)
89 throws SystemException {
90
91 if (serviceContext == null) {
92 return null;
93 }
94
95 PortletPreferencesIds portletPreferencesIds =
96 serviceContext.getPortletPreferencesIds();
97
98 if (portletPreferencesIds == null) {
99 return null;
100 }
101 else {
102 return PortletPreferencesLocalServiceUtil.getPreferences(
103 portletPreferencesIds.getCompanyId(),
104 portletPreferencesIds.getOwnerId(),
105 portletPreferencesIds.getOwnerType(),
106 portletPreferencesIds.getPlid(),
107 portletPreferencesIds.getPortletId());
108 }
109 }
110
111 }