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.portlet.journal.model.JournalTemplate;
30 import com.liferay.portlet.journal.service.base.JournalTemplateServiceBaseImpl;
31 import com.liferay.portlet.journal.service.permission.JournalPermission;
32 import com.liferay.portlet.journal.service.permission.JournalStructurePermission;
33 import com.liferay.portlet.journal.service.permission.JournalTemplatePermission;
34
35 import java.io.File;
36
37 import java.util.ArrayList;
38 import java.util.Iterator;
39 import java.util.List;
40
41
47 public class JournalTemplateServiceImpl extends JournalTemplateServiceBaseImpl {
48
49 public JournalTemplate addTemplate(
50 long groupId, String templateId, boolean autoTemplateId,
51 String structureId, String name, String description, String xsl,
52 boolean formatXsl, String langType, boolean cacheable,
53 boolean smallImage, String smallImageURL, File smallFile,
54 boolean addCommunityPermissions, boolean addGuestPermissions)
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, smallImage,
63 smallImageURL, smallFile, addCommunityPermissions,
64 addGuestPermissions);
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 String[] communityPermissions, String[] guestPermissions)
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, communityPermissions, guestPermissions);
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, boolean smallImage, String smallImageURL,
150 File smallFile)
151 throws PortalException, SystemException {
152
153 JournalTemplatePermission.check(
154 getPermissionChecker(), groupId, templateId, ActionKeys.UPDATE);
155
156 return journalTemplateLocalService.updateTemplate(
157 groupId, templateId, structureId, name, description, xsl, formatXsl,
158 langType, cacheable, smallImage, smallImageURL, smallFile);
159 }
160
161 }