/core/src/main/java/org/b3log/solo/repository/impl/ArchiveDateArticleRepositoryImpl.java

http://github.com/b3log/b3log-solo · Java · 86 lines · 41 code · 10 blank · 35 comment · 2 complexity · 354908b74743d4b69985cc36a022f833 MD5 · raw file

  1. /*
  2. * Copyright (c) 2009, 2010, 2011, 2012, B3log Team
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.b3log.solo.repository.impl;
  17. import org.b3log.latke.Keys;
  18. import org.b3log.latke.repository.*;
  19. import org.b3log.solo.model.Article;
  20. import org.b3log.solo.model.ArchiveDate;
  21. import org.b3log.solo.repository.ArchiveDateArticleRepository;
  22. import org.json.JSONArray;
  23. import org.json.JSONObject;
  24. /**
  25. * Archive date-Article relation repository.
  26. *
  27. * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
  28. * @version 1.0.0.6, Nov 9, 2011
  29. * @since 0.3.1
  30. */
  31. public final class ArchiveDateArticleRepositoryImpl extends AbstractRepository implements ArchiveDateArticleRepository {
  32. /**
  33. * Singleton.
  34. */
  35. private static final ArchiveDateArticleRepositoryImpl SINGLETON =
  36. new ArchiveDateArticleRepositoryImpl(ArchiveDate.ARCHIVE_DATE + "_" + Article.ARTICLE);
  37. @Override
  38. public JSONObject getByArchiveDateId(final String archiveDateId, final int currentPageNum, final int pageSize)
  39. throws RepositoryException {
  40. final Query query = new Query().setFilter(new PropertyFilter(ArchiveDate.ARCHIVE_DATE + "_" + Keys.OBJECT_ID,
  41. FilterOperator.EQUAL, archiveDateId)).
  42. addSort(Article.ARTICLE + "_" + Keys.OBJECT_ID,
  43. SortDirection.DESCENDING).
  44. setCurrentPageNum(currentPageNum).
  45. setPageSize(pageSize).
  46. setPageCount(1);
  47. return get(query);
  48. }
  49. @Override
  50. public JSONObject getByArticleId(final String articleId) throws RepositoryException {
  51. final Query query = new Query();
  52. query.setFilter(new PropertyFilter(Article.ARTICLE + "_" + Keys.OBJECT_ID, FilterOperator.EQUAL, articleId));
  53. final JSONObject result = get(query);
  54. final JSONArray array = result.optJSONArray(Keys.RESULTS);
  55. if (0 == array.length()) {
  56. return null;
  57. }
  58. return array.optJSONObject(0);
  59. }
  60. /**
  61. * Gets the {@link ArchiveDateArticleRepositoryImpl} singleton.
  62. *
  63. * @return the singleton
  64. */
  65. public static ArchiveDateArticleRepositoryImpl getInstance() {
  66. return SINGLETON;
  67. }
  68. /**
  69. * Private constructor.
  70. *
  71. * @param name the specified name
  72. */
  73. private ArchiveDateArticleRepositoryImpl(final String name) {
  74. super(name);
  75. }
  76. }