1
22
23 package com.liferay.portal.service;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.json.JSONObject;
27 import com.liferay.portal.kernel.util.LocaleUtil;
28 import com.liferay.portal.kernel.util.StringUtil;
29 import com.liferay.portal.model.PortletPreferencesIds;
30
31 import java.util.Locale;
32
33 import javax.portlet.PortletPreferences;
34
35
43 public class ServiceContextUtil {
44
45 public static Object deserialize(JSONObject jsonObject) {
46 ServiceContext serviceContext = new ServiceContext();
47
48
50 serviceContext.setCompanyId(jsonObject.getLong("companyId"));
51 serviceContext.setLayoutURL(jsonObject.getString("layoutURL"));
52 serviceContext.setPathMain(jsonObject.getString("pathMain"));
53 serviceContext.setPlid(jsonObject.getLong("plid"));
54 serviceContext.setPortalURL(jsonObject.getString("portalURL"));
55 serviceContext.setScopeGroupId(jsonObject.getLong("scopeGroupId"));
56 serviceContext.setUserDisplayURL(
57 jsonObject.getString("userDisplayURL"));
58
59
61 String[] communityPermissions = StringUtil.split(
62 jsonObject.getString("communityPermissions"));
63 String[] guestPermissions = StringUtil.split(
64 jsonObject.getString("guestPermissions"));
65
66 serviceContext.setAddCommunityPermissions(
67 jsonObject.getBoolean("addCommunityPermissions"));
68 serviceContext.setAddGuestPermissions(
69 jsonObject.getBoolean("addGuestPermissions"));
70 serviceContext.setCommunityPermissions(communityPermissions);
71 serviceContext.setGuestPermissions(guestPermissions);
72
73
75 String[] tagsCategories = StringUtil.split(
76 jsonObject.getString("tagsCategories"));
77 String[] tagsEntries = StringUtil.split(
78 jsonObject.getString("tagsEntries"));
79
80 serviceContext.setTagsCategories(tagsCategories);
81 serviceContext.setTagsEntries(tagsEntries);
82
83 return serviceContext;
84 }
85
86 public static Locale getLocale(ServiceContext serviceContext) {
87 return LocaleUtil.fromLanguageId(serviceContext.getLanguageId());
88 }
89
90 public static PortletPreferences getPortletPreferences(
91 ServiceContext serviceContext)
92 throws SystemException {
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 }