Commit 2188c8a7 authored by Liang Ding's avatar Liang Ding

#12633

parent 3a8be1ee
...@@ -21,7 +21,7 @@ package org.b3log.solo.model; ...@@ -21,7 +21,7 @@ package org.b3log.solo.model;
* This class defines all archive date model relevant keys. * This class defines all archive date model relevant keys.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.4, Jan 18, 2013 * @version 1.0.0.5, Jan 28, 2019
*/ */
public final class ArchiveDate { public final class ArchiveDate {
...@@ -40,11 +40,6 @@ public final class ArchiveDate { ...@@ -40,11 +40,6 @@ public final class ArchiveDate {
*/ */
public static final String ARCHIVE_TIME = "archiveTime"; public static final String ARCHIVE_TIME = "archiveTime";
/**
* Key of archive date article count.
*/
public static final String ARCHIVE_DATE_ARTICLE_COUNT = "archiveDateArticleCount";
/** /**
* Key of archive date article count. * Key of archive date article count.
*/ */
......
...@@ -643,9 +643,7 @@ public class ArticleMgmtService { ...@@ -643,9 +643,7 @@ public class ArticleMgmtService {
final JSONObject archiveDateArticleRelation = archiveDateArticleRepository.getByArticleId(articleId); final JSONObject archiveDateArticleRelation = archiveDateArticleRepository.getByArticleId(articleId);
final String archiveDateId = archiveDateArticleRelation.getString(ArchiveDate.ARCHIVE_DATE + "_" + Keys.OBJECT_ID); final String archiveDateId = archiveDateArticleRelation.getString(ArchiveDate.ARCHIVE_DATE + "_" + Keys.OBJECT_ID);
final JSONObject archiveDate = archiveDateRepository.get(archiveDateId); final JSONObject archiveDate = archiveDateRepository.get(archiveDateId);
int archiveDateArticleCnt = archiveDate.getInt(ArchiveDate.ARCHIVE_DATE_ARTICLE_COUNT);
--archiveDateArticleCnt;
int archiveDatePublishedArticleCnt = archiveDate.getInt(ArchiveDate.ARCHIVE_DATE_PUBLISHED_ARTICLE_COUNT); int archiveDatePublishedArticleCnt = archiveDate.getInt(ArchiveDate.ARCHIVE_DATE_PUBLISHED_ARTICLE_COUNT);
final JSONObject article = articleRepository.get(articleId); final JSONObject article = articleRepository.get(articleId);
...@@ -653,13 +651,10 @@ public class ArticleMgmtService { ...@@ -653,13 +651,10 @@ public class ArticleMgmtService {
--archiveDatePublishedArticleCnt; --archiveDatePublishedArticleCnt;
} }
if (0 == archiveDateArticleCnt) { if (0 == archiveDatePublishedArticleCnt) {
archiveDateRepository.remove(archiveDateId); archiveDateRepository.remove(archiveDateId);
} else { } else {
final JSONObject newArchiveDate = new JSONObject(archiveDate, final JSONObject newArchiveDate = new JSONObject(archiveDate, CollectionUtils.jsonArrayToArray(archiveDate.names(), String[].class));
CollectionUtils.jsonArrayToArray(archiveDate.names(), String[].class));
newArchiveDate.put(ArchiveDate.ARCHIVE_DATE_ARTICLE_COUNT, archiveDateArticleCnt);
newArchiveDate.put(ArchiveDate.ARCHIVE_DATE_PUBLISHED_ARTICLE_COUNT, archiveDatePublishedArticleCnt); newArchiveDate.put(ArchiveDate.ARCHIVE_DATE_PUBLISHED_ARTICLE_COUNT, archiveDatePublishedArticleCnt);
archiveDateRepository.update(archiveDateId, newArchiveDate); archiveDateRepository.update(archiveDateId, newArchiveDate);
} }
...@@ -939,7 +934,6 @@ public class ArticleMgmtService { ...@@ -939,7 +934,6 @@ public class ArticleMgmtService {
archiveDate = new JSONObject(); archiveDate = new JSONObject();
try { try {
archiveDate.put(ArchiveDate.ARCHIVE_TIME, DateUtils.parseDate(createDateString, new String[]{"yyyy/MM"}).getTime()); archiveDate.put(ArchiveDate.ARCHIVE_TIME, DateUtils.parseDate(createDateString, new String[]{"yyyy/MM"}).getTime());
archiveDate.put(ArchiveDate.ARCHIVE_DATE_ARTICLE_COUNT, 0);
archiveDate.put(ArchiveDate.ARCHIVE_DATE_PUBLISHED_ARTICLE_COUNT, 0); archiveDate.put(ArchiveDate.ARCHIVE_DATE_PUBLISHED_ARTICLE_COUNT, 0);
archiveDateRepository.add(archiveDate); archiveDateRepository.add(archiveDate);
} catch (final ParseException e) { } catch (final ParseException e) {
...@@ -949,10 +943,8 @@ public class ArticleMgmtService { ...@@ -949,10 +943,8 @@ public class ArticleMgmtService {
} }
final JSONObject newArchiveDate = new JSONObject(archiveDate, CollectionUtils.jsonArrayToArray(archiveDate.names(), String[].class)); final JSONObject newArchiveDate = new JSONObject(archiveDate, CollectionUtils.jsonArrayToArray(archiveDate.names(), String[].class));
newArchiveDate.put(ArchiveDate.ARCHIVE_DATE_ARTICLE_COUNT, archiveDate.optInt(ArchiveDate.ARCHIVE_DATE_ARTICLE_COUNT) + 1);
if (article.optBoolean(Article.ARTICLE_IS_PUBLISHED)) { if (article.optBoolean(Article.ARTICLE_IS_PUBLISHED)) {
newArchiveDate.put(ArchiveDate.ARCHIVE_DATE_PUBLISHED_ARTICLE_COUNT, newArchiveDate.put(ArchiveDate.ARCHIVE_DATE_PUBLISHED_ARTICLE_COUNT, archiveDate.optInt(ArchiveDate.ARCHIVE_DATE_PUBLISHED_ARTICLE_COUNT) + 1);
archiveDate.optInt(ArchiveDate.ARCHIVE_DATE_PUBLISHED_ARTICLE_COUNT) + 1);
} }
archiveDateRepository.update(archiveDate.optString(Keys.OBJECT_ID), newArchiveDate); archiveDateRepository.update(archiveDate.optString(Keys.OBJECT_ID), newArchiveDate);
......
...@@ -336,9 +336,7 @@ public class InitService { ...@@ -336,9 +336,7 @@ public class InitService {
try { try {
archiveDate.put(ArchiveDate.ARCHIVE_TIME, DateUtils.parseDate(createDateString, new String[]{"yyyy/MM"}).getTime()); archiveDate.put(ArchiveDate.ARCHIVE_TIME, DateUtils.parseDate(createDateString, new String[]{"yyyy/MM"}).getTime());
archiveDate.put(ArchiveDate.ARCHIVE_DATE_ARTICLE_COUNT, 1);
archiveDate.put(ArchiveDate.ARCHIVE_DATE_PUBLISHED_ARTICLE_COUNT, 1); archiveDate.put(ArchiveDate.ARCHIVE_DATE_PUBLISHED_ARTICLE_COUNT, 1);
archiveDateRepository.add(archiveDate); archiveDateRepository.add(archiveDate);
} catch (final ParseException e) { } catch (final ParseException e) {
LOGGER.log(Level.ERROR, e.getMessage(), e); LOGGER.log(Level.ERROR, e.getMessage(), e);
...@@ -346,10 +344,8 @@ public class InitService { ...@@ -346,10 +344,8 @@ public class InitService {
} }
final JSONObject archiveDateArticleRelation = new JSONObject(); final JSONObject archiveDateArticleRelation = new JSONObject();
archiveDateArticleRelation.put(ArchiveDate.ARCHIVE_DATE + "_" + Keys.OBJECT_ID, archiveDate.optString(Keys.OBJECT_ID)); archiveDateArticleRelation.put(ArchiveDate.ARCHIVE_DATE + "_" + Keys.OBJECT_ID, archiveDate.optString(Keys.OBJECT_ID));
archiveDateArticleRelation.put(Article.ARTICLE + "_" + Keys.OBJECT_ID, article.optString(Keys.OBJECT_ID)); archiveDateArticleRelation.put(Article.ARTICLE + "_" + Keys.OBJECT_ID, article.optString(Keys.OBJECT_ID));
archiveDateArticleRepository.add(archiveDateArticleRelation); archiveDateArticleRepository.add(archiveDateArticleRelation);
} }
...@@ -364,10 +360,8 @@ public class InitService { ...@@ -364,10 +360,8 @@ public class InitService {
for (int i = 0; i < tags.length(); i++) { for (int i = 0; i < tags.length(); i++) {
final JSONObject tag = tags.optJSONObject(i); final JSONObject tag = tags.optJSONObject(i);
final JSONObject tagArticleRelation = new JSONObject(); final JSONObject tagArticleRelation = new JSONObject();
tagArticleRelation.put(Tag.TAG + "_" + Keys.OBJECT_ID, tag.optString(Keys.OBJECT_ID)); tagArticleRelation.put(Tag.TAG + "_" + Keys.OBJECT_ID, tag.optString(Keys.OBJECT_ID));
tagArticleRelation.put(Article.ARTICLE + "_" + Keys.OBJECT_ID, article.optString(Keys.OBJECT_ID)); tagArticleRelation.put(Article.ARTICLE + "_" + Keys.OBJECT_ID, article.optString(Keys.OBJECT_ID));
tagArticleRepository.add(tagArticleRelation); tagArticleRepository.add(tagArticleRelation);
} }
} }
...@@ -387,16 +381,12 @@ public class InitService { ...@@ -387,16 +381,12 @@ public class InitService {
final String tagTitle = tagTitles[i].trim(); final String tagTitle = tagTitles[i].trim();
final JSONObject tag = new JSONObject(); final JSONObject tag = new JSONObject();
LOGGER.log(Level.TRACE, "Found a new tag[title={0}] in article[title={1}]", LOGGER.log(Level.TRACE, "Found a new tag[title={0}] in article[title={1}]", tagTitle, article.optString(Article.ARTICLE_TITLE));
tagTitle, article.optString(Article.ARTICLE_TITLE));
tag.put(Tag.TAG_TITLE, tagTitle); tag.put(Tag.TAG_TITLE, tagTitle);
tag.put(Tag.TAG_REFERENCE_COUNT, 1); tag.put(Tag.TAG_REFERENCE_COUNT, 1);
tag.put(Tag.TAG_PUBLISHED_REFERENCE_COUNT, 1); tag.put(Tag.TAG_PUBLISHED_REFERENCE_COUNT, 1);
final String tagId = tagRepository.add(tag); final String tagId = tagRepository.add(tag);
tag.put(Keys.OBJECT_ID, tagId); tag.put(Keys.OBJECT_ID, tagId);
ret.put(tag); ret.put(tag);
} }
...@@ -429,7 +419,6 @@ public class InitService { ...@@ -429,7 +419,6 @@ public class InitService {
avatar = Solos.getGravatarURL(requestJSONObject.getString(User.USER_EMAIL), "128"); avatar = Solos.getGravatarURL(requestJSONObject.getString(User.USER_EMAIL), "128");
} }
admin.put(UserExt.USER_AVATAR, avatar); admin.put(UserExt.USER_AVATAR, avatar);
userRepository.add(admin); userRepository.add(admin);
LOGGER.debug("Initialized admin"); LOGGER.debug("Initialized admin");
...@@ -446,9 +435,7 @@ public class InitService { ...@@ -446,9 +435,7 @@ public class InitService {
link.put(Link.LINK_TITLE, "黑客派"); link.put(Link.LINK_TITLE, "黑客派");
link.put(Link.LINK_ADDRESS, "https://hacpai.com"); link.put(Link.LINK_ADDRESS, "https://hacpai.com");
link.put(Link.LINK_DESCRIPTION, "黑客与画家的社区"); link.put(Link.LINK_DESCRIPTION, "黑客与画家的社区");
final int maxOrder = linkRepository.getMaxOrder(); final int maxOrder = linkRepository.getMaxOrder();
link.put(Link.LINK_ORDER, maxOrder + 1); link.put(Link.LINK_ORDER, maxOrder + 1);
final String ret = linkRepository.add(link); final String ret = linkRepository.add(link);
} }
...@@ -480,7 +467,6 @@ public class InitService { ...@@ -480,7 +467,6 @@ public class InitService {
LOGGER.debug("Initializing reply notification template"); LOGGER.debug("Initializing reply notification template");
final JSONObject replyNotificationTemplate = new JSONObject(DefaultPreference.DEFAULT_REPLY_NOTIFICATION_TEMPLATE); final JSONObject replyNotificationTemplate = new JSONObject(DefaultPreference.DEFAULT_REPLY_NOTIFICATION_TEMPLATE);
replyNotificationTemplate.put(Keys.OBJECT_ID, "replyNotificationTemplate"); replyNotificationTemplate.put(Keys.OBJECT_ID, "replyNotificationTemplate");
final JSONObject subjectOpt = new JSONObject(); final JSONObject subjectOpt = new JSONObject();
......
...@@ -31,7 +31,7 @@ import java.util.List; ...@@ -31,7 +31,7 @@ import java.util.List;
* {@link ArchiveDateRepository} test case. * {@link ArchiveDateRepository} 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, Jul 20, 2017 * @version 1.0.0.3, Jan 28, 2019
*/ */
@Test(suiteName = "repository") @Test(suiteName = "repository")
public class ArchiveDateRepositoryImplTestCase extends AbstractTestCase { public class ArchiveDateRepositoryImplTestCase extends AbstractTestCase {
...@@ -46,9 +46,7 @@ public class ArchiveDateRepositoryImplTestCase extends AbstractTestCase { ...@@ -46,9 +46,7 @@ public class ArchiveDateRepositoryImplTestCase extends AbstractTestCase {
final ArchiveDateRepository archiveDateRepository = getArchiveDateRepository(); final ArchiveDateRepository archiveDateRepository = getArchiveDateRepository();
final JSONObject archiveDate = new JSONObject(); final JSONObject archiveDate = new JSONObject();
archiveDate.put(ArchiveDate.ARCHIVE_TIME, DateUtils.parseDate("2011/12", new String[]{"yyyy/MM"}).getTime()); archiveDate.put(ArchiveDate.ARCHIVE_TIME, DateUtils.parseDate("2011/12", new String[]{"yyyy/MM"}).getTime());
archiveDate.put(ArchiveDate.ARCHIVE_DATE_ARTICLE_COUNT, 1);
archiveDate.put(ArchiveDate.ARCHIVE_DATE_PUBLISHED_ARTICLE_COUNT, 1); archiveDate.put(ArchiveDate.ARCHIVE_DATE_PUBLISHED_ARTICLE_COUNT, 1);
final Transaction transaction = archiveDateRepository.beginTransaction(); final Transaction transaction = archiveDateRepository.beginTransaction();
...@@ -71,7 +69,7 @@ public class ArchiveDateRepositoryImplTestCase extends AbstractTestCase { ...@@ -71,7 +69,7 @@ public class ArchiveDateRepositoryImplTestCase extends AbstractTestCase {
final JSONObject archiveDate = archiveDateRepository.getByArchiveDate("2011/12"); final JSONObject archiveDate = archiveDateRepository.getByArchiveDate("2011/12");
Assert.assertNotNull(archiveDate); Assert.assertNotNull(archiveDate);
Assert.assertEquals(archiveDate.optInt(ArchiveDate.ARCHIVE_DATE_ARTICLE_COUNT), 1); Assert.assertEquals(archiveDate.optInt(ArchiveDate.ARCHIVE_DATE_PUBLISHED_ARTICLE_COUNT), 1);
//System.out.println(archiveDate.toString(SoloServletListener.JSON_PRINT_INDENT_FACTOR)); //System.out.println(archiveDate.toString(SoloServletListener.JSON_PRINT_INDENT_FACTOR));
} }
} }
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