001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.json.JSONArray;
019    import com.liferay.portal.kernel.json.JSONFactoryUtil;
020    import com.liferay.portal.kernel.json.JSONObject;
021    import com.liferay.portal.kernel.jsonwebservice.JSONWebService;
022    import com.liferay.portal.kernel.jsonwebservice.JSONWebServiceMode;
023    import com.liferay.portal.model.Portlet;
024    import com.liferay.portal.model.PortletApp;
025    import com.liferay.portal.model.RoleConstants;
026    import com.liferay.portal.security.auth.PrincipalException;
027    import com.liferay.portal.service.base.PortletServiceBaseImpl;
028    
029    import java.util.List;
030    
031    /**
032     * @author Brian Wing Shun Chan
033     */
034    @JSONWebService(mode = JSONWebServiceMode.MANUAL)
035    public class PortletServiceImpl extends PortletServiceBaseImpl {
036    
037            @Override
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            @Override
061            public Portlet updatePortlet(
062                            long companyId, String portletId, String roles, boolean active)
063                    throws PortalException {
064    
065                    if (!roleLocalService.hasUserRole(
066                                    getUserId(), companyId, RoleConstants.ADMINISTRATOR, true)) {
067    
068                            throw new PrincipalException();
069                    }
070    
071                    return portletLocalService.updatePortlet(
072                            companyId, portletId, roles, active);
073            }
074    
075    }