001    /**
002     * Copyright (c) 2000-present 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.dynamicdatamapping.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.util.OrderByComparator;
019    import com.liferay.portal.security.permission.ActionKeys;
020    import com.liferay.portal.service.ServiceContext;
021    import com.liferay.portal.util.PortalUtil;
022    import com.liferay.portlet.dynamicdatamapping.model.DDMTemplate;
023    import com.liferay.portlet.dynamicdatamapping.service.base.DDMTemplateServiceBaseImpl;
024    import com.liferay.portlet.dynamicdatamapping.service.permission.DDMPermission;
025    import com.liferay.portlet.dynamicdatamapping.service.permission.DDMTemplatePermission;
026    import com.liferay.portlet.dynamicdatamapping.util.DDMDisplay;
027    import com.liferay.portlet.dynamicdatamapping.util.DDMUtil;
028    
029    import java.io.File;
030    
031    import java.util.ArrayList;
032    import java.util.List;
033    import java.util.Locale;
034    import java.util.Map;
035    
036    /**
037     * Provides the remote service for accessing, adding, copying, deleting, and
038     * updating dynamic data mapping (DDM) templates. Its methods include security
039     * checks.
040     *
041     * @author Brian Wing Shun Chan
042     * @author Eduardo Lundgren
043     * @author Marcellus Tavares
044     * @see    com.liferay.portlet.dynamicdatamapping.service.impl.DDMTemplateLocalServiceImpl
045     */
046    public class DDMTemplateServiceImpl extends DDMTemplateServiceBaseImpl {
047    
048            /**
049             * Adds a template.
050             *
051             * @param  groupId the primary key of the group
052             * @param  classNameId the primary key of the class name for template's
053             *         related model
054             * @param  classPK the primary key of the template's related entity
055             * @param  nameMap the template's locales and localized names
056             * @param  descriptionMap the template's locales and localized descriptions
057             * @param  type the template's type. For more information, see {@link
058             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
059             * @param  mode the template's mode. For more information, see {@link
060             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
061             * @param  language the template's script language. For more information,
062             *         see {@link
063             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
064             * @param  script the template's script
065             * @param  serviceContext the service context to be applied. Must have the
066             *         <code>ddmResource</code> attribute to check permissions. Can set
067             *         the UUID, creation date, modification date, guest permissions,
068             *         and group permissions for the template.
069             * @return the template
070             * @throws PortalException if the user did not have permission to add the
071             *         template or if a portal exception occurred
072             */
073            @Override
074            public DDMTemplate addTemplate(
075                            long groupId, long classNameId, long classPK,
076                            Map<Locale, String> nameMap, Map<Locale, String> descriptionMap,
077                            String type, String mode, String language, String script,
078                            ServiceContext serviceContext)
079                    throws PortalException {
080    
081                    DDMDisplay ddmDisplay = DDMUtil.getDDMDisplay(serviceContext);
082    
083                    DDMPermission.check(
084                            getPermissionChecker(), serviceContext.getScopeGroupId(),
085                            ddmDisplay.getResourceName(classNameId),
086                            ddmDisplay.getAddTemplateActionId());
087    
088                    return ddmTemplateLocalService.addTemplate(
089                            getUserId(), groupId, classNameId, classPK, null, nameMap,
090                            descriptionMap, type, mode, language, script, false, false, null,
091                            null, serviceContext);
092            }
093    
094            /**
095             * Adds a template with additional parameters.
096             *
097             * @param  groupId the primary key of the group
098             * @param  classNameId the primary key of the class name for template's
099             *         related model
100             * @param  classPK the primary key of the template's related entity
101             * @param  templateKey the unique string identifying the template
102             *         (optionally <code>null</code>)
103             * @param  nameMap the template's locales and localized names
104             * @param  descriptionMap the template's locales and localized descriptions
105             * @param  type the template's type. For more information, see {@link
106             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
107             * @param  mode the template's mode. For more information, see {@link
108             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
109             * @param  language the template's script language. For more information,
110             *         see {@link
111             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
112             * @param  script the template's script
113             * @param  cacheable whether the template is cacheable
114             * @param  smallImage whether the template has a small image
115             * @param  smallImageURL the template's small image URL (optionally
116             *         <code>null</code>)
117             * @param  smallImageFile the template's small image file (optionally
118             *         <code>null</code>)
119             * @param  serviceContext the service context to be applied. Must have the
120             *         <code>ddmResource</code> attribute to check permissions. Can set
121             *         the UUID, creation date, modification date, guest permissions,
122             *         and group permissions for the template.
123             * @return the template
124             * @throws PortalException if the user did not have permission to add the
125             *         template or if a portal exception occurred
126             */
127            @Override
128            public DDMTemplate addTemplate(
129                            long groupId, long classNameId, long classPK, String templateKey,
130                            Map<Locale, String> nameMap, Map<Locale, String> descriptionMap,
131                            String type, String mode, String language, String script,
132                            boolean cacheable, boolean smallImage, String smallImageURL,
133                            File smallImageFile, ServiceContext serviceContext)
134                    throws PortalException {
135    
136                    DDMDisplay ddmDisplay = DDMUtil.getDDMDisplay(serviceContext);
137    
138                    DDMPermission.check(
139                            getPermissionChecker(), serviceContext.getScopeGroupId(),
140                            ddmDisplay.getResourceName(classNameId),
141                            ddmDisplay.getAddTemplateActionId());
142    
143                    return ddmTemplateLocalService.addTemplate(
144                            getUserId(), groupId, classNameId, classPK, templateKey, nameMap,
145                            descriptionMap, type, mode, language, script, cacheable, smallImage,
146                            smallImageURL, smallImageFile, serviceContext);
147            }
148    
149            /**
150             * Copies the template, creating a new template with all the values
151             * extracted from the original one. This method supports defining a new name
152             * and description.
153             *
154             * @param  templateId the primary key of the template to be copied
155             * @param  nameMap the new template's locales and localized names
156             * @param  descriptionMap the new template's locales and localized
157             *         descriptions
158             * @param  serviceContext the service context to be applied. Must have the
159             *         <code>ddmResource</code> attribute to check permissions. Can set
160             *         the UUID, creation date, modification date, guest permissions,
161             *         and group permissions for the template.
162             * @return the new template
163             * @throws PortalException if the user did not have permission to add the
164             *         template or if a portal exception occurred
165             */
166            @Override
167            public DDMTemplate copyTemplate(
168                            long templateId, Map<Locale, String> nameMap,
169                            Map<Locale, String> descriptionMap, ServiceContext serviceContext)
170                    throws PortalException {
171    
172                    DDMDisplay ddmDisplay = DDMUtil.getDDMDisplay(serviceContext);
173    
174                    DDMTemplate template = ddmTemplatePersistence.findByPrimaryKey(
175                            templateId);
176    
177                    long classNameId = template.getClassNameId();
178    
179                    DDMPermission.check(
180                            getPermissionChecker(), serviceContext.getScopeGroupId(),
181                            ddmDisplay.getResourceName(classNameId),
182                            ddmDisplay.getAddTemplateActionId());
183    
184                    return ddmTemplateLocalService.copyTemplate(
185                            getUserId(), templateId, nameMap, descriptionMap, serviceContext);
186            }
187    
188            @Override
189            public DDMTemplate copyTemplate(
190                            long templateId, ServiceContext serviceContext)
191                    throws PortalException {
192    
193                    DDMDisplay ddmDisplay = DDMUtil.getDDMDisplay(serviceContext);
194    
195                    DDMTemplate template = ddmTemplatePersistence.findByPrimaryKey(
196                            templateId);
197    
198                    long classNameId = template.getClassNameId();
199    
200                    DDMPermission.check(
201                            getPermissionChecker(), serviceContext.getScopeGroupId(),
202                            ddmDisplay.getResourceName(classNameId),
203                            ddmDisplay.getAddTemplateActionId());
204    
205                    return ddmTemplateLocalService.copyTemplate(
206                            getUserId(), templateId, serviceContext);
207            }
208    
209            /**
210             * Copies all the templates matching the class name ID, class PK, and type.
211             * This method creates new templates, extracting all the values from the old
212             * ones and updating their class PKs.
213             *
214             * @param  classNameId the primary key of the class name for template's
215             *         related model
216             * @param  classPK the primary key of the original template's related entity
217             * @param  newClassPK the primary key of the new template's related entity
218             * @param  type the template's type. For more information, see {@link
219             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
220             * @param  serviceContext the service context to be applied. Must have the
221             *         <code>ddmResource</code> attribute to check permissions. Can set
222             *         the UUID, creation date, modification date, guest permissions,
223             *         and group permissions for the template.
224             * @return the new template
225             * @throws PortalException if the user did not have permission to add the
226             *         template or if a portal exception occurred
227             */
228            @Override
229            public List<DDMTemplate> copyTemplates(
230                            long classNameId, long classPK, long newClassPK, String type,
231                            ServiceContext serviceContext)
232                    throws PortalException {
233    
234                    DDMDisplay ddmDisplay = DDMUtil.getDDMDisplay(serviceContext);
235    
236                    DDMPermission.check(
237                            getPermissionChecker(), serviceContext.getScopeGroupId(),
238                            ddmDisplay.getResourceName(classNameId),
239                            ddmDisplay.getAddTemplateActionId());
240    
241                    return ddmTemplateLocalService.copyTemplates(
242                            getUserId(), classNameId, classPK, newClassPK, type,
243                            serviceContext);
244            }
245    
246            /**
247             * Deletes the template and its resources.
248             *
249             * @param  templateId the primary key of the template to be deleted
250             * @throws PortalException if the user did not have permission to delete the
251             *         template or if a portal exception occurred
252             */
253            @Override
254            public void deleteTemplate(long templateId) throws PortalException {
255                    DDMTemplatePermission.check(
256                            getPermissionChecker(), templateId, ActionKeys.DELETE);
257    
258                    ddmTemplateLocalService.deleteTemplate(templateId);
259            }
260    
261            /**
262             * Returns the template matching the group and template key.
263             *
264             * @param  groupId the primary key of the group
265             * @param  classNameId the primary key of the class name for template's
266             *         related model
267             * @param  templateKey the unique string identifying the template
268             * @return the matching template, or <code>null</code> if a matching
269             *         template could not be found
270             * @throws PortalException if the user did not have permission to view the
271             *         template
272             */
273            @Override
274            public DDMTemplate fetchTemplate(
275                            long groupId, long classNameId, String templateKey)
276                    throws PortalException {
277    
278                    DDMTemplate ddmTemplate = ddmTemplateLocalService.fetchTemplate(
279                            groupId, classNameId, templateKey);
280    
281                    if (ddmTemplate != null) {
282                            DDMTemplatePermission.check(
283                                    getPermissionChecker(), ddmTemplate, ActionKeys.VIEW);
284                    }
285    
286                    return ddmTemplate;
287            }
288    
289            /**
290             * Returns the template with the ID.
291             *
292             * @param  templateId the primary key of the template
293             * @return the template with the ID
294             * @throws PortalException if the user did not have permission to view the
295             *         template or if a matching template could not be found
296             */
297            @Override
298            public DDMTemplate getTemplate(long templateId) throws PortalException {
299                    DDMTemplatePermission.check(
300                            getPermissionChecker(), templateId, ActionKeys.VIEW);
301    
302                    return ddmTemplatePersistence.findByPrimaryKey(templateId);
303            }
304    
305            /**
306             * Returns the template matching the group and template key.
307             *
308             * @param  groupId the primary key of the group
309             * @param  classNameId the primary key of the class name for template's
310             *         related model
311             * @param  templateKey the unique string identifying the template
312             * @return the matching template
313             * @throws PortalException if a matching template could not be found
314             */
315            @Override
316            public DDMTemplate getTemplate(
317                            long groupId, long classNameId, String templateKey)
318                    throws PortalException {
319    
320                    DDMTemplate ddmTemplate = ddmTemplateLocalService.getTemplate(
321                            groupId, classNameId, templateKey);
322    
323                    DDMTemplatePermission.check(
324                            getPermissionChecker(), ddmTemplate, ActionKeys.VIEW);
325    
326                    return ddmTemplate;
327            }
328    
329            /**
330             * Returns the template matching the group and template key, optionally
331             * searching ancestor sites (that have sharing enabled) and global scoped
332             * sites.
333             *
334             * <p>
335             * This method first searches in the group. If the template is still not
336             * found and <code>includeAncestorTemplates</code> is set to
337             * <code>true</code>, this method searches the group's ancestor sites (that
338             * have sharing enabled) and lastly searches global scoped sites.
339             * </p>
340             *
341             * @param  groupId the primary key of the group
342             * @param  classNameId the primary key of the class name for template's
343             *         related model
344             * @param  templateKey the unique string identifying the template
345             * @param  includeAncestorTemplates whether to include ancestor sites (that
346             *         have sharing enabled) and include global scoped sites in the
347             *         search
348             * @return the matching template
349             * @throws PortalException if a matching template could not be found
350             */
351            @Override
352            public DDMTemplate getTemplate(
353                            long groupId, long classNameId, String templateKey,
354                            boolean includeAncestorTemplates)
355                    throws PortalException {
356    
357                    DDMTemplate ddmTemplate = ddmTemplateLocalService.getTemplate(
358                            groupId, classNameId, templateKey, includeAncestorTemplates);
359    
360                    DDMTemplatePermission.check(
361                            getPermissionChecker(), ddmTemplate, ActionKeys.VIEW);
362    
363                    return ddmTemplate;
364            }
365    
366            /**
367             * Returns all the templates matching the group and class name ID.
368             *
369             * @param  groupId the primary key of the group
370             * @param  classNameId the primary key of the class name for template's
371             *         related model
372             * @return the matching templates
373             */
374            @Override
375            public List<DDMTemplate> getTemplates(long groupId, long classNameId) {
376                    return ddmTemplatePersistence.filterFindByG_C(groupId, classNameId);
377            }
378    
379            /**
380             * Returns all the templates matching the group, class name ID, and class
381             * PK.
382             *
383             * @param  groupId the primary key of the group
384             * @param  classNameId the primary key of the class name for template's
385             *         related model
386             * @param  classPK the primary key of the template's related entity
387             * @return the matching templates
388             */
389            @Override
390            public List<DDMTemplate> getTemplates(
391                    long groupId, long classNameId, long classPK) {
392    
393                    return ddmTemplatePersistence.filterFindByG_C_C(
394                            groupId, classNameId, classPK);
395            }
396    
397            @Override
398            public List<DDMTemplate> getTemplates(
399                            long groupId, long classNameId, long classPK,
400                            boolean includeAncestorTemplates)
401                    throws PortalException {
402    
403                    List<DDMTemplate> ddmTemplates = new ArrayList<DDMTemplate>();
404    
405                    ddmTemplates.addAll(
406                            ddmTemplatePersistence.filterFindByG_C_C(
407                                    groupId, classNameId, classPK));
408    
409                    if (!includeAncestorTemplates) {
410                            return ddmTemplates;
411                    }
412    
413                    ddmTemplates.addAll(
414                            ddmTemplatePersistence.filterFindByG_C_C(
415                                    PortalUtil.getAncestorSiteGroupIds(groupId), classNameId,
416                                    classPK));
417    
418                    return ddmTemplates;
419            }
420    
421            /**
422             * Returns all the templates matching the class name ID, class PK, type, and
423             * mode.
424             *
425             * @param  groupId the primary key of the group
426             * @param  classNameId the primary key of the class name for template's
427             *         related model
428             * @param  classPK the primary key of the template's related entity
429             * @param  type the template's type. For more information, see {@link
430             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
431             * @return the matching templates
432             */
433            @Override
434            public List<DDMTemplate> getTemplates(
435                    long groupId, long classNameId, long classPK, String type) {
436    
437                    return ddmTemplatePersistence.filterFindByG_C_C_T(
438                            groupId, classNameId, classPK, type);
439            }
440    
441            @Override
442            public List<DDMTemplate> getTemplates(
443                    long groupId, long classNameId, long classPK, String type,
444                    String mode) {
445    
446                    return ddmTemplatePersistence.filterFindByG_C_C_T_M(
447                            groupId, classNameId, classPK, type, mode);
448            }
449    
450            /**
451             * Returns all the templates matching the group and class PK.
452             *
453             * @param  groupId the primary key of the group
454             * @param  classPK the primary key of the template's related entity
455             * @return the matching templates
456             */
457            @Override
458            public List<DDMTemplate> getTemplatesByClassPK(long groupId, long classPK) {
459                    return ddmTemplatePersistence.filterFindByG_CPK(groupId, classPK);
460            }
461    
462            /**
463             * Returns an ordered range of all the templates matching the group and
464             * structure class name ID and all the generic templates matching the group.
465             *
466             * <p>
467             * Useful when paginating results. Returns a maximum of <code>end -
468             * start</code> instances. <code>start</code> and <code>end</code> are not
469             * primary keys, they are indexes in the result set. Thus, <code>0</code>
470             * refers to the first result in the set. Setting both <code>start</code>
471             * and <code>end</code> to {@link
472             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
473             * result set.
474             * </p>
475             *
476             * @param  groupId the primary key of the group
477             * @param  structureClassNameId the primary key of the class name for the
478             *         template's related structure (optionally <code>0</code>). Specify
479             *         <code>0</code> to return generic templates only.
480             * @param  start the lower bound of the range of templates to return
481             * @param  end the upper bound of the range of templates to return (not
482             *         inclusive)
483             * @param  orderByComparator the comparator to order the templates
484             *         (optionally <code>null</code>)
485             * @return the range of matching templates ordered by the comparator
486             */
487            @Override
488            public List<DDMTemplate> getTemplatesByStructureClassNameId(
489                    long groupId, long structureClassNameId, int start, int end,
490                    OrderByComparator<DDMTemplate> orderByComparator) {
491    
492                    return ddmTemplateFinder.filterFindByG_SC(
493                            groupId, structureClassNameId, start, end, orderByComparator);
494            }
495    
496            /**
497             * Returns the number of templates matching the group and structure class
498             * name ID plus the number of generic templates matching the group.
499             *
500             * @param  groupId the primary key of the group
501             * @param  structureClassNameId the primary key of the class name for the
502             *         template's related structure (optionally <code>0</code>). Specify
503             *         <code>0</code> to count generic templates only.
504             * @return the number of matching templates plus the number of matching
505             *         generic templates
506             */
507            @Override
508            public int getTemplatesByStructureClassNameIdCount(
509                    long groupId, long structureClassNameId) {
510    
511                    return ddmTemplateFinder.filterCountByG_SC(
512                            groupId, structureClassNameId);
513            }
514    
515            /**
516             * Returns an ordered range of all the templates matching the group, class
517             * name ID, class PK, type, and mode, and matching the keywords in the
518             * template names and descriptions.
519             *
520             * <p>
521             * Useful when paginating results. Returns a maximum of <code>end -
522             * start</code> instances. <code>start</code> and <code>end</code> are not
523             * primary keys, they are indexes in the result set. Thus, <code>0</code>
524             * refers to the first result in the set. Setting both <code>start</code>
525             * and <code>end</code> to {@link
526             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
527             * result set.
528             * </p>
529             *
530             * @param  companyId the primary key of the template's company
531             * @param  groupId the primary key of the group
532             * @param  classNameId the primary key of the class name for template's
533             *         related model
534             * @param  classPK the primary key of the template's related entity
535             * @param  keywords the keywords (space separated), which may occur in the
536             *         template's name or description (optionally <code>null</code>)
537             * @param  type the template's type (optionally <code>null</code>). For more
538             *         information, see {@link
539             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
540             * @param  mode the template's mode (optionally <code>null</code>) For more
541             *         information, see {@link
542             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
543             * @param  start the lower bound of the range of templates to return
544             * @param  end the upper bound of the range of templates to return (not
545             *         inclusive)
546             * @param  orderByComparator the comparator to order the templates
547             *         (optionally <code>null</code>)
548             * @return the matching templates ordered by the comparator
549             */
550            @Override
551            public List<DDMTemplate> search(
552                    long companyId, long groupId, long classNameId, long classPK,
553                    String keywords, String type, String mode, int start, int end,
554                    OrderByComparator<DDMTemplate> orderByComparator) {
555    
556                    return ddmTemplateFinder.filterFindByKeywords(
557                            companyId, groupId, classNameId, classPK, keywords, type, mode,
558                            start, end, orderByComparator);
559            }
560    
561            /**
562             * Returns an ordered range of all the templates matching the group, class
563             * name ID, class PK, name keyword, description keyword, type, mode, and
564             * language.
565             *
566             * <p>
567             * Useful when paginating results. Returns a maximum of <code>end -
568             * start</code> instances. <code>start</code> and <code>end</code> are not
569             * primary keys, they are indexes in the result set. Thus, <code>0</code>
570             * refers to the first result in the set. Setting both <code>start</code>
571             * and <code>end</code> to {@link
572             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
573             * result set.
574             * </p>
575             *
576             * @param  companyId the primary key of the template's company
577             * @param  groupId the primary key of the group
578             * @param  classNameId the primary key of the class name for template's
579             *         related model
580             * @param  classPK the primary key of the template's related entity
581             * @param  name the name keywords (optionally <code>null</code>)
582             * @param  description the description keywords (optionally
583             *         <code>null</code>)
584             * @param  type the template's type (optionally <code>null</code>). For more
585             *         information, see {@link
586             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
587             * @param  mode the template's mode (optionally <code>null</code>). For more
588             *         information, see {@link
589             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
590             * @param  language the template's script language (optionally
591             *         <code>null</code>). For more information, see {@link
592             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
593             * @param  andOperator whether every field must match its keywords, or just
594             *         one field.
595             * @param  start the lower bound of the range of templates to return
596             * @param  end the upper bound of the range of templates to return (not
597             *         inclusive)
598             * @param  orderByComparator the comparator to order the templates
599             *         (optionally <code>null</code>)
600             * @return the matching templates ordered by the comparator
601             */
602            @Override
603            public List<DDMTemplate> search(
604                    long companyId, long groupId, long classNameId, long classPK,
605                    String name, String description, String type, String mode,
606                    String language, boolean andOperator, int start, int end,
607                    OrderByComparator<DDMTemplate> orderByComparator) {
608    
609                    return ddmTemplateFinder.filterFindByC_G_C_C_N_D_T_M_L(
610                            companyId, groupId, classNameId, classPK, name, description, type,
611                            mode, language, andOperator, start, end, orderByComparator);
612            }
613    
614            /**
615             * Returns an ordered range of all the templates matching the group IDs,
616             * class name IDs, class PK, type, and mode, and matching the keywords in
617             * the template names and descriptions.
618             *
619             * <p>
620             * Useful when paginating results. Returns a maximum of <code>end -
621             * start</code> instances. <code>start</code> and <code>end</code> are not
622             * primary keys, they are indexes in the result set. Thus, <code>0</code>
623             * refers to the first result in the set. Setting both <code>start</code>
624             * and <code>end</code> to {@link
625             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
626             * result set.
627             * </p>
628             *
629             * @param  companyId the primary key of the template's company
630             * @param  groupIds the primary keys of the groups
631             * @param  classNameIds the primary keys of the entity's instances the
632             *         templates are related to
633             * @param  classPKs the primary keys of the template's related entities
634             * @param  keywords the keywords (space separated), which may occur in the
635             *         template's name or description (optionally <code>null</code>)
636             * @param  type the template's type (optionally <code>null</code>). For more
637             *         information, see {@link
638             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
639             * @param  mode the template's mode (optionally <code>null</code>). For more
640             *         information, see {@link
641             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
642             * @param  start the lower bound of the range of templates to return
643             * @param  end the upper bound of the range of templates to return (not
644             *         inclusive)
645             * @param  orderByComparator the comparator to order the templates
646             *         (optionally <code>null</code>)
647             * @return the matching templates ordered by the comparator
648             */
649            @Override
650            public List<DDMTemplate> search(
651                    long companyId, long[] groupIds, long[] classNameIds, long[] classPKs,
652                    String keywords, String type, String mode, int start, int end,
653                    OrderByComparator<DDMTemplate> orderByComparator) {
654    
655                    return ddmTemplateFinder.filterFindByKeywords(
656                            companyId, groupIds, classNameIds, classPKs, keywords, type, mode,
657                            start, end, orderByComparator);
658            }
659    
660            /**
661             * Returns an ordered range of all the templates matching the group IDs,
662             * class name IDs, class PK, name keyword, description keyword, type, mode,
663             * and language.
664             *
665             * <p>
666             * Useful when paginating results. Returns a maximum of <code>end -
667             * start</code> instances. <code>start</code> and <code>end</code> are not
668             * primary keys, they are indexes in the result set. Thus, <code>0</code>
669             * refers to the first result in the set. Setting both <code>start</code>
670             * and <code>end</code> to {@link
671             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
672             * result set.
673             * </p>
674             *
675             * @param  companyId the primary key of the template's company
676             * @param  groupIds the primary keys of the groups
677             * @param  classNameIds the primary keys of the entity's instances the
678             *         templates are related to
679             * @param  classPKs the primary keys of the template's related entities
680             * @param  name the name keywords (optionally <code>null</code>)
681             * @param  description the description keywords (optionally
682             *         <code>null</code>)
683             * @param  type the template's type (optionally <code>null</code>). For more
684             *         information, see {@link
685             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
686             * @param  mode the template's mode (optionally <code>null</code>). For more
687             *         information, see {@link
688             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
689             * @param  language the template's script language (optionally
690             *         <code>null</code>). For more information, see {@link
691             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
692             * @param  andOperator whether every field must match its keywords, or just
693             *         one field.
694             * @param  start the lower bound of the range of templates to return
695             * @param  end the upper bound of the range of templates to return (not
696             *         inclusive)
697             * @param  orderByComparator the comparator to order the templates
698             *         (optionally <code>null</code>)
699             * @return the matching templates ordered by the comparator
700             */
701            @Override
702            public List<DDMTemplate> search(
703                    long companyId, long[] groupIds, long[] classNameIds, long[] classPKs,
704                    String name, String description, String type, String mode,
705                    String language, boolean andOperator, int start, int end,
706                    OrderByComparator<DDMTemplate> orderByComparator) {
707    
708                    return ddmTemplateFinder.filterFindByC_G_C_C_N_D_T_M_L(
709                            companyId, groupIds, classNameIds, classPKs, name, description,
710                            type, mode, language, andOperator, start, end, orderByComparator);
711            }
712    
713            /**
714             * Returns the number of templates matching the group, class name ID, class
715             * PK, type, and mode, and matching the keywords in the template names and
716             * descriptions.
717             *
718             * @param  companyId the primary key of the template's company
719             * @param  groupId the primary key of the group
720             * @param  classNameId the primary key of the class name for template's
721             *         related model
722             * @param  classPK the primary key of the template's related entity
723             * @param  keywords the keywords (space separated), which may occur in the
724             *         template's name or description (optionally <code>null</code>)
725             * @param  type the template's type (optionally <code>null</code>). For more
726             *         information, see {@link
727             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
728             * @param  mode the template's mode (optionally <code>null</code>). For more
729             *         information, see {@link
730             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
731             * @return the number of matching templates
732             */
733            @Override
734            public int searchCount(
735                    long companyId, long groupId, long classNameId, long classPK,
736                    String keywords, String type, String mode) {
737    
738                    return ddmTemplateFinder.filterCountByKeywords(
739                            companyId, groupId, classNameId, classPK, keywords, type, mode);
740            }
741    
742            /**
743             * Returns the number of templates matching the group, class name ID, class
744             * PK, name keyword, description keyword, type, mode, and language.
745             *
746             * @param  companyId the primary key of the template's company
747             * @param  groupId the primary key of the group
748             * @param  classNameId the primary key of the class name for template's
749             *         related model
750             * @param  classPK the primary key of the template's related entity
751             * @param  name the name keywords (optionally <code>null</code>)
752             * @param  description the description keywords (optionally
753             *         <code>null</code>)
754             * @param  type the template's type (optionally <code>null</code>). For more
755             *         information, see {@link
756             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
757             * @param  mode the template's mode (optionally <code>null</code>). For more
758             *         information, see {@link
759             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
760             * @param  language the template's script language (optionally
761             *         <code>null</code>). For more information, see {@link
762             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
763             * @param  andOperator whether every field must match its keywords, or just
764             *         one field.
765             * @return the number of matching templates
766             */
767            @Override
768            public int searchCount(
769                    long companyId, long groupId, long classNameId, long classPK,
770                    String name, String description, String type, String mode,
771                    String language, boolean andOperator) {
772    
773                    return ddmTemplateFinder.filterCountByC_G_C_C_N_D_T_M_L(
774                            companyId, groupId, classNameId, classPK, name, description, type,
775                            mode, language, andOperator);
776            }
777    
778            /**
779             * Returns the number of templates matching the group IDs, class name IDs,
780             * class PK, type, and mode, and matching the keywords in the template names
781             * and descriptions.
782             *
783             * @param  companyId the primary key of the template's company
784             * @param  groupIds the primary keys of the groups
785             * @param  classNameIds the primary keys of the entity's instances the
786             *         templates are related to
787             * @param  classPKs the primary keys of the template's related entities
788             * @param  keywords the keywords (space separated), which may occur in the
789             *         template's name or description (optionally <code>null</code>)
790             * @param  type the template's type (optionally <code>null</code>). For more
791             *         information, see {@link
792             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
793             * @param  mode the template's mode (optionally <code>null</code>). For more
794             *         information, see {@link
795             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
796             * @return the number of matching templates
797             */
798            @Override
799            public int searchCount(
800                    long companyId, long[] groupIds, long[] classNameIds, long[] classPKs,
801                    String keywords, String type, String mode) {
802    
803                    return ddmTemplateFinder.filterCountByKeywords(
804                            companyId, groupIds, classNameIds, classPKs, keywords, type, mode);
805            }
806    
807            /**
808             * Returns the number of templates matching the group IDs, class name IDs,
809             * class PK, name keyword, description keyword, type, mode, and language.
810             *
811             * @param  companyId the primary key of the template's company
812             * @param  groupIds the primary keys of the groups
813             * @param  classNameIds the primary keys of the entity's instances the
814             *         templates are related to
815             * @param  classPKs the primary keys of the template's related entities
816             * @param  name the name keywords (optionally <code>null</code>)
817             * @param  description the description keywords (optionally
818             *         <code>null</code>)
819             * @param  type the template's type (optionally <code>null</code>). For more
820             *         information, see {@link
821             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
822             * @param  mode the template's mode (optionally <code>null</code>). For more
823             *         information, see {@link
824             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
825             * @param  language the template's script language (optionally
826             *         <code>null</code>). For more information, see {@link
827             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
828             * @param  andOperator whether every field must match its keywords, or just
829             *         one field.
830             * @return the number of matching templates
831             */
832            @Override
833            public int searchCount(
834                    long companyId, long[] groupIds, long[] classNameIds, long[] classPKs,
835                    String name, String description, String type, String mode,
836                    String language, boolean andOperator) {
837    
838                    return ddmTemplateFinder.filterCountByC_G_C_C_N_D_T_M_L(
839                            companyId, groupIds, classNameIds, classPKs, name, description,
840                            type, mode, language, andOperator);
841            }
842    
843            /**
844             * Updates the template matching the ID.
845             *
846             * @param  templateId the primary key of the template
847             * @param  classPK the primary key of the template's related entity
848             * @param  nameMap the template's new locales and localized names
849             * @param  descriptionMap the template's new locales and localized
850             *         description
851             * @param  type the template's type. For more information, see {@link
852             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
853             * @param  mode the template's mode. For more information, see {@link
854             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
855             * @param  language the template's script language. For more information,
856             *         see {@link
857             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
858             * @param  script the template's script
859             * @param  cacheable whether the template is cacheable
860             * @param  smallImage whether the template has a small image
861             * @param  smallImageURL the template's small image URL (optionally
862             *         <code>null</code>)
863             * @param  smallImageFile the template's small image file (optionally
864             *         <code>null</code>)
865             * @param  serviceContext the service context to be applied. Can set the
866             *         modification date.
867             * @return the updated template
868             * @throws PortalException if the user did not have permission to update the
869             *         template or if a portal exception occurred
870             */
871            @Override
872            public DDMTemplate updateTemplate(
873                            long templateId, long classPK, Map<Locale, String> nameMap,
874                            Map<Locale, String> descriptionMap, String type, String mode,
875                            String language, String script, boolean cacheable,
876                            boolean smallImage, String smallImageURL, File smallImageFile,
877                            ServiceContext serviceContext)
878                    throws PortalException {
879    
880                    DDMTemplatePermission.check(
881                            getPermissionChecker(), templateId, ActionKeys.UPDATE);
882    
883                    return ddmTemplateLocalService.updateTemplate(
884                            templateId, classPK, nameMap, descriptionMap, type, mode, language,
885                            script, cacheable, smallImage, smallImageURL, smallImageFile,
886                            serviceContext);
887            }
888    
889            /**
890             * Updates the template matching the ID.
891             *
892             * @param  templateId the primary key of the template
893             * @param  classPK the primary key of the template's related entity
894             * @param  nameMap the template's new locales and localized names
895             * @param  descriptionMap the template's new locales and localized
896             *         description
897             * @param  type the template's type. For more information, see {@link
898             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
899             * @param  mode the template's mode. For more information, see {@link
900             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
901             * @param  language the template's script language. For more information,
902             *         see {@link
903             *         com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
904             * @param  script the template's script
905             * @param  cacheable whether the template is cacheable
906             * @param  serviceContext the service context to be applied. Can set the
907             *         modification date.
908             * @return the updated template
909             * @throws PortalException if the user did not have permission to update the
910             *         template or if a portal exception occurred
911             */
912            @Override
913            public DDMTemplate updateTemplate(
914                            long templateId, long classPK, Map<Locale, String> nameMap,
915                            Map<Locale, String> descriptionMap, String type, String mode,
916                            String language, String script, boolean cacheable,
917                            ServiceContext serviceContext)
918                    throws PortalException {
919    
920                    DDMTemplatePermission.check(
921                            getPermissionChecker(), templateId, ActionKeys.UPDATE);
922    
923                    return ddmTemplateLocalService.updateTemplate(
924                            templateId, classPK, nameMap, descriptionMap, type, mode, language,
925                            script, cacheable, serviceContext);
926            }
927    
928    }