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