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