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.kernel.poller;
016    
017    import com.liferay.portal.kernel.util.StringBundler;
018    import com.liferay.portal.kernel.util.Validator;
019    
020    import java.util.Collections;
021    import java.util.Map;
022    import java.util.Set;
023    
024    import javax.servlet.http.HttpServletRequest;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     */
029    public class PollerRequest {
030    
031            public PollerRequest(
032                    HttpServletRequest request, PollerHeader pollerHeader, String portletId,
033                    Map<String, String> parameterMap, String chunkId,
034                    boolean receiveRequest) {
035    
036                    _request = request;
037                    _pollerHeader = pollerHeader;
038                    _portletId = portletId;
039                    _parameterMap = parameterMap;
040                    _chunkId = chunkId;
041                    _receiveRequest = receiveRequest;
042            }
043    
044            @Override
045            public boolean equals(Object obj) {
046                    if (this == obj) {
047                            return true;
048                    }
049    
050                    if (!(obj instanceof PollerRequest)) {
051                            return false;
052                    }
053    
054                    PollerRequest portletRequest = (PollerRequest)obj;
055    
056                    if (Validator.equals(_portletId, portletRequest._portletId)) {
057                            return true;
058                    }
059    
060                    return false;
061            }
062    
063            public long getBrowserKey() {
064                    return _pollerHeader.getBrowserKey();
065            }
066    
067            public String getChunkId() {
068                    return _chunkId;
069            }
070    
071            public long getCompanyId() {
072                    return _pollerHeader.getCompanyId();
073            }
074    
075            public Map<String, String> getParameterMap() {
076                    return _parameterMap;
077            }
078    
079            public PollerHeader getPollerHeader() {
080                    return _pollerHeader;
081            }
082    
083            public String getPortletId() {
084                    return _portletId;
085            }
086    
087            public Set<String> getPortletIds() {
088                    Map<String, Boolean> portletIdsMap = _pollerHeader.getPortletIdsMap();
089    
090                    return portletIdsMap.keySet();
091            }
092    
093            public HttpServletRequest getRequest() {
094                    return _request;
095            }
096    
097            public long getTimestamp() {
098                    return _pollerHeader.getTimestamp();
099            }
100    
101            public long getUserId() {
102                    return _pollerHeader.getUserId();
103            }
104    
105            @Override
106            public int hashCode() {
107                    if (_portletId != null) {
108                            return _portletId.hashCode();
109                    }
110                    else {
111                            return 0;
112                    }
113            }
114    
115            public boolean isInitialRequest() {
116                    Map<String, Boolean> portletIdsMap = _pollerHeader.getPortletIdsMap();
117    
118                    return portletIdsMap.get(_portletId);
119            }
120    
121            public boolean isReceiveRequest() {
122                    return _receiveRequest;
123            }
124    
125            public boolean isStartPolling() {
126                    return _pollerHeader.isStartPolling();
127            }
128    
129            @Override
130            public String toString() {
131                    StringBundler sb = new StringBundler(11);
132    
133                    sb.append("{chunkId=");
134                    sb.append(_chunkId);
135                    sb.append(", parameterMap=");
136                    sb.append(_parameterMap);
137                    sb.append(", pollerHeader=");
138                    sb.append(_pollerHeader);
139                    sb.append(", portletId=");
140                    sb.append(_portletId);
141                    sb.append(", receiveRequest=");
142                    sb.append(_receiveRequest);
143                    sb.append("}");
144    
145                    return sb.toString();
146            }
147    
148            private String _chunkId;
149            private Map<String, String> _parameterMap = Collections.emptyMap();
150            private PollerHeader _pollerHeader;
151            private String _portletId;
152            private boolean _receiveRequest;
153            private HttpServletRequest _request;
154    
155    }