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
49 public class JournalTemplateServiceImpl extends JournalTemplateServiceBaseImpl {
50
51 public JournalTemplate addTemplate(
52 long groupId, String templateId, boolean autoTemplateId,
53 String structureId, String name, String description, String xsl,
54 boolean formatXsl, String langType, boolean cacheable,
55 ServiceContext serviceContext)
56 throws PortalException, SystemException {
57
58 JournalPermission.check(
59 getPermissionChecker(), groupId, ActionKeys.ADD_TEMPLATE);
60
61 return journalTemplateLocalService.addTemplate(
62 getUserId(), groupId, templateId, autoTemplateId, structureId, name,
63 description, xsl, formatXsl, langType, cacheable, false, null, null,
64 serviceContext);
65 }
66
67 public JournalTemplate addTemplate(
68 long groupId, String templateId, boolean autoTemplateId,
69 String structureId, String name, String description, String xsl,
70 boolean formatXsl, String langType, boolean cacheable,
71 boolean smallImage, String smallImageURL, File smallFile,
72 ServiceContext serviceContext)
73 throws PortalException, SystemException {
74
75 JournalPermission.check(
76 getPermissionChecker(), groupId, ActionKeys.ADD_TEMPLATE);
77
78 return journalTemplateLocalService.addTemplate(
79 getUserId(), groupId, templateId, autoTemplateId, structureId, name,
80 description, xsl, formatXsl, langType, cacheable, smallImage,
81 smallImageURL, smallFile, serviceContext);
82 }
83
84 public JournalTemplate copyTemplate(
85 long groupId, String oldTemplateId, String newTemplateId,
86 boolean autoTemplateId)
87 throws PortalException, SystemException {
88
89 JournalPermission.check(
90 getPermissionChecker(), groupId, ActionKeys.ADD_TEMPLATE);
91
92 return journalTemplateLocalService.copyTemplate(
93 getUserId(), groupId, oldTemplateId, newTemplateId, autoTemplateId);
94 }
95
96 public void deleteTemplate(long groupId, String templateId)
97 throws PortalException, SystemException {
98
99 JournalTemplatePermission.check(
100 getPermissionChecker(), groupId, templateId, ActionKeys.DELETE);
101
102 journalTemplateLocalService.deleteTemplate(groupId, templateId);
103 }
104
105 public List<JournalTemplate> getStructureTemplates(
106 long groupId, String structureId)
107 throws PortalException, SystemException {
108
109 if (!JournalStructurePermission.contains(
110 getPermissionChecker(), groupId, structureId,
111 ActionKeys.VIEW)) {
112
113 return new ArrayList<JournalTemplate>();
114 }
115
116 List<JournalTemplate> list =
117 journalTemplateLocalService.getStructureTemplates(
118 groupId, structureId);
119
120 list = ListUtil.copy(list);
121
122 Iterator<JournalTemplate> itr = list.iterator();
123
124 while (itr.hasNext()) {
125 JournalTemplate template = itr.next();
126
127 if (!JournalTemplatePermission.contains(
128 getPermissionChecker(), template, ActionKeys.VIEW)) {
129
130 itr.remove();
131 }
132 }
133
134 return list;
135 }
136
137 public JournalTemplate getTemplate(long groupId, String templateId)
138 throws PortalException, SystemException {
139
140 JournalTemplatePermission.check(
141 getPermissionChecker(), groupId, templateId, ActionKeys.VIEW);
142
143 return journalTemplateLocalService.getTemplate(groupId, templateId);
144 }
145
146 public JournalTemplate updateTemplate(
147 long groupId, String templateId, String structureId, String name,
148 String description, String xsl, boolean formatXsl, String langType,
149 boolean cacheable, ServiceContext serviceContext)
150 throws PortalException, SystemException {
151
152 JournalTemplatePermission.check(
153 getPermissionChecker(), groupId, templateId, ActionKeys.UPDATE);
154
155 return journalTemplateLocalService.updateTemplate(
156 groupId, templateId, structureId, name, description, xsl, formatXsl,
157 langType, cacheable, false, null, null, serviceContext);
158 }
159
160 public JournalTemplate updateTemplate(
161 long groupId, String templateId, String structureId, String name,
162 String description, String xsl, boolean formatXsl, String langType,
163 boolean cacheable, boolean smallImage, String smallImageURL,
164 File smallFile, ServiceContext serviceContext)
165 throws PortalException, SystemException {
166
167 JournalTemplatePermission.check(
168 getPermissionChecker(), groupId, templateId, ActionKeys.UPDATE);
169
170 return journalTemplateLocalService.updateTemplate(
171 groupId, templateId, structureId, name, description, xsl, formatXsl,
172 langType, cacheable, smallImage, smallImageURL, smallFile,
173 serviceContext);
174 }
175
176 }