public static Document createDocument(Bookmark bookmark) {
if (bookmark == null) {
return null;
}
Document doc = new Document();
if (bookmark.getId() <= 0) {
logger.error("DocumentCreator detects an input Bookmark ID <= 0");
return null;
}
doc.add(createFieldBookmarkId(bookmark.getId()));
if (bookmark.getTitle() == null || bookmark.getTitle().length() == 0) {
logger.error("DocumentCreator detects an input "
+ "Bookmark Title has length 0. BookmarkId="
+ bookmark.getId());
return null;
}
doc.add(createFieldTitle(bookmark.getTitle()));
doc.add(createFieldText(bookmark.getTitle()));
// user:
if (bookmark.getUser() == null
|| bookmark.getUser().getUsername() == null) {
logger.error("DocumentCreator detects an input "
+ "Bookmark Username == null. BookmarkId="
+ bookmark.getId());
return null;
}
doc.add(createFieldUser(bookmark.getUser().getUsername()));
if (bookmark.getLink() == null || bookmark.getLink().getUrl() == null) {
logger.error("DocumentCreator detects an input "
+ "Bookmark URL == null. BookmarkId=" + bookmark.getId());
return null;
}
doc.add(createFieldUrl(bookmark.getLink().getUrl()));
// url: & urlMD5:
if (bookmark.getLink() == null || bookmark.getLink().getUrlHash() == null) {
logger.error("DocumentCreator detects an input "
+ "Bookmark URL Hash == null. BookmarkId=" + bookmark.getId());
return null;
}
doc.add(createFieldUrlHash(bookmark.getLink().getUrlHash()));
// notes:
String notes = extractText(bookmark.getNotes());
if (notes != null) {
doc.add(createFieldNotes(bookmark.getNotes()));
doc.add(createFieldText(bookmark.getNotes()));
}
// tag:
List<String> tagList = bookmark.getTagList();
for (String tag : tagList) {
doc.add(createFieldTag(tag));
doc.add(createFieldText(tag));
}
// createdOn:
if (bookmark.getCreatedOn() == null) {
logger.error("DocumentCreator detects an input "
+ "Bookmark createdOn == null. BookmarkId="
+ bookmark.getId());
return null;
}
doc.add(createFieldCreatedOn(bookmark.getCreatedOn()));
// lastUpdated:
if (bookmark.getLastUpdated() == null) {
logger.error("DocumentCreator detects an input "
+ "Bookmark lastUpdated == null. BookmarkId="
+ bookmark.getId());
return null;
}
doc.add(createFieldLastUpdated(bookmark.getLastUpdated()));
return doc;
}