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 if (_languageId != null) { 422 return _languageId; 423 } 424 425 return LocaleUtil.toLanguageId(LocaleUtil.getMostRelevantLocale()); 426 } 427 428 /** 429 * Returns the complete URL of the current page if a page context can be 430 * determined for this service context. 431 * 432 * @return the complete URL of the current page 433 */ 434 public String getLayoutFullURL() { 435 return _layoutFullURL; 436 } 437 438 /** 439 * Returns the relative URL of the current page if a page context can be 440 * determined for this service context. 441 * 442 * @return the relative URL of the current page 443 */ 444 public String getLayoutURL() { 445 return _layoutURL; 446 } 447 448 public Locale getLocale() { 449 return LocaleUtil.fromLanguageId(_languageId); 450 } 451 452 /** 453 * Returns the date when an entity was modified if this service context is 454 * being passed as a parameter to a method which updates an entity. 455 * 456 * @return the date when an entity was modified if this service context is 457 * being passed as a parameter to a method which updates an entity 458 */ 459 public Date getModifiedDate() { 460 return _modifiedDate; 461 } 462 463 /** 464 * Returns the date when an entity was modified if this service context is 465 * being passed as a parameter to a method which modifies an entity. 466 * 467 * @param defaultModifiedDate an optional default modified date to use if 468 * this service context does not have a modified date 469 * @return the modified date if available; the default date otherwise 470 */ 471 public Date getModifiedDate(Date defaultModifiedDate) { 472 if (_modifiedDate != null) { 473 return _modifiedDate; 474 } 475 else if (defaultModifiedDate != null) { 476 return defaultModifiedDate; 477 } 478 else { 479 return new Date(); 480 } 481 } 482 483 /** 484 * Returns the main context path of the portal, concatenated with 485 * <code>/c</code>. 486 * 487 * @return the main context path of the portal 488 */ 489 public String getPathMain() { 490 return _pathMain; 491 } 492 493 /** 494 * Returns the portal layout ID of the current page of this service context. 495 * 496 * @return the portal layout ID of the current page 497 */ 498 public long getPlid() { 499 return _plid; 500 } 501 502 /** 503 * Returns the URL of this service context's portal, including the protocol, 504 * domain, and non-default port relative to the company instance and any 505 * virtual host. 506 * 507 * <p> 508 * The URL returned does not include the port if a default port is used. 509 * </p> 510 * 511 * @return the URL of this service context's portal, including the protocol, 512 * domain, and non-default port relative to company instance and any 513 * virtual host 514 */ 515 public String getPortalURL() { 516 return _portalURL; 517 } 518 519 /** 520 * Returns the ID of the current portlet if this service context is being 521 * passed as a parameter to a portlet. 522 * 523 * @return the ID of the current portlet 524 * @see com.liferay.portal.model.PortletPreferencesIds 525 */ 526 public String getPortletId() { 527 if (_portletPreferencesIds == null) { 528 return null; 529 } 530 531 return _portletPreferencesIds.getPortletId(); 532 } 533 534 /** 535 * Returns the portlet preferences IDs of the current portlet if the service 536 * context is being passed as a parameter to a portlet. 537 * 538 * <p> 539 * The {@link com.liferay.portal.model.PortletPreferencesIds} can be used to 540 * look up portlet preferences of the current portlet. 541 * </p> 542 * 543 * @return the portlet preferences IDs of the current portlet 544 * @see com.liferay.portal.model.PortletPreferencesIds 545 */ 546 public PortletPreferencesIds getPortletPreferencesIds() { 547 return _portletPreferencesIds; 548 } 549 550 /** 551 * Returns the remote address of the user making the request in this service 552 * context. 553 * 554 * @return the remote address of the user making the request 555 */ 556 public String getRemoteAddr() { 557 return _remoteAddr; 558 } 559 560 /** 561 * Returns the remote host name of the user making the request in this 562 * service context. 563 * 564 * @return the remote host name of the user making the request 565 */ 566 public String getRemoteHost() { 567 return _remoteHost; 568 } 569 570 public HttpServletRequest getRequest() { 571 return _request; 572 } 573 574 public String getRootPortletId() { 575 String portletId = getPortletId(); 576 577 if (portletId == null) { 578 return null; 579 } 580 581 return PortletConstants.getRootPortletId(portletId); 582 } 583 584 /** 585 * Returns the ID of the group corresponding to the current data scope of 586 * this service context. 587 * 588 * @return the ID of the group corresponding to the current data scope 589 * @see com.liferay.portal.model.Group 590 */ 591 public long getScopeGroupId() { 592 return _scopeGroupId; 593 } 594 595 /** 596 * Returns the user-agent request header of this service context. 597 * 598 * @return the user-agent request header 599 * @see com.liferay.portal.kernel.servlet.HttpHeaders 600 */ 601 public String getUserAgent() { 602 if (_request == null) { 603 return null; 604 } 605 606 return _request.getHeader(HttpHeaders.USER_AGENT); 607 } 608 609 /** 610 * Returns the complete URL of this service context's current user's profile 611 * page. 612 * 613 * @return the complete URL of this service context's current user's profile 614 * page 615 */ 616 public String getUserDisplayURL() { 617 return _userDisplayURL; 618 } 619 620 /** 621 * Returns the ID of this service context's current user. 622 * 623 * @return the ID of this service context's current user 624 */ 625 public long getUserId() { 626 return _userId; 627 } 628 629 /** 630 * Returns the UUID (universally unique identifier) of this service 631 * context's current entity. 632 * 633 * @return the UUID (universally unique identifier) of this service 634 * context's current entity 635 */ 636 public String getUuid() { 637 String uuid = _uuid; 638 639 _uuid = null; 640 641 return uuid; 642 } 643 644 /** 645 * Returns the workflow action to take if this service context is being 646 * passed as a parameter to a method that processes a workflow action. 647 * 648 * @return the workflow action to take 649 */ 650 public int getWorkflowAction() { 651 return _workflowAction; 652 } 653 654 /** 655 * Returns <code>true</code> if this service context is being passed as a 656 * parameter to a method which manipulates a resource to which default group 657 * permissions apply. 658 * 659 * @return <code>true</code> if this service context is being passed as a 660 * parameter to a method which manipulates a resource to which 661 * default group permissions apply; <code>false</code> otherwise 662 */ 663 public boolean isAddGroupPermissions() { 664 return _addGroupPermissions; 665 } 666 667 /** 668 * Returns <code>true</code> if this service context is being passed as a 669 * parameter to a method which manipulates a resource to which default guest 670 * permissions apply. 671 * 672 * @return <code>true</code> if this service context is being passed as a 673 * parameter to a method which manipulates a resource to which 674 * default guest permissions apply; <code>false</code> otherwise 675 */ 676 public boolean isAddGuestPermissions() { 677 return _addGuestPermissions; 678 } 679 680 public boolean isAssetEntryVisible() { 681 return _assetEntryVisible; 682 } 683 684 /** 685 * Returns <code>true</code> if this service context contains an add command 686 * (i.e. has command value {@link 687 * com.liferay.portal.kernel.util.Constants#ADD}) 688 * 689 * @return <code>true</code> if this service context contains an add 690 * command; <code>false</code> otherwise 691 */ 692 public boolean isCommandAdd() { 693 if (Validator.equals(_command, Constants.ADD)) { 694 return true; 695 } 696 else { 697 return false; 698 } 699 } 700 701 /** 702 * Returns <code>true</code> if this service context contains an update 703 * command (i.e. has command value {@link 704 * com.liferay.portal.kernel.util.Constants#UPDATE}) 705 * 706 * @return <code>true</code> if this service context contains an update 707 * command; <code>false</code> otherwise 708 */ 709 public boolean isCommandUpdate() { 710 if (Validator.equals(_command, Constants.UPDATE)) { 711 return true; 712 } 713 else { 714 return false; 715 } 716 } 717 718 public boolean isDeriveDefaultPermissions() { 719 return _deriveDefaultPermissions; 720 } 721 722 /** 723 * Returns whether the primary entity of this service context is to be 724 * indexed/re-indexed. 725 * 726 * @return <code>true</code> the primary entity of this service context is 727 * to be indexed/re-indexed; <code>false</code> otherwise 728 */ 729 public boolean isIndexingEnabled() { 730 return _indexingEnabled; 731 } 732 733 /** 734 * Returns <code>true</code> if the sender of this service context's request 735 * is signed in. 736 * 737 * @return <code>true</code> if the sender of this service context's request 738 * is signed in; <code>false</code> otherwise 739 */ 740 public boolean isSignedIn() { 741 return _signedIn; 742 } 743 744 /** 745 * Removes the mapping of the serializable object to the name of the 746 * standard parameter of this service context. 747 * 748 * @param name the name of the standard parameter 749 * @return the serializable object associated to the name 750 */ 751 public Serializable removeAttribute(String name) { 752 return _attributes.remove(name); 753 } 754 755 /** 756 * Sets whether or not default community permissions should apply to a 757 * resource being manipulated by a method to which this service context is 758 * passed as a parameter. 759 * 760 * @param addCommunityPermissions indicates whether or not to apply 761 * default community permissions 762 * @deprecated As of 6.1, renamed to {@link 763 * #setAddGroupPermissions(boolean)} 764 */ 765 public void setAddCommunityPermissions(boolean addCommunityPermissions) { 766 setAddGroupPermissions(addCommunityPermissions); 767 } 768 769 /** 770 * Sets whether or not default group permissions should apply to a resource 771 * being manipulated by a method to which this service context is passed as 772 * a parameter. 773 * 774 * @param addGroupPermissions indicates whether or not to apply default 775 * group permissions 776 */ 777 public void setAddGroupPermissions(boolean addGroupPermissions) { 778 _addGroupPermissions = addGroupPermissions; 779 } 780 781 /** 782 * Sets whether or not default guest permissions should apply to a resource 783 * being manipulated by a method to which this service context is passed as 784 * a parameter. 785 * 786 * @param addGuestPermissions indicates whether or not to apply default 787 * guest permissions 788 */ 789 public void setAddGuestPermissions(boolean addGuestPermissions) { 790 _addGuestPermissions = addGuestPermissions; 791 } 792 793 /** 794 * Sets an array of asset category IDs to be applied to an asset entry if 795 * this service context is being passed as a parameter to a method which 796 * manipulates the asset entry. 797 * 798 * @param assetCategoryIds the primary keys of the asset categories 799 */ 800 public void setAssetCategoryIds(long[] assetCategoryIds) { 801 _assetCategoryIds = assetCategoryIds; 802 } 803 804 public void setAssetEntryVisible(boolean assetEntryVisible) { 805 _assetEntryVisible = assetEntryVisible; 806 } 807 808 /** 809 * Sets an array of the primary keys of asset entries to be linked to an 810 * asset entry if this service context is being passed as a parameter to a 811 * method which manipulates the asset entry. 812 * 813 * @param assetLinkEntryIds the primary keys of the asset entries to be 814 * linked to an asset entry 815 */ 816 public void setAssetLinkEntryIds(long[] assetLinkEntryIds) { 817 _assetLinkEntryIds = assetLinkEntryIds; 818 } 819 820 /** 821 * Sets an array of asset tag names to be applied to an asset entry if this 822 * service context is being passed as a parameter to a method which 823 * manipulates the asset entry. 824 * 825 * @param assetTagNames the tag names to be applied to an asset entry 826 */ 827 public void setAssetTagNames(String[] assetTagNames) { 828 _assetTagNames = assetTagNames; 829 } 830 831 /** 832 * Sets a mapping of a standard parameter's name to its serializable object. 833 * 834 * @param name the standard parameter name to associate with the value 835 * @param value the serializable object to be associated with the name 836 */ 837 public void setAttribute(String name, Serializable value) { 838 _attributes.put(name, value); 839 } 840 841 /** 842 * Sets the map of the name/value pairs that are the standard parameters of 843 * this service context. Each value must be serializable. 844 * 845 * @param attributes the map of the name/value pairs that are the standard 846 * parameters of this service context 847 */ 848 public void setAttributes(Map<String, Serializable> attributes) { 849 _attributes = attributes; 850 } 851 852 /** 853 * Sets the value of the {@link 854 * com.liferay.portal.kernel.util.Constants#CMD} parameter used in most 855 * Liferay forms for internal portlets. 856 * 857 * @param command the value of the {@link 858 * com.liferay.portal.kernel.util.Constants#CMD} parameter 859 */ 860 public void setCommand(String command) { 861 _command = command; 862 } 863 864 /** 865 * Sets an array containing specific community permissions for a resource if 866 * this service context is being passed as a parameter to a method which 867 * manipulates the resource. 868 * 869 * @param communityPermissions the community permissions (optionally 870 * <code>null</code>) 871 * @deprecated As of 6.1, renamed to {@link #setGroupPermissions(String[])} 872 */ 873 public void setCommunityPermissions(String[] communityPermissions) { 874 setGroupPermissions(communityPermissions); 875 } 876 877 /** 878 * Sets the company ID of this service context's current portal instance. 879 * 880 * @param companyId the primary key of this service context's current portal 881 * instance 882 */ 883 public void setCompanyId(long companyId) { 884 _companyId = companyId; 885 } 886 887 /** 888 * Sets the date when an entity was created if this service context is being 889 * passed as a parameter to a method which creates an entity. 890 * 891 * @param createDate the date the entity was created 892 */ 893 public void setCreateDate(Date createDate) { 894 _createDate = createDate; 895 } 896 897 /** 898 * Sets the current URL of this service context 899 * 900 * @param currentURL the current URL of this service context 901 */ 902 public void setCurrentURL(String currentURL) { 903 _currentURL = currentURL; 904 } 905 906 public void setDeriveDefaultPermissions(boolean deriveDefaultPermissions) { 907 _deriveDefaultPermissions = deriveDefaultPermissions; 908 } 909 910 /** 911 * Sets an arbitrary number of attributes of an entity to be persisted. 912 * 913 * <p> 914 * These attributes should only include fields that {@link 915 * com.liferay.portal.service.ServiceContext} does not possess by default. 916 * </p> 917 * 918 * @param expandoBridgeAttributes the expando bridge attributes (optionally 919 * <code>null</code>) 920 */ 921 public void setExpandoBridgeAttributes( 922 Map<String, Serializable> expandoBridgeAttributes) { 923 924 _expandoBridgeAttributes = expandoBridgeAttributes; 925 } 926 927 /** 928 * Sets the date when an <code>aui:form</code> was generated in this service 929 * context. The form date can be used in detecting situations in which an 930 * entity has been modified while another client was editing that entity. 931 * </p> 932 * 933 * <p> 934 * Example: 935 * </p> 936 * 937 * <p> 938 * Person1 and person2 start editing the same version of a Web Content 939 * article. Person1 publishes changes to the article first. When person2 940 * attempts to publish changes to that article, the service implementation 941 * finds that a modification to that article has already been published some 942 * time after person2 started editing the article. Since the the article 943 * modification date was found to be later than the form date for person2, 944 * person2 could be alerted to the modification and make a backup copy of 945 * his edits before synchronizing with the published changes by person1. 946 * </p> 947 * 948 * @param formDate the date that an <code>aui:form</code> was generated for 949 * this service context (optionally <code>null</code>) 950 */ 951 public void setFormDate(Date formDate) { 952 _formDate = formDate; 953 } 954 955 /** 956 * Sets an array containing specific group permissions for a resource if 957 * this service context is being passed as a parameter to a method which 958 * manipulates the resource. 959 * 960 * @param groupPermissions the permissions (optionally <code>null</code>) 961 */ 962 public void setGroupPermissions(String[] groupPermissions) { 963 _groupPermissions = groupPermissions; 964 } 965 966 /** 967 * Sets an array containing specific guest permissions for a resource if 968 * this service context is being passed as a parameter to a method which 969 * manipulates the resource. 970 * 971 * @param guestPermissions the guest permissions (optionally 972 * <code>null</code>) 973 */ 974 public void setGuestPermissions(String[] guestPermissions) { 975 _guestPermissions = guestPermissions; 976 } 977 978 /** 979 * Sets the map of request header name/value pairs of this service context. 980 * 981 * @param headers map of request header name/value pairs of this service 982 * context 983 * @see com.liferay.portal.kernel.servlet.HttpHeaders 984 */ 985 public void setHeaders(Map<String, String> headers) { 986 _headers = headers; 987 } 988 989 /** 990 * Sets whether the primary entity of this service context is to be 991 * indexed/re-indexed. 992 * 993 * <p> 994 * The entity is only indexed/re-indexed if the method receiving this 995 * service context as a parameter does indexing. 996 * </p> 997 * 998 * @param indexingEnabled whether the primary entity of this service context 999 * is to be indexed/re-indexed (default is <code>true</code>) 1000 */ 1001 public void setIndexingEnabled(boolean indexingEnabled) { 1002 _indexingEnabled = indexingEnabled; 1003 } 1004 1005 /** 1006 * Sets the language ID of the locale of this service context. 1007 * 1008 * @param languageId the language ID of the locale of this service context's 1009 * current user 1010 */ 1011 public void setLanguageId(String languageId) { 1012 _languageId = languageId; 1013 } 1014 1015 /** 1016 * Sets the complete URL of the current page for this service context. 1017 * 1018 * @param layoutFullURL the complete URL of the current page if a page 1019 * context can be determined for this service context 1020 */ 1021 public void setLayoutFullURL(String layoutFullURL) { 1022 _layoutFullURL = layoutFullURL; 1023 } 1024 1025 /** 1026 * Sets the relative URL of the current page for this service context. 1027 * 1028 * @param layoutURL the relative URL of the current page if a page context 1029 * can be determined for this service context 1030 */ 1031 public void setLayoutURL(String layoutURL) { 1032 _layoutURL = layoutURL; 1033 } 1034 1035 /** 1036 * Sets the date when an entity was modified in this service context. 1037 * 1038 * @param modifiedDate the date when an entity was modified in this service 1039 * context 1040 */ 1041 public void setModifiedDate(Date modifiedDate) { 1042 _modifiedDate = modifiedDate; 1043 } 1044 1045 /** 1046 * Sets the main context path of the portal, concatenated with 1047 * <code>/c</code>. 1048 * 1049 * @param pathMain the main context path of the portal 1050 */ 1051 public void setPathMain(String pathMain) { 1052 _pathMain = pathMain; 1053 } 1054 1055 /** 1056 * Sets the portal layout ID of the current page in this service context. 1057 * 1058 * @param plid the portal layout ID of the current page 1059 */ 1060 public void setPlid(long plid) { 1061 _plid = plid; 1062 } 1063 1064 /** 1065 * Sets the URL of this service context's portal, including the protocol, 1066 * domain, and non-default port relative to the company instance and any 1067 * virtual host. 1068 * 1069 * <p> 1070 * The URL should not include the port if a default port is used. 1071 * </p> 1072 * 1073 * @param portalURL the portal URL 1074 */ 1075 public void setPortalURL(String portalURL) { 1076 _portalURL = portalURL; 1077 } 1078 1079 /** 1080 * Sets the portlet preferences IDs of the current portlet if this service 1081 * context is being passed as a parameter to a portlet. 1082 * 1083 * <p> 1084 * The {@link com.liferay.portal.model.PortletPreferencesIds} can be used to 1085 * look up portlet preferences of the current portlet. 1086 * </p> 1087 * 1088 * @param portletPreferencesIds the portlet preferences 1089 * @see com.liferay.portal.model.PortletPreferencesIds 1090 */ 1091 public void setPortletPreferencesIds( 1092 PortletPreferencesIds portletPreferencesIds) { 1093 1094 _portletPreferencesIds = portletPreferencesIds; 1095 } 1096 1097 /** 1098 * Sets the remote address of the user making the request in this service 1099 * context. 1100 * 1101 * @param remoteAddr the remote address of the user making the request in 1102 * this service context 1103 */ 1104 public void setRemoteAddr(String remoteAddr) { 1105 _remoteAddr = remoteAddr; 1106 } 1107 1108 /** 1109 * Sets the remote host name of the user making the request in this service 1110 * context. 1111 * 1112 * @param remoteHost the remote host name of the user making the request in 1113 * this service context 1114 */ 1115 public void setRemoteHost(String remoteHost) { 1116 _remoteHost = remoteHost; 1117 } 1118 1119 /** 1120 * Sets the optional request used when instantiating this service context. 1121 * The field is volatile and so will be discarded on serialization. 1122 * 1123 * @param request the request 1124 */ 1125 public void setRequest(HttpServletRequest request) { 1126 _request = request; 1127 } 1128 1129 /** 1130 * Sets the ID of the group corresponding to the current data scope of this 1131 * service context. 1132 * 1133 * @param scopeGroupId the ID of the group corresponding to the current data 1134 * scope of this service context 1135 * @see com.liferay.portal.model.Group 1136 */ 1137 public void setScopeGroupId(long scopeGroupId) { 1138 _scopeGroupId = scopeGroupId; 1139 } 1140 1141 /** 1142 * Sets whether the sender of this service context's request is signed in. 1143 * 1144 * @param signedIn whether the sender of this service context's request is 1145 * signed in 1146 */ 1147 public void setSignedIn(boolean signedIn) { 1148 _signedIn = signedIn; 1149 } 1150 1151 /** 1152 * Sets the complete URL of this service context's current user's profile 1153 * page. 1154 * 1155 * @param userDisplayURL the complete URL of the current user's profile page 1156 */ 1157 public void setUserDisplayURL(String userDisplayURL) { 1158 _userDisplayURL = userDisplayURL; 1159 } 1160 1161 /** 1162 * Sets the ID of this service context's current user. 1163 * 1164 * @param userId the ID of the current user 1165 */ 1166 public void setUserId(long userId) { 1167 _userId = userId; 1168 } 1169 1170 /** 1171 * Sets the UUID (universally unique identifier) of this service context's 1172 * current entity. 1173 * 1174 * @param uuid the UUID (universally unique identifier) of the current 1175 * entity 1176 */ 1177 public void setUuid(String uuid) { 1178 _uuid = uuid; 1179 } 1180 1181 /** 1182 * Sets the workflow action to take if this service context is being passed 1183 * as parameter to a method that processes a workflow action. 1184 * 1185 * @param workflowAction workflow action to take (default is {@link 1186 * com.liferay.portal.kernel.workflow.WorkflowConstants#ACTION_PUBLISH}) 1187 */ 1188 public void setWorkflowAction(int workflowAction) { 1189 _workflowAction = workflowAction; 1190 } 1191 1192 public String translate(String pattern, Object... arguments) { 1193 Locale locale = getLocale(); 1194 1195 return LanguageUtil.format(locale, pattern, arguments); 1196 } 1197 1198 public void validateModifiedDate( 1199 AuditedModel auditedModel, Class<? extends PortalException> clazz) 1200 throws PortalException { 1201 1202 int value = DateUtil.compareTo( 1203 auditedModel.getModifiedDate(), _formDate); 1204 1205 if (value > 0) { 1206 try { 1207 throw clazz.newInstance(); 1208 } 1209 catch (IllegalAccessException iae) { 1210 throw new RuntimeException(iae); 1211 } 1212 catch (InstantiationException ie) { 1213 throw new RuntimeException(ie); 1214 } 1215 } 1216 } 1217 1218 private boolean _addGroupPermissions; 1219 private boolean _addGuestPermissions; 1220 private long[] _assetCategoryIds; 1221 private boolean _assetEntryVisible = true; 1222 private long[] _assetLinkEntryIds; 1223 private String[] _assetTagNames; 1224 private Map<String, Serializable> _attributes; 1225 private String _command; 1226 private long _companyId; 1227 private Date _createDate; 1228 private String _currentURL; 1229 private boolean _deriveDefaultPermissions; 1230 private Map<String, Serializable> _expandoBridgeAttributes; 1231 private Date _formDate; 1232 private String[] _groupPermissions; 1233 private String[] _guestPermissions; 1234 private Map<String, String> _headers; 1235 private boolean _indexingEnabled = true; 1236 private String _languageId; 1237 private String _layoutFullURL; 1238 private String _layoutURL; 1239 private Date _modifiedDate; 1240 private String _pathMain; 1241 private long _plid; 1242 private String _portalURL; 1243 private PortletPreferencesIds _portletPreferencesIds; 1244 private String _remoteAddr; 1245 private String _remoteHost; 1246 private transient HttpServletRequest _request; 1247 private long _scopeGroupId; 1248 private boolean _signedIn; 1249 private String _userDisplayURL; 1250 private long _userId; 1251 private String _uuid; 1252 private int _workflowAction = WorkflowConstants.ACTION_PUBLISH; 1253 1254 }