Beispiel #1
0
 private void processCategories(List<Category> categories) throws ServiceException {
   Stats stats = new Stats();
   // Get all existing contact groups
   Map<Integer, ContactGroup> groups = new HashMap<Integer, ContactGroup>();
   for (Category cat : categories) {
     groups.put(cat.getId(), new ContactGroup(cat.getName()));
   }
   // Get all contact mappings and update contact group dlist information
   Collection<DataSourceItem> mappings = localData.getAllContactMappings();
   for (DataSourceItem dsi : mappings) {
     if (dsi.remoteId != null) {
       RemoteId rid = RemoteId.parse(dsi.remoteId);
       if (rid.isContact()) {
         Contact contact = getContact(dsi);
         if (contact != null) {
           List<Category> cats = contact.getCategories();
           if (!cats.isEmpty()) {
             List<String> emails = getEmailAddresses(contact);
             if (!emails.isEmpty()) {
               for (Category cat : cats) {
                 ContactGroup group = groups.get(cat.getId());
                 if (group != null) {
                   group.addEmail(emails.get(0));
                 }
               }
             }
           }
         }
       }
     }
   }
   // Remove contact groups deleted remotely
   for (DataSourceItem dsi : mappings) {
     if (dsi.remoteId != null) {
       RemoteId rid = RemoteId.parse(dsi.remoteId);
       if (rid.isCategory() && !groups.containsKey(rid.getId())) {
         localData.deleteContactGroup(dsi.itemId);
         groups.remove(rid.getId());
         stats.deleted++;
       }
     }
   }
   // Create new or update existring contact groups
   for (Map.Entry<Integer, ContactGroup> me : groups.entrySet()) {
     RemoteId rid = RemoteId.categoryId(me.getKey());
     updateGroup(rid.toString(), me.getValue(), stats);
   }
   LOG.debug("Processed remote category changes: %s", stats);
 }
Beispiel #2
0
 private void processEvent(SyncResponseEvent event, Stats stats) throws ServiceException {
   Contact contact = event.getContact();
   RemoteId rid = RemoteId.contactId(contact.getId());
   DataSourceItem dsi = localData.getReverseMapping(rid.toString());
   if (event.isAddContact() || event.isUpdateContact()) {
     if (dsi.itemId > 0) {
       // Don't update contact if it has been modified locally since
       // sync request was sent. Wait until we send the new changes
       // before updating the local contact.
       if (!contactChanges.containsKey(dsi.itemId)) {
         updateContact(contact, dsi, stats);
       }
     } else {
       addContact(contact, stats);
     }
   } else if (event.isRemoveContact()) {
     if (dsi.itemId > 0) {
       deleteContact(dsi.itemId, stats);
     }
   }
 }
Beispiel #3
0
 private void updateContactMapping(int itemId, Contact contact) throws ServiceException {
   RemoteId rid = RemoteId.contactId(contact.getId());
   localData.updateMapping(itemId, rid.toString(), toXml(contact));
 }