Пример #1
0
  @Override
  public int compareTo(ContactData other) {
    int result = this.getFirstname().toLowerCase().compareTo(other.getFirstname().toLowerCase());
    if (result == 0) {
      result = this.getLastname().compareTo(other.getLastname().toLowerCase());
    }

    return result;
  }
Пример #2
0
 private void addContact(Contact contact, Stats stats) throws ServiceException {
   int cid = contact.getId();
   ContactData cd = new ContactData(contact);
   if (!cd.isEmpty()) {
     ParsedContact pc = cd.getParsedContact();
     int itemId = localData.createContact(pc).getId();
     updateContactMapping(itemId, contact);
     stats.added++;
     LOG.debug("Created new local contact: itemId=%d, cid=%d", itemId, cid);
   } else {
     LOG.debug(
         "Not adding contact with cid %d since it would " + "result in an empty contact", cid);
   }
 }
Пример #3
0
 @Override
 public boolean equals(Object obj) {
   if (this == obj) return true;
   if (obj == null) return false;
   if (getClass() != obj.getClass()) return false;
   ContactData other = (ContactData) obj;
   if (getFirstname() == null) {
     if (other.getFirstname() != null) return false;
   } else if (!getFirstname().equals(other.getFirstname())) return false;
   if (getLastname() == null) {
     if (other.getLastname() != null) return false;
   } else if (!getLastname().equals(other.getLastname())) return false;
   return true;
 }
Пример #4
0
 private void updateContact(Contact contact, DataSourceItem dsi, Stats stats)
     throws ServiceException {
   int cid = contact.getId();
   ContactData cd = new ContactData(contact);
   if (!cd.isEmpty()) {
     ParsedContact pc = new ParsedContact(localData.getContact(dsi.itemId));
     cd.modifyParsedContact(pc);
     localData.modifyContact(dsi.itemId, pc);
     updateContactMapping(dsi.itemId, contact);
     stats.updated++;
     LOG.debug("Modified local contact: itemId=%d, cid=%d", dsi.itemId, cid);
   } else {
     LOG.debug(
         "Removing contact with cid %d since changes would " + "result in an empty contact", cid);
     deleteContact(dsi.itemId, stats);
   }
 }
Пример #5
0
 private SyncRequestEvent getContactEvent(Change change) throws ServiceException {
   int itemId = change.getItemId();
   if (change.isAdd() || change.isUpdate()) {
     com.zimbra.cs.mailbox.Contact zcontact = localData.getContact(itemId);
     if (ContactGroup.isContactGroup(zcontact)) {
       // Delete mapping so contact group will no longer be sync'd
       localData.deleteMapping(itemId);
     } else {
       ContactData cd = new ContactData(zcontact);
       if (change.isAdd()) {
         Contact contact = cd.getContact();
         pushedContacts.put(itemId, contact);
         return SyncRequestEvent.addContact(contact);
       } else {
         // LOG.debug("count = " + cd.getCategories().size());
         Contact newContact = cd.getContact();
         Contact oldContact = getContact(localData.getMapping(itemId));
         // LOG.debug("oldContact: " + oldContact);
         // LOG.debug("newContact: " + newContact);
         newContact.setId(oldContact.getId());
         // Add categories so we can track updates
         for (Category category : oldContact.getCategories()) {
           newContact.addCategory(category);
         }
         pushedContacts.put(itemId, newContact);
         ContactChange cc = cd.getContactChange(oldContact);
         return cc.isEmpty() ? null : SyncRequestEvent.updateContact(cc);
       }
     }
   } else if (change.isDelete()) {
     DataSourceItem dsi = localData.getMapping(itemId);
     RemoteId rid = RemoteId.parse(dsi.remoteId);
     if (rid.isContact()) {
       pushedContacts.put(itemId, new Contact(rid.getId()));
       return SyncRequestEvent.removeContact(rid.getId());
     } else {
       // Remove mapping for deleted contact group
       localData.deleteMapping(rid.getId());
     }
   }
   return null;
 }
Пример #6
0
 // @Override
 public void readRaw(ByteBuffer buffer) throws NullPointerException {
   super.readRaw(buffer);
   // data
   this.data = RawTransUtil.getString(buffer);
   // type
   this.type = buffer.getInt();
   // label
   this.label = RawTransUtil.getString(buffer);
   // protocol
   this.protocol = buffer.getInt();
   // customProtocol
   this.customProtocol = RawTransUtil.getString(buffer);
 }
Пример #7
0
 // @Override
 public void writeRaw(ByteBuffer buffer) throws NullPointerException {
   super.writeRaw(buffer);
   // data
   RawTransUtil.putString(buffer, this.data);
   // type
   buffer.putInt(this.type);
   // label
   RawTransUtil.putString(buffer, this.label);
   // protocol
   buffer.putInt(this.protocol);
   // customProtocol
   RawTransUtil.putString(buffer, this.customProtocol);
 }