001    /**
002     * Copyright (c) 2000-2010 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.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.model.Portlet;
023    import com.liferay.portal.model.PortletApp;
024    import com.liferay.portal.model.RoleConstants;
025    import com.liferay.portal.security.auth.PrincipalException;
026    import com.liferay.portal.service.base.PortletServiceBaseImpl;
027    
028    import java.util.List;
029    
030    /**
031     * @author Brian Wing Shun Chan
032     */
033    public class PortletServiceImpl extends PortletServiceBaseImpl {
034    
035            public JSONArray getWARPortlets() {
036                    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
037    
038                    List<Portlet> portlets = portletLocalService.getPortlets();
039    
040                    for (Portlet portlet : portlets) {
041                            PortletApp portletApp = portlet.getPortletApp();
042    
043                            if (portletApp.isWARFile()) {
044                                    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
045    
046                                    jsonObject.put("portlet_name", portlet.getPortletName());
047                                    jsonObject.put(
048                                            "servlet_context_name",
049                                            portletApp.getServletContextName());
050    
051                                    jsonArray.put(jsonObject);
052                            }
053                    }
054    
055                    return jsonArray;
056            }
057    
058            public Portlet updatePortlet(
059                            long companyId, String portletId, String roles, boolean active)
060                    throws PortalException, SystemException {
061    
062                    if (!roleLocalService.hasUserRole(
063                                    getUserId(), companyId, RoleConstants.ADMINISTRATOR, true)) {
064    
065                            throw new PrincipalException();
066                    }
067    
068                    return portletLocalService.updatePortlet(
069                            companyId, portletId, roles, active);
070            }
071    
072    }