1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.service.impl;
16  
17  import com.liferay.portal.kernel.exception.PortalException;
18  import com.liferay.portal.kernel.exception.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  }