1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.journal.service.impl;
21  
22  import com.liferay.portal.PortalException;
23  import com.liferay.portal.SystemException;
24  import com.liferay.portal.kernel.util.ListUtil;
25  import com.liferay.portal.security.permission.ActionKeys;
26  import com.liferay.portal.service.ServiceContext;
27  import com.liferay.portlet.journal.model.JournalTemplate;
28  import com.liferay.portlet.journal.service.base.JournalTemplateServiceBaseImpl;
29  import com.liferay.portlet.journal.service.permission.JournalPermission;
30  import com.liferay.portlet.journal.service.permission.JournalStructurePermission;
31  import com.liferay.portlet.journal.service.permission.JournalTemplatePermission;
32  
33  import java.io.File;
34  
35  import java.util.ArrayList;
36  import java.util.Iterator;
37  import java.util.List;
38  
39  /**
40   * <a href="JournalTemplateServiceImpl.java.html"><b><i>View Source</i></b></a>
41   *
42   * @author Brian Wing Shun Chan
43   * @author Raymond Augé
44   *
45   */
46  public class JournalTemplateServiceImpl extends JournalTemplateServiceBaseImpl {
47  
48      public JournalTemplate addTemplate(
49              long groupId, String templateId, boolean autoTemplateId,
50              String structureId, String name, String description, String xsl,
51              boolean formatXsl, String langType, boolean cacheable,
52              ServiceContext serviceContext)
53          throws PortalException, SystemException {
54  
55          JournalPermission.check(
56              getPermissionChecker(), groupId, ActionKeys.ADD_TEMPLATE);
57  
58          return journalTemplateLocalService.addTemplate(
59              getUserId(), groupId, templateId, autoTemplateId, structureId, name,
60              description, xsl, formatXsl, langType, cacheable, false, null, null,
61              serviceContext);
62      }
63  
64      public JournalTemplate addTemplate(
65              long groupId, String templateId, boolean autoTemplateId,
66              String structureId, String name, String description, String xsl,
67              boolean formatXsl, String langType, boolean cacheable,
68              boolean smallImage, String smallImageURL, File smallFile,
69              ServiceContext serviceContext)
70          throws PortalException, SystemException {
71  
72          JournalPermission.check(
73              getPermissionChecker(), groupId, ActionKeys.ADD_TEMPLATE);
74  
75          return journalTemplateLocalService.addTemplate(
76              getUserId(), groupId, templateId, autoTemplateId, structureId, name,
77              description, xsl, formatXsl, langType, cacheable, smallImage,
78              smallImageURL, smallFile, serviceContext);
79      }
80  
81      public JournalTemplate copyTemplate(
82              long groupId, String oldTemplateId, String newTemplateId,
83              boolean autoTemplateId)
84          throws PortalException, SystemException {
85  
86          JournalPermission.check(
87              getPermissionChecker(), groupId, ActionKeys.ADD_TEMPLATE);
88  
89          return journalTemplateLocalService.copyTemplate(
90              getUserId(), groupId, oldTemplateId, newTemplateId, autoTemplateId);
91      }
92  
93      public void deleteTemplate(long groupId, String templateId)
94          throws PortalException, SystemException {
95  
96          JournalTemplatePermission.check(
97              getPermissionChecker(), groupId, templateId, ActionKeys.DELETE);
98  
99          journalTemplateLocalService.deleteTemplate(groupId, templateId);
100     }
101 
102     public List<JournalTemplate> getStructureTemplates(
103             long groupId, String structureId)
104         throws PortalException, SystemException {
105 
106         if (!JournalStructurePermission.contains(
107                 getPermissionChecker(), groupId, structureId,
108                 ActionKeys.VIEW)) {
109 
110             return new ArrayList<JournalTemplate>();
111         }
112 
113         List<JournalTemplate> list =
114             journalTemplateLocalService.getStructureTemplates(
115                 groupId, structureId);
116 
117         list = ListUtil.copy(list);
118 
119         Iterator<JournalTemplate> itr = list.iterator();
120 
121         while (itr.hasNext()) {
122             JournalTemplate template = itr.next();
123 
124             if (!JournalTemplatePermission.contains(
125                     getPermissionChecker(), template, ActionKeys.VIEW)) {
126 
127                 itr.remove();
128             }
129         }
130 
131         return list;
132     }
133 
134     public JournalTemplate getTemplate(long groupId, String templateId)
135         throws PortalException, SystemException {
136 
137         JournalTemplatePermission.check(
138             getPermissionChecker(), groupId, templateId, ActionKeys.VIEW);
139 
140         return journalTemplateLocalService.getTemplate(groupId, templateId);
141     }
142 
143     public JournalTemplate updateTemplate(
144             long groupId, String templateId, String structureId, String name,
145             String description, String xsl, boolean formatXsl, String langType,
146             boolean cacheable, ServiceContext serviceContext)
147         throws PortalException, SystemException {
148 
149         JournalTemplatePermission.check(
150             getPermissionChecker(), groupId, templateId, ActionKeys.UPDATE);
151 
152         return journalTemplateLocalService.updateTemplate(
153             groupId, templateId, structureId, name, description, xsl, formatXsl,
154             langType, cacheable, false, null, null, serviceContext);
155     }
156 
157     public JournalTemplate updateTemplate(
158             long groupId, String templateId, String structureId, String name,
159             String description, String xsl, boolean formatXsl, String langType,
160             boolean cacheable, boolean smallImage, String smallImageURL,
161             File smallFile, ServiceContext serviceContext)
162         throws PortalException, SystemException {
163 
164         JournalTemplatePermission.check(
165             getPermissionChecker(), groupId, templateId, ActionKeys.UPDATE);
166 
167         return journalTemplateLocalService.updateTemplate(
168             groupId, templateId, structureId, name, description, xsl, formatXsl,
169             langType, cacheable, smallImage, smallImageURL, smallFile,
170             serviceContext);
171     }
172 
173 }