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