001    /**
002     * Copyright (c) 2000-2013 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.monitoring.statistics.portlet;
016    
017    import com.liferay.portal.kernel.util.StringBundler;
018    import com.liferay.portal.model.Portlet;
019    import com.liferay.portal.monitoring.MonitorNames;
020    import com.liferay.portal.monitoring.statistics.BaseDataSample;
021    import com.liferay.portlet.PortletResponseImpl;
022    
023    import javax.portlet.PortletRequest;
024    import javax.portlet.PortletResponse;
025    
026    /**
027     * @author Karthik Sudarshan
028     * @author Michael C. Han
029     * @author Brian Wing Shun Chan
030     */
031    public class PortletRequestDataSample extends BaseDataSample {
032    
033            public PortletRequestDataSample(
034                    PortletRequestType requestType, PortletRequest portletRequest,
035                    PortletResponse portletResponse) {
036    
037                    PortletResponseImpl portletResponseImpl =
038                            (PortletResponseImpl)portletResponse;
039    
040                    Portlet portlet = portletResponseImpl.getPortlet();
041    
042                    setCompanyId(portlet.getCompanyId());
043                    setUser(portletRequest.getRemoteUser());
044                    setNamespace(MonitorNames.PORTLET);
045                    setName(portlet.getPortletName());
046                    _portletId = portlet.getPortletId();
047                    _displayName = portlet.getDisplayName();
048                    _requestType = requestType;
049            }
050    
051            public String getDisplayName() {
052                    return _displayName;
053            }
054    
055            public String getPortletId() {
056                    return _portletId;
057            }
058    
059            public PortletRequestType getRequestType() {
060                    return _requestType;
061            }
062    
063            @Override
064            public String toString() {
065                    StringBundler sb = new StringBundler(9);
066    
067                    sb.append("{displayName=");
068                    sb.append(_displayName);
069                    sb.append(", portletId=");
070                    sb.append(_portletId);
071                    sb.append(", requestType=");
072                    sb.append(_requestType);
073                    sb.append(", ");
074                    sb.append(super.toString());
075                    sb.append("}");
076    
077                    return sb.toString();
078            }
079    
080            private String _displayName;
081            private String _portletId;
082            private PortletRequestType _requestType;
083    
084    }