1   /**
2    * Copyright (c) 2000-2009 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.kernel.util.ListUtil;
28  import com.liferay.portal.security.permission.ActionKeys;
29  import com.liferay.portal.service.ServiceContext;
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.JournalPermission;
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   * @author Raymond Augé
47   *
48   */
49  public class JournalTemplateServiceImpl extends JournalTemplateServiceBaseImpl {
50  
51      public JournalTemplate addTemplate(
52              long groupId, String templateId, boolean autoTemplateId,
53              String structureId, String name, String description, String xsl,
54              boolean formatXsl, String langType, boolean cacheable,
55              ServiceContext serviceContext)
56          throws PortalException, SystemException {
57  
58          JournalPermission.check(
59              getPermissionChecker(), groupId, ActionKeys.ADD_TEMPLATE);
60  
61          return journalTemplateLocalService.addTemplate(
62              getUserId(), groupId, templateId, autoTemplateId, structureId, name,
63              description, xsl, formatXsl, langType, cacheable, false, null, null,
64              serviceContext);
65      }
66  
67      public JournalTemplate addTemplate(
68              long groupId, String templateId, boolean autoTemplateId,
69              String structureId, String name, String description, String xsl,
70              boolean formatXsl, String langType, boolean cacheable,
71              boolean smallImage, String smallImageURL, File smallFile,
72              ServiceContext serviceContext)
73          throws PortalException, SystemException {
74  
75          JournalPermission.check(
76              getPermissionChecker(), groupId, ActionKeys.ADD_TEMPLATE);
77  
78          return journalTemplateLocalService.addTemplate(
79              getUserId(), groupId, templateId, autoTemplateId, structureId, name,
80              description, xsl, formatXsl, langType, cacheable, smallImage,
81              smallImageURL, smallFile, serviceContext);
82      }
83  
84      public JournalTemplate copyTemplate(
85              long groupId, String oldTemplateId, String newTemplateId,
86              boolean autoTemplateId)
87          throws PortalException, SystemException {
88  
89          JournalPermission.check(
90              getPermissionChecker(), groupId, ActionKeys.ADD_TEMPLATE);
91  
92          return journalTemplateLocalService.copyTemplate(
93              getUserId(), groupId, oldTemplateId, newTemplateId, autoTemplateId);
94      }
95  
96      public void deleteTemplate(long groupId, String templateId)
97          throws PortalException, SystemException {
98  
99          JournalTemplatePermission.check(
100             getPermissionChecker(), groupId, templateId, ActionKeys.DELETE);
101 
102         journalTemplateLocalService.deleteTemplate(groupId, templateId);
103     }
104 
105     public List<JournalTemplate> getStructureTemplates(
106             long groupId, String structureId)
107         throws PortalException, SystemException {
108 
109         if (!JournalStructurePermission.contains(
110                 getPermissionChecker(), groupId, structureId,
111                 ActionKeys.VIEW)) {
112 
113             return new ArrayList<JournalTemplate>();
114         }
115 
116         List<JournalTemplate> list =
117             journalTemplateLocalService.getStructureTemplates(
118                 groupId, structureId);
119 
120         list = ListUtil.copy(list);
121 
122         Iterator<JournalTemplate> itr = list.iterator();
123 
124         while (itr.hasNext()) {
125             JournalTemplate template = itr.next();
126 
127             if (!JournalTemplatePermission.contains(
128                     getPermissionChecker(), template, ActionKeys.VIEW)) {
129 
130                 itr.remove();
131             }
132         }
133 
134         return list;
135     }
136 
137     public JournalTemplate getTemplate(long groupId, String templateId)
138         throws PortalException, SystemException {
139 
140         JournalTemplatePermission.check(
141             getPermissionChecker(), groupId, templateId, ActionKeys.VIEW);
142 
143         return journalTemplateLocalService.getTemplate(groupId, templateId);
144     }
145 
146     public JournalTemplate updateTemplate(
147             long groupId, String templateId, String structureId, String name,
148             String description, String xsl, boolean formatXsl, String langType,
149             boolean cacheable, ServiceContext serviceContext)
150         throws PortalException, SystemException {
151 
152         JournalTemplatePermission.check(
153             getPermissionChecker(), groupId, templateId, ActionKeys.UPDATE);
154 
155         return journalTemplateLocalService.updateTemplate(
156             groupId, templateId, structureId, name, description, xsl, formatXsl,
157             langType, cacheable, false, null, null, serviceContext);
158     }
159 
160     public JournalTemplate updateTemplate(
161             long groupId, String templateId, String structureId, String name,
162             String description, String xsl, boolean formatXsl, String langType,
163             boolean cacheable, boolean smallImage, String smallImageURL,
164             File smallFile, ServiceContext serviceContext)
165         throws PortalException, SystemException {
166 
167         JournalTemplatePermission.check(
168             getPermissionChecker(), groupId, templateId, ActionKeys.UPDATE);
169 
170         return journalTemplateLocalService.updateTemplate(
171             groupId, templateId, structureId, name, description, xsl, formatXsl,
172             langType, cacheable, smallImage, smallImageURL, smallFile,
173             serviceContext);
174     }
175 
176 }