1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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  public class JournalTemplateServiceImpl extends JournalTemplateServiceBaseImpl {
49  
50      public JournalTemplate addTemplate(
51              long groupId, String templateId, boolean autoTemplateId,
52              String structureId, String name, String description, String xsl,
53              boolean formatXsl, String langType, boolean cacheable,
54              ServiceContext serviceContext)
55          throws PortalException, SystemException {
56  
57          JournalPermission.check(
58              getPermissionChecker(), groupId, ActionKeys.ADD_TEMPLATE);
59  
60          return journalTemplateLocalService.addTemplate(
61              getUserId(), groupId, templateId, autoTemplateId, structureId, name,
62              description, xsl, formatXsl, langType, cacheable, false, null, null,
63              serviceContext);
64      }
65  
66      public JournalTemplate addTemplate(
67              long groupId, String templateId, boolean autoTemplateId,
68              String structureId, String name, String description, String xsl,
69              boolean formatXsl, String langType, boolean cacheable,
70              boolean smallImage, String smallImageURL, File smallFile,
71              ServiceContext serviceContext)
72          throws PortalException, SystemException {
73  
74          JournalPermission.check(
75              getPermissionChecker(), groupId, ActionKeys.ADD_TEMPLATE);
76  
77          return journalTemplateLocalService.addTemplate(
78              getUserId(), groupId, templateId, autoTemplateId, structureId, name,
79              description, xsl, formatXsl, langType, cacheable, smallImage,
80              smallImageURL, smallFile, serviceContext);
81      }
82  
83      public JournalTemplate copyTemplate(
84              long groupId, String oldTemplateId, String newTemplateId,
85              boolean autoTemplateId)
86          throws PortalException, SystemException {
87  
88          JournalPermission.check(
89              getPermissionChecker(), groupId, ActionKeys.ADD_TEMPLATE);
90  
91          return journalTemplateLocalService.copyTemplate(
92              getUserId(), groupId, oldTemplateId, newTemplateId, autoTemplateId);
93      }
94  
95      public void deleteTemplate(long groupId, String templateId)
96          throws PortalException, SystemException {
97  
98          JournalTemplatePermission.check(
99              getPermissionChecker(), groupId, templateId, ActionKeys.DELETE);
100 
101         journalTemplateLocalService.deleteTemplate(groupId, templateId);
102     }
103 
104     public List<JournalTemplate> getStructureTemplates(
105             long groupId, String structureId)
106         throws PortalException, SystemException {
107 
108         if (!JournalStructurePermission.contains(
109                 getPermissionChecker(), groupId, structureId,
110                 ActionKeys.VIEW)) {
111 
112             return new ArrayList<JournalTemplate>();
113         }
114 
115         List<JournalTemplate> list =
116             journalTemplateLocalService.getStructureTemplates(
117                 groupId, structureId);
118 
119         list = ListUtil.copy(list);
120 
121         Iterator<JournalTemplate> itr = list.iterator();
122 
123         while (itr.hasNext()) {
124             JournalTemplate template = itr.next();
125 
126             if (!JournalTemplatePermission.contains(
127                     getPermissionChecker(), template, ActionKeys.VIEW)) {
128 
129                 itr.remove();
130             }
131         }
132 
133         return list;
134     }
135 
136     public JournalTemplate getTemplate(long groupId, String templateId)
137         throws PortalException, SystemException {
138 
139         JournalTemplatePermission.check(
140             getPermissionChecker(), groupId, templateId, ActionKeys.VIEW);
141 
142         return journalTemplateLocalService.getTemplate(groupId, templateId);
143     }
144 
145     public JournalTemplate updateTemplate(
146             long groupId, String templateId, String structureId, String name,
147             String description, String xsl, boolean formatXsl, String langType,
148             boolean cacheable, ServiceContext serviceContext)
149         throws PortalException, SystemException {
150 
151         JournalTemplatePermission.check(
152             getPermissionChecker(), groupId, templateId, ActionKeys.UPDATE);
153 
154         return journalTemplateLocalService.updateTemplate(
155             groupId, templateId, structureId, name, description, xsl, formatXsl,
156             langType, cacheable, false, null, null, serviceContext);
157     }
158 
159     public JournalTemplate updateTemplate(
160             long groupId, String templateId, String structureId, String name,
161             String description, String xsl, boolean formatXsl, String langType,
162             boolean cacheable, boolean smallImage, String smallImageURL,
163             File smallFile, ServiceContext serviceContext)
164         throws PortalException, SystemException {
165 
166         JournalTemplatePermission.check(
167             getPermissionChecker(), groupId, templateId, ActionKeys.UPDATE);
168 
169         return journalTemplateLocalService.updateTemplate(
170             groupId, templateId, structureId, name, description, xsl, formatXsl,
171             langType, cacheable, smallImage, smallImageURL, smallFile,
172             serviceContext);
173     }
174 
175 }