001    /**
002     * Copyright (c) 2000-2013 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.OrderByComparator;
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.JournalTemplatePermission;
026    
027    import java.io.File;
028    
029    import java.util.List;
030    import java.util.Locale;
031    import java.util.Map;
032    
033    /**
034     * @author Brian Wing Shun Chan
035     * @author Raymond Aug??
036     */
037    public class JournalTemplateServiceImpl extends JournalTemplateServiceBaseImpl {
038    
039            @Override
040            public JournalTemplate addTemplate(
041                            long groupId, String templateId, boolean autoTemplateId,
042                            String structureId, Map<Locale, String> nameMap,
043                            Map<Locale, String> descriptionMap, String xsl, boolean formatXsl,
044                            String langType, boolean cacheable, boolean smallImage,
045                            String smallImageURL, File smallFile, ServiceContext serviceContext)
046                    throws PortalException, SystemException {
047    
048                    JournalPermission.check(
049                            getPermissionChecker(), groupId, ActionKeys.ADD_TEMPLATE);
050    
051                    return journalTemplateLocalService.addTemplate(
052                            getUserId(), groupId, templateId, autoTemplateId, structureId,
053                            nameMap, descriptionMap, xsl, formatXsl, langType, cacheable,
054                            smallImage, smallImageURL, smallFile, serviceContext);
055            }
056    
057            @Override
058            public JournalTemplate addTemplate(
059                            long groupId, String templateId, boolean autoTemplateId,
060                            String structureId, Map<Locale, String> nameMap,
061                            Map<Locale, String> descriptionMap, String xsl, boolean formatXsl,
062                            String langType, boolean cacheable, ServiceContext serviceContext)
063                    throws PortalException, SystemException {
064    
065                    JournalPermission.check(
066                            getPermissionChecker(), groupId, ActionKeys.ADD_TEMPLATE);
067    
068                    return journalTemplateLocalService.addTemplate(
069                            getUserId(), groupId, templateId, autoTemplateId, structureId,
070                            nameMap, descriptionMap, xsl, formatXsl, langType, cacheable, false,
071                            null, null, serviceContext);
072            }
073    
074            @Override
075            public JournalTemplate copyTemplate(
076                            long groupId, String oldTemplateId, String newTemplateId,
077                            boolean autoTemplateId)
078                    throws PortalException, SystemException {
079    
080                    JournalPermission.check(
081                            getPermissionChecker(), groupId, ActionKeys.ADD_TEMPLATE);
082    
083                    return journalTemplateLocalService.copyTemplate(
084                            getUserId(), groupId, oldTemplateId, newTemplateId, autoTemplateId);
085            }
086    
087            @Override
088            public void deleteTemplate(long groupId, String templateId)
089                    throws PortalException, SystemException {
090    
091                    JournalTemplatePermission.check(
092                            getPermissionChecker(), groupId, templateId, ActionKeys.DELETE);
093    
094                    journalTemplateLocalService.deleteTemplate(groupId, templateId);
095            }
096    
097            @Override
098            public List<JournalTemplate> getStructureTemplates(
099                            long groupId, String structureId)
100                    throws SystemException {
101    
102                    return journalTemplatePersistence.filterFindByG_S(groupId, structureId);
103            }
104    
105            @Override
106            public JournalTemplate getTemplate(long groupId, String templateId)
107                    throws PortalException, SystemException {
108    
109                    JournalTemplatePermission.check(
110                            getPermissionChecker(), groupId, templateId, ActionKeys.VIEW);
111    
112                    return journalTemplateLocalService.getTemplate(groupId, templateId);
113            }
114    
115            @Override
116            public JournalTemplate getTemplate(
117                            long groupId, String templateId, boolean includeGlobalTemplates)
118                    throws PortalException, SystemException {
119    
120                    JournalTemplatePermission.check(
121                            getPermissionChecker(), groupId, templateId, ActionKeys.VIEW);
122    
123                    return journalTemplateLocalService.getTemplate(
124                            groupId, templateId, includeGlobalTemplates);
125            }
126    
127            @Override
128            public List<JournalTemplate> search(
129                            long companyId, long[] groupIds, String keywords,
130                            String structureId, String structureIdComparator, int start,
131                            int end, OrderByComparator obc)
132                    throws SystemException {
133    
134                    return journalTemplateFinder.filterFindByKeywords(
135                            companyId, groupIds, keywords, structureId, structureIdComparator,
136                            start, end, obc);
137            }
138    
139            @Override
140            public List<JournalTemplate> search(
141                            long companyId, long[] groupIds, String templateId,
142                            String structureId, String structureIdComparator, String name,
143                            String description, boolean andOperator, int start, int end,
144                            OrderByComparator obc)
145                    throws SystemException {
146    
147                    return journalTemplateFinder.filterFindByC_G_T_S_N_D(
148                            companyId, groupIds, templateId, structureId, structureIdComparator,
149                            name, description, andOperator, start, end, obc);
150            }
151    
152            @Override
153            public int searchCount(
154                            long companyId, long[] groupIds, String keywords,
155                            String structureId, String structureIdComparator)
156                    throws SystemException {
157    
158                    return journalTemplateFinder.filterCountByKeywords(
159                            companyId, groupIds, keywords, structureId, structureIdComparator);
160            }
161    
162            @Override
163            public int searchCount(
164                            long companyId, long[] groupIds, String templateId,
165                            String structureId, String structureIdComparator, String name,
166                            String description, boolean andOperator)
167                    throws SystemException {
168    
169                    return journalTemplateFinder.filterCountByC_G_T_S_N_D(
170                            companyId, groupIds, templateId, structureId, structureIdComparator,
171                            name, description, andOperator);
172            }
173    
174            @Override
175            public JournalTemplate updateTemplate(
176                            long groupId, String templateId, String structureId,
177                            Map<Locale, String> nameMap, Map<Locale, String> descriptionMap,
178                            String xsl, boolean formatXsl, String langType, boolean cacheable,
179                            boolean smallImage, String smallImageURL, File smallFile,
180                            ServiceContext serviceContext)
181                    throws PortalException, SystemException {
182    
183                    JournalTemplatePermission.check(
184                            getPermissionChecker(), groupId, templateId, ActionKeys.UPDATE);
185    
186                    return journalTemplateLocalService.updateTemplate(
187                            groupId, templateId, structureId, nameMap, descriptionMap, xsl,
188                            formatXsl, langType, cacheable, smallImage, smallImageURL,
189                            smallFile, serviceContext);
190            }
191    
192            @Override
193            public JournalTemplate updateTemplate(
194                            long groupId, String templateId, String structureId,
195                            Map<Locale, String> nameMap, Map<Locale, String> descriptionMap,
196                            String xsl, boolean formatXsl, String langType, boolean cacheable,
197                            ServiceContext serviceContext)
198                    throws PortalException, SystemException {
199    
200                    JournalTemplatePermission.check(
201                            getPermissionChecker(), groupId, templateId, ActionKeys.UPDATE);
202    
203                    return journalTemplateLocalService.updateTemplate(
204                            groupId, templateId, structureId, nameMap, descriptionMap, xsl,
205                            formatXsl, langType, cacheable, false, null, null, serviceContext);
206            }
207    
208    }