001 /** 002 * Copyright (c) 2000-2011 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>(), 204 type, hidden, friendlyURL, serviceContext); 205 } 206 207 /** 208 * Deletes the layout with the plid, also deleting the layout's child 209 * layouts, and associated resources. 210 * 211 * @param plid the primary key of the layout 212 * @param serviceContext the service context 213 * @throws PortalException if the user did not have permission to delete the 214 * layout, if a layout with the primary key could not be found , or 215 * if some other portal exception occurred 216 * @throws SystemException if a system exception occurred 217 */ 218 public void deleteLayout(long plid, ServiceContext serviceContext) 219 throws PortalException, SystemException { 220 221 LayoutPermissionUtil.check( 222 getPermissionChecker(), plid, ActionKeys.DELETE); 223 224 layoutLocalService.deleteLayout(plid, serviceContext); 225 } 226 227 /** 228 * Deletes the layout with the primary key, also deleting the layout's child 229 * layouts, and associated resources. 230 * 231 * @param groupId the primary key of the group 232 * @param privateLayout whether the layout is private to the group 233 * @param layoutId the primary key of the layout 234 * @param serviceContext the service context 235 * @throws PortalException if the user did not have permission to delete the 236 * layout, if a matching layout could not be found , or if some 237 * other portal exception occurred 238 * @throws SystemException if a system exception occurred 239 */ 240 public void deleteLayout( 241 long groupId, boolean privateLayout, long layoutId, 242 ServiceContext serviceContext) 243 throws PortalException, SystemException { 244 245 LayoutPermissionUtil.check( 246 getPermissionChecker(), groupId, privateLayout, layoutId, 247 ActionKeys.DELETE); 248 249 layoutLocalService.deleteLayout( 250 groupId, privateLayout, layoutId, 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, 760 cronText); 761 762 String command = StringPool.BLANK; 763 764 if (scope.equals("all-pages")) { 765 command = LayoutsLocalPublisherRequest.COMMAND_ALL_PAGES; 766 } 767 else if (scope.equals("selected-pages")) { 768 command = LayoutsLocalPublisherRequest.COMMAND_SELECTED_PAGES; 769 } 770 771 LayoutsLocalPublisherRequest publisherRequest = 772 new LayoutsLocalPublisherRequest( 773 command, getUserId(), sourceGroupId, targetGroupId, 774 privateLayout, layoutIdMap, parameterMap, startDate, endDate); 775 776 SchedulerEngineUtil.schedule( 777 trigger, StorageType.PERSISTED, description, 778 DestinationNames.LAYOUTS_LOCAL_PUBLISHER, publisherRequest, 0); 779 } 780 781 /** 782 * Schedules a range of layouts to be stored. 783 * 784 * @param sourceGroupId the primary key of the source group 785 * @param privateLayout whether the layout is private to the group 786 * @param layoutIdMap the layouts considered for publishing, specified by 787 * the layout IDs and booleans indicating whether they have children 788 * @param parameterMap the mapping of parameters indicating which 789 * information will be used. See {@link 790 * com.liferay.portal.kernel.lar.PortletDataHandlerKeys} 791 * @param remoteAddress the remote address 792 * @param remotePort the remote port 793 * @param secureConnection whether the connection is secure 794 * @param remoteGroupId the primary key of the remote group 795 * @param remotePrivateLayout whether remote group's layout is private 796 * @param startDate the start date 797 * @param endDate the end date 798 * @param groupName the group name. Optionally {@link 799 * com.liferay.portal.kernel.messaging.DestinationNames#LAYOUTS_LOCAL_PUBLISHER}). 800 * See {@link com.liferay.portal.kernel.messaging.DestinationNames}. 801 * @param cronText the cron text. See {@link 802 * com.liferay.portal.kernel.cal.RecurrenceSerializer #toCronText} 803 * @param schedulerStartDate the scheduler start date 804 * @param schedulerEndDate the scheduler end date 805 * @param description the scheduler description 806 * @throws PortalException if a group with the source group primary key was 807 * not found or if the group did not have permission to publish 808 * @throws SystemException if a system exception occurred 809 */ 810 public void schedulePublishToRemote( 811 long sourceGroupId, boolean privateLayout, 812 Map<Long, Boolean> layoutIdMap, 813 Map<String, String[]> parameterMap, String remoteAddress, 814 int remotePort, boolean secureConnection, long remoteGroupId, 815 boolean remotePrivateLayout, Date startDate, Date endDate, 816 String groupName, String cronText, Date schedulerStartDate, 817 Date schedulerEndDate, String description) 818 throws PortalException, SystemException { 819 820 GroupPermissionUtil.check( 821 getPermissionChecker(), sourceGroupId, ActionKeys.PUBLISH_STAGING); 822 823 LayoutsRemotePublisherRequest publisherRequest = 824 new LayoutsRemotePublisherRequest( 825 getUserId(), sourceGroupId, privateLayout, layoutIdMap, 826 parameterMap, remoteAddress, remotePort, secureConnection, 827 remoteGroupId, remotePrivateLayout, startDate, endDate); 828 829 String jobName = PortalUUIDUtil.generate(); 830 831 Trigger trigger = new CronTrigger( 832 jobName, groupName, schedulerStartDate, schedulerEndDate, cronText); 833 834 SchedulerEngineUtil.schedule( 835 trigger, StorageType.PERSISTED, description, 836 DestinationNames.LAYOUTS_REMOTE_PUBLISHER, publisherRequest, 0); 837 } 838 839 /** 840 * Sets the layouts for the group, replacing and prioritizing all layouts of 841 * the parent layout. 842 * 843 * @param groupId the primary key of the group 844 * @param privateLayout whether the layout is private to the group 845 * @param parentLayoutId the primary key of the parent layout 846 * @param layoutIds the primary keys of the layouts 847 * @param serviceContext the service context 848 * @throws PortalException if a group or layout with the primary key could 849 * not be found, if the group did not have permission to manage the 850 * layouts, if no layouts were specified, if the first layout was 851 * not page-able, if the first layout was hidden, or if some other 852 * portal exception occurred 853 * @throws SystemException if a system exception occurred 854 */ 855 public void setLayouts( 856 long groupId, boolean privateLayout, long parentLayoutId, 857 long[] layoutIds, ServiceContext serviceContext) 858 throws PortalException, SystemException { 859 860 GroupPermissionUtil.check( 861 getPermissionChecker(), groupId, ActionKeys.UPDATE); 862 863 layoutLocalService.setLayouts( 864 groupId, privateLayout, parentLayoutId, layoutIds, serviceContext); 865 } 866 867 /** 868 * Deletes the job from the scheduler's queue. 869 * 870 * @param groupId the primary key of the group 871 * @param jobName the job name 872 * @param groupName the group name (optionally {@link 873 * com.liferay.portal.kernel.messaging.DestinationNames#LAYOUTS_LOCAL_PUBLISHER}). 874 * See {@link com.liferay.portal.kernel.messaging.DestinationNames}. 875 * @throws PortalException if the group did not permission to manage staging 876 * and publish 877 * @throws SystemException if a system exception occurred 878 */ 879 public void unschedulePublishToLive( 880 long groupId, String jobName, String groupName) 881 throws PortalException, SystemException { 882 883 GroupPermissionUtil.check( 884 getPermissionChecker(), groupId, ActionKeys.PUBLISH_STAGING); 885 886 SchedulerEngineUtil.delete(jobName, groupName, StorageType.PERSISTED); 887 } 888 889 /** 890 * Deletes the job from the scheduler's persistent queue. 891 * 892 * @param groupId the primary key of the group 893 * @param jobName the job name 894 * @param groupName the group name (optionally {@link 895 * com.liferay.portal.kernel.messaging.DestinationNames#LAYOUTS_LOCAL_PUBLISHER}). 896 * See {@link com.liferay.portal.kernel.messaging.DestinationNames}. 897 * @throws PortalException if a group with the primary key could not be 898 * found or if the group did not have permission to publish 899 * @throws SystemException if a system exception occurred 900 */ 901 public void unschedulePublishToRemote( 902 long groupId, String jobName, String groupName) 903 throws PortalException, SystemException { 904 905 GroupPermissionUtil.check( 906 getPermissionChecker(), groupId, ActionKeys.PUBLISH_STAGING); 907 908 SchedulerEngineUtil.delete(jobName, groupName, StorageType.PERSISTED); 909 } 910 911 /** 912 * Updates the layout. 913 * 914 * @param groupId the primary key of the group 915 * @param privateLayout whether the layout is private to the group 916 * @param layoutId the primary key of the layout 917 * @param parentLayoutId the primary key of the layout's new parent layout 918 * @param localeNamesMap the layout's locales and localized names 919 * @param localeTitlesMap the layout's locales and localized titles 920 * @param descriptionMap the locales and localized descriptions to merge 921 * (optionally <code>null</code>) 922 * @param keywordsMap the locales and localized keywords to merge 923 * (optionally <code>null</code>) 924 * @param robotsMap the locales and localized robots to merge (optionally 925 * <code>null</code>) 926 * @param type the layout's new type (optionally {@link 927 * com.liferay.portal.model.LayoutConstants#TYPE_PORTLET}) 928 * @param hidden whether the layout is hidden 929 * @param friendlyURL the layout's new friendly URL (optionally {@link 930 * com.liferay.portal.util.PropsValues#DEFAULT_USER_PRIVATE_LAYOUT_FRIENDLY_URL} 931 * or {@link 932 * com.liferay.portal.util.PropsValues#DEFAULT_USER_PRIVATE_LAYOUT_FRIENDLY_URL}). 933 * The default values can be overridden in 934 * <code>portal-ext.properties</code> by specifying new values for 935 * the corresponding properties defined in {@link 936 * com.liferay.portal.util.PropsValues}. To see how the URL is 937 * normalized when accessed see {@link 938 * com.liferay.portal.kernel.util.FriendlyURLNormalizerUtil#normalize( 939 * String)}. 940 * @param iconImage whether the icon image will be updated 941 * @param iconBytes the byte array of the layout's new icon image 942 * @param serviceContext the service context. Can set the modification date 943 * and expando bridge attributes for the layout. 944 * @return the updated layout 945 * @throws PortalException if a group or layout with the primary key could 946 * not be found, if the user did not have permission to update the 947 * layout, if a unique friendly URL could not be generated, if a 948 * valid parent layout ID to use could not be found, or if the 949 * layout parameters were invalid 950 * @throws SystemException if a system exception occurred 951 */ 952 public Layout updateLayout( 953 long groupId, boolean privateLayout, long layoutId, 954 long parentLayoutId, Map<Locale, String> localeNamesMap, 955 Map<Locale, String> localeTitlesMap, 956 Map<Locale, String> descriptionMap, Map<Locale, String> keywordsMap, 957 Map<Locale, String> robotsMap, String type, boolean hidden, 958 String friendlyURL, Boolean iconImage, byte[] iconBytes, 959 ServiceContext serviceContext) 960 throws PortalException, SystemException { 961 962 LayoutPermissionUtil.check( 963 getPermissionChecker(), groupId, privateLayout, layoutId, 964 ActionKeys.UPDATE); 965 966 return layoutLocalService.updateLayout( 967 groupId, privateLayout, layoutId, parentLayoutId, localeNamesMap, 968 localeTitlesMap, descriptionMap, keywordsMap, robotsMap, type, 969 hidden, friendlyURL, iconImage, iconBytes, serviceContext); 970 } 971 972 /** 973 * Updates the layout replacing its type settings. 974 * 975 * @param groupId the primary key of the group 976 * @param privateLayout whether the layout is private to the group 977 * @param layoutId the primary key of the layout 978 * @param typeSettings the settings to load the unicode properties object. 979 * See {@link com.liferay.portal.kernel.util.UnicodeProperties 980 * #fastLoad(String)}. 981 * @return the updated layout 982 * @throws PortalException if a matching layout could not be found or if the 983 * user did not have permission to update the layout 984 * @throws SystemException if a system exception occurred 985 */ 986 public Layout updateLayout( 987 long groupId, boolean privateLayout, long layoutId, 988 String typeSettings) 989 throws PortalException, SystemException { 990 991 LayoutPermissionUtil.check( 992 getPermissionChecker(), groupId, privateLayout, layoutId, 993 ActionKeys.UPDATE); 994 995 return layoutLocalService.updateLayout( 996 groupId, privateLayout, layoutId, typeSettings); 997 } 998 999 /** 1000 * Updates the look and feel of the layout. 1001 * 1002 * @param groupId the primary key of the group 1003 * @param privateLayout whether the layout is private to the group 1004 * @param layoutId the primary key of the layout 1005 * @param themeId the primary key of the layout's new theme 1006 * @param colorSchemeId the primary key of the layout's new color scheme 1007 * @param css the layout's new CSS 1008 * @param wapTheme whether the theme is for WAP browsers 1009 * @return the updated layout 1010 * @throws PortalException if a matching layout could not be found, or if 1011 * the user did not have permission to update the layout and 1012 * permission to apply the theme 1013 * @throws SystemException if a system exception occurred 1014 */ 1015 public Layout updateLookAndFeel( 1016 long groupId, boolean privateLayout, long layoutId, String themeId, 1017 String colorSchemeId, String css, boolean wapTheme) 1018 throws PortalException, SystemException { 1019 1020 LayoutPermissionUtil.check( 1021 getPermissionChecker(), groupId, privateLayout, layoutId, 1022 ActionKeys.UPDATE); 1023 1024 pluginSettingLocalService.checkPermission( 1025 getUserId(), themeId, Plugin.TYPE_THEME); 1026 1027 return layoutLocalService.updateLookAndFeel( 1028 groupId, privateLayout, layoutId, themeId, colorSchemeId, css, 1029 wapTheme); 1030 } 1031 1032 /** 1033 * Updates the name of the layout matching the group, layout ID, and 1034 * privacy. 1035 * 1036 * @param groupId the primary key of the group 1037 * @param privateLayout whether the layout is private to the group 1038 * @param layoutId the primary key of the layout 1039 * @param name the layout's new name 1040 * @param languageId the primary key of the language. For more information 1041 * see {@link java.util.Locale}. 1042 * @return the updated layout 1043 * @throws PortalException if a matching layout could not be found, if the 1044 * user did not have permission to update the layout, or if the new 1045 * name was <code>null</code> 1046 * @throws SystemException if a system exception occurred 1047 */ 1048 public Layout updateName( 1049 long groupId, boolean privateLayout, long layoutId, String name, 1050 String languageId) 1051 throws PortalException, SystemException { 1052 1053 LayoutPermissionUtil.check( 1054 getPermissionChecker(), groupId, privateLayout, layoutId, 1055 ActionKeys.UPDATE); 1056 1057 return layoutLocalService.updateName( 1058 groupId, privateLayout, layoutId, name, languageId); 1059 } 1060 1061 /** 1062 * Updates the name of the layout matching the primary key. 1063 * 1064 * @param plid the primary key of the layout 1065 * @param name the name to be assigned 1066 * @param languageId the primary key of the language. For more information 1067 * see {@link java.util.Locale}. 1068 * @return the updated layout 1069 * @throws PortalException if a layout with the primary key could not be 1070 * found, or if the user did not have permission to update the 1071 * layout, or if the name was <code>null</code> 1072 * @throws SystemException if a system exception occurred 1073 */ 1074 public Layout updateName(long plid, String name, String languageId) 1075 throws PortalException, SystemException { 1076 1077 LayoutPermissionUtil.check( 1078 getPermissionChecker(), plid, ActionKeys.UPDATE); 1079 1080 return layoutLocalService.updateName(plid, name, languageId); 1081 } 1082 1083 /** 1084 * Updates the parent layout ID of the layout matching the group, layout ID, 1085 * and privacy. 1086 * 1087 * @param groupId the primary key of the group 1088 * @param privateLayout whether the layout is private to the group 1089 * @param layoutId the primary key of the layout 1090 * @param parentLayoutId the primary key to be assigned to the parent 1091 * layout 1092 * @return the matching layout 1093 * @throws PortalException if a valid parent layout ID to use could not be 1094 * found, if a matching layout could not be found, or if the user 1095 * did not have permission to update the layout 1096 * @throws SystemException if a system exception occurred 1097 */ 1098 public Layout updateParentLayoutId( 1099 long groupId, boolean privateLayout, long layoutId, 1100 long parentLayoutId) 1101 throws PortalException, SystemException { 1102 1103 LayoutPermissionUtil.check( 1104 getPermissionChecker(), groupId, privateLayout, layoutId, 1105 ActionKeys.UPDATE); 1106 1107 return layoutLocalService.updateParentLayoutId( 1108 groupId, privateLayout, layoutId, parentLayoutId); 1109 } 1110 1111 /** 1112 * Updates the parent layout ID of the layout matching the primary key. If a 1113 * layout matching the parent primary key is found, the layout ID of that 1114 * layout is assigned, otherwise {@link 1115 * com.liferay.portal.model.LayoutConstants#DEFAULT_PARENT_LAYOUT_ID} is 1116 * assigned. 1117 * 1118 * @param plid the primary key of the layout 1119 * @param parentPlid the primary key of the parent layout 1120 * @return the layout matching the primary key 1121 * @throws PortalException if a layout with the primary key could not be 1122 * found, if the user did not have permission to update the layout, 1123 * or if a valid parent layout ID to use could not be found 1124 * @throws SystemException if a system exception occurred 1125 */ 1126 public Layout updateParentLayoutId(long plid, long parentPlid) 1127 throws PortalException, SystemException { 1128 1129 LayoutPermissionUtil.check( 1130 getPermissionChecker(), plid, ActionKeys.UPDATE); 1131 1132 return layoutLocalService.updateParentLayoutId(plid, parentPlid); 1133 } 1134 1135 /** 1136 * Updates the priority of the layout matching the group, layout ID, and 1137 * privacy. 1138 * 1139 * @param groupId the primary key of the group 1140 * @param privateLayout whether the layout is private to the group 1141 * @param layoutId the primary key of the layout 1142 * @param priority the layout's new priority 1143 * @return the updated layout 1144 * @throws PortalException if a matching layout could not be found or if the 1145 * user did not have permission to update the layout 1146 * @throws SystemException if a system exception occurred 1147 */ 1148 public Layout updatePriority( 1149 long groupId, boolean privateLayout, long layoutId, int priority) 1150 throws PortalException, SystemException { 1151 1152 LayoutPermissionUtil.check( 1153 getPermissionChecker(), groupId, privateLayout, layoutId, 1154 ActionKeys.UPDATE); 1155 1156 return layoutLocalService.updatePriority( 1157 groupId, privateLayout, layoutId, priority); 1158 } 1159 1160 /** 1161 * Updates the priority of the layout matching the primary key. 1162 * 1163 * @param plid the primary key of the layout 1164 * @param priority the layout's new priority 1165 * @return the updated layout 1166 * @throws PortalException if a layout with the primary key could not be 1167 * found 1168 * @throws SystemException if a system exception occurred 1169 */ 1170 public Layout updatePriority(long plid, int priority) 1171 throws PortalException, SystemException { 1172 1173 LayoutPermissionUtil.check( 1174 getPermissionChecker(), plid, ActionKeys.UPDATE); 1175 1176 return layoutLocalService.updatePriority(plid, priority); 1177 } 1178 1179 protected List<Layout> filterLayouts(List<Layout> layouts) 1180 throws PortalException, SystemException { 1181 1182 List<Layout> filteredLayouts = new ArrayList<Layout>(); 1183 1184 for (Layout layout : layouts) { 1185 if (LayoutPermissionUtil.contains( 1186 getPermissionChecker(), layout.getPlid(), 1187 ActionKeys.VIEW)) { 1188 1189 filteredLayouts.add(layout); 1190 } 1191 } 1192 1193 return filteredLayouts; 1194 } 1195 1196 }