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.scheduler;
029
030import org.opencms.scheduler.CmsScheduledJobInfo;
031import org.opencms.ui.CmsCssIcon;
032import org.opencms.ui.components.OpenCmsTheme;
033import org.opencms.util.CmsUUID;
034
035import java.util.Date;
036
037import com.vaadin.server.Resource;
038
039/**
040 * Don't use CmsScheduledJobInfo directly, so we don't need to change it if we want to change how the values are
041 * rendered, and having only the fields we want displayed in the table makes it easier to understand.
042 */
043public class CmsJobBean {
044
045    /** The job icon resource. */
046    private static CmsCssIcon ICON = new CmsCssIcon(OpenCmsTheme.ICON_JOB);
047
048    /** Internal id. */
049    private CmsUUID m_id = new CmsUUID();
050
051    /** The wrapped scheduled job info. */
052    protected CmsScheduledJobInfo m_jobInfo;
053
054    /**
055     * Creates a new instance.<p>
056     *
057     * @param info the scheduled job info to wrap
058     */
059    public CmsJobBean(CmsScheduledJobInfo info) {
060
061        m_jobInfo = info;
062    }
063
064    /**
065     * @see java.lang.Object#equals(java.lang.Object)
066     */
067    @Override
068    public boolean equals(Object obj) {
069
070        if (obj instanceof CmsJobBean) {
071            return ((CmsJobBean)obj).m_id.equals(m_id);
072        }
073        return false;
074
075    }
076
077    /**
078     * Gets the class name for the job.<p>
079     *
080     * @return the class name
081     */
082    public String getClassName() {
083
084        return m_jobInfo.getClassName();
085    }
086
087    /**
088     * Returns the job icon resource.<p>
089     *
090     * @return the job icon resource
091     */
092    public Resource getIcon() {
093
094        return ICON;
095    }
096
097    /**
098     * Gets the scheduled job.<p>
099     *
100     * @return the scheduled job
101     */
102    public CmsScheduledJobInfo getJob() {
103
104        return m_jobInfo;
105    }
106
107    /**
108     * Gets the last execution date.<p>
109     *
110     * @return the last execution date
111     */
112    public Date getLastExecution() {
113
114        return m_jobInfo.getExecutionTimePrevious();
115    }
116
117    /**
118     * Gets the job name.<p>
119     *
120     * @return the job name
121     */
122    public String getName() {
123
124        return m_jobInfo.getJobName();
125    }
126
127    /**
128     * Gets the next execution date.<p>
129     *
130     * @return the next execution date
131     */
132    public Date getNextExecution() {
133
134        return m_jobInfo.getExecutionTimeNext();
135    }
136
137    /**
138     * @see java.lang.Object#hashCode()
139     */
140    @Override
141    public int hashCode() {
142
143        return m_id.hashCode();
144    }
145}