1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.journal.service.impl;
24  
25  import com.liferay.portal.PortalException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.kernel.util.ListUtil;
28  import com.liferay.portal.security.permission.ActionKeys;
29  import com.liferay.portal.service.permission.PortletPermissionUtil;
30  import com.liferay.portal.util.PortletKeys;
31  import com.liferay.portlet.journal.model.JournalTemplate;
32  import com.liferay.portlet.journal.service.base.JournalTemplateServiceBaseImpl;
33  import com.liferay.portlet.journal.service.permission.JournalStructurePermission;
34  import com.liferay.portlet.journal.service.permission.JournalTemplatePermission;
35  
36  import java.io.File;
37  
38  import java.util.ArrayList;
39  import java.util.Iterator;
40  import java.util.List;
41  
42  /**
43   * <a href="JournalTemplateServiceImpl.java.html"><b><i>View Source</i></b></a>
44   *
45   * @author Brian Wing Shun Chan
46   */
47  public class JournalTemplateServiceImpl extends JournalTemplateServiceBaseImpl {
48  
49      public JournalTemplate addTemplate(
50              String templateId, boolean autoTemplateId, long plid,
51              String structureId, String name, String description, String xsl,
52              boolean formatXsl, String langType, boolean cacheable,
53              boolean smallImage, String smallImageURL, File smallFile,
54              boolean addCommunityPermissions, boolean addGuestPermissions)
55          throws PortalException, SystemException {
56  
57          PortletPermissionUtil.check(
58              getPermissionChecker(), plid, PortletKeys.JOURNAL,
59              ActionKeys.ADD_TEMPLATE);
60  
61          return journalTemplateLocalService.addTemplate(
62              getUserId(), templateId, autoTemplateId, plid, structureId, name,
63              description, xsl, formatXsl, langType, cacheable, smallImage,
64              smallImageURL, smallFile, addCommunityPermissions,
65              addGuestPermissions);
66      }
67  
68      public JournalTemplate addTemplate(
69              String templateId, boolean autoTemplateId, long plid,
70              String structureId, String name, String description, String xsl,
71              boolean formatXsl, String langType, boolean cacheable,
72              boolean smallImage, String smallImageURL, File smallFile,
73              String[] communityPermissions, String[] guestPermissions)
74          throws PortalException, SystemException {
75  
76          PortletPermissionUtil.check(
77              getPermissionChecker(), plid, PortletKeys.JOURNAL,
78              ActionKeys.ADD_TEMPLATE);
79  
80          return journalTemplateLocalService.addTemplate(
81              getUserId(), templateId, autoTemplateId, plid, structureId, name,
82              description, xsl, formatXsl, langType, cacheable, smallImage,
83              smallImageURL, smallFile, communityPermissions, guestPermissions);
84      }
85  
86      public JournalTemplate copyTemplate(
87              long groupId, String oldTemplateId, String newTemplateId,
88              boolean autoTemplateId)
89          throws PortalException, SystemException {
90  
91          JournalTemplatePermission.check(
92              getPermissionChecker(), groupId, oldTemplateId,
93              ActionKeys.ADD_TEMPLATE);
94  
95          return journalTemplateLocalService.copyTemplate(
96              getUserId(), groupId, oldTemplateId, newTemplateId, autoTemplateId);
97      }
98  
99      public void deleteTemplate(long groupId, String templateId)
100         throws PortalException, SystemException {
101 
102         JournalTemplatePermission.check(
103             getPermissionChecker(), groupId, templateId, ActionKeys.DELETE);
104 
105         journalTemplateLocalService.deleteTemplate(groupId, templateId);
106     }
107 
108     public List<JournalTemplate> getStructureTemplates(
109             long groupId, String structureId)
110         throws PortalException, SystemException {
111 
112         if (!JournalStructurePermission.contains(
113                 getPermissionChecker(), groupId, structureId,
114                 ActionKeys.VIEW)) {
115 
116             return new ArrayList<JournalTemplate>();
117         }
118 
119         List<JournalTemplate> list =
120             journalTemplateLocalService.getStructureTemplates(
121                 groupId, structureId);
122 
123         list = ListUtil.copy(list);
124 
125         Iterator<JournalTemplate> itr = list.iterator();
126 
127         while (itr.hasNext()) {
128             JournalTemplate template = itr.next();
129 
130             if (!JournalTemplatePermission.contains(
131                     getPermissionChecker(), template, ActionKeys.VIEW)) {
132 
133                 itr.remove();
134             }
135         }
136 
137         return list;
138     }
139 
140     public JournalTemplate getTemplate(long groupId, String templateId)
141         throws PortalException, SystemException {
142 
143         JournalTemplatePermission.check(
144             getPermissionChecker(), groupId, templateId, ActionKeys.VIEW);
145 
146         return journalTemplateLocalService.getTemplate(groupId, templateId);
147     }
148 
149     public JournalTemplate updateTemplate(
150             long groupId, String templateId, String structureId, String name,
151             String description, String xsl, boolean formatXsl, String langType,
152             boolean cacheable, boolean smallImage, String smallImageURL,
153             File smallFile)
154         throws PortalException, SystemException {
155 
156         JournalTemplatePermission.check(
157             getPermissionChecker(), groupId, templateId, ActionKeys.UPDATE);
158 
159         return journalTemplateLocalService.updateTemplate(
160             groupId, templateId, structureId, name, description, xsl, formatXsl,
161             langType, cacheable, smallImage, smallImageURL, smallFile);
162     }
163 
164 }