From 0985b5840de6f03fbcd608b1a58e229d82ff60d0 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sun, 16 Sep 2018 17:03:25 +0800 Subject: [PATCH] =?UTF-8?q?:recycle:=20#12509=20=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E4=BD=9C=E8=80=85=20id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../solo/api/metaweblog/MetaWeblogAPI.java | 7 +-- .../solo/api/symphony/ArticleReceiver.java | 3 +- .../org/b3log/solo/dev/ArticleGenerator.java | 6 +-- .../solo/event/rhythm/ArticleSender.java | 8 +++- .../solo/event/rhythm/ArticleUpdater.java | 8 +++- .../java/org/b3log/solo/model/Article.java | 7 ++- .../solo/processor/ArticleProcessor.java | 9 ++-- .../b3log/solo/processor/BlogProcessor.java | 2 +- .../b3log/solo/processor/FeedProcessor.java | 3 +- .../processor/console/ArticleConsole.java | 4 +- .../solo/repository/ArticleRepository.java | 6 +-- .../impl/ArticleRepositoryImpl.java | 4 +- .../solo/service/ArticleMgmtService.java | 15 +++---- .../solo/service/ArticleQueryService.java | 41 +++++++---------- .../solo/service/CommentQueryService.java | 5 +-- .../org/b3log/solo/service/ImportService.java | 5 ++- .../org/b3log/solo/service/InitService.java | 3 +- src/main/resources/repository.json | 6 +-- .../processor/CommentProcessorTestCase.java | 4 +- .../impl/ArticleRepositoryImplTestCase.java | 12 ++--- .../service/ArticleMgmtServiceTestCase.java | 44 +++++++++++++------ 21 files changed, 111 insertions(+), 91 deletions(-) diff --git a/src/main/java/org/b3log/solo/api/metaweblog/MetaWeblogAPI.java b/src/main/java/org/b3log/solo/api/metaweblog/MetaWeblogAPI.java index 22f071167..6dbd2b88e 100644 --- a/src/main/java/org/b3log/solo/api/metaweblog/MetaWeblogAPI.java +++ b/src/main/java/org/b3log/solo/api/metaweblog/MetaWeblogAPI.java @@ -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))) { @@ -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("").append("").append(article.getString(Keys.OBJECT_ID)).append( @@ -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); diff --git a/src/main/java/org/b3log/solo/api/symphony/ArticleReceiver.java b/src/main/java/org/b3log/solo/api/symphony/ArticleReceiver.java index 398704ce5..64a2f914f 100644 --- a/src/main/java/org/b3log/solo/api/symphony/ArticleReceiver.java +++ b/src/main/java/org/b3log/solo/api/symphony/ArticleReceiver.java @@ -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; @@ -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); diff --git a/src/main/java/org/b3log/solo/dev/ArticleGenerator.java b/src/main/java/org/b3log/solo/dev/ArticleGenerator.java index f90db2e15..c3a7c5d40 100644 --- a/src/main/java/org/b3log/solo/dev/ArticleGenerator.java +++ b/src/main/java/org/b3log/solo/dev/ArticleGenerator.java @@ -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; @@ -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(); @@ -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"); diff --git a/src/main/java/org/b3log/solo/event/rhythm/ArticleSender.java b/src/main/java/org/b3log/solo/event/rhythm/ArticleSender.java index aa4020edf..29faf1e0a 100644 --- a/src/main/java/org/b3log/solo/event/rhythm/ArticleSender.java +++ b/src/main/java/org/b3log/solo/event/rhythm/ArticleSender.java @@ -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; @@ -79,6 +81,7 @@ public void action(final Event 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) { @@ -95,6 +98,9 @@ public void action(final Event 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(); @@ -102,7 +108,7 @@ public void action(final Event event) { 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)); diff --git a/src/main/java/org/b3log/solo/event/rhythm/ArticleUpdater.java b/src/main/java/org/b3log/solo/event/rhythm/ArticleUpdater.java index 0844ce817..43dad0052 100644 --- a/src/main/java/org/b3log/solo/event/rhythm/ArticleUpdater.java +++ b/src/main/java/org/b3log/solo/event/rhythm/ArticleUpdater.java @@ -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; @@ -75,6 +77,7 @@ public void action(final Event 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) { @@ -91,6 +94,9 @@ public void action(final Event 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(); @@ -98,7 +104,7 @@ public void action(final Event event) { 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)); diff --git a/src/main/java/org/b3log/solo/model/Article.java b/src/main/java/org/b3log/solo/model/Article.java index 7c4eba887..414ce46e3 100644 --- a/src/main/java/org/b3log/solo/model/Article.java +++ b/src/main/java/org/b3log/solo/model/Article.java @@ -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. diff --git a/src/main/java/org/b3log/solo/processor/ArticleProcessor.java b/src/main/java/org/b3log/solo/processor/ArticleProcessor.java index cd24dd2e4..ec4656b84 100644 --- a/src/main/java/org/b3log/solo/processor/ArticleProcessor.java +++ b/src/main/java/org/b3log/solo/processor/ArticleProcessor.java @@ -67,7 +67,7 @@ * * @author Liang Ding * @author Zephyr - * @version 1.4.4.3, Sep 7, 2018 + * @version 1.4.4.4, Sep 16, 2018 * @since 0.3.1 */ @RequestProcessor @@ -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); @@ -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 articles = articleQueryService.getArticlesByAuthorEmail(authorEmail, currentPageNum, pageSize); + final List articles = articleQueryService.getArticlesByAuthorId(authorId, currentPageNum, pageSize); if (!articles.isEmpty()) { filler.setArticlesExProperties(request, articles, author, preference); } @@ -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 articles = articleQueryService.getArticlesByAuthorEmail(authorEmail, currentPageNum, pageSize); + final List articles = articleQueryService.getArticlesByAuthorId(authorEmail, currentPageNum, pageSize); if (articles.isEmpty()) { try { response.sendError(HttpServletResponse.SC_NOT_FOUND); diff --git a/src/main/java/org/b3log/solo/processor/BlogProcessor.java b/src/main/java/org/b3log/solo/processor/BlogProcessor.java index 6305f6fc2..86ae3a046 100644 --- a/src/main/java/org/b3log/solo/processor/BlogProcessor.java +++ b/src/main/java/org/b3log/solo/processor/BlogProcessor.java @@ -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); diff --git a/src/main/java/org/b3log/solo/processor/FeedProcessor.java b/src/main/java/org/b3log/solo/processor/FeedProcessor.java index ad3bd37ff..5af8140ab 100644 --- a/src/main/java/org/b3log/solo/processor/FeedProcessor.java +++ b/src/main/java/org/b3log/solo/processor/FeedProcessor.java @@ -556,11 +556,10 @@ private Item getItemForArticles(final List 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) { diff --git a/src/main/java/org/b3log/solo/processor/console/ArticleConsole.java b/src/main/java/org/b3log/solo/processor/console/ArticleConsole.java index ae8ad56c0..5dd2182f4 100644 --- a/src/main/java/org/b3log/solo/processor/console/ArticleConsole.java +++ b/src/main/java/org/b3log/solo/processor/console/ArticleConsole.java @@ -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); @@ -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); diff --git a/src/main/java/org/b3log/solo/repository/ArticleRepository.java b/src/main/java/org/b3log/solo/repository/ArticleRepository.java index 90461d5ad..cbf2e215e 100644 --- a/src/main/java/org/b3log/solo/repository/ArticleRepository.java +++ b/src/main/java/org/b3log/solo/repository/ArticleRepository.java @@ -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 @@ -51,7 +51,7 @@ public interface ArticleRepository extends Repository { * * @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. diff --git a/src/main/java/org/b3log/solo/repository/impl/ArticleRepositoryImpl.java b/src/main/java/org/b3log/solo/repository/impl/ArticleRepositoryImpl.java index 2615c47a6..00700248f 100644 --- a/src/main/java/org/b3log/solo/repository/impl/ArticleRepositoryImpl.java +++ b/src/main/java/org/b3log/solo/repository/impl/ArticleRepositoryImpl.java @@ -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); diff --git a/src/main/java/org/b3log/solo/service/ArticleMgmtService.java b/src/main/java/org/b3log/solo/service/ArticleMgmtService.java index c2e8535b8..1f109c007 100644 --- a/src/main/java/org/b3log/solo/service/ArticleMgmtService.java +++ b/src/main/java/org/b3log/solo/service/ArticleMgmtService.java @@ -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); @@ -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); } @@ -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": "", @@ -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); @@ -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); @@ -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()); } diff --git a/src/main/java/org/b3log/solo/service/ArticleQueryService.java b/src/main/java/org/b3log/solo/service/ArticleQueryService.java index c40809d2a..e7c4da469 100644 --- a/src/main/java/org/b3log/solo/service/ArticleQueryService.java +++ b/src/main/java/org/b3log/solo/service/ArticleQueryService.java @@ -269,9 +269,9 @@ public boolean canAccessArticle(final String articleId, final HttpServletRequest } final JSONObject article = articleRepository.get(articleId); - final String currentUserEmail = userQueryService.getCurrentUser(request).getString(User.USER_EMAIL); + final String currentUserId = userQueryService.getCurrentUser(request).getString(Keys.OBJECT_ID); - return article.getString(Article.ARTICLE_AUTHOR_EMAIL).equals(currentUserEmail); + return article.getString(Article.ARTICLE_AUTHOR_ID).equals(currentUserId); } /** @@ -343,7 +343,7 @@ public long getRecentArticleTime() throws ServiceException { /** * Gets the specified article's author. *

