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