001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.journal.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.util.ListUtil;
020    import com.liferay.portal.security.permission.ActionKeys;
021    import com.liferay.portal.service.ServiceContext;
022    import com.liferay.portlet.journal.model.JournalTemplate;
023    import com.liferay.portlet.journal.service.base.JournalTemplateServiceBaseImpl;
024    import com.liferay.portlet.journal.service.permission.JournalPermission;
025    import com.liferay.portlet.journal.service.permission.JournalStructurePermission;
026    import com.liferay.portlet.journal.service.permission.JournalTemplatePermission;
027    
028    import java.io.File;
029    
030    import java.util.ArrayList;
031    import java.util.Iterator;
032    import java.util.List;
033    
034    /**
035     * @author Brian Wing Shun Chan
036     * @author Raymond Augé
037     */
038    public class JournalTemplateServiceImpl extends JournalTemplateServiceBaseImpl {
039    
040            public JournalTemplate addTemplate(
041                            long groupId, String templateId, boolean autoTemplateId,
042                            String structureId, String name, String description, String xsl,
043                            boolean formatXsl, String langType, boolean cacheable,
044                            ServiceContext serviceContext)
045                    throws PortalException, SystemException {
046    
047                    JournalPermission.check(
048                            getPermissionChecker(), groupId, ActionKeys.ADD_TEMPLATE);
049    
050                    return journalTemplateLocalService.addTemplate(
051                            getUserId(), groupId, templateId, autoTemplateId, structureId, name,
052                            description, xsl, formatXsl, langType, cacheable, false, null, null,
053                            serviceContext);
054            }
055    
056            public JournalTemplate addTemplate(
057                            long groupId, String templateId, boolean autoTemplateId,
058                            String structureId, String name, String description, String xsl,
059                            boolean formatXsl, String langType, boolean cacheable,
060                            boolean smallImage, String smallImageURL, File smallFile,
061                            ServiceContext serviceContext)
062                    throws PortalException, SystemException {
063    
064                    JournalPermission.check(
065                            getPermissionChecker(), groupId, ActionKeys.ADD_TEMPLATE);
066    
067                    return journalTemplateLocalService.addTemplate(
068                            getUserId(), groupId, templateId, autoTemplateId, structureId, name,
069                            description, xsl, formatXsl, langType, cacheable, smallImage,
070                            smallImageURL, smallFile, serviceContext);
071            }
072    
073            public JournalTemplate copyTemplate(
074                            long groupId, String oldTemplateId, String newTemplateId,
075                            boolean autoTemplateId)
076                    throws PortalException, SystemException {
077    
078                    JournalPermission.check(
079                            getPermissionChecker(), groupId, ActionKeys.ADD_TEMPLATE);
080    
081                    return journalTemplateLocalService.copyTemplate(
082                            getUserId(), groupId, oldTemplateId, newTemplateId, autoTemplateId);
083            }
084    
085            public void deleteTemplate(long groupId, String templateId)
086                    throws PortalException, SystemException {
087    
088                    JournalTemplatePermission.check(
089                            getPermissionChecker(), groupId, templateId, ActionKeys.DELETE);
090    
091                    journalTemplateLocalService.deleteTemplate(groupId, templateId);
092            }
093    
094            public List<JournalTemplate> getStructureTemplates(
095                            long groupId, String structureId)
096                    throws PortalException, SystemException {
097    
098                    if (!JournalStructurePermission.contains(
099                                    getPermissionChecker(), groupId, structureId,
100                                    ActionKeys.VIEW)) {
101    
102                            return new ArrayList<JournalTemplate>();
103                    }
104    
105                    List<JournalTemplate> list =
106                            journalTemplateLocalService.getStructureTemplates(
107                                    groupId, structureId);
108    
109                    list = ListUtil.copy(list);
110    
111                    Iterator<JournalTemplate> itr = list.iterator();
112    
113                    while (itr.hasNext()) {
114                            JournalTemplate template = itr.next();
115    
116                            if (!JournalTemplatePermission.contains(
117                                            getPermissionChecker(), template, ActionKeys.VIEW)) {
118    
119                                    itr.remove();
120                            }
121                    }
122    
123                    return list;
124            }
125    
126            public JournalTemplate getTemplate(long groupId, String templateId)
127                    throws PortalException, SystemException {
128    
129                    JournalTemplatePermission.check(
130                            getPermissionChecker(), groupId, templateId, ActionKeys.VIEW);
131    
132                    return journalTemplateLocalService.getTemplate(groupId, templateId);
133            }
134    
135            public JournalTemplate updateTemplate(
136                            long groupId, String templateId, String structureId, String name,
137                            String description, String xsl, boolean formatXsl, String langType,
138                            boolean cacheable, ServiceContext serviceContext)
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, false, null, null, serviceContext);
147            }
148    
149            public JournalTemplate updateTemplate(
150                            long groupId, String templateId, String structureId, String name,
151                            String description, String xsl, boolean formatXsl, String langType,
152                            boolean cacheable, boolean smallImage, String smallImageURL,
153                            File smallFile, ServiceContext serviceContext)
154                    throws PortalException, SystemException {
155    
156                    JournalTemplatePermission.check(
157                            getPermissionChecker(), groupId, templateId, ActionKeys.UPDATE);
158    
159                    return journalTemplateLocalService.updateTemplate(
160                            groupId, templateId, structureId, name, description, xsl, formatXsl,
161                            langType, cacheable, smallImage, smallImageURL, smallFile,
162                            serviceContext);
163            }
164    
165    }