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 void deleteTemplate(long groupId, String templateId)
87 throws PortalException, SystemException {
88
89 JournalTemplatePermission.check(
90 getPermissionChecker(), groupId, templateId, ActionKeys.DELETE);
91
92 journalTemplateLocalService.deleteTemplate(groupId, templateId);
93 }
94
95 public List<JournalTemplate> getStructureTemplates(
96 long groupId, String structureId)
97 throws PortalException, SystemException {
98
99 if (!JournalStructurePermission.contains(
100 getPermissionChecker(), groupId, structureId,
101 ActionKeys.VIEW)) {
102
103 return new ArrayList<JournalTemplate>();
104 }
105
106 List<JournalTemplate> list =
107 journalTemplateLocalService.getStructureTemplates(
108 groupId, structureId);
109
110 Iterator<JournalTemplate> itr = list.iterator();
111
112 while (itr.hasNext()) {
113 JournalTemplate template = itr.next();
114
115 if (!JournalTemplatePermission.contains(
116 getPermissionChecker(), template, ActionKeys.VIEW)) {
117
118 itr.remove();
119 }
120 }
121
122 return list;
123 }
124
125 public JournalTemplate getTemplate(long groupId, String templateId)
126 throws PortalException, SystemException {
127
128 JournalTemplatePermission.check(
129 getPermissionChecker(), groupId, templateId, ActionKeys.VIEW);
130
131 return journalTemplateLocalService.getTemplate(groupId, templateId);
132 }
133
134 public JournalTemplate updateTemplate(
135 long groupId, String templateId, String structureId, String name,
136 String description, String xsl, boolean formatXsl, String langType,
137 boolean cacheable, boolean smallImage, String smallImageURL,
138 File smallFile)
139 throws PortalException, SystemException {
140
141 JournalTemplatePermission.check(
142 getPermissionChecker(), groupId, templateId, ActionKeys.UPDATE);
143
144 return journalTemplateLocalService.updateTemplate(
145 groupId, templateId, structureId, name, description, xsl, formatXsl,
146 langType, cacheable, smallImage, smallImageURL, smallFile);
147 }
148
149 }