001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.service.http;
022:
023: import com.liferay.portal.service.RoleServiceUtil;
024:
025: import org.json.JSONArray;
026: import org.json.JSONObject;
027:
028: /**
029: * <a href="RoleServiceJSON.java.html"><b><i>View Source</i></b></a>
030: *
031: * <p>
032: * ServiceBuilder generated this class. Modifications in this class will be
033: * overwritten the next time is generated.
034: * </p>
035: *
036: * <p>
037: * This class provides a JSON utility for the
038: * <code>com.liferay.portal.service.RoleServiceUtil</code>
039: * service utility. The static methods of this class calls the same methods of
040: * the service utility. However, the signatures are different because it is
041: * difficult for JSON to support certain types.
042: * </p>
043: *
044: * <p>
045: * ServiceBuilder follows certain rules in translating the methods. For example,
046: * if the method in the service utility returns a <code>java.util.List</code>,
047: * that is translated to a <code>org.json.JSONArray</code>. If the method in the
048: * service utility returns a <code>com.liferay.portal.model.Role</code>,
049: * that is translated to a <code>org.json.JSONObject</code>. Methods that JSON
050: * cannot safely use are skipped. The logic for the translation is encapsulated
051: * in <code>com.liferay.portal.service.http.RoleJSONSerializer</code>.
052: * </p>
053: *
054: * <p>
055: * This allows you to call the the backend services directly from JavaScript.
056: * See <code>portal-web/docroot/html/portlet/tags_admin/unpacked.js</code> for a
057: * reference of how that portlet uses the generated JavaScript in
058: * <code>portal-web/docroot/html/js/service.js</code> to call the backend
059: * services directly from JavaScript.
060: * </p>
061: *
062: * <p>
063: * The JSON utility is only generated for remote services.
064: * </p>
065: *
066: * @author Brian Wing Shun Chan
067: *
068: * @see com.liferay.portal.service.RoleServiceUtil
069: * @see com.liferay.portal.service.http.RoleJSONSerializer
070: *
071: */
072: public class RoleServiceJSON {
073: public static JSONObject addRole(java.lang.String name,
074: java.lang.String description, int type)
075: throws java.rmi.RemoteException,
076: com.liferay.portal.SystemException,
077: com.liferay.portal.PortalException {
078: com.liferay.portal.model.Role returnValue = RoleServiceUtil
079: .addRole(name, description, type);
080:
081: return RoleJSONSerializer.toJSONObject(returnValue);
082: }
083:
084: public static void addUserRoles(long userId, long[] roleIds)
085: throws java.rmi.RemoteException,
086: com.liferay.portal.SystemException,
087: com.liferay.portal.PortalException {
088: RoleServiceUtil.addUserRoles(userId, roleIds);
089: }
090:
091: public static void deleteRole(long roleId)
092: throws java.rmi.RemoteException,
093: com.liferay.portal.SystemException,
094: com.liferay.portal.PortalException {
095: RoleServiceUtil.deleteRole(roleId);
096: }
097:
098: public static JSONObject getGroupRole(long companyId, long groupId)
099: throws java.rmi.RemoteException,
100: com.liferay.portal.SystemException,
101: com.liferay.portal.PortalException {
102: com.liferay.portal.model.Role returnValue = RoleServiceUtil
103: .getGroupRole(companyId, groupId);
104:
105: return RoleJSONSerializer.toJSONObject(returnValue);
106: }
107:
108: public static JSONArray getGroupRoles(long groupId)
109: throws java.rmi.RemoteException,
110: com.liferay.portal.SystemException,
111: com.liferay.portal.PortalException {
112: java.util.List returnValue = RoleServiceUtil
113: .getGroupRoles(groupId);
114:
115: return RoleJSONSerializer.toJSONArray(returnValue);
116: }
117:
118: public static JSONObject getRole(long roleId)
119: throws java.rmi.RemoteException,
120: com.liferay.portal.SystemException,
121: com.liferay.portal.PortalException {
122: com.liferay.portal.model.Role returnValue = RoleServiceUtil
123: .getRole(roleId);
124:
125: return RoleJSONSerializer.toJSONObject(returnValue);
126: }
127:
128: public static JSONObject getRole(long companyId,
129: java.lang.String name) throws java.rmi.RemoteException,
130: com.liferay.portal.SystemException,
131: com.liferay.portal.PortalException {
132: com.liferay.portal.model.Role returnValue = RoleServiceUtil
133: .getRole(companyId, name);
134:
135: return RoleJSONSerializer.toJSONObject(returnValue);
136: }
137:
138: public static JSONArray getUserGroupRoles(long userId, long groupId)
139: throws java.rmi.RemoteException,
140: com.liferay.portal.SystemException,
141: com.liferay.portal.PortalException {
142: java.util.List returnValue = RoleServiceUtil.getUserGroupRoles(
143: userId, groupId);
144:
145: return RoleJSONSerializer.toJSONArray(returnValue);
146: }
147:
148: public static JSONArray getUserRelatedRoles(long userId,
149: java.util.List groups) throws java.rmi.RemoteException,
150: com.liferay.portal.SystemException,
151: com.liferay.portal.PortalException {
152: java.util.List returnValue = RoleServiceUtil
153: .getUserRelatedRoles(userId, groups);
154:
155: return RoleJSONSerializer.toJSONArray(returnValue);
156: }
157:
158: public static JSONArray getUserRoles(long userId)
159: throws java.rmi.RemoteException,
160: com.liferay.portal.SystemException,
161: com.liferay.portal.PortalException {
162: java.util.List returnValue = RoleServiceUtil
163: .getUserRoles(userId);
164:
165: return RoleJSONSerializer.toJSONArray(returnValue);
166: }
167:
168: public static boolean hasUserRole(long userId, long companyId,
169: java.lang.String name, boolean inherited)
170: throws java.rmi.RemoteException,
171: com.liferay.portal.SystemException,
172: com.liferay.portal.PortalException {
173: boolean returnValue = RoleServiceUtil.hasUserRole(userId,
174: companyId, name, inherited);
175:
176: return returnValue;
177: }
178:
179: public static boolean hasUserRoles(long userId, long companyId,
180: java.lang.String[] names, boolean inherited)
181: throws java.rmi.RemoteException,
182: com.liferay.portal.SystemException,
183: com.liferay.portal.PortalException {
184: boolean returnValue = RoleServiceUtil.hasUserRoles(userId,
185: companyId, names, inherited);
186:
187: return returnValue;
188: }
189:
190: public static void unsetUserRoles(long userId, long[] roleIds)
191: throws java.rmi.RemoteException,
192: com.liferay.portal.SystemException,
193: com.liferay.portal.PortalException {
194: RoleServiceUtil.unsetUserRoles(userId, roleIds);
195: }
196:
197: public static JSONObject updateRole(long roleId,
198: java.lang.String name, java.lang.String description)
199: throws java.rmi.RemoteException,
200: com.liferay.portal.SystemException,
201: com.liferay.portal.PortalException {
202: com.liferay.portal.model.Role returnValue = RoleServiceUtil
203: .updateRole(roleId, name, description);
204:
205: return RoleJSONSerializer.toJSONObject(returnValue);
206: }
207: }
|