1 7 8 package org.roller.pojos; 9 10 import org.roller.RollerException; 11 import org.roller.model.Roller; 12 import org.roller.model.RollerFactory; 13 import org.roller.model.AutoPingManager; 14 import org.roller.model.PingQueueManager; 15 16 import java.io.Serializable ; 17 import java.util.List ; 18 import java.sql.Timestamp ; 19 20 30 public class PingTargetData extends PersistentObject implements Serializable 31 { 32 protected String id; 33 protected String name; 34 protected String pingUrl; 35 protected WebsiteData website; 36 protected int conditionCode; 37 protected Timestamp lastSuccess; 38 39 public static final int CONDITION_OK = 0; public static final int CONDITION_FAILING = 1; public static final int CONDITION_DISABLED = 2; 43 static final long serialVersionUID = -6354583200913127874L; 44 45 48 public PingTargetData() 49 { 50 } 51 52 60 public PingTargetData(String id, String name, String pingUrl, WebsiteData website) 61 { 62 this.id = id; 63 this.name = name; 64 this.pingUrl = pingUrl; 65 this.website = website; 66 this.conditionCode = CONDITION_OK; 67 this.lastSuccess = null; 68 } 69 70 73 public void setData(PersistentObject vo) 74 { 75 PingTargetData other = (PingTargetData) vo; 76 id = other.id; 77 name = other.name; 78 pingUrl = other.pingUrl; 79 website = other.website; 80 conditionCode = other.conditionCode; 81 lastSuccess = other.lastSuccess; 82 } 83 84 85 93 public java.lang.String getId() 94 { 95 return this.id; 96 } 97 98 104 public void setId(java.lang.String id) 105 { 106 this.id = id; 107 } 108 109 117 public java.lang.String getName() 118 { 119 return this.name; 120 } 121 122 128 public void setName(java.lang.String name) 129 { 130 this.name = name; 131 } 132 133 140 public String getPingUrl() 141 { 142 return pingUrl; 143 } 144 145 151 public void setPingUrl(String pingUrl) 152 { 153 this.pingUrl = pingUrl; 154 } 155 156 165 public WebsiteData getWebsite() 166 { 167 return website; 168 } 169 170 177 public void setWebsite(WebsiteData website) 178 { 179 this.website = website; 180 } 181 182 192 public int getConditionCode() 193 { 194 return conditionCode; 195 } 196 197 203 public void setConditionCode(int conditionCode) 204 { 205 this.conditionCode = conditionCode; 206 } 207 208 215 public Timestamp getLastSuccess() 216 { 217 return lastSuccess; 218 } 219 220 226 public void setLastSuccess(Timestamp lastSuccess) 227 { 228 this.lastSuccess = lastSuccess; 229 } 230 231 234 public int hashCode() 235 { 236 return id.hashCode(); 237 } 238 239 242 public boolean equals(Object o) 243 { 244 if (this == o) return true; 245 if (!(o instanceof PingTargetData)) return false; 246 247 final PingTargetData pingTargetData = (PingTargetData) o; 248 249 if (conditionCode != pingTargetData.conditionCode) return false; 250 if (id != null ? !id.equals(pingTargetData.id) : pingTargetData.id != null) return false; 251 if (lastSuccess != null ? !lastSuccess.equals(pingTargetData.lastSuccess) : pingTargetData.lastSuccess != null) return false; 252 if (name != null ? !name.equals(pingTargetData.name) : pingTargetData.name != null) return false; 253 if (pingUrl != null ? !pingUrl.equals(pingTargetData.pingUrl) : pingTargetData.pingUrl != null) return false; 254 if (website != null ? !website.equals(pingTargetData.website) : pingTargetData.website != null) return false; 255 256 return true; 257 } 258 259 265 public boolean canSave() throws RollerException 266 { 267 Roller roller = RollerFactory.getRoller(); 268 UserData user = roller.getUser(); 269 if (user.equals(UserData.SYSTEM_USER)) 271 { 272 return true; 273 } 274 if (website == null && user.hasRole("admin")) 275 { 276 return true; 277 } 278 if (website != null && website.getUser().equals(user)) 279 { 280 return true; 281 } 282 return false; 283 } 284 285 291 public void remove() throws RollerException 292 { 293 PingQueueManager pingQueueMgr = RollerFactory.getRoller().getPingQueueManager(); 295 pingQueueMgr.removeQueueEntriesByPingTarget(this); 296 AutoPingManager autoPingMgr = RollerFactory.getRoller().getAutopingManager(); 297 List autopings = autoPingMgr.getAutoPingsByTarget(this); 298 autoPingMgr.removeAutoPings(autopings); 299 super.remove(); 300 } 301 302 308 public String toString() 309 { 310 return "PingTargetData{" + 311 "id='" + id + "'" + 312 ", name='" + name + "'" + 313 ", pingUrl='" + pingUrl + "'" + 314 ", website= " + (website == null ? "null" : "{id='" + website.getId() + "', user='" + website.getUser().getUserName() + "'} ") + 315 ", conditionCode=" + conditionCode + 316 ", lastSuccess=" + lastSuccess + 317 "}"; 318 } 319 } 320 | Popular Tags |