1
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
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 }