1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.service.impl;
16  
17  import com.liferay.portal.PortalException;
18  import com.liferay.portal.SystemException;
19  import com.liferay.portal.kernel.json.JSONArray;
20  import com.liferay.portal.kernel.json.JSONFactoryUtil;
21  import com.liferay.portal.kernel.json.JSONObject;
22  import com.liferay.portal.model.Portlet;
23  import com.liferay.portal.model.PortletApp;
24  import com.liferay.portal.model.RoleConstants;
25  import com.liferay.portal.security.auth.PrincipalException;
26  import com.liferay.portal.service.base.PortletServiceBaseImpl;
27  
28  import java.util.List;
29  
30  /**
31   * <a href="PortletServiceImpl.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Brian Wing Shun Chan
34   */
35  public class PortletServiceImpl extends PortletServiceBaseImpl {
36  
37      public JSONArray getWARPortlets() {
38          JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
39  
40          List<Portlet> portlets = portletLocalService.getPortlets();
41  
42          for (Portlet portlet : portlets) {
43              PortletApp portletApp = portlet.getPortletApp();
44  
45              if (portletApp.isWARFile()) {
46                  JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
47  
48                  jsonObject.put("portlet_name", portlet.getPortletName());
49                  jsonObject.put(
50                      "servlet_context_name",
51                      portletApp.getServletContextName());
52  
53                  jsonArray.put(jsonObject);
54              }
55          }
56  
57          return jsonArray;
58      }
59  
60      public Portlet updatePortlet(
61              long companyId, String portletId, String roles, boolean active)
62          throws PortalException, SystemException {
63  
64          if (!roleLocalService.hasUserRole(
65                  getUserId(), companyId, RoleConstants.ADMINISTRATOR, true)) {
66  
67              throw new PrincipalException();
68          }
69  
70          return portletLocalService.updatePortlet(
71              companyId, portletId, roles, active);
72      }
73  
74  }