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, false);
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 getPageResource(long pageResourcePrimKey)
055                    throws PortalException, SystemException {
056    
057                    return wikiPageResourcePersistence.findByPrimaryKey(
058                            pageResourcePrimKey);
059            }
060    
061            @Override
062            public WikiPageResource getPageResource(long nodeId, String title)
063                    throws PortalException, SystemException {
064    
065                    return wikiPageResourcePersistence.findByN_T(nodeId, title);
066            }
067    
068            @Override
069            public long getPageResourcePrimKey(long nodeId, String title)
070                    throws SystemException {
071    
072                    WikiPageResource pageResource = wikiPageResourcePersistence.fetchByN_T(
073                            nodeId, title);
074    
075                    if (pageResource == null) {
076                            long pageResourcePrimKey = counterLocalService.increment();
077    
078                            pageResource = wikiPageResourcePersistence.create(
079                                    pageResourcePrimKey);
080    
081                            pageResource.setNodeId(nodeId);
082                            pageResource.setTitle(title);
083    
084                            wikiPageResourcePersistence.update(pageResource, false);
085                    }
086    
087                    return pageResource.getResourcePrimKey();
088            }
089    
090    }