Commit 0985b584 authored by Liang Ding's avatar Liang Ding

#12509 文章作者 id

parent 7af50222
...@@ -221,8 +221,9 @@ public class MetaWeblogAPI { ...@@ -221,8 +221,9 @@ public class MetaWeblogAPI {
final String userEmail = params.getJSONObject(INDEX_USER_EMAIL).getJSONObject("value").getString("string"); final String userEmail = params.getJSONObject(INDEX_USER_EMAIL).getJSONObject("value").getString("string");
final JSONObject user = userQueryService.getUserByEmail(userEmail); final JSONObject user = userQueryService.getUserByEmail(userEmail);
if (null == user) { 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"); final String userPwd = params.getJSONObject(INDEX_USER_PWD).getJSONObject("value").getString("string");
if (!user.getString(User.USER_PASSWORD).equals(DigestUtils.md5Hex(userPwd))) { if (!user.getString(User.USER_PASSWORD).equals(DigestUtils.md5Hex(userPwd))) {
...@@ -238,7 +239,7 @@ public class MetaWeblogAPI { ...@@ -238,7 +239,7 @@ public class MetaWeblogAPI {
responseContent = getRecentPosts(numOfPosts); responseContent = getRecentPosts(numOfPosts);
} else if (METHOD_NEW_POST.equals(methodName)) { } else if (METHOD_NEW_POST.equals(methodName)) {
final JSONObject article = parsetPost(methodCall); final JSONObject article = parsetPost(methodCall);
article.put(Article.ARTICLE_AUTHOR_EMAIL, userEmail); article.put(Article.ARTICLE_AUTHOR_ID, userId);
addArticle(article); 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( 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(
...@@ -251,7 +252,7 @@ public class MetaWeblogAPI { ...@@ -251,7 +252,7 @@ public class MetaWeblogAPI {
final JSONObject article = parsetPost(methodCall); final JSONObject article = parsetPost(methodCall);
final String postId = params.getJSONObject(INDEX_POST_ID).getJSONObject("value").getString("string"); final String postId = params.getJSONObject(INDEX_POST_ID).getJSONObject("value").getString("string");
article.put(Keys.OBJECT_ID, postId); 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(); final JSONObject updateArticleRequest = new JSONObject();
updateArticleRequest.put(Article.ARTICLE, article); updateArticleRequest.put(Article.ARTICLE, article);
articleMgmtService.updateArticle(updateArticleRequest); articleMgmtService.updateArticle(updateArticleRequest);
......
...@@ -21,7 +21,6 @@ import org.b3log.latke.Keys; ...@@ -21,7 +21,6 @@ import org.b3log.latke.Keys;
import org.b3log.latke.ioc.inject.Inject; import org.b3log.latke.ioc.inject.Inject;
import org.b3log.latke.logging.Level; import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger; import org.b3log.latke.logging.Logger;
import org.b3log.latke.model.User;
import org.b3log.latke.service.ServiceException; import org.b3log.latke.service.ServiceException;
import org.b3log.latke.servlet.HTTPRequestContext; import org.b3log.latke.servlet.HTTPRequestContext;
import org.b3log.latke.servlet.HTTPRequestMethod; import org.b3log.latke.servlet.HTTPRequestMethod;
...@@ -123,7 +122,7 @@ public class ArticleReceiver { ...@@ -123,7 +122,7 @@ public class ArticleReceiver {
final JSONObject admin = userQueryService.getAdmin(); 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); final String articleContent = article.optString(Article.ARTICLE_CONTENT);
article.put(Article.ARTICLE_ABSTRACT, Article.getAbstract(articleContent)); article.put(Article.ARTICLE_ABSTRACT, Article.getAbstract(articleContent));
article.put(Article.ARTICLE_IS_PUBLISHED, true); article.put(Article.ARTICLE_IS_PUBLISHED, true);
......
...@@ -18,11 +18,11 @@ ...@@ -18,11 +18,11 @@
package org.b3log.solo.dev; package org.b3log.solo.dev;
import org.apache.commons.lang.time.DateUtils; import org.apache.commons.lang.time.DateUtils;
import org.b3log.latke.Keys;
import org.b3log.latke.Latkes; import org.b3log.latke.Latkes;
import org.b3log.latke.ioc.inject.Inject; import org.b3log.latke.ioc.inject.Inject;
import org.b3log.latke.logging.Level; import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger; import org.b3log.latke.logging.Logger;
import org.b3log.latke.model.User;
import org.b3log.latke.servlet.HTTPRequestMethod; import org.b3log.latke.servlet.HTTPRequestMethod;
import org.b3log.latke.servlet.annotation.RequestProcessing; import org.b3log.latke.servlet.annotation.RequestProcessing;
import org.b3log.latke.servlet.annotation.RequestProcessor; import org.b3log.latke.servlet.annotation.RequestProcessor;
...@@ -89,7 +89,7 @@ public class ArticleGenerator { ...@@ -89,7 +89,7 @@ public class ArticleGenerator {
try { try {
final JSONObject admin = userQueryService.getAdmin(); 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++) { for (int i = 0; i < num; i++) {
final JSONObject article = new JSONObject(); final JSONObject article = new JSONObject();
...@@ -98,7 +98,7 @@ public class ArticleGenerator { ...@@ -98,7 +98,7 @@ public class ArticleGenerator {
final int deviationTag = 3; final int deviationTag = 3;
article.put(Article.ARTICLE_TAGS_REF, "taga,tagb,tag" + i % deviationTag); 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_COMMENT_COUNT, 0);
article.put(Article.ARTICLE_VIEW_COUNT, 0); article.put(Article.ARTICLE_VIEW_COUNT, 0);
article.put(Article.ARTICLE_CONTENT, "article content"); article.put(Article.ARTICLE_CONTENT, "article content");
......
...@@ -28,12 +28,14 @@ import org.b3log.latke.ioc.LatkeBeanManager; ...@@ -28,12 +28,14 @@ import org.b3log.latke.ioc.LatkeBeanManager;
import org.b3log.latke.ioc.Lifecycle; import org.b3log.latke.ioc.Lifecycle;
import org.b3log.latke.logging.Level; import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger; import org.b3log.latke.logging.Logger;
import org.b3log.latke.model.User;
import org.b3log.latke.util.Strings; import org.b3log.latke.util.Strings;
import org.b3log.solo.SoloServletListener; import org.b3log.solo.SoloServletListener;
import org.b3log.solo.event.EventTypes; import org.b3log.solo.event.EventTypes;
import org.b3log.solo.model.Article; import org.b3log.solo.model.Article;
import org.b3log.solo.model.Common; import org.b3log.solo.model.Common;
import org.b3log.solo.model.Option; import org.b3log.solo.model.Option;
import org.b3log.solo.service.ArticleQueryService;
import org.b3log.solo.service.PreferenceQueryService; import org.b3log.solo.service.PreferenceQueryService;
import org.b3log.solo.util.Solos; import org.b3log.solo.util.Solos;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -79,6 +81,7 @@ public final class ArticleSender extends AbstractEventListener<JSONObject> { ...@@ -79,6 +81,7 @@ public final class ArticleSender extends AbstractEventListener<JSONObject> {
final LatkeBeanManager beanManager = Lifecycle.getBeanManager(); final LatkeBeanManager beanManager = Lifecycle.getBeanManager();
final PreferenceQueryService preferenceQueryService = beanManager.getReference(PreferenceQueryService.class); final PreferenceQueryService preferenceQueryService = beanManager.getReference(PreferenceQueryService.class);
final ArticleQueryService articleQueryService = beanManager.getReference(ArticleQueryService.class);
final JSONObject preference = preferenceQueryService.getPreference(); final JSONObject preference = preferenceQueryService.getPreference();
if (null == preference) { if (null == preference) {
...@@ -95,6 +98,9 @@ public final class ArticleSender extends AbstractEventListener<JSONObject> { ...@@ -95,6 +98,9 @@ public final class ArticleSender extends AbstractEventListener<JSONObject> {
return; return;
} }
final JSONObject author = articleQueryService.getAuthor(originalArticle);
final String authorEmail = author.optString(User.USER_EMAIL);
final JSONObject requestJSONObject = new JSONObject(); final JSONObject requestJSONObject = new JSONObject();
final JSONObject article = new JSONObject(); final JSONObject article = new JSONObject();
...@@ -102,7 +108,7 @@ public final class ArticleSender extends AbstractEventListener<JSONObject> { ...@@ -102,7 +108,7 @@ public final class ArticleSender extends AbstractEventListener<JSONObject> {
article.put(Article.ARTICLE_TITLE, originalArticle.getString(Article.ARTICLE_TITLE)); article.put(Article.ARTICLE_TITLE, originalArticle.getString(Article.ARTICLE_TITLE));
article.put(Article.ARTICLE_PERMALINK, originalArticle.getString(Article.ARTICLE_PERMALINK)); 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_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_CONTENT, originalArticle.getString(Article.ARTICLE_CONTENT));
article.put(Article.ARTICLE_T_CREATE_DATE, originalArticle.getLong(Article.ARTICLE_CREATED)); article.put(Article.ARTICLE_T_CREATE_DATE, originalArticle.getLong(Article.ARTICLE_CREATED));
article.put(Common.POST_TO_COMMUNITY, originalArticle.getBoolean(Common.POST_TO_COMMUNITY)); article.put(Common.POST_TO_COMMUNITY, originalArticle.getBoolean(Common.POST_TO_COMMUNITY));
......
...@@ -28,12 +28,14 @@ import org.b3log.latke.ioc.LatkeBeanManager; ...@@ -28,12 +28,14 @@ import org.b3log.latke.ioc.LatkeBeanManager;
import org.b3log.latke.ioc.Lifecycle; import org.b3log.latke.ioc.Lifecycle;
import org.b3log.latke.logging.Level; import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger; import org.b3log.latke.logging.Logger;
import org.b3log.latke.model.User;
import org.b3log.latke.util.Strings; import org.b3log.latke.util.Strings;
import org.b3log.solo.SoloServletListener; import org.b3log.solo.SoloServletListener;
import org.b3log.solo.event.EventTypes; import org.b3log.solo.event.EventTypes;
import org.b3log.solo.model.Article; import org.b3log.solo.model.Article;
import org.b3log.solo.model.Common; import org.b3log.solo.model.Common;
import org.b3log.solo.model.Option; import org.b3log.solo.model.Option;
import org.b3log.solo.service.ArticleQueryService;
import org.b3log.solo.service.PreferenceQueryService; import org.b3log.solo.service.PreferenceQueryService;
import org.b3log.solo.util.Solos; import org.b3log.solo.util.Solos;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -75,6 +77,7 @@ public final class ArticleUpdater extends AbstractEventListener<JSONObject> { ...@@ -75,6 +77,7 @@ public final class ArticleUpdater extends AbstractEventListener<JSONObject> {
final LatkeBeanManager beanManager = Lifecycle.getBeanManager(); final LatkeBeanManager beanManager = Lifecycle.getBeanManager();
final PreferenceQueryService preferenceQueryService = beanManager.getReference(PreferenceQueryService.class); final PreferenceQueryService preferenceQueryService = beanManager.getReference(PreferenceQueryService.class);
final ArticleQueryService articleQueryService = beanManager.getReference(ArticleQueryService.class);
final JSONObject preference = preferenceQueryService.getPreference(); final JSONObject preference = preferenceQueryService.getPreference();
if (null == preference) { if (null == preference) {
...@@ -91,6 +94,9 @@ public final class ArticleUpdater extends AbstractEventListener<JSONObject> { ...@@ -91,6 +94,9 @@ public final class ArticleUpdater extends AbstractEventListener<JSONObject> {
return; return;
} }
final JSONObject author = articleQueryService.getAuthor(originalArticle);
final String authorEmail = author.optString(User.USER_EMAIL);
final JSONObject requestJSONObject = new JSONObject(); final JSONObject requestJSONObject = new JSONObject();
final JSONObject article = new JSONObject(); final JSONObject article = new JSONObject();
...@@ -98,7 +104,7 @@ public final class ArticleUpdater extends AbstractEventListener<JSONObject> { ...@@ -98,7 +104,7 @@ public final class ArticleUpdater extends AbstractEventListener<JSONObject> {
article.put(Article.ARTICLE_TITLE, originalArticle.getString(Article.ARTICLE_TITLE)); article.put(Article.ARTICLE_TITLE, originalArticle.getString(Article.ARTICLE_TITLE));
article.put(Article.ARTICLE_PERMALINK, originalArticle.getString(Article.ARTICLE_PERMALINK)); 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_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_CONTENT, originalArticle.getString(Article.ARTICLE_CONTENT));
article.put(Article.ARTICLE_T_CREATE_DATE, originalArticle.getLong(Article.ARTICLE_CREATED)); article.put(Article.ARTICLE_T_CREATE_DATE, originalArticle.getLong(Article.ARTICLE_CREATED));
article.put(Common.POST_TO_COMMUNITY, originalArticle.getBoolean(Common.POST_TO_COMMUNITY)); article.put(Common.POST_TO_COMMUNITY, originalArticle.getBoolean(Common.POST_TO_COMMUNITY));
......
...@@ -125,10 +125,15 @@ public final class Article { ...@@ -125,10 +125,15 @@ public final class Article {
*/ */
public static final String ARTICLE_IS_PUBLISHED = "articleIsPublished"; public static final String ARTICLE_IS_PUBLISHED = "articleIsPublished";
/**
* Key of author id.
*/
public static final String ARTICLE_AUTHOR_ID = "articleAuthorId";
/** /**
* Key of author email. * 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. * Key of had been published.
......
...@@ -67,7 +67,7 @@ import java.util.*; ...@@ -67,7 +67,7 @@ import java.util.*;
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://zephyr.b3log.org">Zephyr</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 * @since 0.3.1
*/ */
@RequestProcessor @RequestProcessor
...@@ -690,7 +690,7 @@ public class ArticleProcessor { ...@@ -690,7 +690,7 @@ public class ArticleProcessor {
final String authorId = getAuthorsArticlesPagedAuthorId(request.getRequestURI()); final String authorId = getAuthorsArticlesPagedAuthorId(request.getRequestURI());
final int currentPageNum = getAuthorsArticlesPagedCurrentPageNum(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 { try {
jsonObject.put(Keys.STATUS_CODE, true); jsonObject.put(Keys.STATUS_CODE, true);
...@@ -705,9 +705,8 @@ public class ArticleProcessor { ...@@ -705,9 +705,8 @@ public class ArticleProcessor {
} }
final JSONObject author = authorRet.getJSONObject(User.USER); 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()) { if (!articles.isEmpty()) {
filler.setArticlesExProperties(request, articles, author, preference); filler.setArticlesExProperties(request, articles, author, preference);
} }
...@@ -785,7 +784,7 @@ public class ArticleProcessor { ...@@ -785,7 +784,7 @@ public class ArticleProcessor {
final JSONObject author = result.getJSONObject(User.USER); final JSONObject author = result.getJSONObject(User.USER);
final String authorEmail = author.getString(User.USER_EMAIL); 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()) { if (articles.isEmpty()) {
try { try {
response.sendError(HttpServletResponse.SC_NOT_FOUND); response.sendError(HttpServletResponse.SC_NOT_FOUND);
......
...@@ -225,7 +225,7 @@ public class BlogProcessor { ...@@ -225,7 +225,7 @@ public class BlogProcessor {
excludes.put(Article.ARTICLE_CONTENT); excludes.put(Article.ARTICLE_CONTENT);
excludes.put(Article.ARTICLE_UPDATED); excludes.put(Article.ARTICLE_UPDATED);
excludes.put(Article.ARTICLE_CREATED); 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_HAD_BEEN_PUBLISHED);
excludes.put(Article.ARTICLE_IS_PUBLISHED); excludes.put(Article.ARTICLE_IS_PUBLISHED);
excludes.put(Article.ARTICLE_RANDOM_DOUBLE); excludes.put(Article.ARTICLE_RANDOM_DOUBLE);
......
...@@ -556,11 +556,10 @@ public class FeedProcessor { ...@@ -556,11 +556,10 @@ public class FeedProcessor {
final String link = Latkes.getServePath() + article.getString(Article.ARTICLE_PERMALINK); final String link = Latkes.getServePath() + article.getString(Article.ARTICLE_PERMALINK);
ret.setLink(link); ret.setLink(link);
ret.setGUID(link); ret.setGUID(link);
final String authorEmail = article.getString(Article.ARTICLE_AUTHOR_EMAIL);
if (hasMultipleUsers) { if (hasMultipleUsers) {
authorName = articleQueryService.getAuthor(article).getString(User.USER_NAME); 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 tagsString = article.getString(Article.ARTICLE_TAGS_REF);
final String[] tagStrings = tagsString.split(","); final String[] tagStrings = tagsString.split(",");
for (final String tagString : tagStrings) { for (final String tagString : tagStrings) {
......
...@@ -308,7 +308,7 @@ public class ArticleConsole { ...@@ -308,7 +308,7 @@ public class ArticleConsole {
excludes.put(Article.ARTICLE_CONTENT); excludes.put(Article.ARTICLE_CONTENT);
excludes.put(Article.ARTICLE_UPDATED); excludes.put(Article.ARTICLE_UPDATED);
excludes.put(Article.ARTICLE_CREATED); 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_HAD_BEEN_PUBLISHED);
excludes.put(Article.ARTICLE_IS_PUBLISHED); excludes.put(Article.ARTICLE_IS_PUBLISHED);
excludes.put(Article.ARTICLE_RANDOM_DOUBLE); excludes.put(Article.ARTICLE_RANDOM_DOUBLE);
...@@ -673,7 +673,7 @@ public class ArticleConsole { ...@@ -673,7 +673,7 @@ public class ArticleConsole {
try { try {
final JSONObject currentUser = userQueryService.getCurrentUser(request); 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); final String articleId = articleMgmtService.addArticle(requestJSONObject);
ret.put(Keys.OBJECT_ID, articleId); ret.put(Keys.OBJECT_ID, articleId);
......
...@@ -33,9 +33,9 @@ import java.util.List; ...@@ -33,9 +33,9 @@ import java.util.List;
public interface ArticleRepository extends Repository { 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 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} * @param pageSize the specified page size(count of a page contains objects), MUST greater then {@code 0}
* @return for example * @return for example
...@@ -51,7 +51,7 @@ public interface ArticleRepository extends Repository { ...@@ -51,7 +51,7 @@ public interface ArticleRepository extends Repository {
* </pre> * </pre>
* @throws RepositoryException repository exception * @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. * Gets an article by the specified permalink.
......
...@@ -99,11 +99,11 @@ public class ArticleRepositoryImpl extends AbstractRepository implements Article ...@@ -99,11 +99,11 @@ public class ArticleRepositoryImpl extends AbstractRepository implements Article
} }
@Override @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 { throws RepositoryException {
final Query query = new Query(). final Query query = new Query().
setFilter(CompositeFilterOperator.and( 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))). new PropertyFilter(Article.ARTICLE_IS_PUBLISHED, FilterOperator.EQUAL, true))).
addSort(Article.ARTICLE_UPDATED, SortDirection.DESCENDING).addSort(Article.ARTICLE_PUT_TOP, SortDirection.DESCENDING). addSort(Article.ARTICLE_UPDATED, SortDirection.DESCENDING).addSort(Article.ARTICLE_PUT_TOP, SortDirection.DESCENDING).
setCurrentPageNum(currentPageNum).setPageSize(pageSize).setPageCount(1); setCurrentPageNum(currentPageNum).setPageSize(pageSize).setPageCount(1);
......
...@@ -212,8 +212,7 @@ public class ArticleMgmtService { ...@@ -212,8 +212,7 @@ public class ArticleMgmtService {
statisticMgmtService.setPublishedBlogCommentCount(blogCmtCnt - articleCmtCnt); 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); author.put(UserExt.USER_PUBLISHED_ARTICLE_COUNT, author.optInt(UserExt.USER_PUBLISHED_ARTICLE_COUNT) - 1);
userRepository.update(author.optString(Keys.OBJECT_ID), author); userRepository.update(author.optString(Keys.OBJECT_ID), author);
...@@ -354,8 +353,7 @@ public class ArticleMgmtService { ...@@ -354,8 +353,7 @@ public class ArticleMgmtService {
statisticMgmtService.setPublishedBlogCommentCount(blogCmtCnt + articleCmtCnt); 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); author.put(UserExt.USER_PUBLISHED_ARTICLE_COUNT, author.optInt(UserExt.USER_PUBLISHED_ARTICLE_COUNT) + 1);
userRepository.update(author.optString(Keys.OBJECT_ID), author); userRepository.update(author.optString(Keys.OBJECT_ID), author);
} }
...@@ -420,7 +418,7 @@ public class ArticleMgmtService { ...@@ -420,7 +418,7 @@ public class ArticleMgmtService {
* @param requestJSONObject the specified request json object, for example, * @param requestJSONObject the specified request json object, for example,
* { * {
* "article": { * "article": {
* "articleAuthorEmail": "", * "articleAuthorId": "",
* "articleTitle": "", * "articleTitle": "",
* "articleAbstract": "", * "articleAbstract": "",
* "articleContent": "", * "articleContent": "",
...@@ -520,7 +518,7 @@ public class ArticleMgmtService { ...@@ -520,7 +518,7 @@ public class ArticleMgmtService {
article.remove(Common.POST_TO_COMMUNITY); // Do not persist this property article.remove(Common.POST_TO_COMMUNITY); // Do not persist this property
// Setp 13: Update user article statistic // 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); final int userArticleCnt = author.optInt(UserExt.USER_ARTICLE_COUNT);
author.put(UserExt.USER_ARTICLE_COUNT, userArticleCnt + 1); author.put(UserExt.USER_ARTICLE_COUNT, userArticleCnt + 1);
...@@ -583,8 +581,7 @@ public class ArticleMgmtService { ...@@ -583,8 +581,7 @@ public class ArticleMgmtService {
statisticMgmtService.decPublishedBlogArticleCount(); 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_PUBLISHED_ARTICLE_COUNT, author.optInt(UserExt.USER_PUBLISHED_ARTICLE_COUNT) - 1);
author.put(UserExt.USER_ARTICLE_COUNT, author.optInt(UserExt.USER_ARTICLE_COUNT) - 1); author.put(UserExt.USER_ARTICLE_COUNT, author.optInt(UserExt.USER_ARTICLE_COUNT) - 1);
userRepository.update(author.optString(Keys.OBJECT_ID), author); userRepository.update(author.optString(Keys.OBJECT_ID), author);
...@@ -1096,7 +1093,7 @@ public class ArticleMgmtService { ...@@ -1096,7 +1093,7 @@ public class ArticleMgmtService {
article.put(ARTICLE_VIEW_COUNT, oldArticle.getInt(ARTICLE_VIEW_COUNT)); article.put(ARTICLE_VIEW_COUNT, oldArticle.getInt(ARTICLE_VIEW_COUNT));
article.put(ARTICLE_PUT_TOP, oldArticle.getBoolean(ARTICLE_PUT_TOP)); 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_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()); article.put(ARTICLE_RANDOM_DOUBLE, Math.random());
} }
......
...@@ -269,9 +269,9 @@ public class ArticleQueryService { ...@@ -269,9 +269,9 @@ public class ArticleQueryService {
} }
final JSONObject article = articleRepository.get(articleId); 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 class ArticleQueryService { ...@@ -343,7 +343,7 @@ public class ArticleQueryService {
/** /**
* Gets the specified article's author. * Gets the specified article's author.
* <p> * <p>
* 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. * get a user from users.
* </p> * </p>
* <p> * <p>
...@@ -357,24 +357,19 @@ public class ArticleQueryService { ...@@ -357,24 +357,19 @@ public class ArticleQueryService {
*/ */
public JSONObject getAuthor(final JSONObject article) throws ServiceException { public JSONObject getAuthor(final JSONObject article) throws ServiceException {
try { try {
final String email = article.getString(Article.ARTICLE_AUTHOR_EMAIL); final String userId = article.getString(Article.ARTICLE_AUTHOR_ID);
JSONObject ret = userRepository.get(userId);
JSONObject ret = userRepository.getByEmail(email);
if (null == ret) { if (null == ret) {
LOGGER.log(Level.WARN, "Gets author of article failed, assumes the administrator is the author of this article[id={0}]", 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)); article.getString(Keys.OBJECT_ID));
// This author may be deleted by admin, use admin as the author // This author may be deleted by admin, use admin as the author of this article
// of this article
ret = userRepository.getAdmin(); ret = userRepository.getAdmin();
} }
return ret; return ret;
} catch (final RepositoryException e) { } catch (final Exception e) {
LOGGER.log(Level.ERROR, "Gets author of article[id={0}] failed", article.optString(Keys.OBJECT_ID)); 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));
throw new ServiceException(e); throw new ServiceException(e);
} }
} }
...@@ -532,7 +527,7 @@ public class ArticleQueryService { ...@@ -532,7 +527,7 @@ public class ArticleQueryService {
article.put(Sign.SIGNS, new JSONArray(preference.getString(Option.ID_C_SIGNS))); article.put(Sign.SIGNS, new JSONArray(preference.getString(Option.ID_C_SIGNS)));
// Remove unused properties // Remove unused properties
article.remove(ARTICLE_AUTHOR_EMAIL); article.remove(ARTICLE_AUTHOR_ID);
article.remove(ARTICLE_COMMENT_COUNT); article.remove(ARTICLE_COMMENT_COUNT);
article.remove(ARTICLE_IS_PUBLISHED); article.remove(ARTICLE_IS_PUBLISHED);
article.remove(ARTICLE_PUT_TOP); article.remove(ARTICLE_PUT_TOP);
...@@ -975,18 +970,18 @@ public class ArticleQueryService { ...@@ -975,18 +970,18 @@ public class ArticleQueryService {
} }
/** /**
* Gets <em>published</em> articles by the specified author email, current page number and page size. * Gets <em>published</em> 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 currentPageNum the specified current page number
* @param pageSize the specified page size * @param pageSize the specified page size
* @return a list of articles, returns an empty list if not found * @return a list of articles, returns an empty list if not found
* @throws ServiceException service exception * @throws ServiceException service exception
*/ */
public List<JSONObject> getArticlesByAuthorEmail(final String authorEmail, final int currentPageNum, final int pageSize) public List<JSONObject> getArticlesByAuthorId(final String authorId, final int currentPageNum, final int pageSize)
throws ServiceException { throws ServiceException {
try { 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 JSONArray articles = result.getJSONArray(Keys.RESULTS);
final List<JSONObject> ret = new ArrayList<>(); final List<JSONObject> ret = new ArrayList<>();
...@@ -1000,10 +995,8 @@ public class ArticleQueryService { ...@@ -1000,10 +995,8 @@ public class ArticleQueryService {
return ret; return ret;
} catch (final Exception e) { } catch (final Exception e) {
LOGGER.log(Level.ERROR, LOGGER.log(Level.ERROR, "Gets articles by author email failed [authorId=" + authorId +
"Gets articles by author email failed[authorEmail=" + authorEmail + ", currentPageNum=" + currentPageNum + ", pageSize=" ", currentPageNum=" + currentPageNum + ", pageSize=" + pageSize + "]", e);
+ pageSize + "]",
e);
throw new ServiceException(e); throw new ServiceException(e);
} }
...@@ -1134,7 +1127,7 @@ public class ArticleQueryService { ...@@ -1134,7 +1127,7 @@ public class ArticleQueryService {
*/ */
public void removeUnusedProperties(final JSONObject article) { public void removeUnusedProperties(final JSONObject article) {
article.remove(Keys.OBJECT_ID); 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_ABSTRACT);
article.remove(Article.ARTICLE_COMMENT_COUNT); article.remove(Article.ARTICLE_COMMENT_COUNT);
article.remove(Article.ARTICLE_CONTENT); article.remove(Article.ARTICLE_CONTENT);
......
...@@ -23,7 +23,6 @@ import org.b3log.latke.ioc.inject.Inject; ...@@ -23,7 +23,6 @@ import org.b3log.latke.ioc.inject.Inject;
import org.b3log.latke.logging.Level; import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger; import org.b3log.latke.logging.Logger;
import org.b3log.latke.model.Pagination; import org.b3log.latke.model.Pagination;
import org.b3log.latke.model.User;
import org.b3log.latke.repository.Query; import org.b3log.latke.repository.Query;
import org.b3log.latke.repository.SortDirection; import org.b3log.latke.repository.SortDirection;
import org.b3log.latke.service.ServiceException; import org.b3log.latke.service.ServiceException;
...@@ -123,9 +122,9 @@ public class CommentQueryService { ...@@ -123,9 +122,9 @@ public class CommentQueryService {
return false; 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);
} }
/** /**
......
...@@ -20,6 +20,7 @@ package org.b3log.solo.service; ...@@ -20,6 +20,7 @@ package org.b3log.solo.service;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils; import org.apache.commons.lang.time.DateUtils;
import org.b3log.latke.Keys;
import org.b3log.latke.ioc.inject.Inject; import org.b3log.latke.ioc.inject.Inject;
import org.b3log.latke.logging.Level; import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger; import org.b3log.latke.logging.Logger;
...@@ -90,7 +91,7 @@ public class ImportService { ...@@ -90,7 +91,7 @@ public class ImportService {
return; return;
} }
final String adminEmail = admin.optString(User.USER_EMAIL); final String adminId = admin.optString(Keys.OBJECT_ID);
int succCnt = 0, failCnt = 0; int succCnt = 0, failCnt = 0;
final Set<String> failSet = new TreeSet<>(); final Set<String> failSet = new TreeSet<>();
...@@ -108,7 +109,7 @@ public class ImportService { ...@@ -108,7 +109,7 @@ public class ImportService {
try { try {
final String fileContent = FileUtils.readFileToString(md, "UTF-8"); final String fileContent = FileUtils.readFileToString(md, "UTF-8");
final JSONObject article = parseArticle(fileName, fileContent); 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(); final JSONObject request = new JSONObject();
request.put(Article.ARTICLE, article); request.put(Article.ARTICLE, article);
......
...@@ -288,13 +288,12 @@ public class InitService { ...@@ -288,13 +288,12 @@ public class InitService {
article.put(Article.ARTICLE_COMMENT_COUNT, 1); article.put(Article.ARTICLE_COMMENT_COUNT, 1);
article.put(Article.ARTICLE_VIEW_COUNT, 0); article.put(Article.ARTICLE_VIEW_COUNT, 0);
final JSONObject admin = userRepository.getAdmin(); final JSONObject admin = userRepository.getAdmin();
final String authorEmail = admin.optString(User.USER_EMAIL);
final long now = System.currentTimeMillis(); final long now = System.currentTimeMillis();
article.put(Article.ARTICLE_CREATED, now); article.put(Article.ARTICLE_CREATED, now);
article.put(Article.ARTICLE_UPDATED, now); article.put(Article.ARTICLE_UPDATED, now);
article.put(Article.ARTICLE_PUT_TOP, false); article.put(Article.ARTICLE_PUT_TOP, false);
article.put(Article.ARTICLE_RANDOM_DOUBLE, Math.random()); 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_COMMENTABLE, true);
article.put(Article.ARTICLE_VIEW_PWD, ""); article.put(Article.ARTICLE_VIEW_PWD, "");
article.put(Article.ARTICLE_EDITOR_TYPE, DefaultPreference.DEFAULT_EDITOR_TYPE); article.put(Article.ARTICLE_EDITOR_TYPE, DefaultPreference.DEFAULT_EDITOR_TYPE);
......
...@@ -487,10 +487,10 @@ ...@@ -487,10 +487,10 @@
"length": 2000 "length": 2000
}, },
{ {
"name": "articleAuthorEmail", "name": "articleAuthorId",
"description": "文章作者邮箱", "description": "文章作者 id",
"type": "String", "type": "String",
"length": 255 "length": 19
}, },
{ {
"name": "articleCommentCount", "name": "articleCommentCount",
......
...@@ -47,7 +47,7 @@ import static org.mockito.Mockito.when; ...@@ -47,7 +47,7 @@ import static org.mockito.Mockito.when;
* {@link CommentProcessorTestCase} test case. * {@link CommentProcessorTestCase} test case.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.2, Feb 13, 2018 * @version 1.0.0.3, Sep 16, 2018
* @since 1.7.0 * @since 1.7.0
*/ */
@Test(suiteName = "processor") @Test(suiteName = "processor")
...@@ -177,7 +177,7 @@ public class CommentProcessorTestCase extends AbstractTestCase { ...@@ -177,7 +177,7 @@ public class CommentProcessorTestCase extends AbstractTestCase {
final JSONObject article = new JSONObject(); final JSONObject article = new JSONObject();
requestJSONObject.put(Article.ARTICLE, article); 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_TITLE, "article1 title");
article.put(Article.ARTICLE_ABSTRACT, "article1 abstract"); article.put(Article.ARTICLE_ABSTRACT, "article1 abstract");
article.put(Article.ARTICLE_CONTENT, "article1 content"); article.put(Article.ARTICLE_CONTENT, "article1 content");
......
...@@ -35,7 +35,7 @@ import java.util.List; ...@@ -35,7 +35,7 @@ import java.util.List;
* {@link ArticleRepositoryImpl} test case. * {@link ArticleRepositoryImpl} test case.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.3, May 1, 2012 * @version 1.0.0.4, Sep 16, 2018
*/ */
@Test(suiteName = "repository") @Test(suiteName = "repository")
public final class ArticleRepositoryImplTestCase extends AbstractTestCase { public final class ArticleRepositoryImplTestCase extends AbstractTestCase {
...@@ -54,7 +54,7 @@ public final class ArticleRepositoryImplTestCase extends AbstractTestCase { ...@@ -54,7 +54,7 @@ public final class ArticleRepositoryImplTestCase extends AbstractTestCase {
article.put(Article.ARTICLE_TITLE, "article title1"); article.put(Article.ARTICLE_TITLE, "article title1");
article.put(Article.ARTICLE_ABSTRACT, "article abstract"); article.put(Article.ARTICLE_ABSTRACT, "article abstract");
article.put(Article.ARTICLE_TAGS_REF, "tag1, tag2"); 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_COMMENT_COUNT, 0);
article.put(Article.ARTICLE_VIEW_COUNT, 0); article.put(Article.ARTICLE_VIEW_COUNT, 0);
article.put(Article.ARTICLE_CONTENT, "article content"); article.put(Article.ARTICLE_CONTENT, "article content");
...@@ -74,7 +74,7 @@ public final class ArticleRepositoryImplTestCase extends AbstractTestCase { ...@@ -74,7 +74,7 @@ public final class ArticleRepositoryImplTestCase extends AbstractTestCase {
articleRepository.add(article); articleRepository.add(article);
transaction.commit(); 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); Assert.assertEquals(results.length(), 1);
} }
...@@ -109,7 +109,7 @@ public final class ArticleRepositoryImplTestCase extends AbstractTestCase { ...@@ -109,7 +109,7 @@ public final class ArticleRepositoryImplTestCase extends AbstractTestCase {
article.put(Article.ARTICLE_TITLE, "article title2"); article.put(Article.ARTICLE_TITLE, "article title2");
article.put(Article.ARTICLE_ABSTRACT, "article abstract"); article.put(Article.ARTICLE_ABSTRACT, "article abstract");
article.put(Article.ARTICLE_TAGS_REF, "tag1, tag2"); 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_COMMENT_COUNT, 1);
article.put(Article.ARTICLE_VIEW_COUNT, 1); article.put(Article.ARTICLE_VIEW_COUNT, 1);
article.put(Article.ARTICLE_CONTENT, "article content"); article.put(Article.ARTICLE_CONTENT, "article content");
...@@ -159,7 +159,7 @@ public final class ArticleRepositoryImplTestCase extends AbstractTestCase { ...@@ -159,7 +159,7 @@ public final class ArticleRepositoryImplTestCase extends AbstractTestCase {
article.put(Article.ARTICLE_TITLE, "article title3"); article.put(Article.ARTICLE_TITLE, "article title3");
article.put(Article.ARTICLE_ABSTRACT, "article abstract"); article.put(Article.ARTICLE_ABSTRACT, "article abstract");
article.put(Article.ARTICLE_TAGS_REF, "tag1, tag2"); 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_COMMENT_COUNT, 2);
article.put(Article.ARTICLE_VIEW_COUNT, 2); article.put(Article.ARTICLE_VIEW_COUNT, 2);
article.put(Article.ARTICLE_CONTENT, "article content"); article.put(Article.ARTICLE_CONTENT, "article content");
...@@ -207,7 +207,7 @@ public final class ArticleRepositoryImplTestCase extends AbstractTestCase { ...@@ -207,7 +207,7 @@ public final class ArticleRepositoryImplTestCase extends AbstractTestCase {
article.put(Article.ARTICLE_TITLE, "article title4"); article.put(Article.ARTICLE_TITLE, "article title4");
article.put(Article.ARTICLE_ABSTRACT, "article abstract"); article.put(Article.ARTICLE_ABSTRACT, "article abstract");
article.put(Article.ARTICLE_TAGS_REF, "tag1, tag2"); 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_COMMENT_COUNT, 3);
article.put(Article.ARTICLE_VIEW_COUNT, 3); article.put(Article.ARTICLE_VIEW_COUNT, 3);
article.put(Article.ARTICLE_CONTENT, "article content"); article.put(Article.ARTICLE_CONTENT, "article content");
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
*/ */
package org.b3log.solo.service; package org.b3log.solo.service;
import java.util.List;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
import org.b3log.latke.model.User; import org.b3log.latke.model.User;
import org.b3log.latke.util.Requests; import org.b3log.latke.util.Requests;
...@@ -29,18 +28,20 @@ import org.json.JSONObject; ...@@ -29,18 +28,20 @@ import org.json.JSONObject;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import java.util.List;
/** /**
* {@link ArticleMgmtService} test case. * {@link ArticleMgmtService} test case.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.5, Sep 11, 2012 * @version 1.0.0.6, Sep 16, 2018
*/ */
@Test(suiteName = "service") @Test(suiteName = "service")
public class ArticleMgmtServiceTestCase extends AbstractTestCase { public class ArticleMgmtServiceTestCase extends AbstractTestCase {
/** /**
* Init. * Init.
* *
* @throws Exception exception * @throws Exception exception
*/ */
@Test @Test
...@@ -51,7 +52,7 @@ public class ArticleMgmtServiceTestCase extends AbstractTestCase { ...@@ -51,7 +52,7 @@ public class ArticleMgmtServiceTestCase extends AbstractTestCase {
requestJSONObject.put(User.USER_EMAIL, "test@gmail.com"); requestJSONObject.put(User.USER_EMAIL, "test@gmail.com");
requestJSONObject.put(User.USER_NAME, "Admin"); requestJSONObject.put(User.USER_NAME, "Admin");
requestJSONObject.put(User.USER_PASSWORD, "pass"); requestJSONObject.put(User.USER_PASSWORD, "pass");
initService.init(requestJSONObject); initService.init(requestJSONObject);
final UserQueryService userQueryService = getUserQueryService(); final UserQueryService userQueryService = getUserQueryService();
...@@ -71,7 +72,10 @@ public class ArticleMgmtServiceTestCase extends AbstractTestCase { ...@@ -71,7 +72,10 @@ public class ArticleMgmtServiceTestCase extends AbstractTestCase {
final JSONObject article = new JSONObject(); final JSONObject article = new JSONObject();
requestJSONObject.put(Article.ARTICLE, article); 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_TITLE, "article1 title");
article.put(Article.ARTICLE_ABSTRACT, "article1 abstract"); article.put(Article.ARTICLE_ABSTRACT, "article1 abstract");
article.put(Article.ARTICLE_CONTENT, "article1 content"); article.put(Article.ARTICLE_CONTENT, "article1 content");
...@@ -101,7 +105,10 @@ public class ArticleMgmtServiceTestCase extends AbstractTestCase { ...@@ -101,7 +105,10 @@ public class ArticleMgmtServiceTestCase extends AbstractTestCase {
final JSONObject article = new JSONObject(); final JSONObject article = new JSONObject();
requestJSONObject.put(Article.ARTICLE, article); 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_TITLE, "article1 title");
article.put(Article.ARTICLE_ABSTRACT, "article1 abstract"); article.put(Article.ARTICLE_ABSTRACT, "article1 abstract");
article.put(Article.ARTICLE_CONTENT, "article1 content"); article.put(Article.ARTICLE_CONTENT, "article1 content");
...@@ -119,7 +126,7 @@ public class ArticleMgmtServiceTestCase extends AbstractTestCase { ...@@ -119,7 +126,7 @@ public class ArticleMgmtServiceTestCase extends AbstractTestCase {
/** /**
* Update Article. * Update Article.
* *
* @throws Exception exception * @throws Exception exception
*/ */
@Test(dependsOnMethods = "init") @Test(dependsOnMethods = "init")
...@@ -130,7 +137,10 @@ public class ArticleMgmtServiceTestCase extends AbstractTestCase { ...@@ -130,7 +137,10 @@ public class ArticleMgmtServiceTestCase extends AbstractTestCase {
final JSONObject article = new JSONObject(); final JSONObject article = new JSONObject();
requestJSONObject.put(Article.ARTICLE, article); 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_TITLE, "article2 title");
article.put(Article.ARTICLE_ABSTRACT, "article2 abstract"); article.put(Article.ARTICLE_ABSTRACT, "article2 abstract");
article.put(Article.ARTICLE_CONTENT, "article2 content"); article.put(Article.ARTICLE_CONTENT, "article2 content");
...@@ -159,7 +169,7 @@ public class ArticleMgmtServiceTestCase extends AbstractTestCase { ...@@ -159,7 +169,7 @@ public class ArticleMgmtServiceTestCase extends AbstractTestCase {
/** /**
* Remove Article. * Remove Article.
* *
* @throws Exception exception * @throws Exception exception
*/ */
@Test(dependsOnMethods = "init") @Test(dependsOnMethods = "init")
...@@ -170,7 +180,10 @@ public class ArticleMgmtServiceTestCase extends AbstractTestCase { ...@@ -170,7 +180,10 @@ public class ArticleMgmtServiceTestCase extends AbstractTestCase {
final JSONObject article = new JSONObject(); final JSONObject article = new JSONObject();
requestJSONObject.put(Article.ARTICLE, article); 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_TITLE, "article3 title");
article.put(Article.ARTICLE_ABSTRACT, "article3 abstract"); article.put(Article.ARTICLE_ABSTRACT, "article3 abstract");
article.put(Article.ARTICLE_CONTENT, "article3 content"); article.put(Article.ARTICLE_CONTENT, "article3 content");
...@@ -195,7 +208,7 @@ public class ArticleMgmtServiceTestCase extends AbstractTestCase { ...@@ -195,7 +208,7 @@ public class ArticleMgmtServiceTestCase extends AbstractTestCase {
/** /**
* Top Article. * Top Article.
* *
* @throws Exception exception * @throws Exception exception
*/ */
@Test(dependsOnMethods = "addArticle") @Test(dependsOnMethods = "addArticle")
...@@ -215,7 +228,7 @@ public class ArticleMgmtServiceTestCase extends AbstractTestCase { ...@@ -215,7 +228,7 @@ public class ArticleMgmtServiceTestCase extends AbstractTestCase {
/** /**
* Cancel Publish Article. * Cancel Publish Article.
* *
* @throws Exception exception * @throws Exception exception
*/ */
@Test(dependsOnMethods = "init") @Test(dependsOnMethods = "init")
...@@ -226,7 +239,10 @@ public class ArticleMgmtServiceTestCase extends AbstractTestCase { ...@@ -226,7 +239,10 @@ public class ArticleMgmtServiceTestCase extends AbstractTestCase {
final JSONObject article = new JSONObject(); final JSONObject article = new JSONObject();
requestJSONObject.put(Article.ARTICLE, article); 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_TITLE, "article4 title");
article.put(Article.ARTICLE_ABSTRACT, "article4 abstract"); article.put(Article.ARTICLE_ABSTRACT, "article4 abstract");
article.put(Article.ARTICLE_CONTENT, "article4 content"); article.put(Article.ARTICLE_CONTENT, "article4 content");
...@@ -256,7 +272,7 @@ public class ArticleMgmtServiceTestCase extends AbstractTestCase { ...@@ -256,7 +272,7 @@ public class ArticleMgmtServiceTestCase extends AbstractTestCase {
/** /**
* Update Articles Random Value. * Update Articles Random Value.
* *
* @throws Exception exception * @throws Exception exception
*/ */
@Test(dependsOnMethods = "addArticle") @Test(dependsOnMethods = "addArticle")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment