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.wiki.service.impl;
16  
17  import com.liferay.portal.kernel.exception.PortalException;
18  import com.liferay.portal.kernel.exception.SystemException;
19  import com.liferay.portlet.wiki.model.WikiPageResource;
20  import com.liferay.portlet.wiki.service.base.WikiPageResourceLocalServiceBaseImpl;
21  
22  /**
23   * <a href="WikiPageResourceLocalServiceImpl.java.html"><b><i>View Source</i>
24   * </b></a>
25   *
26   * @author Brian Wing Shun Chan
27   * @author Raymond Augé
28   */
29  public class WikiPageResourceLocalServiceImpl
30      extends WikiPageResourceLocalServiceBaseImpl {
31  
32      public WikiPageResource addPageResource(long nodeId, String title)
33          throws SystemException {
34  
35          long pageResourcePrimKey = counterLocalService.increment();
36  
37          WikiPageResource pageResource = wikiPageResourcePersistence.create(
38              pageResourcePrimKey);
39  
40          pageResource.setNodeId(nodeId);
41          pageResource.setTitle(title);
42  
43          wikiPageResourcePersistence.update(pageResource, false);
44  
45          return pageResource;
46      }
47  
48      public void deletePageResource(long nodeId, String title)
49          throws PortalException, SystemException {
50  
51          wikiPageResourcePersistence.removeByN_T(nodeId, title);
52      }
53  
54      public WikiPageResource getPageResource(long pageResourcePrimKey)
55          throws PortalException, SystemException {
56  
57          return wikiPageResourcePersistence.findByPrimaryKey(
58              pageResourcePrimKey);
59      }
60  
61      public WikiPageResource getPageResource(long nodeId, String title)
62          throws PortalException, SystemException {
63  
64          return wikiPageResourcePersistence.findByN_T(nodeId, title);
65      }
66  
67      public long getPageResourcePrimKey(long nodeId, String title)
68          throws SystemException {
69  
70          WikiPageResource pageResource = wikiPageResourcePersistence.fetchByN_T(
71              nodeId, title);
72  
73          if (pageResource == null) {
74              long pageResourcePrimKey = counterLocalService.increment();
75  
76              pageResource = wikiPageResourcePersistence.create(
77                  pageResourcePrimKey);
78  
79              pageResource.setNodeId(nodeId);
80              pageResource.setTitle(title);
81  
82              wikiPageResourcePersistence.update(pageResource, false);
83          }
84  
85          return pageResource.getResourcePrimKey();
86      }
87  
88  }