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.db.CmsPublishedResource;
031import org.opencms.file.CmsResource;
032import org.opencms.main.CmsException;
033import org.opencms.main.CmsLog;
034import org.opencms.main.OpenCms;
035import org.opencms.publish.CmsPublishJobBase;
036import org.opencms.publish.CmsPublishJobEnqueued;
037import org.opencms.ui.A_CmsUI;
038import org.opencms.ui.CmsVaadinUtils;
039import org.opencms.ui.apps.Messages;
040import org.opencms.util.CmsUUID;
041
042import java.util.List;
043
044import org.apache.commons.logging.Log;
045
046import com.vaadin.v7.shared.ui.label.ContentMode;
047import com.vaadin.v7.ui.Label;
048import com.vaadin.v7.ui.VerticalLayout;
049
050/**
051 * Class for the published resources dialog.<p>
052 */
053public class CmsPublishResources extends VerticalLayout {
054
055    /** The logger for this class. */
056    private static Log LOG = CmsLog.getLog(CmsPublishResources.class.getName());
057
058    /**vaadin serial id.*/
059    private static final long serialVersionUID = -3197777771233458574L;
060
061    /**Caption of dialog.*/
062    private String m_caption;
063
064    /**vaadin component.*/
065    private VerticalLayout m_panel;
066
067    /**
068     * Public constructor.<p>
069     *
070     * @param id job-id
071     */
072    public CmsPublishResources(String id) {
073
074        CmsVaadinUtils.readAndLocalizeDesign(this, CmsVaadinUtils.getWpMessagesForCurrentLocale(), null);
075
076        final CmsPublishJobBase job = OpenCms.getPublishManager().getJobByPublishHistoryId(new CmsUUID(id));
077
078        m_caption = CmsVaadinUtils.getMessageText(
079            Messages.GUI_PQUEUE_RESOURCES_2,
080            job.getProjectName(),
081            job.getUserName(A_CmsUI.getCmsObject()));
082
083        String resourcesHTML = "";
084
085        try {
086            resourcesHTML = getResourcesHTML(job);
087        } catch (NumberFormatException | CmsException e) {
088            LOG.error("Error reading publish resources", e);
089        }
090
091        Label label = new Label();
092        label.setValue(resourcesHTML);
093        label.setContentMode(ContentMode.HTML);
094        label.setHeight("700px");
095        label.addStyleName("v-scrollable");
096        label.addStyleName("o-report");
097        m_panel.addComponent(label);
098
099    }
100
101    /**
102     * @see com.vaadin.ui.AbstractComponent#getCaption()
103     */
104    @Override
105    public String getCaption() {
106
107        return m_caption;
108    }
109
110    /**
111     * Get String with list of resources from given job formatted in HTML.<p>
112     *
113     * @param job CmsPublishJobBase
114     * @return String
115     * @throws CmsException exception
116     */
117    private String getResourcesHTML(CmsPublishJobBase job) throws CmsException {
118
119        String ret = "";
120        if (job instanceof CmsPublishJobEnqueued) {
121            //job is enqueued ->go over publish list
122            List<CmsResource> resources = ((CmsPublishJobEnqueued)job).getPublishList().getAllResources();
123            for (CmsResource res : resources) {
124                ret += res.getRootPath() + "<br/>";
125            }
126        } else {
127            //job is running or finished
128            List<CmsPublishedResource> resources = A_CmsUI.getCmsObject().readPublishedResources(
129                job.getPublishHistoryId());
130            for (CmsPublishedResource res : resources) {
131                ret += res.getRootPath() + "<br/>";
132            }
133        }
134        return ret;
135    }
136
137}