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