private void enableTagDataSource(ZcsMailbox mbox) throws ServiceException { localIdFromRemote = new LruMap<Integer, Integer>(64); remoteIdFromLocal = new LruMap<Integer, Integer>(64); localIdsByName = new LruMap<String, Integer>(64); mappingRequired = true; initTagDataSource(mbox.getOfflineAccount()); }
/** * 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; } }
public TagSync(ZcsMailbox mbox) { this.mbox = mbox; // TODO: will need inverse implementation for ZD 8 to work with ZCS 7; underpinnings are here // but need to work out details try { if (!mbox.getRemoteServerVersion().isAtLeast8xx()) { enableTagDataSource(mbox); } } catch (ServiceException e) { OfflineLog.offline.error("Unable to intialize tag datasource due to exception.", e); } }
private void initTagDataSource(OfflineAccount account) throws ServiceException { OfflineProvisioning prov = OfflineProvisioning.getOfflineInstance(); tagDs = account.getDataSourceByName(dsName); if (tagDs == null) { OfflineLog.offline.debug("initializing tag datasource"); tagDs = prov.createDataSource( account, DataSourceType.tagmap, dsName, new HashMap<String, Object>()); // initially any previously existing local tags also have same ID as remote. List<Tag> tags = mbox.getTagList(null); for (Tag tag : tags) { mapTag(tag.getId(), tag.getId()); } } }