001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.ui.apps.publishqueue;
029
030import org.opencms.main.CmsException;
031import org.opencms.main.CmsLog;
032import org.opencms.main.OpenCms;
033import org.opencms.publish.CmsPublishJobBase;
034import org.opencms.publish.CmsPublishJobFinished;
035import org.opencms.publish.CmsPublishJobRunning;
036import org.opencms.report.A_CmsReportThread;
037import org.opencms.ui.A_CmsUI;
038import org.opencms.ui.CmsVaadinUtils;
039import org.opencms.ui.apps.Messages;
040import org.opencms.ui.report.CmsReportWidget;
041import org.opencms.util.CmsUUID;
042
043import org.apache.commons.logging.Log;
044
045import com.vaadin.v7.shared.ui.label.ContentMode;
046import com.vaadin.v7.ui.Label;
047import com.vaadin.v7.ui.VerticalLayout;
048
049/**
050 * Vertical Layout showing a publish report of a publish job.<p>
051 */
052
053public class CmsPublishReport extends VerticalLayout {
054
055    /** The logger for this class. */
056    private static Log LOG = CmsLog.getLog(CmsPublishReport.class.getName());
057
058    /**vaadin serial id. */
059    private static final long serialVersionUID = -1630983150603283505L;
060
061    /**object which calls table.*/
062    CmsPublishQueue m_manager;
063
064    /**job id.*/
065    private CmsUUID m_jobId;
066
067    /**vaadin component.*/
068    private VerticalLayout m_panel;
069
070    /**Caption of layout.*/
071    private String m_caption;
072
073    /**
074     * public constructor.<p>
075     *
076     * @param jobId of chosen job
077     */
078    public CmsPublishReport(String jobId) {
079
080        CmsVaadinUtils.readAndLocalizeDesign(this, CmsVaadinUtils.getWpMessagesForCurrentLocale(), null);
081
082        m_jobId = new CmsUUID(jobId);
083
084        //Obtain job and fill panel with CmsReportWidget
085        final CmsPublishJobBase job = OpenCms.getPublishManager().getJobByPublishHistoryId(m_jobId);
086
087        m_caption = CmsVaadinUtils.getMessageText(
088            Messages.GUI_PQUEUE_REPORT_2,
089            job.getProjectName(),
090            job.getUserName(A_CmsUI.getCmsObject()));
091        //switch for job type
092        if (job instanceof CmsPublishJobRunning) {
093            //Running job
094            A_CmsReportThread thread = OpenCms.getThreadStore().retrieveThread(
095                ((CmsPublishJobRunning)job).getThreadUUID());
096            CmsReportWidget report = new CmsReportWidget(thread);
097
098            report.setWidth("100%");
099            report.setHeight("700px");
100            m_panel.addComponent(report);
101
102        } else {
103            //finished job
104            String reportHTML = "";
105            try {
106                reportHTML = new String(OpenCms.getPublishManager().getReportContents((CmsPublishJobFinished)job));
107            } catch (CmsException e) {
108                LOG.error("Error reading Report content of publish job.", e);
109            }
110            Label label = new Label();
111            label.setValue(reportHTML);
112            label.setContentMode(ContentMode.HTML);
113            label.setHeight("700px");
114            label.addStyleName("v-scrollable");
115            label.addStyleName("o-report");
116            m_panel.addComponent(label);
117        }
118    }
119
120    /**
121     * @see com.vaadin.ui.AbstractComponent#getCaption()
122     */
123    @Override
124    public String getCaption() {
125
126        return m_caption;
127    }
128}