- * The specified article has a property {@value Article#ARTICLE_AUTHOR_EMAIL}, this method will use this property to + * The specified article has a property {@value Article#ARTICLE_AUTHOR_ID}, this method will use this property to * get a user from users. *

*

@@ -357,24 +357,19 @@ public long getRecentArticleTime() throws ServiceException { */ public JSONObject getAuthor(final JSONObject article) throws ServiceException { try { - final String email = article.getString(Article.ARTICLE_AUTHOR_EMAIL); - - JSONObject ret = userRepository.getByEmail(email); - + final String userId = article.getString(Article.ARTICLE_AUTHOR_ID); + JSONObject ret = userRepository.get(userId); if (null == ret) { LOGGER.log(Level.WARN, "Gets author of article failed, assumes the administrator is the author of this article[id={0}]", article.getString(Keys.OBJECT_ID)); - // This author may be deleted by admin, use admin as the author - // of this article + // This author may be deleted by admin, use admin as the author of this article ret = userRepository.getAdmin(); } return ret; - } catch (final RepositoryException e) { - LOGGER.log(Level.ERROR, "Gets author of article[id={0}] failed", article.optString(Keys.OBJECT_ID)); - throw new ServiceException(e); - } catch (final JSONException e) { - LOGGER.log(Level.ERROR, "Gets author of article[id={0}] failed", article.optString(Keys.OBJECT_ID)); + } catch (final Exception e) { + LOGGER.log(Level.ERROR, "Gets author of article [id={0}] failed", article.optString(Keys.OBJECT_ID)); + throw new ServiceException(e); } } @@ -532,7 +527,7 @@ public JSONObject getArticle(final String articleId) throws ServiceException { article.put(Sign.SIGNS, new JSONArray(preference.getString(Option.ID_C_SIGNS))); // Remove unused properties - article.remove(ARTICLE_AUTHOR_EMAIL); + article.remove(ARTICLE_AUTHOR_ID); article.remove(ARTICLE_COMMENT_COUNT); article.remove(ARTICLE_IS_PUBLISHED); article.remove(ARTICLE_PUT_TOP); @@ -975,18 +970,18 @@ public JSONObject getArticleByPermalink(final String articlePermalink) throws Se } /** - * 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 * @param pageSize the specified page size * @return a list of articles, returns an empty list if not found * @throws ServiceException service exception */ - public List getArticlesByAuthorEmail(final String authorEmail, final int currentPageNum, final int pageSize) + public List getArticlesByAuthorId(final String authorId, final int currentPageNum, final int pageSize) throws ServiceException { try { - final JSONObject result = articleRepository.getByAuthorEmail(authorEmail, currentPageNum, pageSize); + final JSONObject result = articleRepository.getByAuthorId(authorId, currentPageNum, pageSize); final JSONArray articles = result.getJSONArray(Keys.RESULTS); final List ret = new ArrayList<>(); @@ -1000,10 +995,8 @@ public List getArticlesByAuthorEmail(final String authorEmail, final return ret; } catch (final Exception e) { - LOGGER.log(Level.ERROR, - "Gets articles by author email failed[authorEmail=" + authorEmail + ", currentPageNum=" + currentPageNum + ", pageSize=" - + pageSize + "]", - e); + LOGGER.log(Level.ERROR, "Gets articles by author email failed [authorId=" + authorId + + ", currentPageNum=" + currentPageNum + ", pageSize=" + pageSize + "]", e); throw new ServiceException(e); } @@ -1134,7 +1127,7 @@ public void removeUnusedProperties(final List articles) { */ public void removeUnusedProperties(final JSONObject article) { article.remove(Keys.OBJECT_ID); - article.remove(Article.ARTICLE_AUTHOR_EMAIL); + article.remove(Article.ARTICLE_AUTHOR_ID); article.remove(Article.ARTICLE_ABSTRACT); article.remove(Article.ARTICLE_COMMENT_COUNT); article.remove(Article.ARTICLE_CONTENT); diff --git a/src/main/java/org/b3log/solo/service/CommentQueryService.java b/src/main/java/org/b3log/solo/service/CommentQueryService.java index 67d0e9f5a..5143fecf8 100644 --- a/src/main/java/org/b3log/solo/service/CommentQueryService.java +++ b/src/main/java/org/b3log/solo/service/CommentQueryService.java @@ -23,7 +23,6 @@ import org.b3log.latke.logging.Level; import org.b3log.latke.logging.Logger; import org.b3log.latke.model.Pagination; -import org.b3log.latke.model.User; import org.b3log.latke.repository.Query; import org.b3log.latke.repository.SortDirection; import org.b3log.latke.service.ServiceException; @@ -123,9 +122,9 @@ public boolean canAccessComment(final String commentId, final HttpServletRequest return false; } - final String currentUserEmail = userQueryService.getCurrentUser(request).getString(User.USER_EMAIL); + final String currentUserId = userQueryService.getCurrentUser(request).getString(Keys.OBJECT_ID); - return article.getString(Article.ARTICLE_AUTHOR_EMAIL).equals(currentUserEmail); + return article.getString(Article.ARTICLE_AUTHOR_ID).equals(currentUserId); } /** diff --git a/src/main/java/org/b3log/solo/service/ImportService.java b/src/main/java/org/b3log/solo/service/ImportService.java index f4dc031a4..4a9fa8965 100644 --- a/src/main/java/org/b3log/solo/service/ImportService.java +++ b/src/main/java/org/b3log/solo/service/ImportService.java @@ -20,6 +20,7 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.time.DateUtils; +import org.b3log.latke.Keys; import org.b3log.latke.ioc.inject.Inject; import org.b3log.latke.logging.Level; import org.b3log.latke.logging.Logger; @@ -90,7 +91,7 @@ public void importMarkdowns() { return; } - final String adminEmail = admin.optString(User.USER_EMAIL); + final String adminId = admin.optString(Keys.OBJECT_ID); int succCnt = 0, failCnt = 0; final Set failSet = new TreeSet<>(); @@ -108,7 +109,7 @@ public void importMarkdowns() { try { final String fileContent = FileUtils.readFileToString(md, "UTF-8"); final JSONObject article = parseArticle(fileName, fileContent); - article.put(Article.ARTICLE_AUTHOR_EMAIL, adminEmail); + article.put(Article.ARTICLE_AUTHOR_ID, adminId); final JSONObject request = new JSONObject(); request.put(Article.ARTICLE, article); diff --git a/src/main/java/org/b3log/solo/service/InitService.java b/src/main/java/org/b3log/solo/service/InitService.java index fea3b1670..bb8d09275 100644 --- a/src/main/java/org/b3log/solo/service/InitService.java +++ b/src/main/java/org/b3log/solo/service/InitService.java @@ -288,13 +288,12 @@ private void helloWorld() throws Exception { article.put(Article.ARTICLE_COMMENT_COUNT, 1); article.put(Article.ARTICLE_VIEW_COUNT, 0); final JSONObject admin = userRepository.getAdmin(); - final String authorEmail = admin.optString(User.USER_EMAIL); final long now = System.currentTimeMillis(); article.put(Article.ARTICLE_CREATED, now); article.put(Article.ARTICLE_UPDATED, now); article.put(Article.ARTICLE_PUT_TOP, false); article.put(Article.ARTICLE_RANDOM_DOUBLE, Math.random()); - article.put(Article.ARTICLE_AUTHOR_EMAIL, authorEmail); + article.put(Article.ARTICLE_AUTHOR_ID, admin.optString(Keys.OBJECT_ID)); article.put(Article.ARTICLE_COMMENTABLE, true); article.put(Article.ARTICLE_VIEW_PWD, ""); article.put(Article.ARTICLE_EDITOR_TYPE, DefaultPreference.DEFAULT_EDITOR_TYPE); diff --git a/src/main/resources/repository.json b/src/main/resources/repository.json index e2098d3e8..ad623ae8b 100644 --- a/src/main/resources/repository.json +++ b/src/main/resources/repository.json @@ -487,10 +487,10 @@ "length": 2000 }, { - "name": "articleAuthorEmail", - "description": "文章作者邮箱", + "name": "articleAuthorId", + "description": "文章作者 id", "type": "String", - "length": 255 + "length": 19 }, { "name": "articleCommentCount", diff --git a/src/test/java/org/b3log/solo/processor/CommentProcessorTestCase.java b/src/test/java/org/b3log/solo/processor/CommentProcessorTestCase.java index 8b4d41311..2c6561027 100644 --- a/src/test/java/org/b3log/solo/processor/CommentProcessorTestCase.java +++ b/src/test/java/org/b3log/solo/processor/CommentProcessorTestCase.java @@ -47,7 +47,7 @@ * {@link CommentProcessorTestCase} test case. * * @author Liang Ding - * @version 1.0.0.2, Feb 13, 2018 + * @version 1.0.0.3, Sep 16, 2018 * @since 1.7.0 */ @Test(suiteName = "processor") @@ -177,7 +177,7 @@ private String addArticle() throws Exception { final JSONObject article = new JSONObject(); requestJSONObject.put(Article.ARTICLE, article); - article.put(Article.ARTICLE_AUTHOR_EMAIL, "test@gmail.com"); + article.put(Article.ARTICLE_AUTHOR_ID, "1"); article.put(Article.ARTICLE_TITLE, "article1 title"); article.put(Article.ARTICLE_ABSTRACT, "article1 abstract"); article.put(Article.ARTICLE_CONTENT, "article1 content"); diff --git a/src/test/java/org/b3log/solo/repository/impl/ArticleRepositoryImplTestCase.java b/src/test/java/org/b3log/solo/repository/impl/ArticleRepositoryImplTestCase.java index 1ec091090..e21fba260 100644 --- a/src/test/java/org/b3log/solo/repository/impl/ArticleRepositoryImplTestCase.java +++ b/src/test/java/org/b3log/solo/repository/impl/ArticleRepositoryImplTestCase.java @@ -35,7 +35,7 @@ * {@link ArticleRepositoryImpl} test case. * * @author Liang Ding - * @version 1.0.0.3, May 1, 2012 + * @version 1.0.0.4, Sep 16, 2018 */ @Test(suiteName = "repository") public final class ArticleRepositoryImplTestCase extends AbstractTestCase { @@ -54,7 +54,7 @@ public void add() throws Exception { article.put(Article.ARTICLE_TITLE, "article title1"); article.put(Article.ARTICLE_ABSTRACT, "article abstract"); article.put(Article.ARTICLE_TAGS_REF, "tag1, tag2"); - article.put(Article.ARTICLE_AUTHOR_EMAIL, "test@gmail.com"); + article.put(Article.ARTICLE_AUTHOR_ID, "1"); article.put(Article.ARTICLE_COMMENT_COUNT, 0); article.put(Article.ARTICLE_VIEW_COUNT, 0); article.put(Article.ARTICLE_CONTENT, "article content"); @@ -74,7 +74,7 @@ public void add() throws Exception { articleRepository.add(article); transaction.commit(); - final JSONArray results = articleRepository.getByAuthorEmail("test@gmail.com", 1, Integer.MAX_VALUE).getJSONArray(Keys.RESULTS); + final JSONArray results = articleRepository.getByAuthorId("1", 1, Integer.MAX_VALUE).getJSONArray(Keys.RESULTS); Assert.assertEquals(results.length(), 1); } @@ -109,7 +109,7 @@ public void previousAndNext() throws Exception { article.put(Article.ARTICLE_TITLE, "article title2"); article.put(Article.ARTICLE_ABSTRACT, "article abstract"); article.put(Article.ARTICLE_TAGS_REF, "tag1, tag2"); - article.put(Article.ARTICLE_AUTHOR_EMAIL, "test@gmail.com"); + article.put(Article.ARTICLE_AUTHOR_ID, "1"); article.put(Article.ARTICLE_COMMENT_COUNT, 1); article.put(Article.ARTICLE_VIEW_COUNT, 1); article.put(Article.ARTICLE_CONTENT, "article content"); @@ -159,7 +159,7 @@ public void getMostCommentArticles() throws Exception { article.put(Article.ARTICLE_TITLE, "article title3"); article.put(Article.ARTICLE_ABSTRACT, "article abstract"); article.put(Article.ARTICLE_TAGS_REF, "tag1, tag2"); - article.put(Article.ARTICLE_AUTHOR_EMAIL, "test@gmail.com"); + article.put(Article.ARTICLE_AUTHOR_ID, "1"); article.put(Article.ARTICLE_COMMENT_COUNT, 2); article.put(Article.ARTICLE_VIEW_COUNT, 2); article.put(Article.ARTICLE_CONTENT, "article content"); @@ -207,7 +207,7 @@ public void getMostViewCountArticles() throws Exception { article.put(Article.ARTICLE_TITLE, "article title4"); article.put(Article.ARTICLE_ABSTRACT, "article abstract"); article.put(Article.ARTICLE_TAGS_REF, "tag1, tag2"); - article.put(Article.ARTICLE_AUTHOR_EMAIL, "test@gmail.com"); + article.put(Article.ARTICLE_AUTHOR_ID, "1"); article.put(Article.ARTICLE_COMMENT_COUNT, 3); article.put(Article.ARTICLE_VIEW_COUNT, 3); article.put(Article.ARTICLE_CONTENT, "article content"); diff --git a/src/test/java/org/b3log/solo/service/ArticleMgmtServiceTestCase.java b/src/test/java/org/b3log/solo/service/ArticleMgmtServiceTestCase.java index bb0bc8bb3..5691466c9 100644 --- a/src/test/java/org/b3log/solo/service/ArticleMgmtServiceTestCase.java +++ b/src/test/java/org/b3log/solo/service/ArticleMgmtServiceTestCase.java @@ -17,7 +17,6 @@ */ package org.b3log.solo.service; -import java.util.List; import org.b3log.latke.Keys; import org.b3log.latke.model.User; import org.b3log.latke.util.Requests; @@ -29,18 +28,20 @@ import org.testng.Assert; import org.testng.annotations.Test; +import java.util.List; + /** * {@link ArticleMgmtService} test case. * * @author Liang Ding - * @version 1.0.0.5, Sep 11, 2012 + * @version 1.0.0.6, Sep 16, 2018 */ @Test(suiteName = "service") public class ArticleMgmtServiceTestCase extends AbstractTestCase { /** * Init. - * + * * @throws Exception exception */ @Test @@ -51,7 +52,7 @@ public void init() throws Exception { requestJSONObject.put(User.USER_EMAIL, "test@gmail.com"); requestJSONObject.put(User.USER_NAME, "Admin"); requestJSONObject.put(User.USER_PASSWORD, "pass"); - + initService.init(requestJSONObject); final UserQueryService userQueryService = getUserQueryService(); @@ -71,7 +72,10 @@ public void addArticle() throws Exception { final JSONObject article = new JSONObject(); requestJSONObject.put(Article.ARTICLE, article); - article.put(Article.ARTICLE_AUTHOR_EMAIL, "test@gmail.com"); + final JSONObject admin = getUserQueryService().getAdmin(); + final String userId = admin.optString(Keys.OBJECT_ID); + + article.put(Article.ARTICLE_AUTHOR_ID, userId); article.put(Article.ARTICLE_TITLE, "article1 title"); article.put(Article.ARTICLE_ABSTRACT, "article1 abstract"); article.put(Article.ARTICLE_CONTENT, "article1 content"); @@ -101,7 +105,10 @@ public void addArticleWithoutPermalink() throws Exception { final JSONObject article = new JSONObject(); requestJSONObject.put(Article.ARTICLE, article); - article.put(Article.ARTICLE_AUTHOR_EMAIL, "test@gmail.com"); + final JSONObject admin = getUserQueryService().getAdmin(); + final String userId = admin.optString(Keys.OBJECT_ID); + + article.put(Article.ARTICLE_AUTHOR_ID, userId); article.put(Article.ARTICLE_TITLE, "article1 title"); article.put(Article.ARTICLE_ABSTRACT, "article1 abstract"); article.put(Article.ARTICLE_CONTENT, "article1 content"); @@ -119,7 +126,7 @@ public void addArticleWithoutPermalink() throws Exception { /** * Update Article. - * + * * @throws Exception exception */ @Test(dependsOnMethods = "init") @@ -130,7 +137,10 @@ public void updateArticle() throws Exception { final JSONObject article = new JSONObject(); requestJSONObject.put(Article.ARTICLE, article); - article.put(Article.ARTICLE_AUTHOR_EMAIL, "test@gmail.com"); + final JSONObject admin = getUserQueryService().getAdmin(); + final String userId = admin.optString(Keys.OBJECT_ID); + + article.put(Article.ARTICLE_AUTHOR_ID, userId); article.put(Article.ARTICLE_TITLE, "article2 title"); article.put(Article.ARTICLE_ABSTRACT, "article2 abstract"); article.put(Article.ARTICLE_CONTENT, "article2 content"); @@ -159,7 +169,7 @@ public void updateArticle() throws Exception { /** * Remove Article. - * + * * @throws Exception exception */ @Test(dependsOnMethods = "init") @@ -170,7 +180,10 @@ public void removeArticle() throws Exception { final JSONObject article = new JSONObject(); requestJSONObject.put(Article.ARTICLE, article); - article.put(Article.ARTICLE_AUTHOR_EMAIL, "test@gmail.com"); + final JSONObject admin = getUserQueryService().getAdmin(); + final String userId = admin.optString(Keys.OBJECT_ID); + + article.put(Article.ARTICLE_AUTHOR_ID, userId); article.put(Article.ARTICLE_TITLE, "article3 title"); article.put(Article.ARTICLE_ABSTRACT, "article3 abstract"); article.put(Article.ARTICLE_CONTENT, "article3 content"); @@ -195,7 +208,7 @@ public void removeArticle() throws Exception { /** * Top Article. - * + * * @throws Exception exception */ @Test(dependsOnMethods = "addArticle") @@ -215,7 +228,7 @@ public void topArticle() throws Exception { /** * Cancel Publish Article. - * + * * @throws Exception exception */ @Test(dependsOnMethods = "init") @@ -226,7 +239,10 @@ public void cancelPublishArticle() throws Exception { final JSONObject article = new JSONObject(); requestJSONObject.put(Article.ARTICLE, article); - article.put(Article.ARTICLE_AUTHOR_EMAIL, "test@gmail.com"); + final JSONObject admin = getUserQueryService().getAdmin(); + final String userId = admin.optString(Keys.OBJECT_ID); + + article.put(Article.ARTICLE_AUTHOR_ID, userId); article.put(Article.ARTICLE_TITLE, "article4 title"); article.put(Article.ARTICLE_ABSTRACT, "article4 abstract"); article.put(Article.ARTICLE_CONTENT, "article4 content"); @@ -256,7 +272,7 @@ public void cancelPublishArticle() throws Exception { /** * Update Articles Random Value. - * + * * @throws Exception exception */ @Test(dependsOnMethods = "addArticle")