@VisibleForTesting
void mapMetaFields(NotesDocument crawlDoc, NotesDocument srcDoc)
throws RepositoryException {
final String METHOD = "mapMetaFields";
LOGGER.entering(CLASS_NAME, METHOD);
NotesItem item = null;
for (MetaField mf : metaFields) {
try {
if (null == mf.getFieldName()) {
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.logp(Level.FINEST, CLASS_NAME, METHOD,
"Skipping null fieldname");
}
continue;
}
String configForm = mf.getFormName();
if (null != configForm) {
String docForm = srcDoc.getItemValueString(NCCONST.ITMFORM);
if (!configForm.equalsIgnoreCase(docForm)) {
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.logp(Level.FINEST, CLASS_NAME, METHOD,
"Skipping metafields because configured form {0} does not "
+ "match doc form {1}",
new Object[] { configForm, docForm });
}
continue;
}
}
if (!srcDoc.hasItem(mf.getFieldName())) {
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.logp(Level.FINEST, CLASS_NAME, METHOD,
"Source doc does not have field: " + mf.getFieldName());
}
continue;
}
// If there are multiple items with the same name (not a
// common Notes occurrence), only the first item will be
// mapped.
item = srcDoc.getFirstItem(mf.getFieldName());
if (null == item.getValues()) {
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.logp(Level.FINEST, CLASS_NAME, METHOD,
"Source doc does not have value for: " + mf.getFieldName());
}
continue;
}
Object content = item;
if (item.getType() == NotesItem.RICHTEXT) {
content = item.getText(2 * 1024);
}
if (crawlDoc.hasItem(META_FIELDS_PREFIX + mf.getMetaName())) {
LOGGER.logp(Level.WARNING, CLASS_NAME, METHOD,
"Mapping meta fields: meta field {0} already exists in crawl doc",
mf.getMetaName());
// If multiple Notes fields are mapped to the same meta
// field, only the first mapping will be used.
continue;
}
crawlDoc.replaceItemValue(META_FIELDS_PREFIX + mf.getMetaName(),
content);
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.logp(Level.FINEST, CLASS_NAME, METHOD,
"Mapped meta field : " + META_FIELDS_PREFIX
+ mf.getMetaName() + " = " + content);
}
} catch (RepositoryException e) {
LOGGER.logp(Level.WARNING, CLASS_NAME, METHOD,
"Error mapping MetaField " + mf, e);
} finally {
if (null != item) {
item.recycle();
}
}
}
LOGGER.exiting(CLASS_NAME, METHOD);
}