001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.wiki.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portlet.wiki.model.WikiPageResource;
020    import com.liferay.portlet.wiki.service.base.WikiPageResourceLocalServiceBaseImpl;
021    
022    /**
023     * @author Brian Wing Shun Chan
024     * @author Raymond Aug??
025     */
026    public class WikiPageResourceLocalServiceImpl
027            extends WikiPageResourceLocalServiceBaseImpl {
028    
029            @Override
030            public WikiPageResource addPageResource(long nodeId, String title)
031                    throws SystemException {
032    
033                    long pageResourcePrimKey = counterLocalService.increment();
034    
035                    WikiPageResource pageResource = wikiPageResourcePersistence.create(
036                            pageResourcePrimKey);
037    
038                    pageResource.setNodeId(nodeId);
039                    pageResource.setTitle(title);
040    
041                    wikiPageResourcePersistence.update(pageResource);
042    
043                    return pageResource;
044            }
045    
046            @Override
047            public void deletePageResource(long nodeId, String title)
048                    throws PortalException, SystemException {
049    
050                    wikiPageResourcePersistence.removeByN_T(nodeId, title);
051            }
052    
053            @Override
054            public WikiPageResource fetchPageResource(long nodeId, String title)
055                    throws SystemException {
056    
057                    return wikiPageResourcePersistence.fetchByN_T(nodeId, title);
058            }
059    
060            @Override
061            public WikiPageResource fetchPageResource(String uuid)
062                    throws SystemException {
063    
064                    return wikiPageResourcePersistence.fetchByUuid_First(uuid, null);
065            }
066    
067            @Override
068            public WikiPageResource getPageResource(long pageResourcePrimKey)
069                    throws PortalException, SystemException {
070    
071                    return wikiPageResourcePersistence.findByPrimaryKey(
072                            pageResourcePrimKey);
073            }
074    
075            @Override
076            public WikiPageResource getPageResource(long nodeId, String title)
077                    throws PortalException, SystemException {
078    
079                    return wikiPageResourcePersistence.findByN_T(nodeId, title);
080            }
081    
082            @Override
083            public long getPageResourcePrimKey(long nodeId, String title)
084                    throws SystemException {
085    
086                    WikiPageResource pageResource = wikiPageResourcePersistence.fetchByN_T(
087                            nodeId, title);
088    
089                    if (pageResource == null) {
090                            long pageResourcePrimKey = counterLocalService.increment();
091    
092                            pageResource = wikiPageResourcePersistence.create(
093                                    pageResourcePrimKey);
094    
095                            pageResource.setNodeId(nodeId);
096                            pageResource.setTitle(title);
097    
098                            wikiPageResourcePersistence.update(pageResource);
099                    }
100    
101                    return pageResource.getResourcePrimKey();
102            }
103    
104    }