001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018:
019: package org.apache.roller.pojos;
020:
021: import java.io.Serializable;
022: import java.sql.Timestamp;
023:
024: /**
025: * Ping target. Each instance represents a possible target of a weblog update ping that we send. Ping targets are
026: * either common (defined centrally by an administrator and used by any website), or custom (defined by the user of a
027: * specific website) for update pings issued for that website.
028: *
029: * @author <a href="mailto:anil@busybuddha.org">Anil Gangolli</a>
030: * @ejb:bean name="PingTargetData"
031: * @struts.form include-all="true"
032: * @hibernate.class lazy="false" table="pingtarget"
033: * @hibernate.cache usage="read-write"
034: */
035: public class PingTargetData extends PersistentObject implements
036: Serializable {
037:
038: public static final long serialVersionUID = -6354583200913127874L;
039:
040: public static final int CONDITION_OK = 0; // last use (after possible retrials) was successful
041: public static final int CONDITION_FAILING = 1; // last use failed after retrials
042: public static final int CONDITION_DISABLED = 2; // disabled by failure policy after failures - editing resets
043:
044: private String id = null;
045: private String name = null;
046: private String pingUrl = null;
047: private WebsiteData website = null;
048: private int conditionCode = -1;
049: private Timestamp lastSuccess = null;
050: private boolean autoEnabled = false;
051:
052: /**
053: * Default empty constructor.
054: */
055: public PingTargetData() {
056: }
057:
058: /**
059: * Constructor.
060: *
061: * @param id the id (primary key) of this target
062: * @param name the descriptive name of this target
063: * @param pingUrl the URL to which to send the ping
064: * @param website the website (on this server) for which this is a custom ping target (may be null)
065: */
066: public PingTargetData(String id, String name, String pingUrl,
067: WebsiteData website, boolean autoEnable) {
068: this .id = id;
069: this .name = name;
070: this .pingUrl = pingUrl;
071: this .website = website;
072: this .conditionCode = CONDITION_OK;
073: this .lastSuccess = null;
074: this .autoEnabled = autoEnable;
075: }
076:
077: /**
078: * Setter needed by RollerImpl.storePersistentObject()
079: */
080: public void setData(PersistentObject vo) {
081: PingTargetData other = (PingTargetData) vo;
082:
083: id = other.getId();
084: name = other.getName();
085: pingUrl = other.getPingUrl();
086: website = other.getWebsite();
087: conditionCode = other.getConditionCode();
088: lastSuccess = other.getLastSuccess();
089: autoEnabled = other.isAutoEnabled();
090: }
091:
092: /**
093: * Get the unique id of this ping target.
094: *
095: * @return the unique id of this ping target.
096: * @struts.validator type="required" msgkey="errors.required"
097: * @ejb:persistent-field
098: * @hibernate.id column="id" generator-class="uuid.hex" unsaved-value="null"
099: */
100: public java.lang.String getId() {
101: return this .id;
102: }
103:
104: /**
105: * Set the unique id of this ping target
106: *
107: * @param id
108: * @ejb:persistent-field
109: */
110: public void setId(java.lang.String id) {
111: this .id = id;
112: }
113:
114: /**
115: * get the name of this ping target. This is a name assigned by the administrator or a user (for custom) targets.
116: * It is deescriptive and is not necessarily unique.
117: *
118: * @return the name of this ping target
119: * @ejb:persistent-field
120: * @hibernate.property column="name" non-null="true"
121: */
122: public java.lang.String getName() {
123: return this .name;
124: }
125:
126: /**
127: * Set the name of this ping target.
128: *
129: * @param name the name of this ping target
130: * @ejb:persistent-field
131: */
132: public void setName(java.lang.String name) {
133: this .name = name;
134: }
135:
136: /**
137: * Get the URL to ping.
138: *
139: * @return the URL to ping.
140: * @ejb:persistent-field
141: * @hibernate.property column="pingurl" non-null="true"
142: */
143: public String getPingUrl() {
144: return pingUrl;
145: }
146:
147: /**
148: * Set the URL to ping.
149: *
150: * @param pingUrl
151: * @ejb:persistent-field
152: */
153: public void setPingUrl(String pingUrl) {
154: this .pingUrl = pingUrl;
155: }
156:
157: /**
158: * Get the website (on this server) for which this ping target is a custom target. This may be null, indicating
159: * that it is a common ping target, not a custom one.
160: *
161: * @return the website for which this ping target is a custom target, or null if this ping target is not a custom
162: * target.
163: * @ejb:persistent-field
164: * @hibernate.many-to-one column="websiteid" cascade="none" not-null="false"
165: */
166: public WebsiteData getWebsite() {
167: return website;
168: }
169:
170: /**
171: * Set the website (on this server) for which this ping target is a custom target.
172: *
173: * @param website the website for which this ping target is a custom target, or null if this ping target is not a
174: * custom target
175: * @ejb:persistent-field
176: */
177: public void setWebsite(WebsiteData website) {
178: this .website = website;
179: }
180:
181: /**
182: * Get the condition code value. This code, in combination with the last success timestamp, provides a status
183: * indicator on the ping target based on its usage by the ping queue processor. It can be used to implement a
184: * failure-based disabling policy.
185: *
186: * @return one of the condition codes {@link #CONDITION_OK}, {@link #CONDITION_FAILING}, {@link
187: * #CONDITION_DISABLED}.
188: * @ejb:persistent-field
189: * @hibernate.property column="conditioncode" not-null="true"
190: */
191: public int getConditionCode() {
192: return conditionCode;
193: }
194:
195: /**
196: * Set the condition code value.
197: *
198: * @param conditionCode the condition code value to set
199: * @ejb:persistent-field
200: */
201: public void setConditionCode(int conditionCode) {
202: this .conditionCode = conditionCode;
203: }
204:
205: /**
206: * Get the timestamp of the last successful ping (UTC/GMT).
207: *
208: * @return the timestamp of the last successful ping; <code>null</code> if the target has not yet been used.
209: * @ejb:persistent-field
210: * @hibernate.property column="lastsuccess" not-null="false"
211: */
212: public Timestamp getLastSuccess() {
213: return lastSuccess;
214: }
215:
216: /**
217: * Set the timestamp of the last successful ping.
218: *
219: * @param lastSuccess the timestamp of the last successful ping.
220: * @ejb:persistent-field
221: */
222: public void setLastSuccess(Timestamp lastSuccess) {
223: this .lastSuccess = lastSuccess;
224: }
225:
226: /**
227: * Is this ping target enabled by default for new weblogs?
228: *
229: * @return true if ping target is auto enabled. false otherwise.
230: * @ejb:persistent-field
231: * @hibernate.property column="autoenabled" not-null="true"
232: */
233: public boolean isAutoEnabled() {
234: return autoEnabled;
235: }
236:
237: /**
238: * Set the auto enabled status for this ping target. This field only
239: * applies for common ping targets.
240: *
241: * @param autoEnabled true if the ping target should be auto enabled.
242: * @ejb:persistent-field
243: */
244: public void setAutoEnabled(boolean autoEnabled) {
245: this .autoEnabled = autoEnabled;
246: }
247:
248: /**
249: * @see java.lang.Object#hashCode()
250: */
251: public int hashCode() {
252: return id.hashCode();
253: }
254:
255: /**
256: * @see java.lang.Object#equals(Object o)
257: */
258: public boolean equals(Object o) {
259: if (this == o)
260: return true;
261: if (!(o instanceof PingTargetData))
262: return false;
263:
264: final PingTargetData pingTargetData = (PingTargetData) o;
265:
266: if (conditionCode != pingTargetData.getConditionCode())
267: return false;
268: if (id != null ? !id.equals(pingTargetData.getId())
269: : pingTargetData.getId() != null)
270: return false;
271: if (lastSuccess != null ? !lastSuccess.equals(pingTargetData
272: .getLastSuccess())
273: : pingTargetData.getLastSuccess() != null) {
274: return false;
275: }
276: if (name != null ? !name.equals(pingTargetData.getName())
277: : pingTargetData.getName() != null)
278: return false;
279: if (pingUrl != null ? !pingUrl.equals(pingTargetData
280: .getPingUrl()) : pingTargetData.getPingUrl() != null) {
281: return false;
282: }
283: if (website != null ? !website.equals(pingTargetData
284: .getWebsite()) : pingTargetData.getWebsite() != null) {
285: return false;
286: }
287:
288: return true;
289: }
290:
291: /**
292: * Generate a string form of the object appropriate for logging or debugging.
293: *
294: * @return a string form of the object appropriate for logging or debugging.
295: * @see java.lang.Object#toString()
296: */
297: public String toString() {
298: return "PingTargetData{"
299: + "id='"
300: + id
301: + "'"
302: + ", name='"
303: + name
304: + "'"
305: + ", pingUrl='"
306: + pingUrl
307: + "'"
308: + ", website= "
309: + (website == null ? "null" : "{id='" + website.getId()
310: + "'} ") + ", conditionCode=" + conditionCode
311: + ", lastSuccess=" + lastSuccess + "}";
312: }
313:
314: }
|