001    /**
002     * Copyright (c) 2000-present 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.portlet.wiki.model.WikiPageResource;
019    import com.liferay.portlet.wiki.service.base.WikiPageResourceLocalServiceBaseImpl;
020    
021    /**
022     * @author Brian Wing Shun Chan
023     * @author Raymond Aug??
024     */
025    public class WikiPageResourceLocalServiceImpl
026            extends WikiPageResourceLocalServiceBaseImpl {
027    
028            @Override
029            public WikiPageResource addPageResource(long nodeId, String title) {
030                    long pageResourcePrimKey = counterLocalService.increment();
031    
032                    WikiPageResource pageResource = wikiPageResourcePersistence.create(
033                            pageResourcePrimKey);
034    
035                    pageResource.setNodeId(nodeId);
036                    pageResource.setTitle(title);
037    
038                    wikiPageResourcePersistence.update(pageResource);
039    
040                    return pageResource;
041            }
042    
043            @Override
044            public void deletePageResource(long nodeId, String title)
045                    throws PortalException {
046    
047                    wikiPageResourcePersistence.removeByN_T(nodeId, title);
048            }
049    
050            @Override
051            public WikiPageResource fetchPageResource(long nodeId, String title) {
052                    return wikiPageResourcePersistence.fetchByN_T(nodeId, title);
053            }
054    
055            @Override
056            public WikiPageResource fetchPageResource(String uuid) {
057                    return wikiPageResourcePersistence.fetchByUuid_First(uuid, null);
058            }
059    
060            @Override
061            public WikiPageResource getPageResource(long pageResourcePrimKey)
062                    throws PortalException {
063    
064                    return wikiPageResourcePersistence.findByPrimaryKey(
065                            pageResourcePrimKey);
066            }
067    
068            @Override
069            public WikiPageResource getPageResource(long nodeId, String title)
070                    throws PortalException {
071    
072                    return wikiPageResourcePersistence.findByN_T(nodeId, title);
073            }
074    
075            @Override
076            public long getPageResourcePrimKey(long nodeId, String title) {
077                    WikiPageResource pageResource = wikiPageResourcePersistence.fetchByN_T(
078                            nodeId, title);
079    
080                    if (pageResource == null) {
081                            long pageResourcePrimKey = counterLocalService.increment();
082    
083                            pageResource = wikiPageResourcePersistence.create(
084                                    pageResourcePrimKey);
085    
086                            pageResource.setNodeId(nodeId);
087                            pageResource.setTitle(title);
088    
089                            wikiPageResourcePersistence.update(pageResource);
090                    }
091    
092                    return pageResource.getResourcePrimKey();
093            }
094    
095    }