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