if (badTagSync == null)
badTagSync = new HashMap<String,String>();
else
badTagSync.clear();
Tag enTag = findNextTag();
// This is a hack. Sometimes this function goes flookey and goes into a
// perpetual loop. This causes NeverNote to flood Evernote's servers.
// This is a safety valve to prevent unlimited loops.
int maxCount = conn.getTagTable().getDirty().size()+10;
int loopCount = 0;
while(enTag!=null && loopCount < maxCount) {
loopCount++;
// if (authRefreshNeeded)
// if (!refreshConnection())
// return;
try {
if (enTag.getUpdateSequenceNum() > 0) {
logger.log(logger.EXTREME, "Updating tag");
sequence = noteStore.updateTag(authToken, enTag);
} else {
// Look for a tag with the same name. If one is found, we don't need
// to create another one
logger.log(logger.EXTREME, "New tag. Comparing with remote names");
boolean found = false;
String oldGuid = enTag.getGuid();
for (int k=0; k<remoteList.size() && !found && keepRunning; k++) {
if (remoteList.get(k).getName().equalsIgnoreCase(enTag.getName())) {
conn.getTagTable().updateTagGuid(enTag.getGuid(), remoteList.get(k).getGuid());
enTag = remoteList.get(k);
logger.log(logger.EXTREME, "Matching tag name found");
found = true;
}
}
if (!found)
enTag = noteStore.createTag(authToken, enTag);
else
enTag.setUpdateSequenceNum(noteStore.updateTag(authToken,enTag));
sequence = enTag.getUpdateSequenceNum();
if (!oldGuid.equals(enTag.getGuid())) {
logger.log(logger.EXTREME, "Updating tag guid");
conn.getTagTable().updateTagGuid(oldGuid, enTag.getGuid());
}
}
logger.log(logger.EXTREME, "Updating tag sequence number");
conn.getTagTable().updateTagSequence(enTag.getGuid(), sequence);
logger.log(logger.EXTREME, "Resetting tag dirty flag");
conn.getTagTable().resetDirtyFlag(enTag.getGuid());
logger.log(logger.EXTREME, "Emitting sequence number to the main thread.");
updateSequenceNumber = sequence;
conn.getSyncTable().setUpdateSequenceNumber(updateSequenceNumber);
} catch (EDAMUserException e) {
logger.log(logger.LOW, "*** EDAM User Excepton syncLocalTags: " +enTag.getName());
logger.log(logger.LOW, e.toString());
badTagSync.put(enTag.getGuid(),null);
error = true;
} catch (EDAMSystemException e) {
logger.log(logger.LOW, "** EDAM System Excepton syncLocalTags: " +enTag.getName());
logger.log(logger.LOW, e.toString());
badTagSync.put(enTag.getGuid(),null);
error = true;
} catch (EDAMNotFoundException e) {
logger.log(logger.LOW, "*** EDAM Not Found Excepton syncLocalTags: " +enTag.getName());
logger.log(logger.LOW, e.toString());
badTagSync.put(enTag.getGuid(),null);
error = true;
} catch (TException e) {
logger.log(logger.LOW, "*** EDAM TExcepton syncLocalTags: " +enTag.getName());
logger.log(logger.LOW, e.toString());
badTagSync.put(enTag.getGuid(),null);
error = true;
}
// Find the next tag
logger.log(logger.EXTREME, "Finding next tag");