1 18 19 package sync4j.exchange.items.contact.manager; 20 21 import java.io.IOException ; 22 23 import java.util.List ; 24 25 import sync4j.exchange.items.contact.dao.ContactDAO; 26 import sync4j.exchange.items.contact.model.Contact; 27 import sync4j.exchange.DataAccessException; 28 29 import sync4j.foundation.pdi.contact.ContactDetail; 30 import sync4j.foundation.pdi.contact.Email; 31 import sync4j.foundation.pdi.contact.PersonalDetail; 32 33 41 public class ContactManager { 42 43 45 47 ContactDAO cd = null ; 48 49 51 public ContactManager(String exchangeServerHost , 52 int exchangeServerPort ) 53 throws DataAccessException { 54 55 this.cd = new ContactDAO (exchangeServerHost , 56 exchangeServerPort); 57 } 58 59 61 72 public Contact[] getAllContacts(String username , 73 String credentials , 74 String exchangeFolder ) 75 throws DataAccessException { 76 77 return this.cd.getContacts(username , 78 credentials , 79 new String [0] , 80 exchangeFolder ); 81 82 } 83 84 96 public Contact[] getContacts(String username , 97 String credentials , 98 String [] ids , 99 String exchangeFolder ) 100 throws DataAccessException { 101 102 return this.cd.getContacts(username , 103 credentials , 104 ids , 105 exchangeFolder ); 106 107 } 108 109 120 public Contact getContactById(String username , 121 String credentials , 122 String id , 123 String exchangeFolder ) 124 throws DataAccessException { 125 126 Contact[] contacts = null; 127 128 contacts = this.cd.getContacts(username , 129 credentials , 130 new String [] {id} , 131 exchangeFolder ); 132 133 if (contacts == null || !(contacts.length > 0)) { 134 return null; 135 } 136 137 return contacts[0]; 138 139 } 140 141 153 public Contact getContactTwin(Contact contact , 154 String username , 155 String credentials , 156 String exchangeFolder) 157 throws DataAccessException { 158 159 Contact[] contacts = null; 160 161 162 String firstName = null ; 163 String lastName = null ; 164 String middleName = null ; 165 166 String emailAddress = null ; 167 168 List emails = null ; 169 170 Email email = null ; 171 172 PersonalDetail personalDetail = null ; 173 ContactDetail personalContactDetail = null ; 174 175 personalDetail = contact.getPersonalDetail(); 176 177 if (personalDetail != null) { 178 emails = personalDetail.getEmails(); 179 } 180 181 if (emails != null && emails != null) { 182 183 for (int i=0, l = emails.size(); i < l; i++) { 184 185 email = (Email) emails.get(i); 186 187 if ((ContactDAO.FIELD_TYPE_EMAIL1_ADDRESS).equals(email.getEmailType())) { 188 emailAddress = email.getPropertyValueAsString(); 189 } 190 191 } 192 193 } 194 195 if (contact.getName().getFirstName() != null) { 196 firstName = contact.getName(). 197 getFirstName (). 198 getPropertyValueAsString(); 199 } 200 if (contact.getName().getLastName() != null) { 201 lastName = contact.getName(). 202 getLastName(). 203 getPropertyValueAsString(); 204 } 205 if (contact.getName().getMiddleName() != null) { 206 middleName = contact.getName(). 207 getMiddleName(). 208 getPropertyValueAsString(); 209 } 210 211 String [] fields = { 212 ContactDAO.TAG_FIRSTNAME, 213 ContactDAO.TAG_LASTNAME, 214 ContactDAO.TAG_MIDDLENAME, 215 ContactDAO.TAG_EMAIL1 216 }; 217 218 Object [] values = { 219 firstName, 220 lastName, 221 middleName, 222 emailAddress 223 }; 224 225 226 contacts = this.cd.getContacts(username , 227 credentials , 228 fields , 229 values , 230 exchangeFolder ); 231 232 if (contacts == null || !(contacts.length > 0)) { 233 return null; 234 } 235 236 return contacts[0]; 237 } 238 239 251 public Contact setContact(Contact contact , 252 String username , 253 String credentials , 254 String exchangeFolder ) 255 throws DataAccessException { 256 257 return this.cd.setContact(contact , 258 username , 259 credentials , 260 exchangeFolder ); 261 262 } 263 264 274 public void removeContact(Contact contact , 275 String username , 276 String principal , 277 String exchangeFolder ) 278 throws DataAccessException { 279 280 this.cd.removeContact(contact , 281 username , 282 principal , 283 exchangeFolder ); 284 285 } 286 287 } 288 | Popular Tags |