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.security.permission.ActionKeys;
28 import com.liferay.portal.service.permission.PortletPermissionUtil;
29 import com.liferay.portal.util.PortletKeys;
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.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 String templateId, boolean autoTemplateId, long plid,
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 PortletPermissionUtil.check(
58 getPermissionChecker(), plid, PortletKeys.JOURNAL,
59 ActionKeys.ADD_TEMPLATE);
60
61 return journalTemplateLocalService.addTemplate(
62 getUserId(), templateId, autoTemplateId, plid, structureId, name,
63 description, xsl, formatXsl, langType, cacheable, smallImage,
64 smallImageURL, smallFile, addCommunityPermissions,
65 addGuestPermissions);
66 }
67
68 public JournalTemplate addTemplate(
69 String templateId, boolean autoTemplateId, long plid,
70 String structureId, String name, String description, String xsl,
71 boolean formatXsl, String langType, boolean cacheable,
72 boolean smallImage, String smallImageURL, File smallFile,
73 String[] communityPermissions, String[] guestPermissions)
74 throws PortalException, SystemException {
75
76 PortletPermissionUtil.check(
77 getPermissionChecker(), plid, PortletKeys.JOURNAL,
78 ActionKeys.ADD_TEMPLATE);
79
80 return journalTemplateLocalService.addTemplate(
81 getUserId(), templateId, autoTemplateId, plid, structureId, name,
82 description, xsl, formatXsl, langType, cacheable, smallImage,
83 smallImageURL, smallFile, communityPermissions, guestPermissions);
84 }
85
86 public JournalTemplate copyTemplate(
87 long groupId, String oldTemplateId, String newTemplateId,
88 boolean autoTemplateId)
89 throws PortalException, SystemException {
90
91 JournalTemplatePermission.check(
92 getPermissionChecker(), groupId, oldTemplateId,
93 ActionKeys.ADD_TEMPLATE);
94
95 return journalTemplateLocalService.copyTemplate(
96 getUserId(), groupId, oldTemplateId, newTemplateId, autoTemplateId);
97 }
98
99 public void deleteTemplate(long groupId, String templateId)
100 throws PortalException, SystemException {
101
102 JournalTemplatePermission.check(
103 getPermissionChecker(), groupId, templateId, ActionKeys.DELETE);
104
105 journalTemplateLocalService.deleteTemplate(groupId, templateId);
106 }
107
108 public List<JournalTemplate> getStructureTemplates(
109 long groupId, String structureId)
110 throws PortalException, SystemException {
111
112 if (!JournalStructurePermission.contains(
113 getPermissionChecker(), groupId, structureId,
114 ActionKeys.VIEW)) {
115
116 return new ArrayList<JournalTemplate>();
117 }
118
119 List<JournalTemplate> list =
120 journalTemplateLocalService.getStructureTemplates(
121 groupId, structureId);
122
123 Iterator<JournalTemplate> itr = list.iterator();
124
125 while (itr.hasNext()) {
126 JournalTemplate template = itr.next();
127
128 if (!JournalTemplatePermission.contains(
129 getPermissionChecker(), template, ActionKeys.VIEW)) {
130
131 itr.remove();
132 }
133 }
134
135 return list;
136 }
137
138 public JournalTemplate getTemplate(long groupId, String templateId)
139 throws PortalException, SystemException {
140
141 JournalTemplatePermission.check(
142 getPermissionChecker(), groupId, templateId, ActionKeys.VIEW);
143
144 return journalTemplateLocalService.getTemplate(groupId, templateId);
145 }
146
147 public JournalTemplate updateTemplate(
148 long groupId, String templateId, String structureId, String name,
149 String description, String xsl, boolean formatXsl, String langType,
150 boolean cacheable, boolean smallImage, String smallImageURL,
151 File smallFile)
152 throws PortalException, SystemException {
153
154 JournalTemplatePermission.check(
155 getPermissionChecker(), groupId, templateId, ActionKeys.UPDATE);
156
157 return journalTemplateLocalService.updateTemplate(
158 groupId, templateId, structureId, name, description, xsl, formatXsl,
159 langType, cacheable, smallImage, smallImageURL, smallFile);
160 }
161
162 }