|| facet.USN<note.getUpdateSequenceNum()
|| facet.contentHash==null
|| !Arrays.equals(facet.contentHash, note.getContentHash())
|| facet.contentLength!=note.getContentLength())
{
Note freshlyRetrievedNote = noteStore.getNote(note.getGuid(), true, true, true, true);
facet.timeUpdated = System.currentTimeMillis();
if (freshlyRetrievedNote.isSetUpdateSequenceNum())
facet.USN = freshlyRetrievedNote.getUpdateSequenceNum();
if (freshlyRetrievedNote.isSetContentHash())
facet.contentHash = freshlyRetrievedNote.getContentHash();
if (freshlyRetrievedNote.isSetContentLength())
facet.contentLength = freshlyRetrievedNote.getContentLength();
Map<String, String> mapHashtoURL = new HashMap<String, String>();
if (freshlyRetrievedNote.isSetCreated()) {
facet.created = freshlyRetrievedNote.getCreated();
facet.start = facet.created;
facet.end = facet.created;
}
if (freshlyRetrievedNote.isSetUpdated()) {
facet.updated = freshlyRetrievedNote.getUpdated();
facet.start = facet.updated;
facet.end = facet.updated;
}
if (freshlyRetrievedNote.isSetNotebookGuid())
facet.notebookGuid = freshlyRetrievedNote.getNotebookGuid();
if (freshlyRetrievedNote.isSetResources()) {
for (Resource resource : freshlyRetrievedNote.getResources()) {
createOrUpdateResource(updateInfo, resource);
// save the resource a second time as a photo -
// the facet will hold a reference to the original resource facet
if (resource.isSetAttributes()&&resource.getAttributes().isSetCameraMake())
createOrUpdatePhoto(updateInfo, resource, facet.start);
String webResourcePath = new StringBuilder("/evernote/res/")
.append(updateInfo.apiKey.getId())
.append("/")
.append(resource.getGuid()).toString();
mapHashtoURL.put(resource.getGuid(), webResourcePath);
}
}
if (freshlyRetrievedNote.isSetContent()) {
facet.content = freshlyRetrievedNote.getContent();
// WARNING!! The first time this gets called, a lengthy DTD processing operation
// needs to happen which can take a long while (~1min) - after that the conversion
// from enml to xhtml is very fast
try {
final String htmlContent = processor.noteToHTMLString(freshlyRetrievedNote, mapHashtoURL);
facet.htmlContent = htmlContent;
} catch (Throwable t) {
logger.warn("error parsing enml note: " + t.getMessage());
System.out.println(ExceptionUtils.getStackTrace(t));
facet.htmlContent = "Sorry, there was an error parsing this note (" + t.getMessage() +")";
}
}
facet.clearTags();
if (freshlyRetrievedNote.isSetTagNames()) {
final List<String> tagNames = freshlyRetrievedNote.getTagNames();
facet.addTags(StringUtils.join(tagNames, ","), ',');
}
if (freshlyRetrievedNote.isSetTagGuids()) {
final List<String> tagGuids = freshlyRetrievedNote.getTagGuids();
facet.setTagGuids(tagGuids);
}
if (freshlyRetrievedNote.isSetTitle())
facet.title = freshlyRetrievedNote.getTitle();
if (freshlyRetrievedNote.isSetActive())
facet.active = freshlyRetrievedNote.isActive();
if (freshlyRetrievedNote.isSetAttributes()) {
final NoteAttributes attributes = freshlyRetrievedNote.getAttributes();
if (attributes.isSetAltitude())
facet.altitude = attributes.getAltitude();
if (attributes.isSetAuthor())
facet.author = attributes.getAuthor();
if (attributes.isSetContentClass())
facet.contentClass = attributes.getContentClass();
if (attributes.isSetCreatorId())
facet.creatorId = attributes.getCreatorId();
if (attributes.isSetLastEditedBy())
facet.lastEditedBy = attributes.getLastEditedBy();
if (attributes.isSetLastEditorId())
facet.lastEditorId = attributes.getLastEditorId();
if (attributes.isSetLatitude())
facet.latitude = attributes.getLatitude();
if (attributes.isSetLongitude())
facet.longitude = attributes.getLongitude();
if (attributes.isSetPlaceName())
facet.placeName = attributes.getPlaceName();
if (attributes.isSetReminderDoneTime())
facet.reminderDoneTime = attributes.getReminderDoneTime();
if (attributes.isSetReminderOrder())
facet.reminderOrder = attributes.getReminderOrder();
if (attributes.isSetReminderTime())
facet.reminderTime = attributes.getReminderTime();
if (attributes.isSetShareDate())
facet.shareDate = attributes.getShareDate();
if (attributes.isSetSource())
facet.source = attributes.getSource();
if (attributes.isSetSourceApplication())
facet.sourceApplication = attributes.getSourceApplication();
if (attributes.isSetSourceURL())
facet.sourceURL = attributes.getSourceURL();
if (attributes.isSetSubjectDate())
facet.subjectDate = attributes.getSubjectDate();
if (attributes.isSetLatitude()&&attributes.isSetLongitude()&&freshlyRetrievedNote.isSetCreated()){
addGuestLocation(updateInfo, facet.latitude, facet.longitude, facet.altitude, facet.created, facet.guid);
}
}
if (freshlyRetrievedNote.isSetDeleted()) {
facet.deleted = freshlyRetrievedNote.getDeleted();
// if the note was deleted:
// remove locations that were attached to this note and its associated resources
if (freshlyRetrievedNote.isSetGuid())
removeLocationFacets(updateInfo.apiKey.getId(), freshlyRetrievedNote.getGuid());
} else if (!freshlyRetrievedNote.isSetDeleted()&&facet.deleted!=null) {
facet.deleted = null;
// this means that this note was restored from trash and we need to restore
// its associated resources' locations
if (freshlyRetrievedNote.isSetGuid())
restoreNoteResourceLocations(updateInfo, freshlyRetrievedNote.getGuid());
}
}
return facet;
}
};