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.portal.security.permission.ActionKeys;
020    import com.liferay.portal.service.ServiceContext;
021    import com.liferay.portlet.wiki.model.WikiNode;
022    import com.liferay.portlet.wiki.service.base.WikiNodeServiceBaseImpl;
023    import com.liferay.portlet.wiki.service.permission.WikiNodePermission;
024    import com.liferay.portlet.wiki.service.permission.WikiPermission;
025    
026    import java.io.InputStream;
027    
028    import java.util.Map;
029    
030    /**
031     * Provides the remote service for accessing, adding, deleting, importing,
032     * subscription handling of, trash handling of, and updating wiki nodes. Its
033     * methods include permission checks.
034     *
035     * @author Brian Wing Shun Chan
036     * @author Charles May
037     */
038    public class WikiNodeServiceImpl extends WikiNodeServiceBaseImpl {
039    
040            public WikiNode addNode(
041                            String name, String description, ServiceContext serviceContext)
042                    throws PortalException, SystemException {
043    
044                    WikiPermission.check(
045                            getPermissionChecker(), serviceContext.getScopeGroupId(),
046                            ActionKeys.ADD_NODE);
047    
048                    return wikiNodeLocalService.addNode(
049                            getUserId(), name, description, serviceContext);
050            }
051    
052            public void deleteNode(long nodeId)
053                    throws PortalException, SystemException {
054    
055                    WikiNodePermission.check(
056                            getPermissionChecker(), nodeId, ActionKeys.DELETE);
057    
058                    wikiNodeLocalService.deleteNode(nodeId);
059            }
060    
061            public WikiNode getNode(long nodeId)
062                    throws PortalException, SystemException {
063    
064                    WikiNodePermission.check(
065                            getPermissionChecker(), nodeId, ActionKeys.VIEW);
066    
067                    return wikiNodeLocalService.getNode(nodeId);
068            }
069    
070            public WikiNode getNode(long groupId, String name)
071                    throws PortalException, SystemException {
072    
073                    WikiNodePermission.check(
074                            getPermissionChecker(), groupId, name, ActionKeys.VIEW);
075    
076                    return wikiNodeLocalService.getNode(groupId, name);
077            }
078    
079            public void importPages(
080                            long nodeId, String importer, InputStream[] inputStreams,
081                            Map<String, String[]> options)
082                    throws PortalException, SystemException {
083    
084                    WikiNodePermission.check(
085                            getPermissionChecker(), nodeId, ActionKeys.IMPORT);
086    
087                    wikiNodeLocalService.importPages(
088                            getUserId(), nodeId, importer, inputStreams, options);
089            }
090    
091            public WikiNode moveNodeToTrash(long nodeId)
092                    throws PortalException, SystemException {
093    
094                    WikiNodePermission.check(
095                            getPermissionChecker(), nodeId, ActionKeys.DELETE);
096    
097                    return wikiNodeLocalService.moveNodeToTrash(getUserId(), nodeId);
098            }
099    
100            public void restoreNodeFromTrash(long nodeId)
101                    throws PortalException, SystemException {
102    
103                    WikiNode node = wikiNodeLocalService.getNode(nodeId);
104    
105                    WikiNodePermission.check(
106                            getPermissionChecker(), nodeId, ActionKeys.DELETE);
107    
108                    wikiNodeLocalService.restoreNodeFromTrash(getUserId(), node);
109            }
110    
111            public void subscribeNode(long nodeId)
112                    throws PortalException, SystemException {
113    
114                    WikiNodePermission.check(
115                            getPermissionChecker(), nodeId, ActionKeys.SUBSCRIBE);
116    
117                    wikiNodeLocalService.subscribeNode(getUserId(), nodeId);
118            }
119    
120            public void unsubscribeNode(long nodeId)
121                    throws PortalException, SystemException {
122    
123                    WikiNodePermission.check(
124                            getPermissionChecker(), nodeId, ActionKeys.SUBSCRIBE);
125    
126                    wikiNodeLocalService.unsubscribeNode(getUserId(), nodeId);
127            }
128    
129            public WikiNode updateNode(
130                            long nodeId, String name, String description,
131                            ServiceContext serviceContext)
132                    throws PortalException, SystemException {
133    
134                    WikiNodePermission.check(
135                            getPermissionChecker(), nodeId, ActionKeys.UPDATE);
136    
137                    return wikiNodeLocalService.updateNode(
138                            nodeId, name, description, serviceContext);
139            }
140    
141    }