1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.journal.service.impl;
16  
17  import com.liferay.portal.kernel.exception.PortalException;
18  import com.liferay.portal.kernel.exception.SystemException;
19  import com.liferay.portlet.journal.model.JournalArticleResource;
20  import com.liferay.portlet.journal.service.base.JournalArticleResourceLocalServiceBaseImpl;
21  
22  import java.util.List;
23  
24  /**
25   * <a href="JournalArticleResourceLocalServiceImpl.java.html"><b><i>View Source
26   * </i></b></a>
27   *
28   * @author Brian Wing Shun Chan
29   */
30  public class JournalArticleResourceLocalServiceImpl
31      extends JournalArticleResourceLocalServiceBaseImpl {
32  
33      public void deleteArticleResource(long groupId, String articleId)
34          throws PortalException, SystemException {
35  
36          journalArticleResourcePersistence.removeByG_A(groupId, articleId);
37      }
38  
39      public JournalArticleResource getArticleResource(
40              long articleResourcePrimKey)
41          throws PortalException, SystemException {
42  
43          return journalArticleResourcePersistence.findByPrimaryKey(
44              articleResourcePrimKey);
45      }
46  
47      public long getArticleResourcePrimKey(long groupId, String articleId)
48          throws SystemException {
49  
50          JournalArticleResource articleResource =
51              journalArticleResourcePersistence.fetchByG_A(groupId, articleId);
52  
53          if (articleResource == null) {
54              long articleResourcePrimKey = counterLocalService.increment();
55  
56              articleResource = journalArticleResourcePersistence.create(
57                  articleResourcePrimKey);
58  
59              articleResource.setGroupId(groupId);
60              articleResource.setArticleId(articleId);
61  
62              journalArticleResourcePersistence.update(articleResource, false);
63          }
64  
65          return articleResource.getResourcePrimKey();
66      }
67  
68      public List<JournalArticleResource> getArticleResources(long groupId)
69          throws SystemException {
70  
71          return journalArticleResourcePersistence.findByGroupId(groupId);
72      }
73  
74  }