Skip to content

Commit

Permalink
♻️ b3log#12509 文章作者 id
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Sep 16, 2018
1 parent 7af5022 commit 0985b58
Show file tree
Hide file tree
Showing 21 changed files with 111 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,9 @@ public void metaWeblog(final HttpServletRequest request, final HTTPRequestContex
final String userEmail = params.getJSONObject(INDEX_USER_EMAIL).getJSONObject("value").getString("string");
final JSONObject user = userQueryService.getUserByEmail(userEmail);
if (null == user) {
throw new Exception("No user[email=" + userEmail + "]");
throw new Exception("No user [email=" + userEmail + "]");
}
final String userId = user.optString(Keys.OBJECT_ID);

final String userPwd = params.getJSONObject(INDEX_USER_PWD).getJSONObject("value").getString("string");
if (!user.getString(User.USER_PASSWORD).equals(DigestUtils.md5Hex(userPwd))) {
Expand All @@ -238,7 +239,7 @@ public void metaWeblog(final HttpServletRequest request, final HTTPRequestContex
responseContent = getRecentPosts(numOfPosts);
} else if (METHOD_NEW_POST.equals(methodName)) {
final JSONObject article = parsetPost(methodCall);
article.put(Article.ARTICLE_AUTHOR_EMAIL, userEmail);
article.put(Article.ARTICLE_AUTHOR_ID, userId);
addArticle(article);

final StringBuilder stringBuilder = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?><methodResponse>").append("<params><param><value><string>").append(article.getString(Keys.OBJECT_ID)).append(
Expand All @@ -251,7 +252,7 @@ public void metaWeblog(final HttpServletRequest request, final HTTPRequestContex
final JSONObject article = parsetPost(methodCall);
final String postId = params.getJSONObject(INDEX_POST_ID).getJSONObject("value").getString("string");
article.put(Keys.OBJECT_ID, postId);
article.put(Article.ARTICLE_AUTHOR_EMAIL, userEmail);
article.put(Article.ARTICLE_AUTHOR_ID, userId);
final JSONObject updateArticleRequest = new JSONObject();
updateArticleRequest.put(Article.ARTICLE, article);
articleMgmtService.updateArticle(updateArticleRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.b3log.latke.ioc.inject.Inject;
import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger;
import org.b3log.latke.model.User;
import org.b3log.latke.service.ServiceException;
import org.b3log.latke.servlet.HTTPRequestContext;
import org.b3log.latke.servlet.HTTPRequestMethod;
Expand Down Expand Up @@ -123,7 +122,7 @@ public void addArticle(final HTTPRequestContext context, final JSONObject reques

final JSONObject admin = userQueryService.getAdmin();

article.put(Article.ARTICLE_AUTHOR_EMAIL, admin.getString(User.USER_EMAIL));
article.put(Article.ARTICLE_AUTHOR_ID, admin.getString(Keys.OBJECT_ID));
final String articleContent = article.optString(Article.ARTICLE_CONTENT);
article.put(Article.ARTICLE_ABSTRACT, Article.getAbstract(articleContent));
article.put(Article.ARTICLE_IS_PUBLISHED, true);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/b3log/solo/dev/ArticleGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
package org.b3log.solo.dev;

import org.apache.commons.lang.time.DateUtils;
import org.b3log.latke.Keys;
import org.b3log.latke.Latkes;
import org.b3log.latke.ioc.inject.Inject;
import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger;
import org.b3log.latke.model.User;
import org.b3log.latke.servlet.HTTPRequestMethod;
import org.b3log.latke.servlet.annotation.RequestProcessing;
import org.b3log.latke.servlet.annotation.RequestProcessor;
Expand Down Expand Up @@ -89,7 +89,7 @@ public void genArticles(final HttpServletRequest request, final HttpServletRespo

try {
final JSONObject admin = userQueryService.getAdmin();
final String authorEmail = admin.optString(User.USER_EMAIL);
final String authorId = admin.optString(Keys.OBJECT_ID);

for (int i = 0; i < num; i++) {
final JSONObject article = new JSONObject();
Expand All @@ -98,7 +98,7 @@ public void genArticles(final HttpServletRequest request, final HttpServletRespo
final int deviationTag = 3;

article.put(Article.ARTICLE_TAGS_REF, "taga,tagb,tag" + i % deviationTag);
article.put(Article.ARTICLE_AUTHOR_EMAIL, authorEmail);
article.put(Article.ARTICLE_AUTHOR_ID, authorId);
article.put(Article.ARTICLE_COMMENT_COUNT, 0);
article.put(Article.ARTICLE_VIEW_COUNT, 0);
article.put(Article.ARTICLE_CONTENT, "article content");
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/org/b3log/solo/event/rhythm/ArticleSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
import org.b3log.latke.ioc.Lifecycle;
import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger;
import org.b3log.latke.model.User;
import org.b3log.latke.util.Strings;
import org.b3log.solo.SoloServletListener;
import org.b3log.solo.event.EventTypes;
import org.b3log.solo.model.Article;
import org.b3log.solo.model.Common;
import org.b3log.solo.model.Option;
import org.b3log.solo.service.ArticleQueryService;
import org.b3log.solo.service.PreferenceQueryService;
import org.b3log.solo.util.Solos;
import org.json.JSONObject;
Expand Down Expand Up @@ -79,6 +81,7 @@ public void action(final Event<JSONObject> event) {

final LatkeBeanManager beanManager = Lifecycle.getBeanManager();
final PreferenceQueryService preferenceQueryService = beanManager.getReference(PreferenceQueryService.class);
final ArticleQueryService articleQueryService = beanManager.getReference(ArticleQueryService.class);

final JSONObject preference = preferenceQueryService.getPreference();
if (null == preference) {
Expand All @@ -95,14 +98,17 @@ public void action(final Event<JSONObject> event) {
return;
}

final JSONObject author = articleQueryService.getAuthor(originalArticle);
final String authorEmail = author.optString(User.USER_EMAIL);

final JSONObject requestJSONObject = new JSONObject();
final JSONObject article = new JSONObject();

article.put(Keys.OBJECT_ID, originalArticle.getString(Keys.OBJECT_ID));
article.put(Article.ARTICLE_TITLE, originalArticle.getString(Article.ARTICLE_TITLE));
article.put(Article.ARTICLE_PERMALINK, originalArticle.getString(Article.ARTICLE_PERMALINK));
article.put(Article.ARTICLE_TAGS_REF, originalArticle.getString(Article.ARTICLE_TAGS_REF));
article.put(Article.ARTICLE_AUTHOR_EMAIL, originalArticle.getString(Article.ARTICLE_AUTHOR_EMAIL));
article.put(Article.ARTICLE_T_AUTHOR_EMAIL, authorEmail);
article.put(Article.ARTICLE_CONTENT, originalArticle.getString(Article.ARTICLE_CONTENT));
article.put(Article.ARTICLE_T_CREATE_DATE, originalArticle.getLong(Article.ARTICLE_CREATED));
article.put(Common.POST_TO_COMMUNITY, originalArticle.getBoolean(Common.POST_TO_COMMUNITY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
import org.b3log.latke.ioc.Lifecycle;
import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger;
import org.b3log.latke.model.User;
import org.b3log.latke.util.Strings;
import org.b3log.solo.SoloServletListener;
import org.b3log.solo.event.EventTypes;
import org.b3log.solo.model.Article;
import org.b3log.solo.model.Common;
import org.b3log.solo.model.Option;
import org.b3log.solo.service.ArticleQueryService;
import org.b3log.solo.service.PreferenceQueryService;
import org.b3log.solo.util.Solos;
import org.json.JSONObject;
Expand Down Expand Up @@ -75,6 +77,7 @@ public void action(final Event<JSONObject> event) {

final LatkeBeanManager beanManager = Lifecycle.getBeanManager();
final PreferenceQueryService preferenceQueryService = beanManager.getReference(PreferenceQueryService.class);
final ArticleQueryService articleQueryService = beanManager.getReference(ArticleQueryService.class);

final JSONObject preference = preferenceQueryService.getPreference();
if (null == preference) {
Expand All @@ -91,14 +94,17 @@ public void action(final Event<JSONObject> event) {
return;
}

final JSONObject author = articleQueryService.getAuthor(originalArticle);
final String authorEmail = author.optString(User.USER_EMAIL);

final JSONObject requestJSONObject = new JSONObject();
final JSONObject article = new JSONObject();

article.put(Keys.OBJECT_ID, originalArticle.getString(Keys.OBJECT_ID));
article.put(Article.ARTICLE_TITLE, originalArticle.getString(Article.ARTICLE_TITLE));
article.put(Article.ARTICLE_PERMALINK, originalArticle.getString(Article.ARTICLE_PERMALINK));
article.put(Article.ARTICLE_TAGS_REF, originalArticle.getString(Article.ARTICLE_TAGS_REF));
article.put(Article.ARTICLE_AUTHOR_EMAIL, originalArticle.getString(Article.ARTICLE_AUTHOR_EMAIL));
article.put(Article.ARTICLE_T_AUTHOR_EMAIL, authorEmail);
article.put(Article.ARTICLE_CONTENT, originalArticle.getString(Article.ARTICLE_CONTENT));
article.put(Article.ARTICLE_T_CREATE_DATE, originalArticle.getLong(Article.ARTICLE_CREATED));
article.put(Common.POST_TO_COMMUNITY, originalArticle.getBoolean(Common.POST_TO_COMMUNITY));
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/org/b3log/solo/model/Article.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,15 @@ public final class Article {
*/
public static final String ARTICLE_IS_PUBLISHED = "articleIsPublished";

/**
* Key of author id.
*/
public static final String ARTICLE_AUTHOR_ID = "articleAuthorId";

/**
* Key of author email.
*/
public static final String ARTICLE_AUTHOR_EMAIL = "articleAuthorEmail";
public static final String ARTICLE_T_AUTHOR_EMAIL = "articleAuthorEmail";

/**
* Key of had been published.
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/org/b3log/solo/processor/ArticleProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://zephyr.b3log.org">Zephyr</a>
* @version 1.4.4.3, Sep 7, 2018
* @version 1.4.4.4, Sep 16, 2018
* @since 0.3.1
*/
@RequestProcessor
Expand Down Expand Up @@ -690,7 +690,7 @@ public void getAuthorsArticlesByPage(final HTTPRequestContext context, final Htt
final String authorId = getAuthorsArticlesPagedAuthorId(request.getRequestURI());
final int currentPageNum = getAuthorsArticlesPagedCurrentPageNum(request.getRequestURI());

Stopwatchs.start("Get Author-Articles Paged[authorId=" + authorId + ", pageNum=" + currentPageNum + ']');
Stopwatchs.start("Get Author-Articles Paged [authorId=" + authorId + ", pageNum=" + currentPageNum + ']');
try {
jsonObject.put(Keys.STATUS_CODE, true);

Expand All @@ -705,9 +705,8 @@ public void getAuthorsArticlesByPage(final HTTPRequestContext context, final Htt
}

final JSONObject author = authorRet.getJSONObject(User.USER);
final String authorEmail = author.optString(User.USER_EMAIL);

final List<JSONObject> articles = articleQueryService.getArticlesByAuthorEmail(authorEmail, currentPageNum, pageSize);
final List<JSONObject> articles = articleQueryService.getArticlesByAuthorId(authorId, currentPageNum, pageSize);
if (!articles.isEmpty()) {
filler.setArticlesExProperties(request, articles, author, preference);
}
Expand Down Expand Up @@ -785,7 +784,7 @@ public void showAuthorArticles(final HTTPRequestContext context, final HttpServl

final JSONObject author = result.getJSONObject(User.USER);
final String authorEmail = author.getString(User.USER_EMAIL);
final List<JSONObject> articles = articleQueryService.getArticlesByAuthorEmail(authorEmail, currentPageNum, pageSize);
final List<JSONObject> articles = articleQueryService.getArticlesByAuthorId(authorEmail, currentPageNum, pageSize);
if (articles.isEmpty()) {
try {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/b3log/solo/processor/BlogProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public void getArticlesTags(final HTTPRequestContext context, final HttpServletR
excludes.put(Article.ARTICLE_CONTENT);
excludes.put(Article.ARTICLE_UPDATED);
excludes.put(Article.ARTICLE_CREATED);
excludes.put(Article.ARTICLE_AUTHOR_EMAIL);
excludes.put(Article.ARTICLE_AUTHOR_ID);
excludes.put(Article.ARTICLE_HAD_BEEN_PUBLISHED);
excludes.put(Article.ARTICLE_IS_PUBLISHED);
excludes.put(Article.ARTICLE_RANDOM_DOUBLE);
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/b3log/solo/processor/FeedProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -556,11 +556,10 @@ private Item getItemForArticles(final List<JSONObject> articles, final boolean h
final String link = Latkes.getServePath() + article.getString(Article.ARTICLE_PERMALINK);
ret.setLink(link);
ret.setGUID(link);
final String authorEmail = article.getString(Article.ARTICLE_AUTHOR_EMAIL);
if (hasMultipleUsers) {
authorName = articleQueryService.getAuthor(article).getString(User.USER_NAME);
}
ret.setAuthor(authorEmail + "(" + authorName + ")");
ret.setAuthor(authorName);
final String tagsString = article.getString(Article.ARTICLE_TAGS_REF);
final String[] tagStrings = tagsString.split(",");
for (final String tagString : tagStrings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public void getArticles(final HttpServletRequest request, final HttpServletRespo
excludes.put(Article.ARTICLE_CONTENT);
excludes.put(Article.ARTICLE_UPDATED);
excludes.put(Article.ARTICLE_CREATED);
excludes.put(Article.ARTICLE_AUTHOR_EMAIL);
excludes.put(Article.ARTICLE_AUTHOR_ID);
excludes.put(Article.ARTICLE_HAD_BEEN_PUBLISHED);
excludes.put(Article.ARTICLE_IS_PUBLISHED);
excludes.put(Article.ARTICLE_RANDOM_DOUBLE);
Expand Down Expand Up @@ -673,7 +673,7 @@ public void addArticle(final HttpServletRequest request, final HttpServletRespon

try {
final JSONObject currentUser = userQueryService.getCurrentUser(request);
requestJSONObject.getJSONObject(Article.ARTICLE).put(Article.ARTICLE_AUTHOR_EMAIL, currentUser.getString(User.USER_EMAIL));
requestJSONObject.getJSONObject(Article.ARTICLE).put(Article.ARTICLE_AUTHOR_ID, currentUser.getString(Keys.OBJECT_ID));

final String articleId = articleMgmtService.addArticle(requestJSONObject);
ret.put(Keys.OBJECT_ID, articleId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
public interface ArticleRepository extends Repository {

/**
* Gets published articles by the specified author email, current page number and page size.
* Gets published articles by the specified author id, current page number and page size.
*
* @param authorEmail the specified author email
* @param authorId the specified author id
* @param currentPageNum the specified current page number, MUST greater then {@code 0}
* @param pageSize the specified page size(count of a page contains objects), MUST greater then {@code 0}
* @return for example
Expand All @@ -51,7 +51,7 @@ public interface ArticleRepository extends Repository {
* </pre>
* @throws RepositoryException repository exception
*/
JSONObject getByAuthorEmail(final String authorEmail, final int currentPageNum, final int pageSize) throws RepositoryException;
JSONObject getByAuthorId(final String authorId, final int currentPageNum, final int pageSize) throws RepositoryException;

/**
* Gets an article by the specified permalink.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ public void update(final String id, final JSONObject article) throws RepositoryE
}

@Override
public JSONObject getByAuthorEmail(final String authorEmail, final int currentPageNum, final int pageSize)
public JSONObject getByAuthorId(final String authorId, final int currentPageNum, final int pageSize)
throws RepositoryException {
final Query query = new Query().
setFilter(CompositeFilterOperator.and(
new PropertyFilter(Article.ARTICLE_AUTHOR_EMAIL, FilterOperator.EQUAL, authorEmail),
new PropertyFilter(Article.ARTICLE_AUTHOR_ID, FilterOperator.EQUAL, authorId),
new PropertyFilter(Article.ARTICLE_IS_PUBLISHED, FilterOperator.EQUAL, true))).
addSort(Article.ARTICLE_UPDATED, SortDirection.DESCENDING).addSort(Article.ARTICLE_PUT_TOP, SortDirection.DESCENDING).
setCurrentPageNum(currentPageNum).setPageSize(pageSize).setPageCount(1);
Expand Down
15 changes: 6 additions & 9 deletions src/main/java/org/b3log/solo/service/ArticleMgmtService.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ public void cancelPublishArticle(final String articleId) throws ServiceException

statisticMgmtService.setPublishedBlogCommentCount(blogCmtCnt - articleCmtCnt);

final JSONObject author = userRepository.getByEmail(article.optString(Article.ARTICLE_AUTHOR_EMAIL));

final JSONObject author = userRepository.get(article.optString(Article.ARTICLE_AUTHOR_ID));
author.put(UserExt.USER_PUBLISHED_ARTICLE_COUNT, author.optInt(UserExt.USER_PUBLISHED_ARTICLE_COUNT) - 1);
userRepository.update(author.optString(Keys.OBJECT_ID), author);

Expand Down Expand Up @@ -354,8 +353,7 @@ public void updateArticle(final JSONObject requestJSONObject) throws ServiceExce

statisticMgmtService.setPublishedBlogCommentCount(blogCmtCnt + articleCmtCnt);

final JSONObject author = userRepository.getByEmail(article.optString(Article.ARTICLE_AUTHOR_EMAIL));

final JSONObject author = userRepository.get(article.optString(Article.ARTICLE_AUTHOR_ID));
author.put(UserExt.USER_PUBLISHED_ARTICLE_COUNT, author.optInt(UserExt.USER_PUBLISHED_ARTICLE_COUNT) + 1);
userRepository.update(author.optString(Keys.OBJECT_ID), author);
}
Expand Down Expand Up @@ -420,7 +418,7 @@ public void updateArticle(final JSONObject requestJSONObject) throws ServiceExce
* @param requestJSONObject the specified request json object, for example,
* {
* "article": {
* "articleAuthorEmail": "",
* "articleAuthorId": "",
* "articleTitle": "",
* "articleAbstract": "",
* "articleContent": "",
Expand Down Expand Up @@ -520,7 +518,7 @@ public String addArticleInternal(final JSONObject article) throws ServiceExcepti

article.remove(Common.POST_TO_COMMUNITY); // Do not persist this property
// Setp 13: Update user article statistic
final JSONObject author = userRepository.getByEmail(article.optString(Article.ARTICLE_AUTHOR_EMAIL));
final JSONObject author = userRepository.get(article.optString(Article.ARTICLE_AUTHOR_ID));
final int userArticleCnt = author.optInt(UserExt.USER_ARTICLE_COUNT);

author.put(UserExt.USER_ARTICLE_COUNT, userArticleCnt + 1);
Expand Down Expand Up @@ -583,8 +581,7 @@ public void removeArticle(final String articleId) throws ServiceException {
statisticMgmtService.decPublishedBlogArticleCount();
}

final JSONObject author = userRepository.getByEmail(article.optString(Article.ARTICLE_AUTHOR_EMAIL));

final JSONObject author = userRepository.get(article.optString(Article.ARTICLE_AUTHOR_ID));
author.put(UserExt.USER_PUBLISHED_ARTICLE_COUNT, author.optInt(UserExt.USER_PUBLISHED_ARTICLE_COUNT) - 1);
author.put(UserExt.USER_ARTICLE_COUNT, author.optInt(UserExt.USER_ARTICLE_COUNT) - 1);
userRepository.update(author.optString(Keys.OBJECT_ID), author);
Expand Down Expand Up @@ -1096,7 +1093,7 @@ private void fillAutoProperties(final JSONObject oldArticle, final JSONObject ar
article.put(ARTICLE_VIEW_COUNT, oldArticle.getInt(ARTICLE_VIEW_COUNT));
article.put(ARTICLE_PUT_TOP, oldArticle.getBoolean(ARTICLE_PUT_TOP));
article.put(ARTICLE_HAD_BEEN_PUBLISHED, oldArticle.getBoolean(ARTICLE_HAD_BEEN_PUBLISHED));
article.put(ARTICLE_AUTHOR_EMAIL, oldArticle.getString(ARTICLE_AUTHOR_EMAIL));
article.put(ARTICLE_AUTHOR_ID, oldArticle.getString(ARTICLE_AUTHOR_ID));
article.put(ARTICLE_RANDOM_DOUBLE, Math.random());
}

Expand Down
Loading

0 comments on commit 0985b58

Please sign in to comment.