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.notification;
029
030import org.opencms.file.CmsResource;
031
032import java.util.Date;
033
034/**
035 * Class to encapsulate a resource and the cause of its notification.<p>
036 *
037 */
038public class CmsExtendedNotificationCause implements Comparable<CmsExtendedNotificationCause> {
039
040    /** The notification is sent because the resource will expire soon. */
041    public static final int RESOURCE_EXPIRES = 0;
042
043    /** The notification is sent because the resource will get outdated. */
044    public static final int RESOURCE_OUTDATED = 1;
045
046    /** constant indicating the cause of the notification for a resource. */
047    public static final int RESOURCE_UPDATE_REQUIRED = 2;
048
049    /** The notification is sent because the resource will be released soon. */
050    public static final int RESOURCE_RELEASE = 3;
051
052    /** The reason that the resource occures in the notification. */
053    private int m_cause;
054
055    /** The date when the event (e.g. release or expiration) will happen. */
056    private Date m_date;
057
058    /** The resource. */
059    private CmsResource m_resource;
060
061    /**
062     * Creates a new CmsNotificationResourceInfo.<p>
063     *
064     * @param resource the specific resource
065     * @param cause that the resource occures in the notification
066     * @param date when the event will happen
067     */
068    public CmsExtendedNotificationCause(CmsResource resource, int cause, Date date) {
069
070        m_resource = resource;
071        m_cause = cause;
072        m_date = date;
073    }
074
075    /**
076     *
077     * @see java.lang.Comparable#compareTo(java.lang.Object)
078     */
079    public int compareTo(CmsExtendedNotificationCause o) {
080
081        return getDate().compareTo(o.getDate());
082    }
083
084    /**
085     * Returns true if the Object equals to the corresponding CmsResourceInfo, that means a resource info
086     * with the same resource and cause.
087     *
088     * @return true if the resource info is equal to a notification cause or resource info with the same resource and cause
089     *
090     * @param o the object to check for equality
091     *
092     * @see org.opencms.notification.CmsNotificationCause#equals(java.lang.Object)
093     */
094    @Override
095    public boolean equals(Object o) {
096
097        if (!(o instanceof CmsExtendedNotificationCause) && !(o instanceof CmsNotificationCause)) {
098            return false;
099        }
100        return hashCode() == o.hashCode();
101    }
102
103    /**
104     *
105     * @see java.lang.Object#hashCode()
106     */
107    @Override
108    public int hashCode() {
109
110        return m_cause + m_resource.getStructureId().hashCode();
111    }
112
113    /**
114     * Returns the cause.<p>
115     *
116     * @return the cause
117     */
118    public int getCause() {
119
120        return m_cause;
121    }
122
123    /**
124     * Returns the date.<p>
125     *
126     * @return the date
127     */
128    public Date getDate() {
129
130        return m_date;
131    }
132
133    /**
134     * Returns the resource.<p>
135     *
136     * @return the resource
137     */
138    public CmsResource getResource() {
139
140        return m_resource;
141    }
142
143    /**
144     * Sets the cause.<p>
145     *
146     * @param cause the cause to set
147     */
148    public void setCause(int cause) {
149
150        m_cause = cause;
151    }
152
153    /**
154     * Sets the date.<p>
155     *
156     * @param date the date to set
157     */
158    public void setDate(Date date) {
159
160        m_date = date;
161    }
162
163    /**
164     * Sets the resource.<p>
165     *
166     * @param resource the resource to set
167     */
168    public void setResource(CmsResource resource) {
169
170        m_resource = resource;
171    }
172}