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.DDMStructure; 023 import com.liferay.portlet.dynamicdatamapping.service.base.DDMStructureServiceBaseImpl; 024 import com.liferay.portlet.dynamicdatamapping.service.permission.DDMPermission; 025 import com.liferay.portlet.dynamicdatamapping.service.permission.DDMStructurePermission; 026 import com.liferay.portlet.dynamicdatamapping.util.DDMDisplay; 027 import com.liferay.portlet.dynamicdatamapping.util.DDMUtil; 028 029 import java.util.List; 030 import java.util.Locale; 031 import java.util.Map; 032 033 /** 034 * Provides the remote service for accessing, adding, deleting, and updating 035 * dynamic data mapping (DDM) structures. Its methods include permission checks. 036 * 037 * @author Brian Wing Shun Chan 038 * @author Bruno Basto 039 * @author Marcellus Tavares 040 * @see com.liferay.portlet.dynamicdatamapping.service.impl.DDMStructureLocalServiceImpl 041 */ 042 public class DDMStructureServiceImpl extends DDMStructureServiceBaseImpl { 043 044 /** 045 * Adds a structure referencing a default parent structure, using the portal 046 * property <code>dynamic.data.lists.storage.type</code> storage type and 047 * default structure type. 048 * 049 * @param userId the primary key of the structure's creator/owner 050 * @param groupId the primary key of the group 051 * @param classNameId the primary key of the class name for the structure's 052 * related model 053 * @param nameMap the structure's locales and localized names 054 * @param descriptionMap the structure's locales and localized descriptions 055 * @param xsd the structure's XML schema definition 056 * @param serviceContext the service context to be applied. Can set the 057 * UUID, creation date, modification date, guest permissions, and 058 * group permissions for the structure. 059 * @return the structure 060 * @throws PortalException if a user with the primary key could not be 061 * found, if the user did not have permission to add the structure, 062 * if the XSD was not well-formed, or if a portal exception occurred 063 * @throws SystemException if a system exception occurred 064 */ 065 @Override 066 public DDMStructure addStructure( 067 long userId, long groupId, long classNameId, 068 Map<Locale, String> nameMap, Map<Locale, String> descriptionMap, 069 String xsd, ServiceContext serviceContext) 070 throws PortalException, SystemException { 071 072 DDMDisplay ddmDisplay = DDMUtil.getDDMDisplay(serviceContext); 073 074 DDMPermission.check( 075 getPermissionChecker(), serviceContext.getScopeGroupId(), 076 ddmDisplay.getResourceName(), ddmDisplay.getAddStructureActionId()); 077 078 return ddmStructureLocalService.addStructure( 079 getUserId(), groupId, classNameId, nameMap, descriptionMap, xsd, 080 serviceContext); 081 } 082 083 /** 084 * Adds a structure referencing its parent structure. 085 * 086 * @param groupId the primary key of the group 087 * @param parentStructureId the primary key of the parent structure 088 * (optionally {@link 089 * com.liferay.portlet.dynamicdatamapping.model.DDMStructureConstants#DEFAULT_PARENT_STRUCTURE_ID}) 090 * @param classNameId the primary key of the class name for the structure's 091 * related model 092 * @param structureKey the unique string identifying the structure 093 * (optionally <code>null</code>) 094 * @param nameMap the structure's locales and localized names 095 * @param descriptionMap the structure's locales and localized descriptions 096 * @param xsd the structure's XML schema definition 097 * @param storageType the structure's storage type. It can be "xml" or 098 * "expando". For more information, see {@link 099 * com.liferay.portlet.dynamicdatamapping.storage.StorageType}. 100 * @param type the structure's type. For more information, see {@link 101 * com.liferay.portlet.dynamicdatamapping.model.DDMStructureConstants}. 102 * @param serviceContext the service context to be applied. Can set the 103 * UUID, creation date, modification date, guest permissions, and 104 * group permissions for the structure. 105 * @return the structure 106 * @throws PortalException if the user did not have permission to add the 107 * structure, if the XSD is not well formed, or if a portal 108 * exception occurred 109 * @throws SystemException if a system exception occurred 110 */ 111 @Override 112 public DDMStructure addStructure( 113 long groupId, long parentStructureId, long classNameId, 114 String structureKey, Map<Locale, String> nameMap, 115 Map<Locale, String> descriptionMap, String xsd, String storageType, 116 int type, ServiceContext serviceContext) 117 throws PortalException, SystemException { 118 119 DDMDisplay ddmDisplay = DDMUtil.getDDMDisplay(serviceContext); 120 121 DDMPermission.check( 122 getPermissionChecker(), serviceContext.getScopeGroupId(), 123 ddmDisplay.getResourceName(), ddmDisplay.getAddStructureActionId()); 124 125 return ddmStructureLocalService.addStructure( 126 getUserId(), groupId, parentStructureId, classNameId, structureKey, 127 nameMap, descriptionMap, xsd, storageType, type, serviceContext); 128 } 129 130 /** 131 * Adds a structure referencing the parent structure by its structure key. 132 * In case the parent structure is not found, it uses the default parent 133 * structure ID. 134 * 135 * @param userId the primary key of the structure's creator/owner 136 * @param groupId the primary key of the group 137 * @param parentStructureKey the unique string identifying the structure 138 * @param classNameId the primary key of the class name for the structure's 139 * related model 140 * @param structureKey unique string identifying the structure (optionally 141 * <code>null</code>) 142 * @param nameMap the structure's locales and localized names 143 * @param descriptionMap the structure's locales and localized descriptions 144 * @param xsd the XML schema definition of the structure 145 * @param storageType the storage type of the structure. It can be XML or 146 * expando. For more information, see {@link 147 * com.liferay.portlet.dynamicdatamapping.storage.StorageType}. 148 * @param type the structure's type. For more information, see {@link 149 * com.liferay.portlet.dynamicdatamapping.model.DDMStructureConstants}. 150 * @param serviceContext the service context to be applied. Must have the 151 * <code>ddmResource</code> attribute to check permissions. Can set 152 * the UUID, creation date, modification date, guest permissions, 153 * and group permissions for the structure. 154 * @return the structure 155 * @throws PortalException if a user with the primary key could not be 156 * found, if the user did not have permission to add the structure, 157 * if the XSD was not well-formed, or if a portal exception occurred 158 * @throws SystemException if a system exception occurred 159 */ 160 @Override 161 public DDMStructure addStructure( 162 long userId, long groupId, String parentStructureKey, 163 long classNameId, String structureKey, Map<Locale, String> nameMap, 164 Map<Locale, String> descriptionMap, String xsd, String storageType, 165 int type, ServiceContext serviceContext) 166 throws PortalException, SystemException { 167 168 DDMDisplay ddmDisplay = DDMUtil.getDDMDisplay(serviceContext); 169 170 DDMPermission.check( 171 getPermissionChecker(), serviceContext.getScopeGroupId(), 172 ddmDisplay.getResourceName(), ddmDisplay.getAddStructureActionId()); 173 174 return ddmStructureLocalService.addStructure( 175 userId, groupId, parentStructureKey, classNameId, structureKey, 176 nameMap, descriptionMap, xsd, storageType, type, serviceContext); 177 } 178 179 /** 180 * Copies a structure, creating a new structure with all the values 181 * extracted from the original one. The new structure supports a new name 182 * and description. 183 * 184 * @param structureId the primary key of the structure to be copied 185 * @param nameMap the new structure's locales and localized names 186 * @param descriptionMap the new structure's locales and localized 187 * descriptions 188 * @param serviceContext the service context to be applied. Can set the 189 * UUID, creation date, modification date, guest permissions, and 190 * group permissions for the structure. 191 * @return the new structure 192 * @throws PortalException if the user did not have permission to add the 193 * structure or if a portal exception occurred 194 * @throws SystemException if a system exception occurred 195 */ 196 @Override 197 public DDMStructure copyStructure( 198 long structureId, Map<Locale, String> nameMap, 199 Map<Locale, String> descriptionMap, ServiceContext serviceContext) 200 throws PortalException, SystemException { 201 202 DDMDisplay ddmDisplay = DDMUtil.getDDMDisplay(serviceContext); 203 204 DDMPermission.check( 205 getPermissionChecker(), serviceContext.getScopeGroupId(), 206 ddmDisplay.getResourceName(), ddmDisplay.getAddStructureActionId()); 207 208 return ddmStructureLocalService.copyStructure( 209 getUserId(), structureId, nameMap, descriptionMap, serviceContext); 210 } 211 212 @Override 213 public DDMStructure copyStructure( 214 long structureId, ServiceContext serviceContext) 215 throws PortalException, SystemException { 216 217 DDMDisplay ddmDisplay = DDMUtil.getDDMDisplay(serviceContext); 218 219 DDMPermission.check( 220 getPermissionChecker(), serviceContext.getScopeGroupId(), 221 ddmDisplay.getResourceName(), ddmDisplay.getAddStructureActionId()); 222 223 return ddmStructureLocalService.copyStructure( 224 getUserId(), structureId, serviceContext); 225 } 226 227 /** 228 * Deletes the structure and its resources. 229 * 230 * <p> 231 * Before deleting the structure, the system verifies whether the structure 232 * is required by another entity. If it is needed, an exception is thrown. 233 * </p> 234 * 235 * @param structureId the primary key of the structure to be deleted 236 * @throws PortalException if the user did not have permission to delete the 237 * structure or if a portal exception occurred 238 * @throws SystemException if a system exception occurred 239 */ 240 @Override 241 public void deleteStructure(long structureId) 242 throws PortalException, SystemException { 243 244 DDMStructurePermission.check( 245 getPermissionChecker(), structureId, ActionKeys.DELETE); 246 247 ddmStructureLocalService.deleteStructure(structureId); 248 } 249 250 /** 251 * Returns the structure matching the class name ID, structure key, and 252 * group. 253 * 254 * @param groupId the primary key of the group 255 * @param classNameId the primary key of the class name for the structure's 256 * related model 257 * @param structureKey the unique string identifying the structure 258 * @return the matching structure, or <code>null</code> if a matching 259 * structure could not be found 260 * @throws PortalException if the user did not have permission to view the 261 * structure or if a portal exception occurred 262 * @throws SystemException if a system exception occurred 263 */ 264 @Override 265 public DDMStructure fetchStructure( 266 long groupId, long classNameId, String structureKey) 267 throws PortalException, SystemException { 268 269 DDMStructure ddmStructure = ddmStructurePersistence.fetchByG_C_S( 270 groupId, classNameId, structureKey); 271 272 if (ddmStructure != null) { 273 DDMStructurePermission.check( 274 getPermissionChecker(), ddmStructure, ActionKeys.VIEW); 275 } 276 277 return ddmStructure; 278 } 279 280 @Override 281 public DDMStructure fetchStructure( 282 long groupId, long classNameId, String structureKey, 283 boolean includeAncestorStructures) 284 throws PortalException, SystemException { 285 286 DDMStructure ddmStructure = ddmStructureLocalService.fetchStructure( 287 groupId, classNameId, structureKey, includeAncestorStructures); 288 289 if (ddmStructure != null) { 290 DDMStructurePermission.check( 291 getPermissionChecker(), ddmStructure, ActionKeys.VIEW); 292 } 293 294 return ddmStructure; 295 } 296 297 /** 298 * Returns the structure with the ID. 299 * 300 * @param structureId the primary key of the structure 301 * @return the structure with the ID 302 * @throws PortalException if the user did not have permission to view the 303 * structure or if a structure with the ID could not be found 304 * @throws SystemException if a system exception occurred 305 */ 306 @Override 307 public DDMStructure getStructure(long structureId) 308 throws PortalException, SystemException { 309 310 DDMStructurePermission.check( 311 getPermissionChecker(), structureId, ActionKeys.VIEW); 312 313 return ddmStructurePersistence.findByPrimaryKey(structureId); 314 } 315 316 /** 317 * Returns the structure matching the class name ID, structure key, and 318 * group. 319 * 320 * @param groupId the primary key of the structure's group 321 * @param classNameId the primary key of the class name for the structure's 322 * related model 323 * @param structureKey the unique string identifying the structure 324 * @return the matching structure 325 * @throws PortalException if the user did not have permission to view the 326 * structure or if a matching structure could not be found 327 * @throws SystemException if a system exception occurred 328 */ 329 @Override 330 public DDMStructure getStructure( 331 long groupId, long classNameId, String structureKey) 332 throws PortalException, SystemException { 333 334 DDMStructurePermission.check( 335 getPermissionChecker(), groupId, classNameId, structureKey, 336 ActionKeys.VIEW); 337 338 return ddmStructureLocalService.getStructure( 339 groupId, classNameId, structureKey); 340 } 341 342 /** 343 * Returns the structure matching the class name ID, structure key, and 344 * group, optionally in the global scope. 345 * 346 * <p> 347 * This method first searches in the group. If the structure is still not 348 * found and <code>includeGlobalStructures</code> is set to 349 * <code>true</code>, this method searches the global group. 350 * </p> 351 * 352 * @param groupId the primary key of the structure's group 353 * @param classNameId the primary key of the class name for the structure's 354 * related model 355 * @param structureKey the unique string identifying the structure 356 * @param includeGlobalStructures whether to include the global scope in 357 * the search 358 * @return the matching structure 359 * @throws PortalException if the user did not have permission to view the 360 * structure or if a matching structure could not be found 361 * @throws SystemException if a system exception occurred 362 */ 363 @Override 364 public DDMStructure getStructure( 365 long groupId, long classNameId, String structureKey, 366 boolean includeGlobalStructures) 367 throws PortalException, SystemException { 368 369 DDMStructurePermission.check( 370 getPermissionChecker(), groupId, classNameId, structureKey, 371 ActionKeys.VIEW); 372 373 return ddmStructureLocalService.getStructure( 374 groupId, classNameId, structureKey, includeGlobalStructures); 375 } 376 377 /** 378 * Returns all the structures in the group that the user has permission to 379 * view. 380 * 381 * @param groupId the primary key of the group 382 * @return the structures in the group that the user has permission to view 383 * @throws SystemException if a system exception occurred 384 */ 385 @Override 386 public List<DDMStructure> getStructures(long groupId) 387 throws SystemException { 388 389 return ddmStructurePersistence.filterFindByGroupId(groupId); 390 } 391 392 /** 393 * Returns all the structures in the groups that the user has permission to 394 * view. 395 * 396 * @param groupIds the primary key of the groups 397 * @return the structures in the groups that the user has permission to view 398 * @throws SystemException if a system exception occurred 399 */ 400 @Override 401 public List<DDMStructure> getStructures(long[] groupIds) 402 throws SystemException { 403 404 return ddmStructurePersistence.filterFindByGroupId(groupIds); 405 } 406 407 @Override 408 public List<DDMStructure> getStructures(long[] groupIds, long classNameId) 409 throws SystemException { 410 411 return ddmStructurePersistence.filterFindByG_C(groupIds, classNameId); 412 } 413 414 @Override 415 public List<DDMStructure> getStructures( 416 long[] groupIds, long classNameId, int start, int end) 417 throws SystemException { 418 419 return ddmStructurePersistence.filterFindByG_C( 420 groupIds, classNameId, start, end); 421 } 422 423 /** 424 * Returns an ordered range of all the structures matching the groups and 425 * class name IDs, and matching the keywords in the structure names and 426 * descriptions. 427 * 428 * <p> 429 * Useful when paginating results. Returns a maximum of <code>end - 430 * start</code> instances. <code>start</code> and <code>end</code> are not 431 * primary keys, they are indexes in the result set. Thus, <code>0</code> 432 * refers to the first result in the set. Setting both <code>start</code> 433 * and <code>end</code> to {@link 434 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 435 * result set. 436 * </p> 437 * 438 * @param companyId the primary key of the structure's company 439 * @param groupIds the primary keys of the groups 440 * @param classNameIds the primary keys of the class names of the models 441 * the structures are related to 442 * @param keywords the keywords (space separated), which may occur in the 443 * structure's name or description (optionally <code>null</code>) 444 * @param start the lower bound of the range of structures to return 445 * @param end the upper bound of the range of structures to return (not 446 * inclusive) 447 * @param orderByComparator the comparator to order the structures 448 * (optionally <code>null</code>) 449 * @return the range of matching structures ordered by the comparator 450 * @throws SystemException if a system exception occurred 451 */ 452 @Override 453 public List<DDMStructure> search( 454 long companyId, long[] groupIds, long[] classNameIds, 455 String keywords, int start, int end, 456 OrderByComparator orderByComparator) 457 throws SystemException { 458 459 return ddmStructureFinder.filterFindByKeywords( 460 companyId, groupIds, classNameIds, keywords, start, end, 461 orderByComparator); 462 } 463 464 /** 465 * Returns an ordered range of all the structures matching the groups, class 466 * name IDs, name keyword, description keyword, storage type, and type. 467 * 468 * <p> 469 * Useful when paginating results. Returns a maximum of <code>end - 470 * start</code> instances. <code>start</code> and <code>end</code> are not 471 * primary keys, they are indexes in the result set. Thus, <code>0</code> 472 * refers to the first result in the set. Setting both <code>start</code> 473 * and <code>end</code> to {@link 474 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 475 * result set. 476 * </p> 477 * 478 * @param companyId the primary key of the structure's company 479 * @param groupIds the primary keys of the groups 480 * @param classNameIds the primary keys of the class names of the models 481 * the structures are related to 482 * @param name the name keywords 483 * @param description the description keywords 484 * @param storageType the structure's storage type. It can be "xml" or 485 * "expando". For more information, see {@link 486 * com.liferay.portlet.dynamicdatamapping.storage.StorageType}. 487 * @param type the structure's type. For more information, see {@link 488 * com.liferay.portlet.dynamicdatamapping.model.DDMStructureConstants}. 489 * @param andOperator whether every field must match its keywords, or just 490 * one field 491 * @param start the lower bound of the range of structures to return 492 * @param end the upper bound of the range of structures to return (not 493 * inclusive) 494 * @param orderByComparator the comparator to order the structures 495 * (optionally <code>null</code>) 496 * @return the range of matching structures ordered by the comparator 497 * @throws SystemException if a system exception occurred 498 */ 499 @Override 500 public List<DDMStructure> search( 501 long companyId, long[] groupIds, long[] classNameIds, String name, 502 String description, String storageType, int type, 503 boolean andOperator, int start, int end, 504 OrderByComparator orderByComparator) 505 throws SystemException { 506 507 return ddmStructureFinder.filterFindByC_G_C_N_D_S_T( 508 companyId, groupIds, classNameIds, name, description, storageType, 509 type, andOperator, start, end, orderByComparator); 510 } 511 512 /** 513 * Returns the number of structures matching the groups and class name IDs, 514 * and matching the keywords in the structure names and descriptions. 515 * 516 * @param companyId the primary key of the structure's company 517 * @param groupIds the primary keys of the groups 518 * @param classNameIds the primary keys of the class names of the models 519 * the structures are related to 520 * @param keywords the keywords (space separated), which may occur in the 521 * structure's name or description (optionally <code>null</code>) 522 * @return the number of matching structures 523 * @throws SystemException if a system exception occurred 524 */ 525 @Override 526 public int searchCount( 527 long companyId, long[] groupIds, long[] classNameIds, 528 String keywords) 529 throws SystemException { 530 531 return ddmStructureFinder.filterCountByKeywords( 532 companyId, groupIds, classNameIds, keywords); 533 } 534 535 /** 536 * Returns the number of structures matching the groups, class name IDs, 537 * name keyword, description keyword, storage type, and type 538 * 539 * @param companyId the primary key of the structure's company 540 * @param groupIds the primary keys of the groups 541 * @param classNameIds the primary keys of the class names of the models 542 * the structure's are related to 543 * @param name the name keywords 544 * @param description the description keywords 545 * @param storageType the structure's storage type. It can be "xml" or 546 * "expando". For more information, see {@link 547 * com.liferay.portlet.dynamicdatamapping.storage.StorageType}. 548 * @param type the structure's type. For more information, see {@link 549 * com.liferay.portlet.dynamicdatamapping.model.DDMStructureConstants}. 550 * @param andOperator whether every field must match its keywords, or just 551 * one field 552 * @return the number of matching structures 553 * @throws SystemException if a system exception occurred 554 */ 555 @Override 556 public int searchCount( 557 long companyId, long[] groupIds, long[] classNameIds, String name, 558 String description, String storageType, int type, 559 boolean andOperator) 560 throws SystemException { 561 562 return ddmStructureFinder.filterCountByC_G_C_N_D_S_T( 563 companyId, groupIds, classNameIds, name, description, storageType, 564 type, andOperator); 565 } 566 567 /** 568 * Updates the structure matching the class name ID, structure key, and 569 * group, replacing its old parent structure, name map, description map, and 570 * XSD with new ones. 571 * 572 * @param groupId the primary key of the group 573 * @param parentStructureId the primary key of the new parent structure 574 * @param classNameId the primary key of the class name for the structure's 575 * related model 576 * @param structureKey the unique string identifying the structure 577 * @param nameMap the structure's new locales and localized names 578 * @param descriptionMap the structure's new locales and localized 579 * description 580 * @param xsd the structure's new XML schema definition 581 * @param serviceContext the service context to be applied. Can set the 582 * modification date. 583 * @return the updated structure 584 * @throws PortalException if the user did not have permission to update the 585 * structure or if a portal exception occurred 586 * @throws SystemException if a system exception occurred 587 */ 588 @Override 589 public DDMStructure updateStructure( 590 long groupId, long parentStructureId, long classNameId, 591 String structureKey, Map<Locale, String> nameMap, 592 Map<Locale, String> descriptionMap, String xsd, 593 ServiceContext serviceContext) 594 throws PortalException, SystemException { 595 596 DDMStructurePermission.check( 597 getPermissionChecker(), groupId, classNameId, structureKey, 598 ActionKeys.UPDATE); 599 600 return ddmStructureLocalService.updateStructure( 601 groupId, parentStructureId, classNameId, structureKey, nameMap, 602 descriptionMap, xsd, serviceContext); 603 } 604 605 /** 606 * Updates the structure matching the structure ID, replacing the old parent 607 * structure ID, name map, description map, and XSD with the new values. 608 * 609 * @param structureId the primary key of the structure 610 * @param parentStructureId the new parent structure primary key 611 * @param nameMap the structure's new locales and localized names 612 * @param descriptionMap the structure's new locales and localized 613 * description 614 * @param xsd the new XML schema definition of the structure 615 * @param serviceContext the service context to be applied. Can set the 616 * modification date. 617 * @return the updated structure 618 * @throws PortalException if the user did not have permission to update the 619 * structure or if a portal exception occurred 620 * @throws SystemException if a system exception occurred 621 */ 622 @Override 623 public DDMStructure updateStructure( 624 long structureId, long parentStructureId, 625 Map<Locale, String> nameMap, Map<Locale, String> descriptionMap, 626 String xsd, ServiceContext serviceContext) 627 throws PortalException, SystemException { 628 629 DDMStructurePermission.check( 630 getPermissionChecker(), structureId, ActionKeys.UPDATE); 631 632 return ddmStructureLocalService.updateStructure( 633 structureId, parentStructureId, nameMap, descriptionMap, xsd, 634 serviceContext); 635 } 636 637 }