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