Commit 6916dad9 authored by Liang Ding's avatar Liang Ding

🔥 #45

parent 9792792d
...@@ -22,7 +22,7 @@ package org.b3log.solo.model; ...@@ -22,7 +22,7 @@ package org.b3log.solo.model;
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="https://hacpai.com/member/e">Dongxu Wang</a> * @author <a href="https://hacpai.com/member/e">Dongxu Wang</a>
* @version 1.7.0.6, Sep 17, 2019 * @version 1.7.0.7, Jan 16, 2020
* @since 0.3.1 * @since 0.3.1
*/ */
public final class Common { public final class Common {
...@@ -97,16 +97,6 @@ public final class Common { ...@@ -97,16 +97,6 @@ public final class Common {
*/ */
public static final String MOST_USED_CATEGORIES = "mostUsedCategories"; public static final String MOST_USED_CATEGORIES = "mostUsedCategories";
/**
* Most comment count articles.
*/
public static final String MOST_COMMENT_ARTICLES = "mostCommentArticles";
/**
* Most view count articles.
*/
public static final String MOST_VIEW_COUNT_ARTICLES = "mostViewCountArticles";
/** /**
* Recent articles. * Recent articles.
*/ */
......
...@@ -37,7 +37,7 @@ import java.util.List; ...@@ -37,7 +37,7 @@ import java.util.List;
* Article repository. * Article repository.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.1.13, Jun 6, 2019 * @version 1.1.1.14, Jan 16, 2020
* @since 0.3.1 * @since 0.3.1
*/ */
@Repository @Repository
...@@ -212,40 +212,6 @@ public class ArticleRepository extends AbstractRepository { ...@@ -212,40 +212,6 @@ public class ArticleRepository extends AbstractRepository {
return getList(query); return getList(query);
} }
/**
* Gets most commented and published articles with the specified number.
*
* @param num the specified number
* @return a list of most comment articles, returns an empty list if not found
* @throws RepositoryException repository exception
*/
public List<JSONObject> getMostCommentArticles(final int num) throws RepositoryException {
final Query query = new Query().
addSort(Article.ARTICLE_COMMENT_COUNT, SortDirection.DESCENDING).
addSort(Article.ARTICLE_UPDATED, SortDirection.DESCENDING).
setFilter(new PropertyFilter(Article.ARTICLE_STATUS, FilterOperator.EQUAL, Article.ARTICLE_STATUS_C_PUBLISHED)).
setPage(1, num).setPageCount(1);
return getList(query);
}
/**
* Gets most view count and published articles with the specified number.
*
* @param num the specified number
* @return a list of most view count articles, returns an empty list if not found
* @throws RepositoryException repository exception
*/
public List<JSONObject> getMostViewCountArticles(final int num) throws RepositoryException {
final Query query = new Query().
addSort(Article.ARTICLE_VIEW_COUNT, SortDirection.DESCENDING).
addSort(Article.ARTICLE_UPDATED, SortDirection.DESCENDING).
setFilter(new PropertyFilter(Article.ARTICLE_STATUS, FilterOperator.EQUAL, Article.ARTICLE_STATUS_C_PUBLISHED)).
setPage(1, num).setPageCount(1);
return getList(query);
}
/** /**
* Gets the previous article(by create date) by the specified article id. * Gets the previous article(by create date) by the specified article id.
* *
......
...@@ -60,7 +60,7 @@ import static org.b3log.solo.model.Article.ARTICLE_CONTENT; ...@@ -60,7 +60,7 @@ import static org.b3log.solo.model.Article.ARTICLE_CONTENT;
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://vanessa.b3log.org">Liyuan Li</a> * @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
* @version 1.7.0.13, Jan 9, 2020 * @version 1.7.0.14, Jan 16, 2020
* @since 0.3.1 * @since 0.3.1
*/ */
@Service @Service
...@@ -431,60 +431,6 @@ public class DataModelService { ...@@ -431,60 +431,6 @@ public class DataModelService {
} }
} }
/**
* Fills most view count articles.
*
* @param dataModel data model
* @param preference the specified preference
* @throws ServiceException service exception
*/
public void fillMostViewCountArticles(final Map<String, Object> dataModel, final JSONObject preference) throws ServiceException {
Stopwatchs.start("Fill Most View Articles");
try {
LOGGER.debug("Filling the most view count articles....");
final int mostCommentArticleDisplayCnt = preference.getInt(Option.ID_C_MOST_VIEW_ARTICLE_DISPLAY_CNT);
final List<JSONObject> mostViewCountArticles = articleRepository.getMostViewCountArticles(mostCommentArticleDisplayCnt);
dataModel.put(Common.MOST_VIEW_COUNT_ARTICLES, mostViewCountArticles);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, "Fills most view count articles failed", e);
throw new ServiceException(e);
} finally {
Stopwatchs.end();
}
}
/**
* Fills most comments articles.
*
* @param dataModel data model
* @param preference the specified preference
* @throws ServiceException service exception
*/
public void fillMostCommentArticles(final Map<String, Object> dataModel, final JSONObject preference) throws ServiceException {
if (!preference.optBoolean(Option.ID_C_COMMENTABLE)) {
dataModel.put(Common.MOST_COMMENT_ARTICLES, Collections.emptyList());
return;
}
Stopwatchs.start("Fill Most CMMTs Articles");
try {
LOGGER.debug("Filling most comment articles....");
final int mostCommentArticleDisplayCnt = preference.getInt(Option.ID_C_MOST_COMMENT_ARTICLE_DISPLAY_CNT);
final List<JSONObject> mostCommentArticles = articleRepository.getMostCommentArticles(mostCommentArticleDisplayCnt);
dataModel.put(Common.MOST_COMMENT_ARTICLES, mostCommentArticles);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, "Fills most comment articles failed", e);
throw new ServiceException(e);
} finally {
Stopwatchs.end();
}
}
/** /**
* Fills post articles recently. * Fills post articles recently.
* *
...@@ -800,14 +746,6 @@ public class DataModelService { ...@@ -800,14 +746,6 @@ public class DataModelService {
if (Templates.hasExpression(template, "<#list recentComments as comment>")) { if (Templates.hasExpression(template, "<#list recentComments as comment>")) {
fillRecentComments(dataModel, preference); fillRecentComments(dataModel, preference);
} }
if (Templates.hasExpression(template, "<#list mostCommentArticles as article>")) {
fillMostCommentArticles(dataModel, preference);
}
if (Templates.hasExpression(template, "<#list mostViewCountArticles as article>")) {
fillMostViewCountArticles(dataModel, preference);
}
} catch (final ServiceException e) { } catch (final ServiceException e) {
LOGGER.log(Level.ERROR, "Fills side failed", e); LOGGER.log(Level.ERROR, "Fills side failed", e);
throw new ServiceException(e); throw new ServiceException(e);
...@@ -847,14 +785,6 @@ public class DataModelService { ...@@ -847,14 +785,6 @@ public class DataModelService {
fillRecentComments(dataModel, preference); fillRecentComments(dataModel, preference);
} }
if (Templates.hasExpression(template, "<#list mostCommentArticles as article>")) {
fillMostCommentArticles(dataModel, preference);
}
if (Templates.hasExpression(template, "<#list mostViewCountArticles as article>")) {
fillMostViewCountArticles(dataModel, preference);
}
if (Templates.hasExpression(template, "<#include \"side.ftl\"/>")) { if (Templates.hasExpression(template, "<#include \"side.ftl\"/>")) {
fillSide(context, dataModel, preference); fillSide(context, dataModel, preference);
} }
......
...@@ -34,7 +34,7 @@ import java.util.List; ...@@ -34,7 +34,7 @@ import java.util.List;
* {@link ArticleRepository} test case. * {@link ArticleRepository} 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, Feb 25, 2019 * @version 1.0.0.6, Jan 16, 2020
*/ */
@Test(suiteName = "repository") @Test(suiteName = "repository")
public final class ArticleRepositoryImplTestCase extends AbstractTestCase { public final class ArticleRepositoryImplTestCase extends AbstractTestCase {
...@@ -144,99 +144,6 @@ public final class ArticleRepositoryImplTestCase extends AbstractTestCase { ...@@ -144,99 +144,6 @@ public final class ArticleRepositoryImplTestCase extends AbstractTestCase {
Assert.assertEquals(nextArticle.getString(Article.ARTICLE_TITLE), "article title2"); Assert.assertEquals(nextArticle.getString(Article.ARTICLE_TITLE), "article title2");
} }
/**
* Get Most Comment Articles.
*
* @throws Exception exception
*/
@Test(dependsOnMethods = {"add", "previousAndNext"})
public void getMostCommentArticles() throws Exception {
final ArticleRepository articleRepository = getArticleRepository();
final JSONObject article = new JSONObject();
article.put(Article.ARTICLE_TITLE, "article title3");
article.put(Article.ARTICLE_ABSTRACT, "article abstract");
article.put(Article.ARTICLE_ABSTRACT_TEXT, "article abstract text");
article.put(Article.ARTICLE_TAGS_REF, "tag1, tag2");
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");
article.put(Article.ARTICLE_PERMALINK, "article permalink3");
article.put(Article.ARTICLE_STATUS, Article.ARTICLE_STATUS_C_PUBLISHED);
article.put(Article.ARTICLE_PUT_TOP, false);
article.put(Article.ARTICLE_CREATED, new Date().getTime());
article.put(Article.ARTICLE_UPDATED, new Date().getTime());
article.put(Article.ARTICLE_RANDOM_DOUBLE, Math.random());
article.put(Article.ARTICLE_SIGN_ID, "1");
article.put(Article.ARTICLE_COMMENTABLE, true);
article.put(Article.ARTICLE_VIEW_PWD, "");
article.put(Article.ARTICLE_IMG1_URL, Article.getArticleImg1URL(article));
final Transaction transaction = articleRepository.beginTransaction();
articleRepository.add(article);
transaction.commit();
List<JSONObject> mostCommentArticles = articleRepository.getMostCommentArticles(2);
Assert.assertNotNull(mostCommentArticles);
Assert.assertEquals(mostCommentArticles.size(), 2);
Assert.assertEquals(mostCommentArticles.get(0).getInt(Article.ARTICLE_COMMENT_COUNT), 2);
Assert.assertEquals(mostCommentArticles.get(1).getInt(Article.ARTICLE_COMMENT_COUNT), 1);
mostCommentArticles = articleRepository.getMostCommentArticles(1);
Assert.assertNotNull(mostCommentArticles);
Assert.assertEquals(mostCommentArticles.size(), 1);
Assert.assertEquals(mostCommentArticles.get(0).getInt(Article.ARTICLE_COMMENT_COUNT), 2);
}
/**
* Get Most View Count Articles
*
* @throws Exception exception
*/
@Test(dependsOnMethods = {"add", "previousAndNext", "getMostCommentArticles"})
public void getMostViewCountArticles() throws Exception {
final ArticleRepository articleRepository = getArticleRepository();
final JSONObject article = new JSONObject();
article.put(Article.ARTICLE_TITLE, "article title4");
article.put(Article.ARTICLE_ABSTRACT, "article abstract");
article.put(Article.ARTICLE_ABSTRACT_TEXT, "article abstract text");
article.put(Article.ARTICLE_TAGS_REF, "tag1, tag2");
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");
article.put(Article.ARTICLE_PERMALINK, "article permalink4");
article.put(Article.ARTICLE_STATUS, Article.ARTICLE_STATUS_C_DRAFT);
article.put(Article.ARTICLE_PUT_TOP, false);
article.put(Article.ARTICLE_CREATED, new Date().getTime());
article.put(Article.ARTICLE_UPDATED, new Date().getTime());
article.put(Article.ARTICLE_RANDOM_DOUBLE, Math.random());
article.put(Article.ARTICLE_SIGN_ID, "1");
article.put(Article.ARTICLE_COMMENTABLE, true);
article.put(Article.ARTICLE_VIEW_PWD, "");
article.put(Article.ARTICLE_IMG1_URL, Article.getArticleImg1URL(article));
final Transaction transaction = articleRepository.beginTransaction();
articleRepository.add(article);
transaction.commit();
List<JSONObject> mostViewCountArticles = articleRepository.getMostViewCountArticles(2);
Assert.assertNotNull(mostViewCountArticles);
Assert.assertEquals(mostViewCountArticles.size(), 2);
Assert.assertEquals(mostViewCountArticles.get(0).getInt(Article.ARTICLE_VIEW_COUNT), 2);
Assert.assertEquals(mostViewCountArticles.get(1).getInt(Article.ARTICLE_VIEW_COUNT), 1);
mostViewCountArticles = articleRepository.getMostViewCountArticles(1);
Assert.assertNotNull(mostViewCountArticles);
Assert.assertEquals(mostViewCountArticles.size(), 1);
Assert.assertEquals(mostViewCountArticles.get(0).getInt(Article.ARTICLE_VIEW_COUNT), 2);
}
/** /**
* Get Randomly. * Get Randomly.
* *
......
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