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.permission.PortletPermissionUtil;
22  import com.liferay.portal.util.PortletKeys;
23  import com.liferay.portlet.journal.model.JournalTemplate;
24  import com.liferay.portlet.journal.service.base.JournalTemplateServiceBaseImpl;
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   */
39  public class JournalTemplateServiceImpl extends JournalTemplateServiceBaseImpl {
40  
41      public JournalTemplate addTemplate(
42              String templateId, boolean autoTemplateId, long plid,
43              String structureId, String name, String description, String xsl,
44              boolean formatXsl, String langType, boolean cacheable,
45              boolean smallImage, String smallImageURL, File smallFile,
46              boolean addCommunityPermissions, boolean addGuestPermissions)
47          throws PortalException, SystemException {
48  
49          PortletPermissionUtil.check(
50              getPermissionChecker(), plid, PortletKeys.JOURNAL,
51              ActionKeys.ADD_TEMPLATE);
52  
53          return journalTemplateLocalService.addTemplate(
54              getUserId(), templateId, autoTemplateId, plid, structureId, name,
55              description, xsl, formatXsl, langType, cacheable, smallImage,
56              smallImageURL, smallFile, addCommunityPermissions,
57              addGuestPermissions);
58      }
59  
60      public JournalTemplate addTemplate(
61              String templateId, boolean autoTemplateId, long plid,
62              String structureId, String name, String description, String xsl,
63              boolean formatXsl, String langType, boolean cacheable,
64              boolean smallImage, String smallImageURL, File smallFile,
65              String[] communityPermissions, String[] guestPermissions)
66          throws PortalException, SystemException {
67  
68          PortletPermissionUtil.check(
69              getPermissionChecker(), plid, PortletKeys.JOURNAL,
70              ActionKeys.ADD_TEMPLATE);
71  
72          return journalTemplateLocalService.addTemplate(
73              getUserId(), templateId, autoTemplateId, plid, structureId, name,
74              description, xsl, formatXsl, langType, cacheable, smallImage,
75              smallImageURL, smallFile, communityPermissions, guestPermissions);
76      }
77  
78      public JournalTemplate copyTemplate(
79              long groupId, String oldTemplateId, String newTemplateId,
80              boolean autoTemplateId)
81          throws PortalException, SystemException {
82  
83          JournalTemplatePermission.check(
84              getPermissionChecker(), groupId, oldTemplateId,
85              ActionKeys.ADD_TEMPLATE);
86  
87          return journalTemplateLocalService.copyTemplate(
88              getUserId(), groupId, oldTemplateId, newTemplateId, autoTemplateId);
89      }
90  
91      public void deleteTemplate(long groupId, String templateId)
92          throws PortalException, SystemException {
93  
94          JournalTemplatePermission.check(
95              getPermissionChecker(), groupId, templateId, ActionKeys.DELETE);
96  
97          journalTemplateLocalService.deleteTemplate(groupId, templateId);
98      }
99  
100     public List<JournalTemplate> getStructureTemplates(
101             long groupId, String structureId)
102         throws PortalException, SystemException {
103 
104         if (!JournalStructurePermission.contains(
105                 getPermissionChecker(), groupId, structureId,
106                 ActionKeys.VIEW)) {
107 
108             return new ArrayList<JournalTemplate>();
109         }
110 
111         List<JournalTemplate> list =
112             journalTemplateLocalService.getStructureTemplates(
113                 groupId, structureId);
114 
115         list = ListUtil.copy(list);
116 
117         Iterator<JournalTemplate> itr = list.iterator();
118 
119         while (itr.hasNext()) {
120             JournalTemplate template = itr.next();
121 
122             if (!JournalTemplatePermission.contains(
123                     getPermissionChecker(), template, ActionKeys.VIEW)) {
124 
125                 itr.remove();
126             }
127         }
128 
129         return list;
130     }
131 
132     public JournalTemplate getTemplate(long groupId, String templateId)
133         throws PortalException, SystemException {
134 
135         JournalTemplatePermission.check(
136             getPermissionChecker(), groupId, templateId, ActionKeys.VIEW);
137 
138         return journalTemplateLocalService.getTemplate(groupId, templateId);
139     }
140 
141     public JournalTemplate updateTemplate(
142             long groupId, String templateId, String structureId, String name,
143             String description, String xsl, boolean formatXsl, String langType,
144             boolean cacheable, boolean smallImage, String smallImageURL,
145             File smallFile)
146         throws PortalException, SystemException {
147 
148         JournalTemplatePermission.check(
149             getPermissionChecker(), groupId, templateId, ActionKeys.UPDATE);
150 
151         return journalTemplateLocalService.updateTemplate(
152             groupId, templateId, structureId, name, description, xsl, formatXsl,
153             langType, cacheable, smallImage, smallImageURL, smallFile);
154     }
155 
156 }