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

#12633

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