001 package org.hackystat.tickertape.tickerlingua; 002 003 import org.hackystat.dailyprojectdata.client.DailyProjectDataClient; 004 import org.hackystat.sensorbase.client.SensorBaseClient; 005 import org.hackystat.telemetry.service.client.TelemetryClient; 006 007 /** 008 * Represents a Hackystat User. 009 * @author Philip Johnson 010 */ 011 public class HackystatUser { 012 013 private String id; 014 private String fullname; 015 private String shortname; 016 private String emailaccount; 017 private HackystatService hackystatService; 018 private String hackystatUserEmail; 019 private String hackystatPassword; 020 private TwitterAccount twitterAccount; 021 private FacebookAccount facebookAccount; 022 private String smsAccount; 023 024 /** 025 * Construct a new Hackystat User. 026 * Assumes all fields are valid. 027 * @param id The id. 028 * @param fullname The full name. 029 * @param shortname The nickname. 030 * @param emailaccount The email address. 031 * @param hackystatService Their HackystatService. 032 * @param hackystatUserEmail The email address for their hackystat account. 033 * @param hackystatPassword Their hackystat account password, or null. 034 * @param twitterAccount Their twitter account, or null. 035 * @param facebookAccount Their facebook account, or null. 036 * @param smsAccount Their sms account, or null. 037 */ 038 public HackystatUser(String id, String fullname, String shortname, String emailaccount, 039 HackystatService hackystatService, String hackystatUserEmail, String hackystatPassword, 040 TwitterAccount twitterAccount, FacebookAccount 041 facebookAccount, String smsAccount) { 042 this.id = id; 043 this.fullname = fullname; 044 this.shortname = shortname; 045 this.emailaccount = emailaccount; 046 this.hackystatService = hackystatService; 047 this.hackystatUserEmail = hackystatUserEmail; 048 this.hackystatPassword = hackystatPassword; 049 this.twitterAccount = twitterAccount; 050 this.facebookAccount = facebookAccount; 051 this.smsAccount = smsAccount; 052 } 053 054 /** 055 * The unique id. 056 * @return The id. 057 */ 058 public String getId() { 059 return this.id; 060 } 061 062 /** 063 * Returns the Hackystat user account for this user. 064 * @return The hackystat user account. 065 */ 066 public String getHackystatUserAccount() { 067 return this.hackystatUserEmail; 068 } 069 070 /** 071 * The full name for this user. 072 * @return The full name. 073 */ 074 public String getFullName() { 075 return this.fullname; 076 } 077 078 /** 079 * Returns true if this user has a password specified for them. 080 * @return True if they have a password. 081 */ 082 public boolean hasPassword() { 083 return (this.hackystatPassword != null); 084 } 085 086 /** 087 * The nick name for this user. 088 * @return The nick name. 089 */ 090 public String getShortName() { 091 return this.shortname; 092 } 093 094 /** 095 * This user's email account. 096 * @return Their email address. 097 */ 098 public String getEmailAccount() { 099 return this.emailaccount; 100 } 101 102 /** 103 * This user's twitter account, or null if they don't have one. 104 * @return The twitter account or null. 105 */ 106 public TwitterAccount getTwitterAccount() { 107 return this.twitterAccount; 108 } 109 110 /** 111 * This user's facebook account, or null if they don't have one. 112 * @return The facebook account or null. 113 */ 114 public FacebookAccount getFacebookAccount() { 115 return this.facebookAccount; 116 } 117 /** 118 * This user's text message number, or null if they don't have one. 119 * @return The sms account or null. 120 */ 121 public String getSmsAccount() { 122 return this.smsAccount; 123 } 124 125 /** 126 * Creates a new SensorBaseClient for this user. 127 * Throws a RuntimeException if this user did not have a password provided in tickertape.xml. 128 * @return A sensorbaseclient instance. 129 */ 130 public SensorBaseClient getSensorBaseClient() { 131 if (this.hackystatPassword == null) { 132 throw new RuntimeException("Cannot have client since no password for " + hackystatUserEmail); 133 } 134 return new SensorBaseClient(this.hackystatService.getSensorbase(), this.hackystatUserEmail, 135 this.hackystatPassword); 136 } 137 138 /** 139 * Creates a new DailyProjectDataClient for this user. 140 * Throws a RuntimeException if this user did not have a password provided in tickertape.xml. 141 * @return A DPD client instance. 142 */ 143 public DailyProjectDataClient getDailyProjectDataClient() { 144 if (this.hackystatPassword == null) { 145 throw new RuntimeException("Cannot have client since no password for " + hackystatUserEmail); 146 } 147 return new DailyProjectDataClient(this.hackystatService.getDailyProjectData(), 148 this.hackystatUserEmail, this.hackystatPassword); 149 } 150 151 /** 152 * Creates a new TelemetryClient for this user. 153 * Throws a RuntimeException if this user did not have a password provided in tickertape.xml. 154 * @return A telemetryclient instance. 155 */ 156 public TelemetryClient getTelemetryClient() { 157 if (this.hackystatPassword == null) { 158 throw new RuntimeException("Cannot have client since no password for " + hackystatUserEmail); 159 } 160 return new TelemetryClient(this.hackystatService.getTelemetry(), 161 this.hackystatUserEmail, this.hackystatPassword); 162 } 163 } 164