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; 016 017 import com.liferay.portal.kernel.exception.PortalException; 018 import com.liferay.portal.kernel.exception.SystemException; 019 import com.liferay.portal.kernel.language.LanguageUtil; 020 import com.liferay.portal.kernel.servlet.HttpHeaders; 021 import com.liferay.portal.kernel.util.Constants; 022 import com.liferay.portal.kernel.util.DateUtil; 023 import com.liferay.portal.kernel.util.LocaleUtil; 024 import com.liferay.portal.kernel.util.Validator; 025 import com.liferay.portal.kernel.workflow.WorkflowConstants; 026 import com.liferay.portal.model.AuditedModel; 027 import com.liferay.portal.model.Group; 028 import com.liferay.portal.model.PortletConstants; 029 import com.liferay.portal.model.PortletPreferencesIds; 030 import com.liferay.portal.model.Role; 031 import com.liferay.portal.model.RoleConstants; 032 import com.liferay.portal.security.permission.ResourceActionsUtil; 033 import com.liferay.portal.util.PortalUtil; 034 035 import java.io.Serializable; 036 037 import java.util.ArrayList; 038 import java.util.Date; 039 import java.util.LinkedHashMap; 040 import java.util.List; 041 import java.util.Locale; 042 import java.util.Map; 043 044 import javax.servlet.http.HttpServletRequest; 045 046 /** 047 * Contains context information about a given API call. 048 * 049 * <p> 050 * The <code>ServiceContext</code> object simplifies method signatures and 051 * provides a way to consolidate many different methods with different sets of 052 * optional parameters into a single, easier to use method. It also aggregates 053 * information necessary for transversal features such as permissioning, 054 * tagging, categorization, etc. 055 * </p> 056 * 057 * @author Raymond Augé 058 * @author Brian Wing Shun Chan 059 * @author Jorge Ferrer 060 */ 061 public class ServiceContext implements Cloneable, Serializable { 062 063 /** 064 * Creates a new service context object with an attributes map and an 065 * expando bridge attributes map. The attributes map contains standard 066 * service context parameters and the expando bridge attributes map contains 067 * optional service context parameters. 068 */ 069 public ServiceContext() { 070 _attributes = new LinkedHashMap<String, Serializable>(); 071 _expandoBridgeAttributes = new LinkedHashMap<String, Serializable>(); 072 } 073 074 /** 075 * Returns a new service context object identical to this service context 076 * object. 077 * 078 * @return a new service context object 079 */ 080 @Override 081 public Object clone() { 082 ServiceContext serviceContext = new ServiceContext(); 083 084 serviceContext.setAddGroupPermissions(isAddGroupPermissions()); 085 serviceContext.setAddGuestPermissions(isAddGuestPermissions()); 086 serviceContext.setAssetCategoryIds(getAssetCategoryIds()); 087 serviceContext.setAssetEntryVisible(isAssetEntryVisible()); 088 serviceContext.setAssetLinkEntryIds(getAssetLinkEntryIds()); 089 serviceContext.setAssetTagNames(getAssetTagNames()); 090 serviceContext.setAttributes(getAttributes()); 091 serviceContext.setCommand(getCommand()); 092 serviceContext.setCompanyId(getCompanyId()); 093 serviceContext.setCreateDate(getCreateDate()); 094 serviceContext.setCurrentURL(getCurrentURL()); 095 serviceContext.setExpandoBridgeAttributes(getExpandoBridgeAttributes()); 096 serviceContext.setGroupPermissions(getGroupPermissions()); 097 serviceContext.setGuestPermissions(getGuestPermissions()); 098 serviceContext.setHeaders(getHeaders()); 099 serviceContext.setIndexingEnabled(isIndexingEnabled()); 100 serviceContext.setLanguageId(getLanguageId()); 101 serviceContext.setLayoutFullURL(getLayoutFullURL()); 102 serviceContext.setLayoutURL(getLayoutURL()); 103 serviceContext.setModifiedDate(getModifiedDate()); 104 serviceContext.setPathMain(getPathMain()); 105 serviceContext.setPlid(getPlid()); 106 serviceContext.setPortalURL(getPortalURL()); 107 serviceContext.setPortletPreferencesIds(getPortletPreferencesIds()); 108 serviceContext.setRemoteAddr(getRemoteAddr()); 109 serviceContext.setRemoteHost(getRemoteHost()); 110 serviceContext.setRequest(getRequest()); 111 serviceContext.setScopeGroupId(getScopeGroupId()); 112 serviceContext.setSignedIn(isSignedIn()); 113 serviceContext.setUserDisplayURL(getUserDisplayURL()); 114 serviceContext.setUserId(getUserId()); 115 serviceContext.setUuid(getUuid()); 116 serviceContext.setWorkflowAction(getWorkflowAction()); 117 118 return serviceContext; 119 } 120 121 /** 122 * Derive default permissions based on the logic found in 123 * portal-web/docroot/html/taglib/ui/input_permissions/page.jsp. Do not 124 * update this logic updating the logic in the JSP. 125 */ 126 public void deriveDefaultPermissions(long repositoryId, String modelName) 127 throws PortalException, SystemException { 128 129 long parentGroupId = PortalUtil.getParentGroupId(repositoryId); 130 131 Group parentGroup = GroupLocalServiceUtil.getGroup(parentGroupId); 132 133 Role defaultGroupRole = RoleLocalServiceUtil.getDefaultGroupRole( 134 parentGroupId); 135 136 List<String> groupPermissions = new ArrayList<String>(); 137 List<String> guestPermissions = new ArrayList<String>(); 138 139 String[] roleNames = {RoleConstants.GUEST, defaultGroupRole.getName()}; 140 141 List<String> supportedActions = 142 ResourceActionsUtil.getModelResourceActions(modelName); 143 List<String> groupDefaultActions = 144 ResourceActionsUtil.getModelResourceGroupDefaultActions(modelName); 145 List<String> guestDefaultActions = 146 ResourceActionsUtil.getModelResourceGuestDefaultActions(modelName); 147 List<String> guestUnsupportedActions = 148 ResourceActionsUtil.getModelResourceGuestUnsupportedActions( 149 modelName); 150 151 for (String roleName : roleNames) { 152 for (String action : supportedActions) { 153 if (roleName.equals(RoleConstants.GUEST) && 154 !guestUnsupportedActions.contains(action) && 155 guestDefaultActions.contains(action) && 156 parentGroup.hasPublicLayouts()) { 157 158 guestPermissions.add(action); 159 } 160 else if (roleName.equals(defaultGroupRole.getName()) && 161 groupDefaultActions.contains(action)) { 162 163 groupPermissions.add(action); 164 } 165 } 166 } 167 168 setGroupPermissions( 169 groupPermissions.toArray(new String[groupPermissions.size()])); 170 setGuestPermissions( 171 guestPermissions.toArray(new String[guestPermissions.size()])); 172 } 173 174 /** 175 * Returns <code>true</code> if this service context is being passed as a 176 * parameter to a method which manipulates a resource to which default group 177 * permissions apply. 178 * 179 * @return <code>true</code> if this service context is being passed as 180 * a parameter to a method which manipulates a resource to which 181 * default community permissions apply; <code>false</code> 182 * otherwise 183 * @deprecated As of 6.1, renamed to {@link #isAddGroupPermissions()} 184 */ 185 public boolean getAddCommunityPermissions() { 186 return isAddGroupPermissions(); 187 } 188 189 /** 190 * Returns the asset category IDs to be applied to an asset entry if the 191 * service context is being passed as a parameter to a method which 192 * manipulates the asset entry. 193 * 194 * @return the asset category IDs 195 */ 196 public long[] getAssetCategoryIds() { 197 return _assetCategoryIds; 198 } 199 200 /** 201 * Returns the primary keys of the asset entries linked to an asset entry if 202 * the service context is being passed as a parameter to a method which 203 * manipulates the asset entry. 204 * 205 * @return the primary keys of the asset entries 206 */ 207 public long[] getAssetLinkEntryIds() { 208 return _assetLinkEntryIds; 209 } 210 211 /** 212 * Returns the asset tag names to be applied to an asset entry if the 213 * service context is being passed as a parameter to a method which 214 * manipulates the asset entry. 215 * 216 * @return the asset tag names 217 */ 218 public String[] getAssetTagNames() { 219 return _assetTagNames; 220 } 221 222 /** 223 * Returns the serializable object associated with the name of the standard 224 * parameter of this service context. 225 * 226 * @param name the name of the standard parameter 227 * @return the serializable object associated with the name 228 */ 229 public Serializable getAttribute(String name) { 230 return _attributes.get(name); 231 } 232 233 /** 234 * Returns the map of name/value pairs that are the standard parameters of 235 * this service context. Each value is serializable. 236 * 237 * @return the map of name/value pairs 238 */ 239 public Map<String, Serializable> getAttributes() { 240 return _attributes; 241 } 242 243 /** 244 * Returns the value of the {@link 245 * com.liferay.portal.kernel.util.Constants#CMD} parameter used in most 246 * Liferay forms for internal portlets. 247 * 248 * @return the value of the command parameter 249 */ 250 public String getCommand() { 251 return _command; 252 } 253 254 /** 255 * Returns the specific community permissions for a resource if the service 256 * context is being passed as a parameter to a method which manipulates the 257 * resource. 258 * 259 * @return the community permissions 260 * @deprecated As of 6.1, renamed to {@link #getGroupPermissions()} 261 */ 262 public String[] getCommunityPermissions() { 263 return getGroupPermissions(); 264 } 265 266 /** 267 * Returns the company ID of this service context's current portal instance. 268 * 269 * @return the company ID 270 */ 271 public long getCompanyId() { 272 return _companyId; 273 } 274 275 /** 276 * Returns the date when an entity was created if this service context is 277 * being passed as a parameter to a method which creates an entity. 278 * 279 * @return the creation date 280 */ 281 public Date getCreateDate() { 282 return _createDate; 283 } 284 285 /** 286 * Returns the date when an entity was created (or a default date) if this 287 * service context is being passed as a parameter to a method which creates 288 * an entity. 289 * 290 * @param defaultCreateDate an optional default create date to use if the 291 * service context does not have a create date 292 * @return the creation date if available; the default date otherwise 293 */ 294 public Date getCreateDate(Date defaultCreateDate) { 295 if (_createDate != null) { 296 return _createDate; 297 } 298 else if (defaultCreateDate != null) { 299 return defaultCreateDate; 300 } 301 else { 302 return new Date(); 303 } 304 } 305 306 /** 307 * Returns the current URL of this service context 308 * 309 * @return the current URL 310 */ 311 public String getCurrentURL() { 312 return _currentURL; 313 } 314 315 /** 316 * Returns an arbitrary number of attributes of an entity to be persisted. 317 * 318 * <p> 319 * These attributes only include fields that this service context does not 320 * possess by default. 321 * </p> 322 * 323 * @return the expando bridge attributes 324 */ 325 public Map<String, Serializable> getExpandoBridgeAttributes() { 326 return _expandoBridgeAttributes; 327 } 328 329 /** 330 * Returns the date when an <code>aui:form</code> was generated in this 331 * service context. The form date can be used in detecting situations in 332 * which an entity has been modified while another client was editing that 333 * entity. </p> 334 * 335 * <p> 336 * Example: 337 * </p> 338 * 339 * <p> 340 * Person1 and person2 start editing the same version of a Web Content 341 * article. Person1 publishes changes to the article first. When person2 342 * attempts to publish changes to that article, the service implementation 343 * finds that a modification to that article has already been published some 344 * time after person2 started editing the article. Since the the article 345 * modification date was found to be later than the form date for person2, 346 * person2 could be alerted to the modification and make a backup copy of 347 * his edits before synchronizing with the published changes by person1. 348 * </p> 349 */ 350 public Date getFormDate() { 351 return _formDate; 352 } 353 354 /** 355 * Returns the specific group permissions for a resource if this service 356 * context is being passed as a parameter to a method which manipulates the 357 * resource. 358 * 359 * @return the specific group permissions 360 */ 361 public String[] getGroupPermissions() { 362 return _groupPermissions; 363 } 364 365 /** 366 * Returns this service context's user ID or guest ID if no user ID is 367 * available. 368 * 369 * @return the user ID, or guest ID if there is no user in this service 370 * context, or <code>0</code> if there is no company in this service 371 * context 372 * @throws PortalException if a default user for the company could not be 373 * found 374 * @throws SystemException if a system exception occurred 375 */ 376 public long getGuestOrUserId() throws PortalException, SystemException { 377 long userId = getUserId(); 378 379 if (userId > 0) { 380 return userId; 381 } 382 383 long companyId = getCompanyId(); 384 385 if (companyId > 0) { 386 return UserLocalServiceUtil.getDefaultUserId(getCompanyId()); 387 } 388 389 return 0; 390 } 391 392 /** 393 * Returns the specific guest permissions for a resource if this service 394 * context is being passed as a parameter to a method which manipulates the 395 * resource. 396 * 397 * @return the specific guest permissions 398 */ 399 public String[] getGuestPermissions() { 400 return _guestPermissions; 401 } 402 403 /** 404 * Returns the the map of request header name/value pairs of this service 405 * context. 406 * 407 * @return the the map of request header name/value pairs 408 * @see com.liferay.portal.kernel.servlet.HttpHeaders 409 */ 410 public Map<String, String> getHeaders() { 411 return _headers; 412 } 413 414 /** 415 * Returns the language ID of the locale of this service context's current 416 * user. 417 * 418 * @return the language ID 419 */ 420 public String getLanguageId() { 421 return _languageId; 422 } 423 424 /** 425 * Returns the complete URL of the current page if a page context can be 426 * determined for this service context. 427 * 428 * @return the complete URL of the current page 429 */ 430 public String getLayoutFullURL() { 431 return _layoutFullURL; 432 } 433 434 /** 435 * Returns the relative URL of the current page if a page context can be 436 * determined for this service context. 437 * 438 * @return the relative URL of the current page 439 */ 440 public String getLayoutURL() { 441 return _layoutURL; 442 } 443 444 public Locale getLocale() { 445 return LocaleUtil.fromLanguageId(_languageId); 446 } 447 448 /** 449 * Returns the date when an entity was modified if this service context is 450 * being passed as a parameter to a method which updates an entity. 451 * 452 * @return the date when an entity was modified if this service context is 453 * being passed as a parameter to a method which updates an entity 454 */ 455 public Date getModifiedDate() { 456 return _modifiedDate; 457 } 458 459 /** 460 * Returns the date when an entity was modified if this service context is 461 * being passed as a parameter to a method which modifies an entity. 462 * 463 * @param defaultModifiedDate an optional default modified date to use if 464 * this service context does not have a modified date 465 * @return the modified date if available; the default date otherwise 466 */ 467 public Date getModifiedDate(Date defaultModifiedDate) { 468 if (_modifiedDate != null) { 469 return _modifiedDate; 470 } 471 else if (defaultModifiedDate != null) { 472 return defaultModifiedDate; 473 } 474 else { 475 return new Date(); 476 } 477 } 478 479 /** 480 * Returns the main context path of the portal, concatenated with 481 * <code>/c</code>. 482 * 483 * @return the main context path of the portal 484 */ 485 public String getPathMain() { 486 return _pathMain; 487 } 488 489 /** 490 * Returns the portal layout ID of the current page of this service context. 491 * 492 * @return the portal layout ID of the current page 493 */ 494 public long getPlid() { 495 return _plid; 496 } 497 498 /** 499 * Returns the URL of this service context's portal, including the protocol, 500 * domain, and non-default port relative to the company instance and any 501 * virtual host. 502 * 503 * <p> 504 * The URL returned does not include the port if a default port is used. 505 * </p> 506 * 507 * @return the URL of this service context's portal, including the protocol, 508 * domain, and non-default port relative to company instance and any 509 * virtual host 510 */ 511 public String getPortalURL() { 512 return _portalURL; 513 } 514 515 /** 516 * Returns the ID of the current portlet if this service context is being 517 * passed as a parameter to a portlet. 518 * 519 * @return the ID of the current portlet 520 * @see com.liferay.portal.model.PortletPreferencesIds 521 */ 522 public String getPortletId() { 523 if (_portletPreferencesIds == null) { 524 return null; 525 } 526 527 return _portletPreferencesIds.getPortletId(); 528 } 529 530 /** 531 * Returns the portlet preferences IDs of the current portlet if the service 532 * context is being passed as a parameter to a portlet. 533 * 534 * <p> 535 * The {@link com.liferay.portal.model.PortletPreferencesIds} can be used to 536 * look up portlet preferences of the current portlet. 537 * </p> 538 * 539 * @return the portlet preferences IDs of the current portlet 540 * @see com.liferay.portal.model.PortletPreferencesIds 541 */ 542 public PortletPreferencesIds getPortletPreferencesIds() { 543 return _portletPreferencesIds; 544 } 545 546 /** 547 * Returns the remote address of the user making the request in this service 548 * context. 549 * 550 * @return the remote address of the user making the request 551 */ 552 public String getRemoteAddr() { 553 return _remoteAddr; 554 } 555 556 /** 557 * Returns the remote host name of the user making the request in this 558 * service context. 559 * 560 * @return the remote host name of the user making the request 561 */ 562 public String getRemoteHost() { 563 return _remoteHost; 564 } 565 566 public HttpServletRequest getRequest() { 567 return _request; 568 } 569 570 public String getRootPortletId() { 571 String portletId = getPortletId(); 572 573 if (portletId == null) { 574 return null; 575 } 576 577 return PortletConstants.getRootPortletId(portletId); 578 } 579 580 /** 581 * Returns the ID of the group corresponding to the current data scope of 582 * this service context. 583 * 584 * @return the ID of the group corresponding to the current data scope 585 * @see com.liferay.portal.model.Group 586 */ 587 public long getScopeGroupId() { 588 return _scopeGroupId; 589 } 590 591 /** 592 * Returns the user-agent request header of this service context. 593 * 594 * @return the user-agent request header 595 * @see com.liferay.portal.kernel.servlet.HttpHeaders 596 */ 597 public String getUserAgent() { 598 if (_request == null) { 599 return null; 600 } 601 602 return _request.getHeader(HttpHeaders.USER_AGENT); 603 } 604 605 /** 606 * Returns the complete URL of this service context's current user's profile 607 * page. 608 * 609 * @return the complete URL of this service context's current user's profile 610 * page 611 */ 612 public String getUserDisplayURL() { 613 return _userDisplayURL; 614 } 615 616 /** 617 * Returns the ID of this service context's current user. 618 * 619 * @return the ID of this service context's current user 620 */ 621 public long getUserId() { 622 return _userId; 623 } 624 625 /** 626 * Returns the UUID (universally unique identifier) of this service 627 * context's current entity. 628 * 629 * @return the UUID (universally unique identifier) of this service 630 * context's current entity 631 */ 632 public String getUuid() { 633 String uuid = _uuid; 634 635 _uuid = null; 636 637 return uuid; 638 } 639 640 /** 641 * Returns the workflow action to take if this service context is being 642 * passed as a parameter to a method that processes a workflow action. 643 * 644 * @return the workflow action to take 645 */ 646 public int getWorkflowAction() { 647 return _workflowAction; 648 } 649 650 /** 651 * Returns <code>true</code> if this service context is being passed as a 652 * parameter to a method which manipulates a resource to which default group 653 * permissions apply. 654 * 655 * @return <code>true</code> if this service context is being passed as a 656 * parameter to a method which manipulates a resource to which 657 * default group permissions apply; <code>false</code> otherwise 658 */ 659 public boolean isAddGroupPermissions() { 660 return _addGroupPermissions; 661 } 662 663 /** 664 * Returns <code>true</code> if this service context is being passed as a 665 * parameter to a method which manipulates a resource to which default guest 666 * permissions apply. 667 * 668 * @return <code>true</code> if this service context is being passed as a 669 * parameter to a method which manipulates a resource to which 670 * default guest permissions apply; <code>false</code> otherwise 671 */ 672 public boolean isAddGuestPermissions() { 673 return _addGuestPermissions; 674 } 675 676 public boolean isAssetEntryVisible() { 677 return _assetEntryVisible; 678 } 679 680 /** 681 * Returns <code>true</code> if this service context contains an add command 682 * (i.e. has command value {@link 683 * com.liferay.portal.kernel.util.Constants#ADD}) 684 * 685 * @return <code>true</code> if this service context contains an add 686 * command; <code>false</code> otherwise 687 */ 688 public boolean isCommandAdd() { 689 if (Validator.equals(_command, Constants.ADD)) { 690 return true; 691 } 692 else { 693 return false; 694 } 695 } 696 697 /** 698 * Returns <code>true</code> if this service context contains an update 699 * command (i.e. has command value {@link 700 * com.liferay.portal.kernel.util.Constants#UPDATE}) 701 * 702 * @return <code>true</code> if this service context contains an update 703 * command; <code>false</code> otherwise 704 */ 705 public boolean isCommandUpdate() { 706 if (Validator.equals(_command, Constants.UPDATE)) { 707 return true; 708 } 709 else { 710 return false; 711 } 712 } 713 714 public boolean isDeriveDefaultPermissions() { 715 return _deriveDefaultPermissions; 716 } 717 718 /** 719 * Returns whether the primary entity of this service context is to be 720 * indexed/re-indexed. 721 * 722 * @return <code>true</code> the primary entity of this service context is 723 * to be indexed/re-indexed; <code>false</code> otherwise 724 */ 725 public boolean isIndexingEnabled() { 726 return _indexingEnabled; 727 } 728 729 /** 730 * Returns <code>true</code> if the sender of this service context's request 731 * is signed in. 732 * 733 * @return <code>true</code> if the sender of this service context's request 734 * is signed in; <code>false</code> otherwise 735 */ 736 public boolean isSignedIn() { 737 return _signedIn; 738 } 739 740 /** 741 * Removes the mapping of the serializable object to the name of the 742 * standard parameter of this service context. 743 * 744 * @param name the name of the standard parameter 745 * @return the serializable object associated to the name 746 */ 747 public Serializable removeAttribute(String name) { 748 return _attributes.remove(name); 749 } 750 751 /** 752 * Sets whether or not default community permissions should apply to a 753 * resource being manipulated by a method to which this service context is 754 * passed as a parameter. 755 * 756 * @param addCommunityPermissions indicates whether or not to apply 757 * default community permissions 758 * @deprecated As of 6.1, renamed to {@link 759 * #setAddGroupPermissions(boolean)} 760 */ 761 public void setAddCommunityPermissions(boolean addCommunityPermissions) { 762 setAddGroupPermissions(addCommunityPermissions); 763 } 764 765 /** 766 * Sets whether or not default group permissions should apply to a resource 767 * being manipulated by a method to which this service context is passed as 768 * a parameter. 769 * 770 * @param addGroupPermissions indicates whether or not to apply default 771 * group permissions 772 */ 773 public void setAddGroupPermissions(boolean addGroupPermissions) { 774 _addGroupPermissions = addGroupPermissions; 775 } 776 777 /** 778 * Sets whether or not default guest permissions should apply to a resource 779 * being manipulated by a method to which this service context is passed as 780 * a parameter. 781 * 782 * @param addGuestPermissions indicates whether or not to apply default 783 * guest permissions 784 */ 785 public void setAddGuestPermissions(boolean addGuestPermissions) { 786 _addGuestPermissions = addGuestPermissions; 787 } 788 789 /** 790 * Sets an array of asset category IDs to be applied to an asset entry if 791 * this service context is being passed as a parameter to a method which 792 * manipulates the asset entry. 793 * 794 * @param assetCategoryIds the primary keys of the asset categories 795 */ 796 public void setAssetCategoryIds(long[] assetCategoryIds) { 797 _assetCategoryIds = assetCategoryIds; 798 } 799 800 public void setAssetEntryVisible(boolean assetEntryVisible) { 801 _assetEntryVisible = assetEntryVisible; 802 } 803 804 /** 805 * Sets an array of the primary keys of asset entries to be linked to an 806 * asset entry if this service context is being passed as a parameter to a 807 * method which manipulates the asset entry. 808 * 809 * @param assetLinkEntryIds the primary keys of the asset entries to be 810 * linked to an asset entry 811 */ 812 public void setAssetLinkEntryIds(long[] assetLinkEntryIds) { 813 _assetLinkEntryIds = assetLinkEntryIds; 814 } 815 816 /** 817 * Sets an array of asset tag names to be applied to an asset entry if this 818 * service context is being passed as a parameter to a method which 819 * manipulates the asset entry. 820 * 821 * @param assetTagNames the tag names to be applied to an asset entry 822 */ 823 public void setAssetTagNames(String[] assetTagNames) { 824 _assetTagNames = assetTagNames; 825 } 826 827 /** 828 * Sets a mapping of a standard parameter's name to its serializable object. 829 * 830 * @param name the standard parameter name to associate with the value 831 * @param value the serializable object to be associated with the name 832 */ 833 public void setAttribute(String name, Serializable value) { 834 _attributes.put(name, value); 835 } 836 837 /** 838 * Sets the map of the name/value pairs that are the standard parameters of 839 * this service context. Each value must be serializable. 840 * 841 * @param attributes the map of the name/value pairs that are the standard 842 * parameters of this service context 843 */ 844 public void setAttributes(Map<String, Serializable> attributes) { 845 _attributes = attributes; 846 } 847 848 /** 849 * Sets the value of the {@link 850 * com.liferay.portal.kernel.util.Constants#CMD} parameter used in most 851 * Liferay forms for internal portlets. 852 * 853 * @param command the value of the {@link 854 * com.liferay.portal.kernel.util.Constants#CMD} parameter 855 */ 856 public void setCommand(String command) { 857 _command = command; 858 } 859 860 /** 861 * Sets an array containing specific community permissions for a resource if 862 * this service context is being passed as a parameter to a method which 863 * manipulates the resource. 864 * 865 * @param communityPermissions the community permissions (optionally 866 * <code>null</code>) 867 * @deprecated As of 6.1, renamed to {@link #setGroupPermissions(String[])} 868 */ 869 public void setCommunityPermissions(String[] communityPermissions) { 870 setGroupPermissions(communityPermissions); 871 } 872 873 /** 874 * Sets the company ID of this service context's current portal instance. 875 * 876 * @param companyId the primary key of this service context's current portal 877 * instance 878 */ 879 public void setCompanyId(long companyId) { 880 _companyId = companyId; 881 } 882 883 /** 884 * Sets the date when an entity was created if this service context is being 885 * passed as a parameter to a method which creates an entity. 886 * 887 * @param createDate the date the entity was created 888 */ 889 public void setCreateDate(Date createDate) { 890 _createDate = createDate; 891 } 892 893 /** 894 * Sets the current URL of this service context 895 * 896 * @param currentURL the current URL of this service context 897 */ 898 public void setCurrentURL(String currentURL) { 899 _currentURL = currentURL; 900 } 901 902 public void setDeriveDefaultPermissions(boolean deriveDefaultPermissions) { 903 _deriveDefaultPermissions = deriveDefaultPermissions; 904 } 905 906 /** 907 * Sets an arbitrary number of attributes of an entity to be persisted. 908 * 909 * <p> 910 * These attributes should only include fields that {@link 911 * com.liferay.portal.service.ServiceContext} does not possess by default. 912 * </p> 913 * 914 * @param expandoBridgeAttributes the expando bridge attributes (optionally 915 * <code>null</code>) 916 */ 917 public void setExpandoBridgeAttributes( 918 Map<String, Serializable> expandoBridgeAttributes) { 919 920 _expandoBridgeAttributes = expandoBridgeAttributes; 921 } 922 923 /** 924 * Sets the date when an <code>aui:form</code> was generated in this service 925 * context. The form date can be used in detecting situations in which an 926 * entity has been modified while another client was editing that entity. 927 * </p> 928 * 929 * <p> 930 * Example: 931 * </p> 932 * 933 * <p> 934 * Person1 and person2 start editing the same version of a Web Content 935 * article. Person1 publishes changes to the article first. When person2 936 * attempts to publish changes to that article, the service implementation 937 * finds that a modification to that article has already been published some 938 * time after person2 started editing the article. Since the the article 939 * modification date was found to be later than the form date for person2, 940 * person2 could be alerted to the modification and make a backup copy of 941 * his edits before synchronizing with the published changes by person1. 942 * </p> 943 * 944 * @param formDate the date that an <code>aui:form</code> was generated for 945 * this service context (optionally <code>null</code>) 946 */ 947 public void setFormDate(Date formDate) { 948 _formDate = formDate; 949 } 950 951 /** 952 * Sets an array containing specific group permissions for a resource if 953 * this service context is being passed as a parameter to a method which 954 * manipulates the resource. 955 * 956 * @param groupPermissions the permissions (optionally <code>null</code>) 957 */ 958 public void setGroupPermissions(String[] groupPermissions) { 959 _groupPermissions = groupPermissions; 960 } 961 962 /** 963 * Sets an array containing specific guest permissions for a resource if 964 * this service context is being passed as a parameter to a method which 965 * manipulates the resource. 966 * 967 * @param guestPermissions the guest permissions (optionally 968 * <code>null</code>) 969 */ 970 public void setGuestPermissions(String[] guestPermissions) { 971 _guestPermissions = guestPermissions; 972 } 973 974 /** 975 * Sets the map of request header name/value pairs of this service context. 976 * 977 * @param headers map of request header name/value pairs of this service 978 * context 979 * @see com.liferay.portal.kernel.servlet.HttpHeaders 980 */ 981 public void setHeaders(Map<String, String> headers) { 982 _headers = headers; 983 } 984 985 /** 986 * Sets whether the primary entity of this service context is to be 987 * indexed/re-indexed. 988 * 989 * <p> 990 * The entity is only indexed/re-indexed if the method receiving this 991 * service context as a parameter does indexing. 992 * </p> 993 * 994 * @param indexingEnabled whether the primary entity of this service context 995 * is to be indexed/re-indexed (default is <code>true</code>) 996 */ 997 public void setIndexingEnabled(boolean indexingEnabled) { 998 _indexingEnabled = indexingEnabled; 999 } 1000 1001 /** 1002 * Sets the language ID of the locale of this service context. 1003 * 1004 * @param languageId the language ID of the locale of this service context's 1005 * current user 1006 */ 1007 public void setLanguageId(String languageId) { 1008 _languageId = languageId; 1009 } 1010 1011 /** 1012 * Sets the complete URL of the current page for this service context. 1013 * 1014 * @param layoutFullURL the complete URL of the current page if a page 1015 * context can be determined for this service context 1016 */ 1017 public void setLayoutFullURL(String layoutFullURL) { 1018 _layoutFullURL = layoutFullURL; 1019 } 1020 1021 /** 1022 * Sets the relative URL of the current page for this service context. 1023 * 1024 * @param layoutURL the relative URL of the current page if a page context 1025 * can be determined for this service context 1026 */ 1027 public void setLayoutURL(String layoutURL) { 1028 _layoutURL = layoutURL; 1029 } 1030 1031 /** 1032 * Sets the date when an entity was modified in this service context. 1033 * 1034 * @param modifiedDate the date when an entity was modified in this service 1035 * context 1036 */ 1037 public void setModifiedDate(Date modifiedDate) { 1038 _modifiedDate = modifiedDate; 1039 } 1040 1041 /** 1042 * Sets the main context path of the portal, concatenated with 1043 * <code>/c</code>. 1044 * 1045 * @param pathMain the main context path of the portal 1046 */ 1047 public void setPathMain(String pathMain) { 1048 _pathMain = pathMain; 1049 } 1050 1051 /** 1052 * Sets the portal layout ID of the current page in this service context. 1053 * 1054 * @param plid the portal layout ID of the current page 1055 */ 1056 public void setPlid(long plid) { 1057 _plid = plid; 1058 } 1059 1060 /** 1061 * Sets the URL of this service context's portal, including the protocol, 1062 * domain, and non-default port relative to the company instance and any 1063 * virtual host. 1064 * 1065 * <p> 1066 * The URL should not include the port if a default port is used. 1067 * </p> 1068 * 1069 * @param portalURL the portal URL 1070 */ 1071 public void setPortalURL(String portalURL) { 1072 _portalURL = portalURL; 1073 } 1074 1075 /** 1076 * Sets the portlet preferences IDs of the current portlet if this service 1077 * context is being passed as a parameter to a portlet. 1078 * 1079 * <p> 1080 * The {@link com.liferay.portal.model.PortletPreferencesIds} can be used to 1081 * look up portlet preferences of the current portlet. 1082 * </p> 1083 * 1084 * @param portletPreferencesIds the portlet preferences 1085 * @see com.liferay.portal.model.PortletPreferencesIds 1086 */ 1087 public void setPortletPreferencesIds( 1088 PortletPreferencesIds portletPreferencesIds) { 1089 1090 _portletPreferencesIds = portletPreferencesIds; 1091 } 1092 1093 /** 1094 * Sets the remote address of the user making the request in this service 1095 * context. 1096 * 1097 * @param remoteAddr the remote address of the user making the request in 1098 * this service context 1099 */ 1100 public void setRemoteAddr(String remoteAddr) { 1101 _remoteAddr = remoteAddr; 1102 } 1103 1104 /** 1105 * Sets the remote host name of the user making the request in this service 1106 * context. 1107 * 1108 * @param remoteHost the remote host name of the user making the request in 1109 * this service context 1110 */ 1111 public void setRemoteHost(String remoteHost) { 1112 _remoteHost = remoteHost; 1113 } 1114 1115 /** 1116 * Sets the optional request used when instantiating this service context. 1117 * The field is volatile and so will be discarded on serialization. 1118 * 1119 * @param request the request 1120 */ 1121 public void setRequest(HttpServletRequest request) { 1122 _request = request; 1123 } 1124 1125 /** 1126 * Sets the ID of the group corresponding to the current data scope of this 1127 * service context. 1128 * 1129 * @param scopeGroupId the ID of the group corresponding to the current data 1130 * scope of this service context 1131 * @see com.liferay.portal.model.Group 1132 */ 1133 public void setScopeGroupId(long scopeGroupId) { 1134 _scopeGroupId = scopeGroupId; 1135 } 1136 1137 /** 1138 * Sets whether the sender of this service context's request is signed in. 1139 * 1140 * @param signedIn whether the sender of this service context's request is 1141 * signed in 1142 */ 1143 public void setSignedIn(boolean signedIn) { 1144 _signedIn = signedIn; 1145 } 1146 1147 /** 1148 * Sets the complete URL of this service context's current user's profile 1149 * page. 1150 * 1151 * @param userDisplayURL the complete URL of the current user's profile page 1152 */ 1153 public void setUserDisplayURL(String userDisplayURL) { 1154 _userDisplayURL = userDisplayURL; 1155 } 1156 1157 /** 1158 * Sets the ID of this service context's current user. 1159 * 1160 * @param userId the ID of the current user 1161 */ 1162 public void setUserId(long userId) { 1163 _userId = userId; 1164 } 1165 1166 /** 1167 * Sets the UUID (universally unique identifier) of this service context's 1168 * current entity. 1169 * 1170 * @param uuid the UUID (universally unique identifier) of the current 1171 * entity 1172 */ 1173 public void setUuid(String uuid) { 1174 _uuid = uuid; 1175 } 1176 1177 /** 1178 * Sets the workflow action to take if this service context is being passed 1179 * as parameter to a method that processes a workflow action. 1180 * 1181 * @param workflowAction workflow action to take (default is {@link 1182 * com.liferay.portal.kernel.workflow.WorkflowConstants#ACTION_PUBLISH}) 1183 */ 1184 public void setWorkflowAction(int workflowAction) { 1185 _workflowAction = workflowAction; 1186 } 1187 1188 public String translate(String pattern, Object... arguments) { 1189 Locale locale = getLocale(); 1190 1191 return LanguageUtil.format(locale, pattern, arguments); 1192 } 1193 1194 public void validateModifiedDate( 1195 AuditedModel auditedModel, Class<? extends PortalException> clazz) 1196 throws PortalException { 1197 1198 int value = DateUtil.compareTo( 1199 auditedModel.getModifiedDate(), _formDate); 1200 1201 if (value > 0) { 1202 try { 1203 throw clazz.newInstance(); 1204 } 1205 catch (IllegalAccessException iae) { 1206 throw new RuntimeException(iae); 1207 } 1208 catch (InstantiationException ie) { 1209 throw new RuntimeException(ie); 1210 } 1211 } 1212 } 1213 1214 private boolean _addGroupPermissions; 1215 private boolean _addGuestPermissions; 1216 private long[] _assetCategoryIds; 1217 private boolean _assetEntryVisible = true; 1218 private long[] _assetLinkEntryIds; 1219 private String[] _assetTagNames; 1220 private Map<String, Serializable> _attributes; 1221 private String _command; 1222 private long _companyId; 1223 private Date _createDate; 1224 private String _currentURL; 1225 private boolean _deriveDefaultPermissions; 1226 private Map<String, Serializable> _expandoBridgeAttributes; 1227 private Date _formDate; 1228 private String[] _groupPermissions; 1229 private String[] _guestPermissions; 1230 private Map<String, String> _headers; 1231 private boolean _indexingEnabled = true; 1232 private String _languageId; 1233 private String _layoutFullURL; 1234 private String _layoutURL; 1235 private Date _modifiedDate; 1236 private String _pathMain; 1237 private long _plid; 1238 private String _portalURL; 1239 private PortletPreferencesIds _portletPreferencesIds; 1240 private String _remoteAddr; 1241 private String _remoteHost; 1242 private transient HttpServletRequest _request; 1243 private long _scopeGroupId; 1244 private boolean _signedIn; 1245 private String _userDisplayURL; 1246 private long _userId; 1247 private String _uuid; 1248 private int _workflowAction = WorkflowConstants.ACTION_PUBLISH; 1249 1250 }