001 package org.hackystat.tickertape.tickerlingua; 002 003 import java.lang.reflect.Constructor; 004 import java.util.HashMap; 005 import java.util.List; 006 import java.util.Map; 007 008 import org.hackystat.tickertape.ticker.Ticker; 009 import org.hackystat.tickertape.tickerlingua.jaxb.Properties; 010 import org.hackystat.tickertape.tickerlingua.jaxb.Property; 011 012 /** 013 * Represents a Tickertape, which is a notification. 014 * @author Philip Johnson 015 */ 016 public class Tickertape { 017 018 private String id; 019 private double intervalHours; 020 private boolean enabled; 021 private String starttime; 022 private String description; 023 private List<HackystatProject> projects; 024 private List<NotificationService> services; 025 private Ticker ticker; 026 private Map<String, String> properties = new HashMap<String, String>(); 027 028 /** 029 * Creates and returns a new Tickertape instance, or throws a TickerLinguaException if the 030 * passed parameters are not valid. 031 * @param id A unique id (not validated). 032 * @param intervalHours The interval as hours. 033 * @param enabled If this ticker is to be instantiated or not. 034 * @param starttime A string indicating the start time. Not yet validated. 035 * @param description A description of this tickertape. 036 * @param projects A non-empty list of HackystatProject instances. 037 * @param services A possibly empty list of notification services. (One might use email). 038 * @param tickerClass The ticker class instance. 039 * @param tickerProperties A possibly empty Properties instance. 040 * @throws TickerLinguaException If there is not at least one project and notification service. 041 */ 042 public Tickertape(String id, double intervalHours, boolean enabled, String starttime, 043 String description, List<HackystatProject> projects, List<NotificationService> services, 044 Class<? extends Ticker> tickerClass, Properties tickerProperties) 045 throws TickerLinguaException { 046 this.id = id; 047 this.intervalHours = intervalHours; 048 this.enabled = enabled; 049 this.starttime = starttime; 050 this.description = description; 051 this.projects = projects; 052 if (this.projects.isEmpty()) { 053 throw new TickerLinguaException("At least one project must be defined."); 054 } 055 this.services = services; 056 try { 057 Constructor<? extends Ticker> ctor = tickerClass.getConstructor(); 058 this.ticker = ctor.newInstance(); 059 } 060 catch (Exception e) { 061 throw new RuntimeException("Ticker could not be instantiated. Shouldn't ever happen!", e); 062 } 063 // Create the properties map. 064 for (Property property : tickerProperties.getProperty()) { 065 properties.put(property.getKey(), property.getValue()); 066 } 067 068 } 069 070 /** 071 * Return the unique ID. 072 * @return The id. 073 */ 074 public String getId() { 075 return this.id; 076 } 077 078 /** 079 * Return the interval in hours for wakeups of this notification. 080 * @return The wakeup interval. 081 */ 082 public double getIntervalHours() { 083 return this.intervalHours; 084 } 085 086 /** 087 * True if this tickertape is enabled. 088 * @return True if enabled. 089 */ 090 public boolean enabled() { 091 return this.enabled; 092 } 093 094 /** 095 * The description of this tickertape. 096 * @return The description. 097 */ 098 public String getDescription() { 099 return this.description; 100 } 101 102 /** 103 * The String representting the time when this should wake up, or null if immediately. 104 * @return The time to wakeup, or null if immediate. 105 */ 106 public String getStartTime() { 107 return this.starttime; 108 } 109 110 /** 111 * The set of projects involved in this notification. 112 * @return The projects. 113 */ 114 public List<HackystatProject> getHackystatProjects() { 115 return this.projects; 116 } 117 118 /** 119 * The notification services for this notification. 120 * @return The notification services. 121 */ 122 public List<NotificationService> getNotificationServices() { 123 return this.services; 124 } 125 126 /** 127 * The class that implements this notification behavior. 128 * @return The notification class. 129 */ 130 public Ticker getTicker() { 131 return this.ticker; 132 } 133 134 /** 135 * Return the (possibly empty) properties associated with this ticker. 136 * @return The ticker properties. 137 */ 138 public Map<String, String> getTickerProperties() { 139 return this.properties; 140 } 141 }