new Object[]{event.getType(),
article,
AbstractAddArticleProcessor.class.getName()});
} catch (final JSONException e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
throw new EventException(e);
}
final String externalBloggingSys = getExternalBloggingSys();
try {
final JSONObject ret = new JSONObject();
final JSONObject blogSyncMgmt =
blogSyncManagementRepository.getByExternalBloggingSystem(
externalBloggingSys);
if (null == blogSyncMgmt) {
LOGGER.log(Level.FINER,
"Not found syn management settings for external blogging system[{0}]",
externalBloggingSys);
ret.put(Keys.STATUS_CODE,
BlogSyncStatusCodes.BLOG_SYNC_NO_NEED_TO_SYNC);
return ret;
}
final boolean hasMultipleUsers = userUtils.hasMultipleUsers();
if (hasMultipleUsers) {
LOGGER.log(Level.FINER,
"Disabled article sync management caused by has multiple users");
ret.put(Keys.STATUS_CODE,
BlogSyncStatusCodes.BLOG_SYNC_NO_NEED_TO_SYNC);
return ret;
}
LOGGER.log(Level.FINER,
"Got a blog sync management setting[{0}]",
blogSyncMgmt.toString(
SoloServletListener.JSON_PRINT_INDENT_FACTOR));
if (!blogSyncMgmt.getBoolean(
BLOG_SYNC_MGMT_UPDATE_ENABLED)) {
LOGGER.log(Level.INFO,
"External blogging system[{0}] need NOT to syn update article",
externalBloggingSys);
ret.put(Keys.STATUS_CODE,
BlogSyncStatusCodes.BLOG_SYNC_NO_NEED_TO_SYNC);
return ret;
} else {
final String userName = blogSyncMgmt.getString(
BLOG_SYNC_EXTERNAL_BLOGGING_SYS_USER_NAME);
final String userPwd = blogSyncMgmt.getString(
BLOG_SYNC_EXTERNAL_BLOGGING_SYS_USER_PASSWORD);
final Post externalArticle = new MetaWeblogPost(article);
final String articleId = article.getString(Keys.OBJECT_ID);
LOGGER.log(Level.FINEST,
"Getting External article-Solo article relation....");
final JSONObject externalArticleSoloArticleRelation =
externalArticleSoloArticleRepository.getBySoloArticleId(
articleId, externalBloggingSys);
if (null == externalArticleSoloArticleRelation) {
// This article published without sync adding enabled.
// See issue 72 for details
ret.put(Keys.STATUS_CODE, BlogSyncStatusCodes.BLOG_SYNC_FAIL);
return ret;
}
final String postId = externalArticleSoloArticleRelation.
getString(BLOG_SYNC_EXTERNAL_ARTICLE_ID);
final MetaWeblog metaWeblog =
BlogFactory.getMetaWeblog(externalBloggingSys);
metaWeblog.setUserName(userName);
metaWeblog.setUserPassword(userPwd);
metaWeblog.editPost(postId, externalArticle);
externalArticleSoloArticleRelation.put(
BLOG_SYNC_EXTERNAL_ARTICLE_ABSTRACT,
article.getString(Article.ARTICLE_ABSTRACT));
externalArticleSoloArticleRelation.put(
BLOG_SYNC_EXTERNAL_ARTICLE_CATEGORIES,
article.getString(Article.ARTICLE_TAGS_REF));
externalArticleSoloArticleRelation.put(
BLOG_SYNC_EXTERNAL_ARTICLE_CONTENT,
article.getString(Article.ARTICLE_CONTENT));
externalArticleSoloArticleRelation.put(
BLOG_SYNC_EXTERNAL_ARTICLE_CREATE_DATE,
article.get(Article.ARTICLE_CREATE_DATE));
externalArticleSoloArticleRelation.put(
BLOG_SYNC_EXTERNAL_ARTICLE_TITLE,
article.getString(Article.ARTICLE_TITLE));
externalArticleSoloArticleRepository.update(
externalArticleSoloArticleRelation.getString(
Keys.OBJECT_ID), externalArticleSoloArticleRelation);
}
ret.put(Keys.STATUS_CODE, BlogSyncStatusCodes.BLOG_SYNC_SUCC);
return ret;
} catch (final SyncException e) {
LOGGER.log(Level.WARNING,
"Can not update article sync, error msg[{0}]",
e.getMessage());
throw e;
} catch (final Exception e) {
LOGGER.log(Level.SEVERE, "Can not handle event[{0}], error msg[{1}]",
new String[]{getEventType(), e.getMessage()});
throw new EventException("Can not handle event[" + getEventType()
+ "]");
}
}