예제 #1
0
 /**
  * Translate a delimted list of tag names to a delimited list of correponding local tagIds
  *
  * @throws ServiceException
  */
 public String localTagsFromNames(String tagNames, String inDelim, String outDelim)
     throws ServiceException {
   if (tagNames != null && tagNames.length() > 0) {
     StringBuilder sb = new StringBuilder();
     String[] names = tagNames.split(inDelim);
     for (String name : names) {
       if (name.trim().length() <= 0) {
         continue;
       }
       Integer tagId = localIdsByName.get(name);
       if (tagId == null) {
         try {
           Tag tag = mbox.getTagByName(null, name);
           tagId = tag.getId();
           localIdsByName.put(name, tagId);
         } catch (MailServiceException mse) {
           if (MailServiceException.NO_SUCH_TAG.equals(mse.getCode())) {
             OfflineLog.offline.debug(
                 "message has tag [" + name + "] which is not visible locally");
             continue;
           } else {
             throw mse;
           }
         }
       }
       sb.append(tagId).append(outDelim);
     }
     if (sb.length() >= outDelim.length()) {
       sb.setLength(sb.length() - outDelim.length());
     }
     return sb.toString();
   } else {
     return tagNames;
   }
 }
예제 #2
0
 /**
  * Return true if a mapping already exists for a given remoteId
  *
  * @throws ServiceException
  */
 public boolean mappingExists(int remoteId) throws ServiceException {
   if (localIdFromRemote.get(remoteId) != null) {
     return true;
   }
   try {
     DataSourceMapping mapping = new DataSourceMapping(tagDs, remoteId + "");
     localIdFromRemote.put(remoteId, mapping.getItemId());
     return true;
   } catch (NoSuchItemException e) {
     return false;
   }
 }
예제 #3
0
 /**
  * Get the local ID corresponding to remote tagId
  *
  * @throws ServiceException
  */
 public int localTagId(int id) throws ServiceException {
   if (!isMappingRequired(id)) {
     return id;
   }
   try {
     if (localIdFromRemote.containsKey(id)) {
       return localIdFromRemote.get(id);
     }
     DataSourceMapping mapping = new DataSourceMapping(tagDs, id + "");
     OfflineLog.offline.debug("got localId %d from remote %d", mapping.getItemId(), id);
     localIdFromRemote.put(id, mapping.getItemId());
     return mapping.getItemId();
   } catch (ServiceException se) {
     if (MailServiceException.NO_SUCH_ITEM.equals(se.getCode())) {
       return -1;
     }
     throw se;
   }
 }
예제 #4
0
 /**
  * Get the remoteId corresponding to local tagId
  *
  * @throws ServiceException
  */
 public int remoteTagId(int id) throws ServiceException {
   if (mappingRequired) {
     if (remoteIdFromLocal.containsKey(id)) {
       return remoteIdFromLocal.get(id);
     }
     try {
       DataSourceMapping mapping = new DataSourceMapping(tagDs, id);
       int remoteId = Integer.valueOf(mapping.getRemoteId());
       OfflineLog.offline.debug("got remoteId %d from localId %d", remoteId, id);
       remoteIdFromLocal.put(id, remoteId);
       return remoteId;
     } catch (ServiceException se) {
       if (MailServiceException.NO_SUCH_ITEM.equals(se.getCode())) {
         return -1;
       }
       throw se;
     }
   } else {
     return id;
   }
 }