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.portal.util.PortalUtil;
023    import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
024    import com.liferay.portlet.dynamicdatamapping.model.DDMTemplate;
025    import com.liferay.portlet.journal.model.JournalStructure;
026    import com.liferay.portlet.journal.model.JournalTemplate;
027    import com.liferay.portlet.journal.service.base.JournalTemplateServiceBaseImpl;
028    import com.liferay.portlet.journal.service.permission.JournalPermission;
029    import com.liferay.portlet.journal.service.permission.JournalTemplatePermission;
030    import com.liferay.portlet.journal.util.JournalUtil;
031    
032    import java.io.File;
033    
034    import java.util.List;
035    import java.util.Locale;
036    import java.util.Map;
037    
038    /**
039     * @author     Brian Wing Shun Chan
040     * @author     Raymond Aug??
041     * @deprecated As of 6.2.0, since Web Content Administration now uses the
042     *             Dynamic Data Mapping framework to handle templates
043     */
044    public class JournalTemplateServiceImpl extends JournalTemplateServiceBaseImpl {
045    
046            @Override
047            public JournalTemplate addTemplate(
048                            long groupId, String templateId, boolean autoTemplateId,
049                            String structureId, Map<Locale, String> nameMap,
050                            Map<Locale, String> descriptionMap, String xsl, boolean formatXsl,
051                            String langType, boolean cacheable, boolean smallImage,
052                            String smallImageURL, File smallFile, ServiceContext serviceContext)
053                    throws PortalException, SystemException {
054    
055                    JournalPermission.check(
056                            getPermissionChecker(), groupId, ActionKeys.ADD_TEMPLATE);
057    
058                    return journalTemplateLocalService.addTemplate(
059                            getUserId(), groupId, templateId, autoTemplateId, structureId,
060                            nameMap, descriptionMap, xsl, formatXsl, langType, cacheable,
061                            smallImage, smallImageURL, smallFile, serviceContext);
062            }
063    
064            @Override
065            public JournalTemplate addTemplate(
066                            long groupId, String templateId, boolean autoTemplateId,
067                            String structureId, Map<Locale, String> nameMap,
068                            Map<Locale, String> descriptionMap, String xsl, boolean formatXsl,
069                            String langType, boolean cacheable, ServiceContext serviceContext)
070                    throws PortalException, SystemException {
071    
072                    JournalPermission.check(
073                            getPermissionChecker(), groupId, ActionKeys.ADD_TEMPLATE);
074    
075                    return journalTemplateLocalService.addTemplate(
076                            getUserId(), groupId, templateId, autoTemplateId, structureId,
077                            nameMap, descriptionMap, xsl, formatXsl, langType, cacheable, false,
078                            null, null, serviceContext);
079            }
080    
081            @Override
082            public JournalTemplate copyTemplate(
083                            long groupId, String oldTemplateId, String newTemplateId,
084                            boolean autoTemplateId)
085                    throws PortalException, SystemException {
086    
087                    JournalPermission.check(
088                            getPermissionChecker(), groupId, ActionKeys.ADD_TEMPLATE);
089    
090                    return journalTemplateLocalService.copyTemplate(
091                            getUserId(), groupId, oldTemplateId, newTemplateId, autoTemplateId);
092            }
093    
094            @Override
095            public void deleteTemplate(long groupId, String templateId)
096                    throws PortalException, SystemException {
097    
098                    JournalTemplatePermission.check(
099                            getPermissionChecker(), groupId, templateId, ActionKeys.DELETE);
100    
101                    journalTemplateLocalService.deleteTemplate(groupId, templateId);
102            }
103    
104            @Override
105            public List<JournalTemplate> getStructureTemplates(
106                            long groupId, String structureId)
107                    throws PortalException, SystemException {
108    
109                    JournalStructure structure = journalStructureLocalService.getStructure(
110                            groupId, structureId);
111    
112                    List<DDMTemplate> ddmTemplates =
113                            ddmTemplatePersistence.filterFindByG_CPK(
114                                    groupId, structure.getPrimaryKey());
115    
116                    return JournalUtil.toJournalTemplates(ddmTemplates);
117            }
118    
119            @Override
120            public JournalTemplate getTemplate(long groupId, String templateId)
121                    throws PortalException, SystemException {
122    
123                    JournalTemplatePermission.check(
124                            getPermissionChecker(), groupId, templateId, ActionKeys.VIEW);
125    
126                    return journalTemplateLocalService.getTemplate(groupId, templateId);
127            }
128    
129            @Override
130            public JournalTemplate getTemplate(
131                            long groupId, String templateId, boolean includeGlobalTemplates)
132                    throws PortalException, SystemException {
133    
134                    JournalTemplatePermission.check(
135                            getPermissionChecker(), groupId, templateId, ActionKeys.VIEW);
136    
137                    return journalTemplateLocalService.getTemplate(
138                            groupId, templateId, includeGlobalTemplates);
139            }
140    
141            @Override
142            public List<JournalTemplate> search(
143                            long companyId, long[] groupIds, String keywords,
144                            String structureId, String structureIdComparator, int start,
145                            int end, OrderByComparator obc)
146                    throws SystemException {
147    
148                    long[] classNameIds = {PortalUtil.getClassNameId(DDMStructure.class)};
149                    long[] classPKs = JournalUtil.getStructureClassPKs(
150                            groupIds, structureId);
151    
152                    List<DDMTemplate> ddmTemplates = ddmTemplateFinder.filterFindByKeywords(
153                            companyId, groupIds, classNameIds, classPKs, keywords, null, null,
154                            start, end, obc);
155    
156                    return JournalUtil.toJournalTemplates(ddmTemplates);
157            }
158    
159            @Override
160            public List<JournalTemplate> search(
161                            long companyId, long[] groupIds, String templateId,
162                            String structureId, String structureIdComparator, String name,
163                            String description, boolean andOperator, int start, int end,
164                            OrderByComparator obc)
165                    throws SystemException {
166    
167                    long[] classNameIds = {PortalUtil.getClassNameId(DDMStructure.class)};
168                    long[] classPKs = JournalUtil.getStructureClassPKs(
169                            groupIds, structureId);
170    
171                    List<DDMTemplate> ddmTemplates =
172                            ddmTemplateFinder.filterFindByC_G_C_C_N_D_T_M_L(
173                                    companyId, groupIds, classNameIds, classPKs, name, description,
174                                    null, null, null, andOperator, start, end, obc);
175    
176                    return JournalUtil.toJournalTemplates(ddmTemplates);
177            }
178    
179            @Override
180            public int searchCount(
181                            long companyId, long[] groupIds, String keywords,
182                            String structureId, String structureIdComparator)
183                    throws SystemException {
184    
185                    long[] classNameIds = {PortalUtil.getClassNameId(DDMStructure.class)};
186                    long[] classPKs = JournalUtil.getStructureClassPKs(
187                            groupIds, structureId);
188    
189                    return ddmTemplateFinder.filterCountByKeywords(
190                            companyId, groupIds, classNameIds, classPKs, keywords, null, null);
191            }
192    
193            @Override
194            public int searchCount(
195                            long companyId, long[] groupIds, String templateId,
196                            String structureId, String structureIdComparator, String name,
197                            String description, boolean andOperator)
198                    throws SystemException {
199    
200                    long[] classNameIds = {PortalUtil.getClassNameId(DDMStructure.class)};
201                    long[] classPKs = JournalUtil.getStructureClassPKs(
202                            groupIds, structureId);
203    
204                    return ddmTemplateFinder.filterCountByC_G_C_C_N_D_T_M_L(
205                            companyId, groupIds, classNameIds, classPKs, name, description,
206                            null, null, null, andOperator);
207            }
208    
209            @Override
210            public JournalTemplate updateTemplate(
211                            long groupId, String templateId, String structureId,
212                            Map<Locale, String> nameMap, Map<Locale, String> descriptionMap,
213                            String xsl, boolean formatXsl, String langType, boolean cacheable,
214                            boolean smallImage, String smallImageURL, File smallFile,
215                            ServiceContext serviceContext)
216                    throws PortalException, SystemException {
217    
218                    JournalTemplatePermission.check(
219                            getPermissionChecker(), groupId, templateId, ActionKeys.UPDATE);
220    
221                    return journalTemplateLocalService.updateTemplate(
222                            groupId, templateId, structureId, nameMap, descriptionMap, xsl,
223                            formatXsl, langType, cacheable, smallImage, smallImageURL,
224                            smallFile, serviceContext);
225            }
226    
227            @Override
228            public JournalTemplate updateTemplate(
229                            long groupId, String templateId, String structureId,
230                            Map<Locale, String> nameMap, Map<Locale, String> descriptionMap,
231                            String xsl, boolean formatXsl, String langType, boolean cacheable,
232                            ServiceContext serviceContext)
233                    throws PortalException, SystemException {
234    
235                    JournalTemplatePermission.check(
236                            getPermissionChecker(), groupId, templateId, ActionKeys.UPDATE);
237    
238                    return journalTemplateLocalService.updateTemplate(
239                            groupId, templateId, structureId, nameMap, descriptionMap, xsl,
240                            formatXsl, langType, cacheable, false, null, null, serviceContext);
241            }
242    
243    }