001 /** 002 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved. 003 * 004 * The contents of this file are subject to the terms of the Liferay Enterprise 005 * Subscription License ("License"). You may not use this file except in 006 * compliance with the License. You can obtain a copy of the License by 007 * contacting Liferay, Inc. See the License for the specific language governing 008 * permissions and limitations under the License, including but not limited to 009 * distribution rights of the Software. 010 * 011 * 012 * 013 */ 014 015 package com.liferay.portal.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.messaging.DestinationNames; 020 import com.liferay.portal.kernel.scheduler.CronTrigger; 021 import com.liferay.portal.kernel.scheduler.SchedulerEngineUtil; 022 import com.liferay.portal.kernel.scheduler.StorageType; 023 import com.liferay.portal.kernel.scheduler.Trigger; 024 import com.liferay.portal.kernel.util.GetterUtil; 025 import com.liferay.portal.kernel.util.LocaleUtil; 026 import com.liferay.portal.kernel.util.StringPool; 027 import com.liferay.portal.kernel.util.Validator; 028 import com.liferay.portal.kernel.uuid.PortalUUIDUtil; 029 import com.liferay.portal.messaging.LayoutsLocalPublisherRequest; 030 import com.liferay.portal.messaging.LayoutsRemotePublisherRequest; 031 import com.liferay.portal.model.Group; 032 import com.liferay.portal.model.Layout; 033 import com.liferay.portal.model.LayoutConstants; 034 import com.liferay.portal.model.LayoutReference; 035 import com.liferay.portal.model.LayoutTypePortlet; 036 import com.liferay.portal.model.Plugin; 037 import com.liferay.portal.security.permission.ActionKeys; 038 import com.liferay.portal.security.permission.PermissionChecker; 039 import com.liferay.portal.service.ServiceContext; 040 import com.liferay.portal.service.base.LayoutServiceBaseImpl; 041 import com.liferay.portal.service.permission.GroupPermissionUtil; 042 import com.liferay.portal.service.permission.LayoutPermissionUtil; 043 import com.liferay.portlet.PortletPreferencesFactoryUtil; 044 045 import java.io.File; 046 import java.io.InputStream; 047 048 import java.util.ArrayList; 049 import java.util.Date; 050 import java.util.HashMap; 051 import java.util.List; 052 import java.util.Locale; 053 import java.util.Map; 054 055 /** 056 * The implementation of the layout service. 057 * 058 * @author Brian Wing Shun Chan 059 * @author Wesley Gong 060 */ 061 public class LayoutServiceImpl extends LayoutServiceBaseImpl { 062 063 /** 064 * Adds a layout with additional parameters. 065 * 066 * <p> 067 * This method handles the creation of the layout including its resources, 068 * metadata, and internal data structures. It is not necessary to make 069 * subsequent calls to any methods to setup default groups, resources, ... 070 * etc. 071 * </p> 072 * 073 * @param groupId the primary key of the group 074 * @param privateLayout whether the layout is private to the group 075 * @param parentLayoutId the primary key of the parent layout (optionally 076 * {@link 077 * com.liferay.portal.model.LayoutConstants#DEFAULT_PARENT_LAYOUT_ID}) 078 * @param localeNamesMap the layout's locales and localized names 079 * @param localeTitlesMap the layout's locales and localized titles 080 * @param descriptionMap the layout's locales and localized descriptions 081 * @param keywordsMap the layout's locales and localized keywords 082 * @param robotsMap the layout's locales and localized robots 083 * @param type the layout's type (optionally {@link 084 * com.liferay.portal.model.LayoutConstants#TYPE_PORTLET}). The 085 * possible types can be found in {@link 086 * com.liferay.portal.model.LayoutConstants}. 087 * @param hidden whether the layout is hidden 088 * @param friendlyURL the layout's friendly URL (optionally {@link 089 * com.liferay.portal.util.PropsValues#DEFAULT_USER_PRIVATE_LAYOUT_FRIENDLY_URL} 090 * or {@link 091 * com.liferay.portal.util.PropsValues#DEFAULT_USER_PUBLIC_LAYOUT_FRIENDLY_URL}). 092 * The default values can be overridden in 093 * <code>portal-ext.properties</code> by specifying new values for 094 * the corresponding properties defined in {@link 095 * com.liferay.portal.util.PropsValues}. To see how the URL is 096 * normalized when accessed see {@link 097 * com.liferay.portal.kernel.util.FriendlyURLNormalizerUtil#normalize( 098 * String)}. 099 * @param locked whether the layout is locked 100 * @param serviceContext the service context. Must specify the replacement 101 * universally unique identifier and can specify the replacement 102 * create date, replacement modified date and the new expando 103 * bridge attributes. 104 * @return the layout 105 * @throws PortalException if a group with the primary key could not be 106 * found, if the group did not have permission to manage the 107 * layouts involved, or if layout values were invalid 108 * @throws SystemException if a system exception occurred 109 */ 110 public Layout addLayout( 111 long groupId, boolean privateLayout, long parentLayoutId, 112 Map<Locale, String> localeNamesMap, 113 Map<Locale, String> localeTitlesMap, 114 Map<Locale, String> descriptionMap, Map<Locale, String> keywordsMap, 115 Map<Locale, String> robotsMap, String type, boolean hidden, 116 String friendlyURL, boolean locked, ServiceContext serviceContext) 117 throws PortalException, SystemException { 118 119 PermissionChecker permissionChecker = getPermissionChecker(); 120 121 if (parentLayoutId == LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) { 122 GroupPermissionUtil.check( 123 permissionChecker, groupId, ActionKeys.ADD_LAYOUT); 124 } 125 else { 126 LayoutPermissionUtil.check( 127 permissionChecker, groupId, privateLayout, parentLayoutId, 128 ActionKeys.ADD_LAYOUT); 129 } 130 131 return layoutLocalService.addLayout( 132 getUserId(), groupId, privateLayout, parentLayoutId, localeNamesMap, 133 localeTitlesMap, descriptionMap, keywordsMap, robotsMap, type, 134 hidden, friendlyURL, locked, serviceContext); 135 } 136 137 /** 138 * Adds a layout with empty maps for descriptions, keywords, and titles , 139 * and a names map containing a mapping for the default locale as its only 140 * entry. 141 * 142 * <p> 143 * This method handles the creation of the layout including its resources, 144 * metadata, and internal data structures. It is not necessary to make 145 * subsequent calls to any methods to setup default groups, resources, ... 146 * etc. 147 * </p> 148 * 149 * @param groupId the primary key of the group 150 * @param privateLayout whether the layout is private to the group 151 * @param parentLayoutId the primary key of the parent layout (optionally 152 * {@link 153 * com.liferay.portal.model.LayoutConstants#DEFAULT_PARENT_LAYOUT_ID}) 154 * @param name Map the layout's locales and localized names 155 * @param title Map the layout's locales and localized titles 156 * @param description Map the layout's locales and localized descriptions 157 * @param type the layout's type (optionally {@link 158 * com.liferay.portal.model.LayoutConstants#TYPE_PORTLET}). The 159 * possible types can be found in {@link 160 * com.liferay.portal.model.LayoutConstants}. 161 * @param hidden whether the layout is hidden 162 * @param friendlyURL the layout's friendly URL (optionally {@link 163 * com.liferay.portal.util.PropsValues#DEFAULT_USER_PRIVATE_LAYOUT_FRIENDLY_URL} 164 * or {@link 165 * com.liferay.portal.util.PropsValues#DEFAULT_USER_PUBLIC_LAYOUT_FRIENDLY_URL}). 166 * The default values can be overridden in 167 * <code>portal-ext.properties</code> by specifying new values for 168 * the corresponding properties defined in {@link 169 * com.liferay.portal.util.PropsValues}. To see how the URL is 170 * normalized when accessed see {@link 171 * com.liferay.portal.kernel.util.FriendlyURLNormalizerUtil#normalize( 172 * String)}. 173 * @param locked whether the layout is locked 174 * @param serviceContext the service context. Must specify the replacement 175 * universally unique identifier and can specify the replacement 176 * create date, replacement modified date and the new expando 177 * bridge attributes. 178 * @return the layout 179 * @throws PortalException if a group with the primary key could not be 180 * found, if the group did not have permission to manage the 181 * layouts involved, or if layout values were invalid 182 * @throws SystemException if a system exception occurred 183 */ 184 public Layout addLayout( 185 long groupId, boolean privateLayout, long parentLayoutId, 186 String name, String title, String description, String type, 187 boolean hidden, String friendlyURL, boolean locked, 188 ServiceContext serviceContext) 189 throws PortalException, SystemException { 190 191 Map<Locale, String> localeNamesMap = new HashMap<Locale, String>(); 192 193 Locale defaultLocale = LocaleUtil.getDefault(); 194 195 localeNamesMap.put(defaultLocale, name); 196 197 return addLayout( 198 groupId, privateLayout, parentLayoutId, localeNamesMap, 199 new HashMap<Locale, String>(), new HashMap<Locale, String>(), 200 new HashMap<Locale, String>(), new HashMap<Locale, String>(), 201 type, hidden, friendlyURL, locked, serviceContext); 202 } 203 204 /** 205 * Deletes the layout with the plid, also deleting the layout's child 206 * layouts, and associated resources. 207 * 208 * @param plid the primary key of the layout 209 * @param serviceContext the service context 210 * @throws PortalException if the user did not have permission to delete 211 * the layout, if a layout with the primary key could not be found 212 * , or if some other portal exception occurred 213 * @throws SystemException if a system exception occurred 214 */ 215 public void deleteLayout(long plid, ServiceContext serviceContext) 216 throws PortalException, SystemException { 217 218 LayoutPermissionUtil.check( 219 getPermissionChecker(), plid, ActionKeys.DELETE); 220 221 layoutLocalService.deleteLayout(plid, serviceContext); 222 } 223 224 /** 225 * Deletes the layout with the primary key, also deleting the layout's 226 * child layouts, and associated resources. 227 * 228 * @param groupId the primary key of the group 229 * @param privateLayout whether the layout is private to the group 230 * @param layoutId the primary key of the layout 231 * @param serviceContext the service context 232 * @throws PortalException if the user did not have permission to delete 233 * the layout, if a matching layout could not be found , or if some 234 * other portal exception occurred 235 * @throws SystemException if a system exception occurred 236 */ 237 public void deleteLayout( 238 long groupId, boolean privateLayout, long layoutId, 239 ServiceContext serviceContext) 240 throws PortalException, SystemException { 241 242 LayoutPermissionUtil.check( 243 getPermissionChecker(), groupId, privateLayout, layoutId, 244 ActionKeys.DELETE); 245 246 layoutLocalService.deleteLayout( 247 groupId, privateLayout, layoutId, serviceContext); 248 } 249 250 /** 251 * Exports the layouts that match the primary keys and the criteria as a 252 * byte array. 253 * 254 * @param groupId the primary key of the group 255 * @param privateLayout whether the layout is private to the group 256 * @param layoutIds the primary keys of the layouts to be exported 257 * @param parameterMap the mapping of parameters indicating which 258 * information to export. For information on the keys used in the 259 * map see {@link 260 * com.liferay.portal.kernel.lar.PortletDataHandlerKeys}. 261 * @param startDate the export's start date 262 * @param endDate the export's end date 263 * @return the layouts as a byte array 264 * @throws PortalException if a group or any layout with the primary key 265 * could not be found, if the group did not have permission to 266 * manage the layouts, or if some other portal exception occurred 267 * @throws SystemException if a system exception occurred 268 */ 269 public byte[] exportLayouts( 270 long groupId, boolean privateLayout, long[] layoutIds, 271 Map<String, String[]> parameterMap, Date startDate, Date endDate) 272 throws PortalException, SystemException { 273 274 GroupPermissionUtil.check( 275 getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS); 276 277 return layoutLocalService.exportLayouts( 278 groupId, privateLayout, layoutIds, parameterMap, startDate, 279 endDate); 280 } 281 282 /** 283 * Exports all layouts that match the criteria as a byte array. 284 * 285 * @param groupId the primary key of the group 286 * @param privateLayout whether the layout is private to the group 287 * @param parameterMap the mapping of parameters indicating which 288 * information to export. For information on the keys used in the 289 * map see {@link 290 * com.liferay.portal.kernel.lar.PortletDataHandlerKeys}. 291 * @param startDate the export's start date 292 * @param endDate the export's end date 293 * @return the layout as a byte array 294 * @throws PortalException if a group with the primary key could not be 295 * found, if the group did not have permission to manage the 296 * layouts, or if some other portal exception occurred 297 * @throws SystemException if a system exception occurred 298 */ 299 public byte[] exportLayouts( 300 long groupId, boolean privateLayout, 301 Map<String, String[]> parameterMap, Date startDate, Date endDate) 302 throws PortalException, SystemException { 303 304 GroupPermissionUtil.check( 305 getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS); 306 307 return layoutLocalService.exportLayouts( 308 groupId, privateLayout, parameterMap, startDate, endDate); 309 } 310 311 /** 312 * Exports all layouts that match the primary keys and criteria as a file. 313 * 314 * @param groupId the primary key of the group 315 * @param privateLayout whether the layout is private to the group 316 * @param layoutIds the primary keys of the layouts to be exported 317 * (optionally <code>null</code>) 318 * @param parameterMap the mapping of parameters indicating which 319 * information to export. For information on the keys used in the 320 * map see {@link 321 * com.liferay.portal.kernel.lar.PortletDataHandlerKeys}. 322 * @param startDate the export's start date 323 * @param endDate the export's end date 324 * @return the layouts as a File 325 * @throws PortalException if a group or any layout with the primary key 326 * could not be found, it the group did not have permission to 327 * manage the layouts, or if some other portal exception occurred 328 * @throws SystemException if a system exception occurred 329 */ 330 public File exportLayoutsAsFile( 331 long groupId, boolean privateLayout, long[] layoutIds, 332 Map<String, String[]> parameterMap, Date startDate, Date endDate) 333 throws PortalException, SystemException { 334 335 GroupPermissionUtil.check( 336 getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS); 337 338 return layoutLocalService.exportLayoutsAsFile( 339 groupId, privateLayout, layoutIds, parameterMap, startDate, 340 endDate); 341 } 342 343 /** 344 * Exports the portlet information (categories, permissions, ... etc.) as a 345 * byte array. 346 * 347 * @param plid the primary key of the layout 348 * @param groupId the primary key of the group 349 * @param portletId the primary key of the portlet 350 * @param parameterMap the mapping of parameters indicating which 351 * information to export. For information on the keys used in the 352 * map see {@link 353 * com.liferay.portal.kernel.lar.PortletDataHandlerKeys}. 354 * @param startDate the export's start date 355 * @param endDate the export's end date 356 * @return the portlet information as a byte array 357 * @throws PortalException if a layout, group, or portlet with the primary 358 * key could not be found, if the group did not have permission to 359 * manage the layouts involved, or if some other portal exception 360 * occurred 361 * @throws SystemException if a system exception occurred 362 */ 363 public byte[] exportPortletInfo( 364 long plid, long groupId, String portletId, 365 Map<String, String[]> parameterMap, Date startDate, Date endDate) 366 throws PortalException, SystemException { 367 368 Layout layout = layoutLocalService.getLayout(plid); 369 370 GroupPermissionUtil.check( 371 getPermissionChecker(), layout.getGroupId(), 372 ActionKeys.EXPORT_IMPORT_PORTLET_INFO); 373 374 return layoutLocalService.exportPortletInfo( 375 plid, groupId, portletId, parameterMap, startDate, endDate); 376 } 377 378 /** 379 * Exports the portlet information (categories, permissions, ... etc.) as a 380 * file. 381 * 382 * @param plid the primary key of the layout 383 * @param groupId the primary key of the group 384 * @param portletId the primary key of the portlet 385 * @param parameterMap the mapping of parameters indicating which 386 * information to export. For information on the keys used in the 387 * map see {@link 388 * com.liferay.portal.kernel.lar.PortletDataHandlerKeys}. 389 * @param startDate the export's start date 390 * @param endDate the export's end date 391 * @return the portlet information as a file 392 * @throws PortalException if a layout, group, or portlet with the primary 393 * key could not be found, it the group did not have permission to 394 * manage the layouts involved, or if some other portal exception 395 * occurred 396 * @throws SystemException if a system exception occurred 397 */ 398 public File exportPortletInfoAsFile( 399 long plid, long groupId, String portletId, 400 Map<String, String[]> parameterMap, Date startDate, Date endDate) 401 throws PortalException, SystemException { 402 403 Layout layout = layoutLocalService.getLayout(plid); 404 405 GroupPermissionUtil.check( 406 getPermissionChecker(), layout.getGroupId(), 407 ActionKeys.EXPORT_IMPORT_PORTLET_INFO); 408 409 return layoutLocalService.exportPortletInfoAsFile( 410 plid, groupId, portletId, parameterMap, startDate, endDate); 411 } 412 413 /** 414 * Returns the primary key of the default layout for the group. 415 * 416 * @param groupId the primary key of the group 417 * @param scopeGroupId the primary key of the scope group. See {@link 418 * ServiceContext#getScopeGroupId()}. 419 * @param privateLayout whether the layout is private to the group 420 * @param portletId the primary key of the portlet 421 * @return Returns the primary key of the default layout group; {@link 422 * com.liferay.portal.model.LayoutConstants#DEFAULT_PLID} otherwise 423 * @throws PortalException if a group, layout, or portlet with the primary 424 * key could not be found 425 * @throws SystemException if a system exception occurred 426 */ 427 public long getDefaultPlid( 428 long groupId, long scopeGroupId, boolean privateLayout, 429 String portletId) 430 throws PortalException, SystemException { 431 432 if (groupId <= 0) { 433 return LayoutConstants.DEFAULT_PLID; 434 } 435 436 PermissionChecker permissionChecker = getPermissionChecker(); 437 438 String scopeGroupLayoutUuid = null; 439 440 Group scopeGroup = groupLocalService.getGroup(scopeGroupId); 441 442 if (scopeGroup.isLayout()) { 443 Layout scopeGroupLayout = layoutLocalService.getLayout( 444 scopeGroup.getClassPK()); 445 446 scopeGroupLayoutUuid = scopeGroupLayout.getUuid(); 447 } 448 449 List<Layout> layouts = new ArrayList<Layout>(); 450 451 layouts.addAll( 452 layoutPersistence.filterFindByG_P(groupId, privateLayout)); 453 layouts.addAll( 454 layoutPersistence.filterFindByG_P(scopeGroupId, privateLayout)); 455 456 for (Layout layout : layouts) { 457 if (!LayoutPermissionUtil.contains( 458 permissionChecker, layout, ActionKeys.VIEW)) { 459 460 continue; 461 } 462 463 if (!layout.isTypePortlet()) { 464 continue; 465 } 466 467 LayoutTypePortlet layoutTypePortlet = 468 (LayoutTypePortlet)layout.getLayoutType(); 469 470 if (!layoutTypePortlet.hasPortletId(portletId)) { 471 continue; 472 } 473 474 javax.portlet.PortletPreferences jxPreferences = 475 PortletPreferencesFactoryUtil.getLayoutPortletSetup( 476 layout, portletId); 477 478 String scopeType = GetterUtil.getString( 479 jxPreferences.getValue("lfrScopeType", null)); 480 481 if (scopeGroup.isLayout()) { 482 String scopeLayoutUuid = GetterUtil.getString( 483 jxPreferences.getValue("lfrScopeLayoutUuid", null)); 484 485 if (Validator.isNotNull(scopeType) && 486 Validator.isNotNull(scopeLayoutUuid) && 487 scopeLayoutUuid.equals(scopeGroupLayoutUuid)) { 488 489 return layout.getPlid(); 490 } 491 } 492 else if (scopeGroup.isCompany()) { 493 if (Validator.isNotNull(scopeType) && 494 scopeType.equals("company")) { 495 496 return layout.getPlid(); 497 } 498 } 499 else { 500 if (Validator.isNull(scopeType)) { 501 return layout.getPlid(); 502 } 503 } 504 } 505 506 return LayoutConstants.DEFAULT_PLID; 507 } 508 509 /** 510 * Returns the name of the layout. 511 * 512 * @param groupId the primary key of the group 513 * @param privateLayout whether the layout is private to the group 514 * @param layoutId the primary key of the layout 515 * @param languageId the primary key of the language. For more information 516 * See {@link java.util.Locale}. 517 * @return the layout's name 518 * @throws PortalException if a matching layout could not be found 519 * @throws SystemException if a system exception occurred 520 */ 521 public String getLayoutName( 522 long groupId, boolean privateLayout, long layoutId, 523 String languageId) 524 throws PortalException, SystemException { 525 526 Layout layout = layoutLocalService.getLayout( 527 groupId, privateLayout, layoutId); 528 529 return layout.getName(languageId); 530 } 531 532 /** 533 * Returns the layout references for all the layouts that belong to the 534 * company and belong to the portlet that matches the preferences. 535 * 536 * @param companyId the primary key of the company 537 * @param portletId the primary key of the portlet 538 * @param preferencesKey the portlet's preference key 539 * @param preferencesValue the portlet's preference value 540 * @return the layout references of the matching layouts 541 * @throws SystemException if a system exception occurred 542 */ 543 public LayoutReference[] getLayoutReferences( 544 long companyId, String portletId, String preferencesKey, 545 String preferencesValue) 546 throws SystemException { 547 548 return layoutLocalService.getLayouts( 549 companyId, portletId, preferencesKey, preferencesValue); 550 } 551 552 /** 553 * Imports the layouts from the byte array. 554 * 555 * @param groupId the primary key of the group 556 * @param privateLayout whether the layout is private to the group 557 * @param parameterMap the mapping of parameters indicating which 558 * information will be imported. For information on the keys used 559 * in the map see {@link 560 * com.liferay.portal.kernel.lar.PortletDataHandlerKeys}. 561 * @param bytes the byte array with the data 562 * @throws PortalException if a group with the primary key could not be 563 * found, if the group did not have permission to manage the 564 * layouts, or if some other portal exception occurred 565 * @throws SystemException if a system exception occurred 566 * @see com.liferay.portal.lar.LayoutImporter 567 */ 568 public void importLayouts( 569 long groupId, boolean privateLayout, 570 Map<String, String[]> parameterMap, byte[] bytes) 571 throws PortalException, SystemException { 572 573 GroupPermissionUtil.check( 574 getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS); 575 576 layoutLocalService.importLayouts( 577 getUserId(), groupId, privateLayout, parameterMap, bytes); 578 } 579 580 /** 581 * Imports the layouts from the file. 582 * 583 * @param groupId the primary key of the group 584 * @param privateLayout whether the layout is private to the group 585 * @param parameterMap the mapping of parameters indicating which 586 * information will be imported. For information on the keys used 587 * in the map see {@link 588 * com.liferay.portal.kernel.lar.PortletDataHandlerKeys}. 589 * @param file the LAR file with the data 590 * @throws PortalException if a group with the primary key could not be 591 * found, if the group did not have permission to manage the 592 * layouts and publish, or if some other portal exception occurred 593 * @throws SystemException if a system exception occurred 594 * @see com.liferay.portal.lar.LayoutImporter 595 */ 596 public void importLayouts( 597 long groupId, boolean privateLayout, 598 Map<String, String[]> parameterMap, File file) 599 throws PortalException, SystemException { 600 601 GroupPermissionUtil.check( 602 getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS); 603 604 layoutLocalService.importLayouts( 605 getUserId(), groupId, privateLayout, parameterMap, file); 606 } 607 608 /** 609 * Imports the layouts from the input stream. 610 * 611 * @param groupId the primary key of the group 612 * @param privateLayout whether the layout is private to the group 613 * @param parameterMap the mapping of parameters indicating which 614 * information will be imported. For information on the keys used 615 * in the map see {@link 616 * com.liferay.portal.kernel.lar.PortletDataHandlerKeys}. 617 * @param is the input stream 618 * @throws PortalException if a group with the primary key could not be 619 * found, if the group did not have permission to manage the 620 * layouts, or if some other portal exception occurred 621 * @throws SystemException if a system exception occurred 622 * @see com.liferay.portal.lar.LayoutImporter 623 */ 624 public void importLayouts( 625 long groupId, boolean privateLayout, 626 Map<String, String[]> parameterMap, InputStream is) 627 throws PortalException, SystemException { 628 629 GroupPermissionUtil.check( 630 getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS); 631 632 layoutLocalService.importLayouts( 633 getUserId(), groupId, privateLayout, parameterMap, is); 634 } 635 636 /** 637 * Imports the portlet information (categories, permissions, ... etc.) from 638 * the file. 639 * 640 * @param plid the primary key of the layout 641 * @param groupId the primary key of the group 642 * @param portletId the primary key of the portlet 643 * @param parameterMap the mapping of parameters indicating which 644 * information will be imported. For information on the keys used 645 * in the map see {@link 646 * com.liferay.portal.kernel.lar.PortletDataHandlerKeys}. 647 * @param file the LAR file with the data 648 * @throws PortalException if a group, layout, or portlet with the primary 649 * key could not be found, or if the group did not have permission 650 * to manage the layouts 651 * @throws SystemException if a system exception occurred 652 */ 653 public void importPortletInfo( 654 long plid, long groupId, String portletId, 655 Map<String, String[]> parameterMap, File file) 656 throws PortalException, SystemException { 657 658 GroupPermissionUtil.check( 659 getPermissionChecker(), groupId, 660 ActionKeys.EXPORT_IMPORT_PORTLET_INFO); 661 662 layoutLocalService.importPortletInfo( 663 getUserId(), plid, groupId, portletId, parameterMap, file); 664 } 665 666 /** 667 * Imports the portlet information (categories, permissions, ... etc.) from 668 * the input stream. 669 * 670 * @param plid the primary key of the layout 671 * @param groupId the primary key of the group 672 * @param portletId the primary key of the portlet 673 * @param parameterMap the mapping of parameters indicating which 674 * information will be imported. For information on the keys used 675 * in the map see {@link 676 * com.liferay.portal.kernel.lar.PortletDataHandlerKeys}. 677 * @param is the input stream 678 * @throws PortalException if a group, portlet, or layout with the primary 679 * key could not be found or if the group did not have permission 680 * to manage the layouts 681 * @throws SystemException if a system exception occurred 682 */ 683 public void importPortletInfo( 684 long plid, long groupId, String portletId, 685 Map<String, String[]> parameterMap, InputStream is) 686 throws PortalException, SystemException { 687 688 GroupPermissionUtil.check( 689 getPermissionChecker(), groupId, 690 ActionKeys.EXPORT_IMPORT_PORTLET_INFO); 691 692 layoutLocalService.importPortletInfo( 693 getUserId(), plid, groupId, portletId, parameterMap, is); 694 } 695 696 /** 697 * Schedules a range of layouts to be published. 698 * 699 * @param sourceGroupId the primary key of the source group 700 * @param targetGroupId the primary key of the target group 701 * @param privateLayout whether the layout is private to the group 702 * @param layoutIdMap the layouts considered for publishing, specified by 703 * the layout IDs and booleans indicating whether they have 704 * children 705 * @param parameterMap the mapping of parameters indicating which 706 * information will be used. See {@link 707 * com.liferay.portal.kernel.lar.PortletDataHandlerKeys} 708 * @param scope the scope of the pages. It can be <code>all-pages</code> 709 * or <code>selected-pages</code>. 710 * @param startDate the start date 711 * @param endDate the end date 712 * @param groupName the group name (optionally {@link 713 * com.liferay.portal.kernel.messaging.DestinationNames#LAYOUTS_LOCAL_PUBLISHER}). 714 * See {@link 715 * com.liferay.portal.kernel.messaging.DestinationNames}. 716 * @param cronText the cron text. See {@link 717 * com.liferay.portal.kernel.cal.RecurrenceSerializer #toCronText} 718 * @param schedulerStartDate the scheduler start date 719 * @param schedulerEndDate the scheduler end date 720 * @param description the scheduler description 721 * @throws PortalException if the group did not have permission to manage 722 * and publish 723 * @throws SystemException if a system exception occurred 724 */ 725 public void schedulePublishToLive( 726 long sourceGroupId, long targetGroupId, boolean privateLayout, 727 Map<Long, Boolean> layoutIdMap, Map<String, String[]> parameterMap, 728 String scope, Date startDate, Date endDate, String groupName, 729 String cronText, Date schedulerStartDate, Date schedulerEndDate, 730 String description) 731 throws PortalException, SystemException { 732 733 GroupPermissionUtil.check( 734 getPermissionChecker(), targetGroupId, ActionKeys.PUBLISH_STAGING); 735 736 String jobName = PortalUUIDUtil.generate(); 737 738 Trigger trigger = new CronTrigger( 739 jobName, groupName, schedulerStartDate, schedulerEndDate, 740 cronText); 741 742 String command = StringPool.BLANK; 743 744 if (scope.equals("all-pages")) { 745 command = LayoutsLocalPublisherRequest.COMMAND_ALL_PAGES; 746 } 747 else if (scope.equals("selected-pages")) { 748 command = LayoutsLocalPublisherRequest.COMMAND_SELECTED_PAGES; 749 } 750 751 LayoutsLocalPublisherRequest publisherRequest = 752 new LayoutsLocalPublisherRequest( 753 command, getUserId(), sourceGroupId, targetGroupId, 754 privateLayout, layoutIdMap, parameterMap, startDate, endDate); 755 756 SchedulerEngineUtil.schedule( 757 trigger, StorageType.PERSISTED, description, 758 DestinationNames.LAYOUTS_LOCAL_PUBLISHER, publisherRequest, 0); 759 } 760 761 /** 762 * Schedules a range of layouts to be stored. 763 * 764 * @param sourceGroupId the primary key of the source group 765 * @param privateLayout whether the layout is private to the group 766 * @param layoutIdMap the layouts considered for publishing, specified by 767 * the layout IDs and booleans indicating whether they have 768 * children 769 * @param parameterMap the mapping of parameters indicating which 770 * information will be used. See {@link 771 * com.liferay.portal.kernel.lar.PortletDataHandlerKeys} 772 * @param remoteAddress the remote address 773 * @param remotePort the remote port 774 * @param secureConnection whether the connection is secure 775 * @param remoteGroupId the primary key of the remote group 776 * @param remotePrivateLayout whether remote group's layout is private 777 * @param startDate the start date 778 * @param endDate the end date 779 * @param groupName the group name. Optionally {@link 780 * com.liferay.portal.kernel.messaging.DestinationNames#LAYOUTS_LOCAL_PUBLISHER}). 781 * See {@link 782 * com.liferay.portal.kernel.messaging.DestinationNames}. 783 * @param cronText the cron text. See {@link 784 * com.liferay.portal.kernel.cal.RecurrenceSerializer #toCronText} 785 * @param schedulerStartDate the scheduler start date 786 * @param schedulerEndDate the scheduler end date 787 * @param description the scheduler description 788 * @throws PortalException if a group with the source group primary key was 789 * not found or if the group did not have permission to publish 790 * @throws SystemException if a system exception occurred 791 */ 792 public void schedulePublishToRemote( 793 long sourceGroupId, boolean privateLayout, 794 Map<Long, Boolean> layoutIdMap, 795 Map<String, String[]> parameterMap, String remoteAddress, 796 int remotePort, boolean secureConnection, long remoteGroupId, 797 boolean remotePrivateLayout, Date startDate, Date endDate, 798 String groupName, String cronText, Date schedulerStartDate, 799 Date schedulerEndDate, String description) 800 throws PortalException, SystemException { 801 802 GroupPermissionUtil.check( 803 getPermissionChecker(), sourceGroupId, ActionKeys.PUBLISH_STAGING); 804 805 LayoutsRemotePublisherRequest publisherRequest = 806 new LayoutsRemotePublisherRequest( 807 getUserId(), sourceGroupId, privateLayout, layoutIdMap, 808 parameterMap, remoteAddress, remotePort, secureConnection, 809 remoteGroupId, remotePrivateLayout, startDate, endDate); 810 811 String jobName = PortalUUIDUtil.generate(); 812 813 Trigger trigger = new CronTrigger( 814 jobName, groupName, schedulerStartDate, schedulerEndDate, cronText); 815 816 SchedulerEngineUtil.schedule( 817 trigger, StorageType.PERSISTED, description, 818 DestinationNames.LAYOUTS_REMOTE_PUBLISHER, publisherRequest, 0); 819 } 820 821 /** 822 * Sets the layouts for the group, replacing and prioritizing all layouts 823 * of the parent layout. 824 * 825 * @param groupId the primary key of the group 826 * @param privateLayout whether the layout is private to the group 827 * @param parentLayoutId the primary key of the parent layout 828 * @param layoutIds the primary keys of the layouts 829 * @param serviceContext the service context 830 * @throws PortalException if a group or layout with the primary key could 831 * not be found, if the group did not have permission to manage the 832 * layouts, if no layouts were specified, if the first layout was 833 * not page-able, if the first layout was hidden, or if some other 834 * portal exception occurred 835 * @throws SystemException if a system exception occurred 836 */ 837 public void setLayouts( 838 long groupId, boolean privateLayout, long parentLayoutId, 839 long[] layoutIds, ServiceContext serviceContext) 840 throws PortalException, SystemException { 841 842 GroupPermissionUtil.check( 843 getPermissionChecker(), groupId, ActionKeys.UPDATE); 844 845 layoutLocalService.setLayouts( 846 groupId, privateLayout, parentLayoutId, layoutIds, serviceContext); 847 } 848 849 /** 850 * Deletes the job from the scheduler's queue. 851 * 852 * @param groupId the primary key of the group 853 * @param jobName the job name 854 * @param groupName the group name (optionally {@link 855 * com.liferay.portal.kernel.messaging.DestinationNames#LAYOUTS_LOCAL_PUBLISHER}). 856 * See {@link 857 * com.liferay.portal.kernel.messaging.DestinationNames}. 858 * @throws PortalException if the group did not permission to manage 859 * staging and publish 860 * @throws SystemException if a system exception occurred 861 */ 862 public void unschedulePublishToLive( 863 long groupId, String jobName, String groupName) 864 throws PortalException, SystemException { 865 866 GroupPermissionUtil.check( 867 getPermissionChecker(), groupId, ActionKeys.PUBLISH_STAGING); 868 869 SchedulerEngineUtil.delete(jobName, groupName, StorageType.PERSISTED); 870 } 871 872 /** 873 * Deletes the job from the scheduler's persistent queue. 874 * 875 * @param groupId the primary key of the group 876 * @param jobName the job name 877 * @param groupName the group name (optionally {@link 878 * com.liferay.portal.kernel.messaging.DestinationNames#LAYOUTS_LOCAL_PUBLISHER}). 879 * See {@link 880 * com.liferay.portal.kernel.messaging.DestinationNames}. 881 * @throws PortalException if a group with the primary key could not be 882 * found or if the group did not have permission to publish 883 * @throws SystemException if a system exception occurred 884 */ 885 public void unschedulePublishToRemote( 886 long groupId, String jobName, String groupName) 887 throws PortalException, SystemException { 888 889 GroupPermissionUtil.check( 890 getPermissionChecker(), groupId, ActionKeys.PUBLISH_STAGING); 891 892 SchedulerEngineUtil.delete(jobName, groupName, StorageType.PERSISTED); 893 } 894 895 /** 896 * Updates the layout. 897 * 898 * @param groupId the primary key of the group 899 * @param privateLayout whether the layout is private to the group 900 * @param layoutId the primary key of the layout 901 * @param parentLayoutId the primary key of the layout's new parent layout 902 * @param localeNamesMap the layout's locales and localized names 903 * @param localeTitlesMap the layout's locales and localized titles 904 * @param descriptionMap the locales and localized descriptions to merge 905 * (optionally <code>null</code>) 906 * @param keywordsMap the locales and localized keywords to merge 907 * (optionally <code>null</code>) 908 * @param robotsMap the locales and localized robots to merge (optionally 909 * <code>null</code>) 910 * @param type the layout's new type (optionally {@link 911 * com.liferay.portal.model.LayoutConstants#TYPE_PORTLET}) 912 * @param hidden whether the layout is hidden 913 * @param friendlyURL the layout's new friendly URL (optionally {@link 914 * com.liferay.portal.util.PropsValues#DEFAULT_USER_PRIVATE_LAYOUT_FRIENDLY_URL} 915 * or {@link 916 * com.liferay.portal.util.PropsValues#DEFAULT_USER_PRIVATE_LAYOUT_FRIENDLY_URL}). 917 * The default values can be overridden in 918 * <code>portal-ext.properties</code> by specifying new values for 919 * the corresponding properties defined in {@link 920 * com.liferay.portal.util.PropsValues}. To see how the URL is 921 * normalized when accessed see {@link 922 * com.liferay.portal.kernel.util.FriendlyURLNormalizerUtil#normalize( 923 * String)}. 924 * @param iconImage whether the icon image will be updated 925 * @param iconBytes the byte array of the layout's new icon image 926 * @param locked whether the layout is locked 927 * @param serviceContext the service context. Can specify the replacement 928 * modified date and new expando bridge attributes. 929 * @return the updated layout 930 * @throws PortalException if a group or layout with the primary key could 931 * not be found, if the user did not have permission to update the 932 * layout, if a unique friendly URL could not be generated, if a 933 * valid parent layout ID to use could not be found, or if the 934 * layout parameters were invalid 935 * @throws SystemException if a system exception occurred 936 */ 937 public Layout updateLayout( 938 long groupId, boolean privateLayout, long layoutId, 939 long parentLayoutId, Map<Locale, String> localeNamesMap, 940 Map<Locale, String> localeTitlesMap, 941 Map<Locale, String> descriptionMap, Map<Locale, String> keywordsMap, 942 Map<Locale, String> robotsMap, String type, boolean hidden, 943 String friendlyURL, Boolean iconImage, byte[] iconBytes, 944 boolean locked, ServiceContext serviceContext) 945 throws PortalException, SystemException { 946 947 LayoutPermissionUtil.check( 948 getPermissionChecker(), groupId, privateLayout, layoutId, 949 ActionKeys.UPDATE); 950 951 return layoutLocalService.updateLayout( 952 groupId, privateLayout, layoutId, parentLayoutId, localeNamesMap, 953 localeTitlesMap, descriptionMap, keywordsMap, robotsMap, type, 954 hidden, friendlyURL, iconImage, iconBytes, locked, serviceContext); 955 } 956 957 /** 958 * Updates the layout replacing its type settings. 959 * 960 * @param groupId the primary key of the group 961 * @param privateLayout whether the layout is private to the group 962 * @param layoutId the primary key of the layout 963 * @param typeSettings the settings to load the unicode properties object. 964 * See {@link com.liferay.portal.kernel.util.UnicodeProperties 965 * #fastLoad(String)}. 966 * @return the updated layout 967 * @throws PortalException if a matching layout could not be found or if 968 * the user did not have permission to update the layout 969 * @throws SystemException if a system exception occurred 970 */ 971 public Layout updateLayout( 972 long groupId, boolean privateLayout, long layoutId, 973 String typeSettings) 974 throws PortalException, SystemException { 975 976 LayoutPermissionUtil.check( 977 getPermissionChecker(), groupId, privateLayout, layoutId, 978 ActionKeys.UPDATE); 979 980 return layoutLocalService.updateLayout( 981 groupId, privateLayout, layoutId, typeSettings); 982 } 983 984 /** 985 * Updates the look and feel of the layout. 986 * 987 * @param groupId the primary key of the group 988 * @param privateLayout whether the layout is private to the group 989 * @param layoutId the primary key of the layout 990 * @param themeId the primary key of the layout's new theme 991 * @param colorSchemeId the primary key of the layout's new color scheme 992 * @param css the layout's new CSS 993 * @param wapTheme whether the theme is for WAP browsers 994 * @return the updated layout 995 * @throws PortalException if a matching layout could not be found, or if 996 * the user did not have permission to update the layout and 997 * permission to apply the theme 998 * @throws SystemException if a system exception occurred 999 */ 1000 public Layout updateLookAndFeel( 1001 long groupId, boolean privateLayout, long layoutId, String themeId, 1002 String colorSchemeId, String css, boolean wapTheme) 1003 throws PortalException, SystemException { 1004 1005 LayoutPermissionUtil.check( 1006 getPermissionChecker(), groupId, privateLayout, layoutId, 1007 ActionKeys.UPDATE); 1008 1009 pluginSettingLocalService.checkPermission( 1010 getUserId(), themeId, Plugin.TYPE_THEME); 1011 1012 return layoutLocalService.updateLookAndFeel( 1013 groupId, privateLayout, layoutId, themeId, colorSchemeId, css, 1014 wapTheme); 1015 } 1016 1017 /** 1018 * Updates the name of the layout matching the group, layout ID, and 1019 * privacy. 1020 * 1021 * @param groupId the primary key of the group 1022 * @param privateLayout whether the layout is private to the group 1023 * @param layoutId the primary key of the layout 1024 * @param name the layout's new name 1025 * @param languageId the primary key of the language. For more information 1026 * see {@link java.util.Locale}. 1027 * @return the updated layout 1028 * @throws PortalException if a matching layout could not be found, if the 1029 * user did not have permission to update the layout, or if the new 1030 * name was <code>null</code> 1031 * @throws SystemException if a system exception occurred 1032 */ 1033 public Layout updateName( 1034 long groupId, boolean privateLayout, long layoutId, String name, 1035 String languageId) 1036 throws PortalException, SystemException { 1037 1038 LayoutPermissionUtil.check( 1039 getPermissionChecker(), groupId, privateLayout, layoutId, 1040 ActionKeys.UPDATE); 1041 1042 return layoutLocalService.updateName( 1043 groupId, privateLayout, layoutId, name, languageId); 1044 } 1045 1046 /** 1047 * Updates the name of the layout matching the primary key. 1048 * 1049 * @param plid the primary key of the layout 1050 * @param name the name to be assigned 1051 * @param languageId the primary key of the language. For more information 1052 * see {@link java.util.Locale}. 1053 * @return the updated layout 1054 * @throws PortalException if a layout with the primary key could not be 1055 * found, or if the user did not have permission to update the 1056 * layout, or if the name was <code>null</code> 1057 * @throws SystemException if a system exception occurred 1058 */ 1059 public Layout updateName(long plid, String name, String languageId) 1060 throws PortalException, SystemException { 1061 1062 LayoutPermissionUtil.check( 1063 getPermissionChecker(), plid, ActionKeys.UPDATE); 1064 1065 return layoutLocalService.updateName(plid, name, languageId); 1066 } 1067 1068 /** 1069 * Updates the parent layout ID of the layout matching the group, layout 1070 * ID, and privacy. 1071 * 1072 * @param groupId the primary key of the group 1073 * @param privateLayout whether the layout is private to the group 1074 * @param layoutId the primary key of the layout 1075 * @param parentLayoutId the primary key to be assigned to the parent 1076 * layout 1077 * @return the matching layout 1078 * @throws PortalException if a valid parent layout ID to use could not be 1079 * found, if a matching layout could not be found, or if the user 1080 * did not have permission to update the layout 1081 * @throws SystemException if a system exception occurred 1082 */ 1083 public Layout updateParentLayoutId( 1084 long groupId, boolean privateLayout, long layoutId, 1085 long parentLayoutId) 1086 throws PortalException, SystemException { 1087 1088 LayoutPermissionUtil.check( 1089 getPermissionChecker(), groupId, privateLayout, layoutId, 1090 ActionKeys.UPDATE); 1091 1092 return layoutLocalService.updateParentLayoutId( 1093 groupId, privateLayout, layoutId, parentLayoutId); 1094 } 1095 1096 /** 1097 * Updates the parent layout ID of the layout matching the primary key. If 1098 * a layout matching the parent primary key is found, the layout ID of that 1099 * layout is assigned, otherwise {@link 1100 * com.liferay.portal.model.LayoutConstants#DEFAULT_PARENT_LAYOUT_ID} is 1101 * assigned. 1102 * 1103 * @param plid the primary key of the layout 1104 * @param parentPlid the primary key of the parent layout 1105 * @return the layout matching the primary key 1106 * @throws PortalException if a layout with the primary key could not be 1107 * found, if the user did not have permission to update the layout, 1108 * or if a valid parent layout ID to use could not be found 1109 * @throws SystemException if a system exception occurred 1110 */ 1111 public Layout updateParentLayoutId(long plid, long parentPlid) 1112 throws PortalException, SystemException { 1113 1114 LayoutPermissionUtil.check( 1115 getPermissionChecker(), plid, ActionKeys.UPDATE); 1116 1117 return layoutLocalService.updateParentLayoutId(plid, parentPlid); 1118 } 1119 1120 /** 1121 * Updates the priority of the layout matching the group, layout ID, and 1122 * privacy. 1123 * 1124 * @param groupId the primary key of the group 1125 * @param privateLayout whether the layout is private to the group 1126 * @param layoutId the primary key of the layout 1127 * @param priority the layout's new priority 1128 * @return the updated layout 1129 * @throws PortalException if a matching layout could not be found or if 1130 * the user did not have permission to update the layout 1131 * @throws SystemException if a system exception occurred 1132 */ 1133 public Layout updatePriority( 1134 long groupId, boolean privateLayout, long layoutId, int priority) 1135 throws PortalException, SystemException { 1136 1137 LayoutPermissionUtil.check( 1138 getPermissionChecker(), groupId, privateLayout, layoutId, 1139 ActionKeys.UPDATE); 1140 1141 return layoutLocalService.updatePriority( 1142 groupId, privateLayout, layoutId, priority); 1143 } 1144 1145 /** 1146 * Updates the priority of the layout matching the primary key. 1147 * 1148 * @param plid the primary key of the layout 1149 * @param priority the layout's new priority 1150 * @return the updated layout 1151 * @throws PortalException if a layout with the primary key could not be 1152 * found 1153 * @throws SystemException if a system exception occurred 1154 */ 1155 public Layout updatePriority(long plid, int priority) 1156 throws PortalException, SystemException { 1157 1158 LayoutPermissionUtil.check( 1159 getPermissionChecker(), plid, ActionKeys.UPDATE); 1160 1161 return layoutLocalService.updatePriority(plid, priority); 1162 } 1163 1164 }