1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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.security.permission.ActionKeys;
28  import com.liferay.portal.service.permission.PortletPermissionUtil;
29  import com.liferay.portal.util.PortletKeys;
30  import com.liferay.portlet.journal.model.JournalTemplate;
31  import com.liferay.portlet.journal.service.base.JournalTemplateServiceBaseImpl;
32  import com.liferay.portlet.journal.service.permission.JournalStructurePermission;
33  import com.liferay.portlet.journal.service.permission.JournalTemplatePermission;
34  
35  import java.io.File;
36  
37  import java.util.ArrayList;
38  import java.util.Iterator;
39  import java.util.List;
40  
41  /**
42   * <a href="JournalTemplateServiceImpl.java.html"><b><i>View Source</i></b></a>
43   *
44   * @author Brian Wing Shun Chan
45   *
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 void deleteTemplate(long groupId, String templateId)
87          throws PortalException, SystemException {
88  
89          JournalTemplatePermission.check(
90              getPermissionChecker(), groupId, templateId, ActionKeys.DELETE);
91  
92          journalTemplateLocalService.deleteTemplate(groupId, templateId);
93      }
94  
95      public List<JournalTemplate> getStructureTemplates(
96              long groupId, String structureId)
97          throws PortalException, SystemException {
98  
99          if (!JournalStructurePermission.contains(
100                 getPermissionChecker(), groupId, structureId,
101                 ActionKeys.VIEW)) {
102 
103             return new ArrayList<JournalTemplate>();
104         }
105 
106         List<JournalTemplate> list =
107             journalTemplateLocalService.getStructureTemplates(
108                 groupId, structureId);
109 
110         Iterator<JournalTemplate> itr = list.iterator();
111 
112         while (itr.hasNext()) {
113             JournalTemplate template = itr.next();
114 
115             if (!JournalTemplatePermission.contains(
116                     getPermissionChecker(), template, ActionKeys.VIEW)) {
117 
118                 itr.remove();
119             }
120         }
121 
122         return list;
123     }
124 
125     public JournalTemplate getTemplate(long groupId, String templateId)
126         throws PortalException, SystemException {
127 
128         JournalTemplatePermission.check(
129             getPermissionChecker(), groupId, templateId, ActionKeys.VIEW);
130 
131         return journalTemplateLocalService.getTemplate(groupId, templateId);
132     }
133 
134     public JournalTemplate updateTemplate(
135             long groupId, String templateId, String structureId, String name,
136             String description, String xsl, boolean formatXsl, String langType,
137             boolean cacheable, boolean smallImage, String smallImageURL,
138             File smallFile)
139         throws PortalException, SystemException {
140 
141         JournalTemplatePermission.check(
142             getPermissionChecker(), groupId, templateId, ActionKeys.UPDATE);
143 
144         return journalTemplateLocalService.updateTemplate(
145             groupId, templateId, structureId, name, description, xsl, formatXsl,
146             langType, cacheable, smallImage, smallImageURL, smallFile);
147     }
148 
149 }