001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.json.JSONArray;
020    import com.liferay.portal.kernel.json.JSONFactoryUtil;
021    import com.liferay.portal.kernel.json.JSONObject;
022    import com.liferay.portal.kernel.jsonwebservice.JSONWebService;
023    import com.liferay.portal.kernel.jsonwebservice.JSONWebServiceMode;
024    import com.liferay.portal.model.Portlet;
025    import com.liferay.portal.model.PortletApp;
026    import com.liferay.portal.model.RoleConstants;
027    import com.liferay.portal.security.auth.PrincipalException;
028    import com.liferay.portal.service.base.PortletServiceBaseImpl;
029    
030    import java.util.List;
031    
032    /**
033     * @author Brian Wing Shun Chan
034     */
035    @JSONWebService(mode = JSONWebServiceMode.MANUAL)
036    public class PortletServiceImpl extends PortletServiceBaseImpl {
037    
038            public JSONArray getWARPortlets() {
039                    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
040    
041                    List<Portlet> portlets = portletLocalService.getPortlets();
042    
043                    for (Portlet portlet : portlets) {
044                            PortletApp portletApp = portlet.getPortletApp();
045    
046                            if (portletApp.isWARFile()) {
047                                    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
048    
049                                    jsonObject.put("portlet_name", portlet.getPortletName());
050                                    jsonObject.put(
051                                            "servlet_context_name", portletApp.getServletContextName());
052    
053                                    jsonArray.put(jsonObject);
054                            }
055                    }
056    
057                    return jsonArray;
058            }
059    
060            public Portlet updatePortlet(
061                            long companyId, String portletId, String roles, boolean active)
062                    throws PortalException, SystemException {
063    
064                    if (!roleLocalService.hasUserRole(
065                                    getUserId(), companyId, RoleConstants.ADMINISTRATOR, true)) {
066    
067                            throw new PrincipalException();
068                    }
069    
070                    return portletLocalService.updatePortlet(
071                            companyId, portletId, roles, active);
072            }
073    
074    }