001/*
002 * The MIT License
003 * Copyright (c) 2012 Microsoft Corporation
004 *
005 * Permission is hereby granted, free of charge, to any person obtaining a copy
006 * of this software and associated documentation files (the "Software"), to deal
007 * in the Software without restriction, including without limitation the rights
008 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
009 * copies of the Software, and to permit persons to whom the Software is
010 * furnished to do so, subject to the following conditions:
011 *
012 * The above copyright notice and this permission notice shall be included in
013 * all copies or substantial portions of the Software.
014 *
015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
018 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
019 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
021 * THE SOFTWARE.
022 */
023
024package microsoft.exchange.webservices.data.core.service.item;
025
026import microsoft.exchange.webservices.data.attribute.Attachable;
027import microsoft.exchange.webservices.data.attribute.ServiceObjectDefinition;
028import microsoft.exchange.webservices.data.core.EwsUtilities;
029import microsoft.exchange.webservices.data.core.ExchangeService;
030import microsoft.exchange.webservices.data.core.PropertySet;
031import microsoft.exchange.webservices.data.core.XmlElementNames;
032import microsoft.exchange.webservices.data.core.service.schema.ContactSchema;
033import microsoft.exchange.webservices.data.core.service.schema.ServiceObjectSchema;
034import microsoft.exchange.webservices.data.core.enumeration.service.ContactSource;
035import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
036import microsoft.exchange.webservices.data.core.enumeration.service.FileAsMapping;
037import microsoft.exchange.webservices.data.core.enumeration.property.PhysicalAddressIndex;
038import microsoft.exchange.webservices.data.core.exception.service.local.PropertyException;
039import microsoft.exchange.webservices.data.core.exception.service.local.ServiceLocalException;
040import microsoft.exchange.webservices.data.core.exception.service.local.ServiceVersionException;
041import microsoft.exchange.webservices.data.misc.OutParam;
042import microsoft.exchange.webservices.data.property.complex.Attachment;
043import microsoft.exchange.webservices.data.property.complex.ByteArrayArray;
044import microsoft.exchange.webservices.data.property.complex.CompleteName;
045import microsoft.exchange.webservices.data.property.complex.EmailAddress;
046import microsoft.exchange.webservices.data.property.complex.EmailAddressCollection;
047import microsoft.exchange.webservices.data.property.complex.EmailAddressDictionary;
048import microsoft.exchange.webservices.data.property.complex.FileAttachment;
049import microsoft.exchange.webservices.data.property.complex.ImAddressDictionary;
050import microsoft.exchange.webservices.data.property.complex.ItemAttachment;
051import microsoft.exchange.webservices.data.property.complex.ItemId;
052import microsoft.exchange.webservices.data.property.complex.PhoneNumberDictionary;
053import microsoft.exchange.webservices.data.property.complex.PhysicalAddressDictionary;
054import microsoft.exchange.webservices.data.property.complex.StringList;
055
056import java.io.File;
057import java.io.InputStream;
058import java.util.Date;
059
060/**
061 * Represents a contact. Properties available on contacts are defined in the
062 * ContactSchema class.
063 */
064@Attachable
065@ServiceObjectDefinition(xmlElementName = XmlElementNames.Contact, returnedByServer = true)
066public class Contact extends Item {
067
068  /**
069   * The Contact picture name.
070   */
071  private final String ContactPictureName = "ContactPicture.jpg";
072
073  /**
074   * Initializes an unsaved local instance of {@link Contact}.
075   * To bind to an existing contact, use Contact.Bind() instead.
076   *
077   * @param service the service
078   * @throws Exception the exception
079   */
080  public Contact(ExchangeService service) throws Exception {
081    super(service);
082  }
083
084  /**
085   * Initializes a new instance of the {@link Contact} class.
086   *
087   * @param parentAttachment the parent attachment
088   * @throws Exception the exception
089   */
090  public Contact(ItemAttachment parentAttachment) throws Exception {
091    super(parentAttachment);
092  }
093
094  /**
095   * Binds to an existing contact and loads the specified set of property.
096   * Calling this method results in a call to EWS.
097   *
098   * @param service     the service
099   * @param id          the id
100   * @param propertySet the property set
101   * @return A Contact instance representing the contact corresponding to the
102   * specified Id.
103   * @throws Exception the exception
104   */
105  public static Contact bind(ExchangeService service, ItemId id,
106      PropertySet propertySet) throws Exception {
107    return service.bindToItem(Contact.class, id, propertySet);
108  }
109
110  /**
111   * Binds to an existing contact and loads its first class property.
112   * Calling this method results in a call to EWS.
113   *
114   * @param service the service
115   * @param id      the id
116   * @return A Contact instance representing the contact corresponding to the
117   * specified Id.
118   * @throws Exception the exception
119   */
120  public static Contact bind(ExchangeService service, ItemId id)
121      throws Exception {
122    return Contact.bind(service, id, PropertySet.getFirstClassProperties());
123  }
124
125  /**
126   * Internal method to return the schema associated with this type of object.
127   *
128   * @return The schema associated with this type of object.
129   */
130  @Override public ServiceObjectSchema getSchema() {
131    return ContactSchema.Instance;
132  }
133
134  /**
135   * Gets the minimum required server version.
136   *
137   * @return Earliest Exchange version in which this service object type is
138   * supported.
139   */
140  @Override public ExchangeVersion getMinimumRequiredServerVersion() {
141    return ExchangeVersion.Exchange2007_SP1;
142  }
143
144  /**
145   * Sets the contact's picture using the specified byte array.
146   *
147   * @param content the new contact picture
148   * @throws Exception the exception
149   */
150  public void setContactPicture(byte[] content) throws Exception {
151    EwsUtilities.validateMethodVersion(this.getService(), ExchangeVersion.Exchange2010, "SetContactPicture");
152
153    internalRemoveContactPicture();
154    FileAttachment fileAttachment = getAttachments().addFileAttachment(
155        ContactPictureName, content);
156    fileAttachment.setIsContactPhoto(true);
157  }
158
159  /**
160   * Sets the contact's picture using the specified stream.
161   *
162   * @param contentStream the new contact picture
163   * @throws Exception the exception
164   */
165  public void setContactPicture(InputStream contentStream) throws Exception {
166    EwsUtilities.validateMethodVersion(this.getService(),
167        ExchangeVersion.Exchange2010, "SetContactPicture");
168
169    internalRemoveContactPicture();
170    FileAttachment fileAttachment = getAttachments().addFileAttachment(
171        ContactPictureName, contentStream);
172    fileAttachment.setIsContactPhoto(true);
173  }
174
175  /**
176   * Sets the contact's picture using the specified file.
177   *
178   * @param fileName the new contact picture
179   * @throws Exception the exception
180   */
181  public void setContactPicture(String fileName) throws Exception {
182    EwsUtilities.validateMethodVersion(this.getService(),
183        ExchangeVersion.Exchange2010, "SetContactPicture");
184
185    internalRemoveContactPicture();
186    FileAttachment fileAttachment = getAttachments().addFileAttachment(
187        new File(fileName).getName(), fileName);
188    fileAttachment.setIsContactPhoto(true);
189  }
190
191  /**
192   * Retrieves the file attachment that holds the contact's picture.
193   *
194   * @return The file attachment that holds the contact's picture.
195   * @throws ServiceLocalException the service local exception
196   */
197  public FileAttachment getContactPictureAttachment()
198      throws ServiceLocalException {
199    EwsUtilities.validateMethodVersion(this.getService(),
200        ExchangeVersion.Exchange2010, "GetContactPictureAttachment");
201
202    if (!this.getPropertyBag().isPropertyLoaded(ContactSchema.Attachments)) {
203      throw new PropertyException("The attachment collection must be loaded.");
204    }
205
206    for (Attachment fileAttachment : this.getAttachments()) {
207      if (fileAttachment instanceof FileAttachment) {
208        if (((FileAttachment) fileAttachment).isContactPhoto()) {
209          return (FileAttachment) fileAttachment;
210        }
211      }
212    }
213    return null;
214  }
215
216  /**
217   * Removes the picture from local attachment collection.
218   *
219   * @throws Exception the exception
220   */
221  private void internalRemoveContactPicture() throws Exception {
222    // Iterates in reverse order to remove file attachments that have
223    // IsContactPhoto set to true.
224    for (int index = this.getAttachments().getCount() - 1; index >= 0; index--) {
225      FileAttachment fileAttachment = (FileAttachment) this
226          .getAttachments().getPropertyAtIndex(index);
227      if (fileAttachment != null) {
228        if (fileAttachment.isContactPhoto()) {
229          this.getAttachments().remove(fileAttachment);
230        }
231      }
232    }
233
234  }
235
236  /**
237   * Removes the contact's picture.
238   *
239   * @throws Exception the exception
240   */
241  public void removeContactPicture() throws Exception {
242    EwsUtilities.validateMethodVersion(this.getService(),
243        ExchangeVersion.Exchange2010, "RemoveContactPicture");
244
245    if (!this.getPropertyBag().isPropertyLoaded(ContactSchema.Attachments)) {
246      throw new PropertyException("The attachment collection must be loaded.");
247    }
248
249    internalRemoveContactPicture();
250  }
251
252  /**
253   * Validates this instance.
254   *
255   * @throws ServiceVersionException the service version exception
256   * @throws Exception               the exception
257   */
258  @Override public void validate() throws ServiceVersionException, Exception {
259    super.validate();
260
261    Object fileAsMapping;
262    OutParam<Object> outParam = new OutParam<Object>();
263    if (this.tryGetProperty(ContactSchema.FileAsMapping, outParam)) {
264      fileAsMapping = outParam.getParam();
265      // FileAsMapping is extended by 5 new values in 2010 mode. Validate
266      // that they are used according the version.
267      EwsUtilities.validateEnumVersionValue(
268          (FileAsMapping) fileAsMapping, this.getService()
269              .getRequestedServerVersion());
270    }
271  }
272
273  /**
274   * Gets  the name under which this contact is filed as. FileAs can be
275   * manually set or can be automatically calculated based on the value of the
276   * FileAsMapping property.
277   *
278   * @return the file as
279   * @throws ServiceLocalException the service local exception
280   */
281  public String getFileAs() throws ServiceLocalException {
282    return getPropertyBag().getObjectFromPropertyDefinition(
283        ContactSchema.FileAs);
284
285  }
286
287  /**
288   * Sets the file as.
289   *
290   * @param value the new file as
291   * @throws Exception the exception
292   */
293  public void setFileAs(String value) throws Exception {
294    this.getPropertyBag().setObjectFromPropertyDefinition(
295        ContactSchema.FileAs, value);
296  }
297
298  /**
299   * Gets a value indicating how the FileAs property should be
300   * automatically calculated.
301   *
302   * @return the file as mapping
303   * @throws ServiceLocalException the service local exception
304   */
305  public FileAsMapping getFileAsMapping() throws ServiceLocalException {
306    return getPropertyBag().getObjectFromPropertyDefinition(ContactSchema.FileAsMapping);
307  }
308
309  /**
310   * Sets the file as.
311   *
312   * @param value the new file as
313   * @throws Exception the exception
314   */
315  public void setFileAs(FileAsMapping value) throws Exception {
316    this.getPropertyBag().setObjectFromPropertyDefinition(
317        ContactSchema.FileAsMapping, value);
318  }
319
320  /**
321   * Gets the display name of the contact.
322   *
323   * @return the display name
324   * @throws ServiceLocalException the service local exception
325   */
326  public String getDisplayName() throws ServiceLocalException {
327    return getPropertyBag().getObjectFromPropertyDefinition(
328        ContactSchema.DisplayName);
329  }
330
331  /**
332   * Sets the display name.
333   *
334   * @param value the new display name
335   * @throws Exception the exception
336   */
337  public void setDisplayName(String value) throws Exception {
338    this.getPropertyBag().setObjectFromPropertyDefinition(
339        ContactSchema.DisplayName, value);
340  }
341
342  /**
343   * Gets  the given name of the contact.
344   *
345   * @return the given name
346   * @throws ServiceLocalException the service local exception
347   */
348  public String getGivenName() throws ServiceLocalException {
349    return getPropertyBag().getObjectFromPropertyDefinition(
350        ContactSchema.GivenName);
351  }
352
353  /**
354   * Sets the given name.
355   *
356   * @param value the new given name
357   * @throws Exception the exception
358   */
359  public void setGivenName(String value) throws Exception {
360    this.getPropertyBag().setObjectFromPropertyDefinition(
361        ContactSchema.GivenName, value);
362  }
363
364  /**
365   * Gets  the initials of the contact.
366   *
367   * @return the initials
368   * @throws ServiceLocalException the service local exception
369   */
370  public String getInitials() throws ServiceLocalException {
371    return getPropertyBag().getObjectFromPropertyDefinition(
372        ContactSchema.Initials);
373  }
374
375  /**
376   * Sets the initials.
377   *
378   * @param value the new initials
379   * @throws Exception the exception
380   */
381  public void setInitials(String value) throws Exception {
382    this.getPropertyBag().setObjectFromPropertyDefinition(
383        ContactSchema.Initials, value);
384  }
385
386  /**
387   * Gets the middle name of the contact.
388   *
389   * @return the middle name
390   * @throws ServiceLocalException the service local exception
391   */
392  public String getMiddleName() throws ServiceLocalException {
393    return getPropertyBag().getObjectFromPropertyDefinition(
394        ContactSchema.MiddleName);
395  }
396
397  /**
398   * Sets the middle name.
399   *
400   * @param value the new middle name
401   * @throws Exception the exception
402   */
403  public void setMiddleName(String value) throws Exception {
404    this.getPropertyBag().setObjectFromPropertyDefinition(
405        ContactSchema.MiddleName, value);
406  }
407
408  /**
409   * Gets the nick name of the contact.
410   *
411   * @return the nick name
412   * @throws ServiceLocalException the service local exception
413   */
414  public String getNickName() throws ServiceLocalException {
415    return getPropertyBag().getObjectFromPropertyDefinition(
416        ContactSchema.NickName);
417  }
418
419  /**
420   * Sets the nick name.
421   *
422   * @param value the new nick name
423   * @throws Exception the exception
424   */
425  public void setNickName(String value) throws Exception {
426    this.getPropertyBag().setObjectFromPropertyDefinition(
427        ContactSchema.NickName, value);
428  }
429
430  /**
431   * Gets the complete name of the contact.
432   *
433   * @return the complete name
434   * @throws ServiceLocalException the service local exception
435   */
436  public CompleteName getCompleteName() throws ServiceLocalException {
437    return getPropertyBag().getObjectFromPropertyDefinition(
438        ContactSchema.CompleteName);
439  }
440
441  /**
442   * Gets  the company name of the contact.
443   *
444   * @return the company name
445   * @throws ServiceLocalException the service local exception
446   */
447  public String getCompanyName() throws ServiceLocalException {
448    return getPropertyBag().getObjectFromPropertyDefinition(
449        ContactSchema.CompanyName);
450  }
451
452  /**
453   * Sets the company name.
454   *
455   * @param value the new company name
456   * @throws Exception the exception
457   */
458  public void setCompanyName(String value) throws Exception {
459    this.getPropertyBag().setObjectFromPropertyDefinition(
460        ContactSchema.CompanyName, value);
461  }
462
463  /**
464   * Gets an indexed list of e-mail addresses for the contact. For example, to
465   * set the first e-mail address, use the following syntax:
466   * EmailAddresses[EmailAddressKey.EmailAddress1] = "john.doe@contoso.com"
467   *
468   * @return the email addresses
469   * @throws ServiceLocalException the service local exception
470   */
471  public EmailAddressDictionary getEmailAddresses()
472      throws ServiceLocalException {
473    return getPropertyBag().getObjectFromPropertyDefinition(ContactSchema.EmailAddresses);
474  }
475
476  /**
477   * Gets an indexed list of physical addresses for the contact. For example,
478   * to set the first business address, use the following syntax:
479   * physical[PhysicalAddressKey.Business] = new PhysicalAddressEntry()
480   *
481   * @return the physical addresses
482   * @throws ServiceLocalException the service local exception
483   */
484  public PhysicalAddressDictionary getPhysicalAddresses()
485      throws ServiceLocalException {
486    return getPropertyBag().getObjectFromPropertyDefinition(ContactSchema.PhysicalAddresses);
487  }
488
489  /**
490   * Gets an indexed list of phone numbers for the contact. For example, to
491   * set the home phone number, use the following syntax:
492   * PhoneNumbers[PhoneNumberKey.HomePhone] = "phone number"
493   *
494   * @return the phone numbers
495   * @throws ServiceLocalException the service local exception
496   */
497  public PhoneNumberDictionary getPhoneNumbers()
498      throws ServiceLocalException {
499    return getPropertyBag()
500        .getObjectFromPropertyDefinition(ContactSchema.PhoneNumbers);
501  }
502
503  /**
504   * Gets the contact's assistant name.
505   *
506   * @return the assistant name
507   * @throws ServiceLocalException the service local exception
508   */
509  public String getAssistantName() throws ServiceLocalException {
510    return getPropertyBag().getObjectFromPropertyDefinition(
511        ContactSchema.AssistantName);
512  }
513
514  /**
515   * Sets the assistant name.
516   *
517   * @param value the new assistant name
518   * @throws Exception the exception
519   */
520  public void setAssistantName(String value) throws Exception {
521    this.getPropertyBag().setObjectFromPropertyDefinition(
522        ContactSchema.AssistantName, value);
523  }
524
525  /**
526   * Gets  the contact's assistant name.
527   *
528   * @return the birthday
529   * @throws ServiceLocalException the service local exception
530   */
531  public Date getBirthday() throws ServiceLocalException {
532    return getPropertyBag().getObjectFromPropertyDefinition(
533        ContactSchema.Birthday);
534
535  }
536
537  /**
538   * Sets the birthday.
539   *
540   * @param value the new birthday
541   * @throws Exception the exception
542   */
543  public void setBirthday(Date value) throws Exception {
544    this.getPropertyBag().setObjectFromPropertyDefinition(
545        ContactSchema.Birthday, value);
546  }
547
548  /**
549   * Gets the business home page of the contact.
550   *
551   * @return the business home page
552   * @throws ServiceLocalException the service local exception
553   */
554  public String getBusinessHomePage() throws ServiceLocalException {
555    return getPropertyBag().getObjectFromPropertyDefinition(
556        ContactSchema.BusinessHomePage);
557
558  }
559
560  /**
561   * Sets the business home page.
562   *
563   * @param value the new business home page
564   * @throws Exception the exception
565   */
566  public void setBusinessHomePage(String value) throws Exception {
567    this.getPropertyBag().setObjectFromPropertyDefinition(
568        ContactSchema.BusinessHomePage, value);
569  }
570
571  /**
572   * Gets  a list of children for the contact.
573   *
574   * @return the children
575   * @throws ServiceLocalException the service local exception
576   */
577  public StringList getChildren() throws ServiceLocalException {
578    return getPropertyBag().getObjectFromPropertyDefinition(
579        ContactSchema.Children);
580  }
581
582  /**
583   * Sets the children.
584   *
585   * @param value the new children
586   * @throws Exception the exception
587   */
588  public void setChildren(StringList value) throws Exception {
589    this.getPropertyBag().setObjectFromPropertyDefinition(
590        ContactSchema.Children, value);
591  }
592
593  /**
594   * Gets  a list of companies for the contact.
595   *
596   * @return the companies
597   * @throws ServiceLocalException the service local exception
598   */
599  public StringList getCompanies() throws ServiceLocalException {
600    return getPropertyBag().getObjectFromPropertyDefinition(
601        ContactSchema.Companies);
602  }
603
604  /**
605   * Sets the companies.
606   *
607   * @param value the new companies
608   * @throws Exception the exception
609   */
610  public void setCompanies(StringList value) throws Exception {
611    this.getPropertyBag().setObjectFromPropertyDefinition(
612        ContactSchema.Companies, value);
613  }
614
615  /**
616   * Gets the source of the contact.
617   *
618   * @return the contact source
619   * @throws ServiceLocalException the service local exception
620   */
621  public ContactSource getContactSource() throws ServiceLocalException {
622    return getPropertyBag()
623        .getObjectFromPropertyDefinition(ContactSchema.ContactSource);
624  }
625
626  /**
627   * Gets  the department of the contact.
628   *
629   * @return the department
630   * @throws ServiceLocalException the service local exception
631   */
632  public String getDepartment() throws ServiceLocalException {
633    return getPropertyBag().getObjectFromPropertyDefinition(
634        ContactSchema.Department);
635  }
636
637  /**
638   * Sets the department.
639   *
640   * @param value the new department
641   * @throws Exception the exception
642   */
643  public void setDepartment(String value) throws Exception {
644    this.getPropertyBag().setObjectFromPropertyDefinition(
645        ContactSchema.Department, value);
646  }
647
648  /**
649   * Gets  the generation of the contact.
650   *
651   * @return the generation
652   * @throws ServiceLocalException the service local exception
653   */
654  public String getGeneration() throws ServiceLocalException {
655    return getPropertyBag().getObjectFromPropertyDefinition(
656        ContactSchema.Generation);
657  }
658
659  /**
660   * Sets the generation.
661   *
662   * @param value the new generation
663   * @throws Exception the exception
664   */
665  public void setGeneration(String value) throws Exception {
666    this.getPropertyBag().setObjectFromPropertyDefinition(
667        ContactSchema.Generation, value);
668  }
669
670  /**
671   * Gets an indexed list of Instant Messaging addresses for the contact. For
672   * example, to set the first IM address, use the following syntax:
673   * ImAddresses[ImAddressKey.ImAddress1] = "john.doe@contoso.com"
674   *
675   * @return the im addresses
676   * @throws ServiceLocalException the service local exception
677   */
678  public ImAddressDictionary getImAddresses() throws ServiceLocalException {
679    return getPropertyBag().getObjectFromPropertyDefinition(ContactSchema.ImAddresses);
680  }
681
682  /**
683   * Gets  the contact's job title.
684   *
685   * @return the job title
686   * @throws ServiceLocalException the service local exception
687   */
688  public String getJobTitle() throws ServiceLocalException {
689    return getPropertyBag().getObjectFromPropertyDefinition(
690        ContactSchema.JobTitle);
691  }
692
693  /**
694   * Sets the job title.
695   *
696   * @param value the new job title
697   * @throws Exception the exception
698   */
699  public void setJobTitle(String value) throws Exception {
700    this.getPropertyBag().setObjectFromPropertyDefinition(
701        ContactSchema.JobTitle, value);
702  }
703
704  /**
705   * Gets the name of the contact's manager.
706   *
707   * @return the manager
708   * @throws ServiceLocalException the service local exception
709   */
710  public String getManager() throws ServiceLocalException {
711    return getPropertyBag().getObjectFromPropertyDefinition(
712        ContactSchema.Manager);
713  }
714
715  /**
716   * Sets the manager.
717   *
718   * @param value the new manager
719   * @throws Exception the exception
720   */
721  public void setManager(String value) throws Exception {
722    this.getPropertyBag().setObjectFromPropertyDefinition(
723        ContactSchema.Manager, value);
724  }
725
726  /**
727   * Gets the mileage for the contact.
728   *
729   * @return the mileage
730   * @throws ServiceLocalException the service local exception
731   */
732  public String getMileage() throws ServiceLocalException {
733    return getPropertyBag().getObjectFromPropertyDefinition(
734        ContactSchema.Mileage);
735  }
736
737  /**
738   * Sets the mileage.
739   *
740   * @param value the new mileage
741   * @throws Exception the exception
742   */
743  public void setMileage(String value) throws Exception {
744    this.getPropertyBag().setObjectFromPropertyDefinition(
745        ContactSchema.Mileage, value);
746  }
747
748  /**
749   * Gets  the location of the contact's office.
750   *
751   * @return the office location
752   * @throws ServiceLocalException the service local exception
753   */
754  public String getOfficeLocation() throws ServiceLocalException {
755    return getPropertyBag().getObjectFromPropertyDefinition(
756        ContactSchema.OfficeLocation);
757  }
758
759  /**
760   * Sets the office location.
761   *
762   * @param value the new office location
763   * @throws Exception the exception
764   */
765  public void setOfficeLocation(String value) throws Exception {
766    this.getPropertyBag().setObjectFromPropertyDefinition(
767        ContactSchema.OfficeLocation, value);
768  }
769
770  /**
771   * Gets the index of the contact's postal address. When set,
772   * PostalAddressIndex refers to an entry in the PhysicalAddresses indexed
773   * list.
774   *
775   * @return the postal address index
776   * @throws ServiceLocalException the service local exception
777   */
778  public PhysicalAddressIndex getPostalAddressIndex()
779      throws ServiceLocalException {
780    return getPropertyBag().getObjectFromPropertyDefinition(
781        ContactSchema.PostalAddressIndex);
782  }
783
784  /**
785   * Sets the postal address index.
786   *
787   * @param value the new postal address index
788   * @throws Exception the exception
789   */
790  public void setPostalAddressIndex(PhysicalAddressIndex value)
791      throws Exception {
792    this.getPropertyBag().setObjectFromPropertyDefinition(
793        ContactSchema.PostalAddressIndex, value);
794  }
795
796  /**
797   * Gets the contact's profession.
798   *
799   * @return the profession
800   * @throws ServiceLocalException the service local exception
801   */
802  public String getProfession() throws ServiceLocalException {
803    return getPropertyBag().getObjectFromPropertyDefinition(
804        ContactSchema.Profession);
805  }
806
807  /**
808   * Sets the profession.
809   *
810   * @param value the new profession
811   * @throws Exception the exception
812   */
813  public void setProfession(String value) throws Exception {
814    this.getPropertyBag().setObjectFromPropertyDefinition(
815        ContactSchema.Profession, value);
816  }
817
818  /**
819   * Gets the name of the contact's spouse.
820   *
821   * @return the spouse name
822   * @throws ServiceLocalException the service local exception
823   */
824  public String getSpouseName() throws ServiceLocalException {
825    return getPropertyBag().getObjectFromPropertyDefinition(
826        ContactSchema.SpouseName);
827  }
828
829  /**
830   * Sets the spouse name.
831   *
832   * @param value the new spouse name
833   * @throws Exception the exception
834   */
835  public void setSpouseName(String value) throws Exception {
836    this.getPropertyBag().setObjectFromPropertyDefinition(
837        ContactSchema.SpouseName, value);
838  }
839
840  /**
841   * Gets the surname of the contact.
842   *
843   * @return the surname
844   * @throws ServiceLocalException the service local exception
845   */
846  public String getSurname() throws ServiceLocalException {
847    return getPropertyBag().getObjectFromPropertyDefinition(
848        ContactSchema.Surname);
849  }
850
851  /**
852   * Sets the surname.
853   *
854   * @param value the new surname
855   * @throws Exception the exception
856   */
857  public void setSurname(String value) throws Exception {
858    this.getPropertyBag().setObjectFromPropertyDefinition(
859        ContactSchema.Surname, value);
860  }
861
862  /**
863   * Gets the date of the contact's wedding anniversary.
864   *
865   * @return the wedding anniversary
866   * @throws ServiceLocalException the service local exception
867   */
868  public Date getWeddingAnniversary() throws ServiceLocalException {
869    return getPropertyBag().getObjectFromPropertyDefinition(
870        ContactSchema.WeddingAnniversary);
871  }
872
873  /**
874   * Sets the wedding anniversary.
875   *
876   * @param value the new wedding anniversary
877   * @throws Exception the exception
878   */
879  public void setWeddingAnniversary(Date value) throws Exception {
880    this.getPropertyBag().setObjectFromPropertyDefinition(
881        ContactSchema.WeddingAnniversary, value);
882  }
883
884  /**
885   * Gets a value indicating whether this contact has a picture associated
886   * with it.
887   *
888   * @return the checks for picture
889   * @throws ServiceLocalException the service local exception
890   */
891  public Boolean getHasPicture() throws ServiceLocalException {
892    return getPropertyBag().getObjectFromPropertyDefinition(
893        ContactSchema.HasPicture);
894  }
895
896  /**
897   * Gets the funn phonetic name from the directory
898   */
899  public String getPhoneticFullName() throws Exception {
900    return getPropertyBag().getObjectFromPropertyDefinition(ContactSchema.PhoneticFullName);
901  }
902
903  /**
904   * Gets the funn phonetic name from the directory
905   */
906  public String getPhoneticFirstName() throws Exception {
907    return getPropertyBag().getObjectFromPropertyDefinition(ContactSchema.PhoneticFirstName);
908  }
909
910  /**
911   * Gets the phonetic last name from the directory
912   *
913   * @throws ServiceLocalException
914   */
915  public String getPhoneticLastName() throws ServiceLocalException {
916    return getPropertyBag().getObjectFromPropertyDefinition(ContactSchema.PhoneticLastName);
917  }
918
919  /**
920   * Gets the Alias from the directory
921   *
922   * @throws ServiceLocalException
923   */
924  public String getAlias() throws ServiceLocalException {
925    return getPropertyBag().getObjectFromPropertyDefinition(ContactSchema.Alias);
926  }
927
928  /**
929   * Get the Notes from the directory
930   *
931   * @throws ServiceLocalException
932   */
933  public String getNotes() throws ServiceLocalException {
934    return getPropertyBag().getObjectFromPropertyDefinition(ContactSchema.Notes);
935  }
936
937  /**
938   * Gets the Photo from the directory
939   *
940   * @throws ServiceLocalException
941   */
942  public byte[] getDirectoryPhoto() throws ServiceLocalException {
943    return getPropertyBag().getObjectFromPropertyDefinition(ContactSchema.Photo);
944  }
945
946  /**
947   * Gets the User SMIME certificate from the directory
948   *
949   * @throws ServiceLocalException
950   */
951  public byte[][] getUserSMIMECertificate() throws ServiceLocalException {
952    ByteArrayArray array = this.getPropertyBag()
953        .getObjectFromPropertyDefinition(ContactSchema.UserSMIMECertificate);
954    return array.getContent();
955  }
956
957  /**
958   * Gets the MSExchange certificate from the directory
959   *
960   * @throws ServiceLocalException
961   */
962  public byte[][] getMSExchangeCertificate() throws ServiceLocalException {
963      ByteArrayArray array = getPropertyBag()
964          .getObjectFromPropertyDefinition(ContactSchema.MSExchangeCertificate);
965      return array.getContent();
966  }
967
968  /**
969   * Gets the DirectoryID as Guid or DN string
970   *
971   * @throws ServiceLocalException
972   */
973  public String getDirectoryId() throws ServiceLocalException {
974    return getPropertyBag().getObjectFromPropertyDefinition(ContactSchema.DirectoryId);
975  }
976
977  /**
978   * Gets the manager mailbox information
979   *
980   * @throws ServiceLocalException
981   */
982  public EmailAddress getManagerMailbox() throws ServiceLocalException {
983    return getPropertyBag().getObjectFromPropertyDefinition(ContactSchema.ManagerMailbox);
984  }
985
986  /**
987   * Get the direct reports mailbox information
988   *
989   * @throws ServiceLocalException
990   */
991  public EmailAddressCollection getDirectReports() throws ServiceLocalException {
992    return getPropertyBag()
993        .getObjectFromPropertyDefinition(ContactSchema.DirectReports);
994  }
995}