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            @Override
041            public WikiNode addNode(
042                            String name, String description, ServiceContext serviceContext)
043                    throws PortalException, SystemException {
044    
045                    WikiPermission.check(
046                            getPermissionChecker(), serviceContext.getScopeGroupId(),
047                            ActionKeys.ADD_NODE);
048    
049                    return wikiNodeLocalService.addNode(
050                            getUserId(), name, description, serviceContext);
051            }
052    
053            @Override
054            public void deleteNode(long nodeId)
055                    throws PortalException, SystemException {
056    
057                    WikiNodePermission.check(
058                            getPermissionChecker(), nodeId, ActionKeys.DELETE);
059    
060                    wikiNodeLocalService.deleteNode(nodeId);
061            }
062    
063            @Override
064            public WikiNode getNode(long nodeId)
065                    throws PortalException, SystemException {
066    
067                    WikiNodePermission.check(
068                            getPermissionChecker(), nodeId, ActionKeys.VIEW);
069    
070                    return wikiNodeLocalService.getNode(nodeId);
071            }
072    
073            @Override
074            public WikiNode getNode(long groupId, String name)
075                    throws PortalException, SystemException {
076    
077                    WikiNodePermission.check(
078                            getPermissionChecker(), groupId, name, ActionKeys.VIEW);
079    
080                    return wikiNodeLocalService.getNode(groupId, name);
081            }
082    
083            @Override
084            public void importPages(
085                            long nodeId, String importer, InputStream[] inputStreams,
086                            Map<String, String[]> options)
087                    throws PortalException, SystemException {
088    
089                    WikiNodePermission.check(
090                            getPermissionChecker(), nodeId, ActionKeys.IMPORT);
091    
092                    wikiNodeLocalService.importPages(
093                            getUserId(), nodeId, importer, inputStreams, options);
094            }
095    
096            @Override
097            public WikiNode moveNodeToTrash(long nodeId)
098                    throws PortalException, SystemException {
099    
100                    WikiNodePermission.check(
101                            getPermissionChecker(), nodeId, ActionKeys.DELETE);
102    
103                    return wikiNodeLocalService.moveNodeToTrash(getUserId(), nodeId);
104            }
105    
106            @Override
107            public void restoreNodeFromTrash(long nodeId)
108                    throws PortalException, SystemException {
109    
110                    WikiNode node = wikiNodeLocalService.getNode(nodeId);
111    
112                    WikiNodePermission.check(
113                            getPermissionChecker(), nodeId, ActionKeys.DELETE);
114    
115                    wikiNodeLocalService.restoreNodeFromTrash(getUserId(), node);
116            }
117    
118            @Override
119            public void subscribeNode(long nodeId)
120                    throws PortalException, SystemException {
121    
122                    WikiNodePermission.check(
123                            getPermissionChecker(), nodeId, ActionKeys.SUBSCRIBE);
124    
125                    wikiNodeLocalService.subscribeNode(getUserId(), nodeId);
126            }
127    
128            @Override
129            public void unsubscribeNode(long nodeId)
130                    throws PortalException, SystemException {
131    
132                    WikiNodePermission.check(
133                            getPermissionChecker(), nodeId, ActionKeys.SUBSCRIBE);
134    
135                    wikiNodeLocalService.unsubscribeNode(getUserId(), nodeId);
136            }
137    
138            @Override
139            public WikiNode updateNode(
140                            long nodeId, String name, String description,
141                            ServiceContext serviceContext)
142                    throws PortalException, SystemException {
143    
144                    WikiNodePermission.check(
145                            getPermissionChecker(), nodeId, ActionKeys.UPDATE);
146    
147                    return wikiNodeLocalService.updateNode(
148                            nodeId, name, description, serviceContext);
149            }
150    
151    }