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.portlet.admin.poller;
016    
017    import com.liferay.portal.kernel.json.JSONFactoryUtil;
018    import com.liferay.portal.kernel.json.JSONObject;
019    import com.liferay.portal.kernel.poller.BasePollerProcessor;
020    import com.liferay.portal.kernel.poller.PollerRequest;
021    import com.liferay.portal.kernel.poller.PollerResponse;
022    import com.liferay.portal.kernel.xuggler.XugglerInstallStatus;
023    import com.liferay.portal.util.WebKeys;
024    
025    import javax.servlet.http.HttpServletRequest;
026    import javax.servlet.http.HttpSession;
027    
028    /**
029     * @author Sergio Gonz??lez
030     */
031    public class AdminPollerProcessor extends BasePollerProcessor {
032    
033            @Override
034            protected void doReceive(
035                            PollerRequest pollerRequest, PollerResponse pollerResponse)
036                    throws Exception {
037    
038                    pollerResponse.setParameter(
039                            PollerResponse.POLLER_HINT_HIGH_CONNECTIVITY,
040                            Boolean.TRUE.toString());
041    
042                    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
043    
044                    String statusLabel = "unknown";
045    
046                    XugglerInstallStatus xugglerInstallStatus = getXugglerInstallStatus(
047                            pollerRequest);
048    
049                    if (xugglerInstallStatus != null) {
050                            statusLabel = xugglerInstallStatus.getStatusLabel();
051                    }
052    
053                    jsonObject.put("status", statusLabel);
054    
055                    boolean success = false;
056    
057                    if (!statusLabel.equals("unknown")) {
058                            success = true;
059                    }
060    
061                    jsonObject.put("success", success);
062    
063                    pollerResponse.setParameter("status", jsonObject);
064            }
065    
066            @Override
067            protected void doSend(PollerRequest pollerRequest) throws Exception {
068                    return;
069            }
070    
071            protected XugglerInstallStatus getXugglerInstallStatus(
072                    PollerRequest pollerRequest) {
073    
074                    HttpServletRequest request = pollerRequest.getRequest();
075    
076                    HttpSession session = request.getSession();
077    
078                    return (XugglerInstallStatus)session.getAttribute(
079                            WebKeys.XUGGLER_INSTALL_STATUS);
080            }
081    
082    }