package gw.api.contact uses gw.api.database.Query uses gw.api.database.Relop class ContactUtil { /** * Mints and returns a new Contact as well as its PrimaryAddress. * * @param contactType Type of contact to create (acceptable values are TC_COMPANY or TC_PERSON) * @return The newly minted contact */ static function createNewContact(contactType : typekey.ContactType) : Contact { var newContact = contactType == typekey.ContactType.TC_COMPANY ? new Company() : new Person() newContact.PrimaryAddress = new Address() return newContact } /** * @param publicID public ID of the contact * @return Contact entity or null if there are no matches */ function getContactByPublicID(publicID: String): entity.Contact { if (publicID == null) { return null } return Query.make(entity.Contact) .compare(entity.Contact#PublicID, Relop.Equals, publicID) .select().AtMostOneRow } /** * Returns a collection of all contact entities related to the given phone number. * * @param phone phone number of the contact. * @return Contact entity collection or empty collection if there are no matches. Never null. */ function getContactsByPhoneNumber(phone: String): Set { if (phone == null) { return Collections.emptySet() } return Query.make(entity.Contact) .compare(entity.Contact#WorkPhone, Relop.Equals, phone) .select().toSet() } /** * Returns a contact search criteria for the given phone number. * * @param phone the phone number to search for in all contacts. * @return a new criteria for contact search. Never null. */ function getContactsSearchCriteria(phone: String): ContactSearchCriteria { final var criteria = new ContactSearchCriteria() criteria.Phone = phone return criteria } }