@JSON public class ServiceContext extends Object implements Cloneable, Serializable
The ServiceContext
object simplifies method signatures and
provides a way to consolidate many different methods with different sets of
optional parameters into a single, easier to use method. It also aggregates
information necessary for transversal features such as permissioning,
tagging, categorization, etc.
Constructor and Description |
---|
ServiceContext()
Creates a new service context object with an attributes map and an
expando bridge attributes map.
|
Modifier and Type | Method and Description |
---|---|
Object |
clone()
Returns a new service context object identical to this service context
object.
|
void |
deriveDefaultPermissions(long repositoryId,
String modelName)
Derive default permissions based on the logic found in
portal-web/docroot/html/taglib/ui/input_permissions/page.jsp.
|
long[] |
getAssetCategoryIds()
Returns the asset category IDs to be applied to an asset entry if the
service context is being passed as a parameter to a method which
manipulates the asset entry.
|
long[] |
getAssetLinkEntryIds()
Returns the primary keys of the asset entries linked to an asset entry if
the service context is being passed as a parameter to a method which
manipulates the asset entry.
|
double |
getAssetPriority()
Returns the priority of an asset entry if this service context is being
passed as a parameter to a method which manipulates the asset entry.
|
String[] |
getAssetTagNames()
Returns the asset tag names to be applied to an asset entry if the
service context is being passed as a parameter to a method which
manipulates the asset entry.
|
Serializable |
getAttribute(String name)
Returns the serializable object associated with the name of the standard
parameter of this service context.
|
Map<String,Serializable> |
getAttributes()
Returns the map of name/value pairs that are the standard parameters of
this service context.
|
String |
getCommand()
Returns the value of the
Constants.CMD parameter used in most
Liferay forms for internal portlets. |
long |
getCompanyId()
Returns the company ID of this service context's current portal instance.
|
Date |
getCreateDate()
Returns the date when an entity was created if this service context is
being passed as a parameter to a method which creates an entity.
|
Date |
getCreateDate(Date defaultCreateDate)
Returns the date when an entity was created (or a default date) if this
service context is being passed as a parameter to a method which creates
an entity.
|
String |
getCurrentURL()
Returns the current URL of this service context
|
Map<String,Serializable> |
getExpandoBridgeAttributes()
Returns an arbitrary number of attributes of an entity to be persisted.
|
Date |
getFormDate()
Returns the date when an
aui:form was generated in this
service context. |
String[] |
getGroupPermissions()
Returns the specific group permissions for a resource if this service
context is being passed as a parameter to a method which manipulates the
resource.
|
long |
getGuestOrUserId()
Returns this service context's user ID or guest ID if no user ID is
available.
|
String[] |
getGuestPermissions()
Returns the specific guest permissions for a resource if this service
context is being passed as a parameter to a method which manipulates the
resource.
|
Map<String,String> |
getHeaders()
Returns the the map of request header name/value pairs of this service
context.
|
String |
getLanguageId()
Returns the language ID of the locale of this service context's current
user.
|
String |
getLayoutFullURL()
Returns the complete URL of the current page if a page context can be
determined for this service context.
|
String |
getLayoutURL()
Returns the relative URL of the current page if a page context can be
determined for this service context.
|
LiferayPortletRequest |
getLiferayPortletRequest() |
LiferayPortletResponse |
getLiferayPortletResponse() |
Locale |
getLocale() |
ModelPermissions |
getModelPermissions() |
Date |
getModifiedDate()
Returns the date when an entity was modified if this service context is
being passed as a parameter to a method which updates an entity.
|
Date |
getModifiedDate(Date defaultModifiedDate)
Returns the date when an entity was modified if this service context is
being passed as a parameter to a method which modifies an entity.
|
String |
getPathFriendlyURLPrivateGroup() |
String |
getPathFriendlyURLPrivateUser() |
String |
getPathFriendlyURLPublic() |
String |
getPathMain()
Returns the main context path of the portal, concatenated with
/c . |
long |
getPlid()
Returns the portal layout ID of the current page of this service context.
|
String |
getPortalURL()
Returns the URL of this service context's portal, including the protocol,
domain, and non-default port relative to the company instance and any
virtual host.
|
String |
getPortletId()
Returns the ID of the current portlet if this service context is being
passed as a parameter to a portlet.
|
PortletPreferencesIds |
getPortletPreferencesIds()
Returns the portlet preferences IDs of the current portlet if the service
context is being passed as a parameter to a portlet.
|
String |
getRemoteAddr()
Returns the remote address of the user making the request in this service
context.
|
String |
getRemoteHost()
Returns the remote host name of the user making the request in this
service context.
|
javax.servlet.http.HttpServletRequest |
getRequest() |
javax.servlet.http.HttpServletResponse |
getResponse() |
String |
getRootPortletId() |
Group |
getScopeGroup() |
long |
getScopeGroupId()
Returns the ID of the group corresponding to the current data scope of
this service context.
|
ThemeDisplay |
getThemeDisplay() |
TimeZone |
getTimeZone() |
String |
getUserAgent()
Returns the user-agent request header of this service context.
|
String |
getUserDisplayURL()
Returns the complete URL of this service context's current user's profile
page.
|
long |
getUserId()
Returns the ID of this service context's current user.
|
String |
getUuid()
Returns the UUID of this service context's current entity.
|
String |
getUuidWithoutReset() |
int |
getWorkflowAction()
Returns the workflow action to take if this service context is being
passed as a parameter to a method that processes a workflow action.
|
boolean |
isAddGroupPermissions()
Returns
true if this service context is being passed as a
parameter to a method which manipulates a resource to which default group
permissions apply. |
boolean |
isAddGuestPermissions()
Returns
true if this service context is being passed as a
parameter to a method which manipulates a resource to which default guest
permissions apply. |
boolean |
isAssetEntryVisible() |
boolean |
isCommandAdd()
Returns
true if this service context contains an add command
(i.e. has command value Constants.ADD ) |
boolean |
isCommandUpdate()
Returns
true if this service context contains an update
command (i.e. has command value Constants.UPDATE ) |
boolean |
isDeriveDefaultPermissions() |
boolean |
isFailOnPortalException()
Returns
true if portal exceptions should be handled as
failures, possibly halting processing, or false if the
exceptions should be handled differently, possibly allowing processing to
continue in some manner. |
boolean |
isIndexingEnabled()
Returns whether the primary entity of this service context is to be
indexed/re-indexed.
|
boolean |
isSignedIn()
Returns
true if the sender of this service context's request
is signed in. |
void |
merge(ServiceContext serviceContext)
Merges all of the specified service context's non-
null
attributes, attributes greater than 0 , and fields (except
the request) with this service context object. |
Serializable |
removeAttribute(String name)
Removes the mapping of the serializable object to the name of the
standard parameter of this service context.
|
void |
setAddGroupPermissions(boolean addGroupPermissions)
Sets whether or not default group permissions should apply to a resource
being manipulated by a method to which this service context is passed as
a parameter.
|
void |
setAddGuestPermissions(boolean addGuestPermissions)
Sets whether or not default guest permissions should apply to a resource
being manipulated by a method to which this service context is passed as
a parameter.
|
void |
setAssetCategoryIds(long[] assetCategoryIds)
Sets an array of asset category IDs to be applied to an asset entry if
this service context is being passed as a parameter to a method which
manipulates the asset entry.
|
void |
setAssetEntryVisible(boolean assetEntryVisible) |
void |
setAssetLinkEntryIds(long[] assetLinkEntryIds)
Sets an array of the primary keys of asset entries to be linked to an
asset entry if this service context is being passed as a parameter to a
method which manipulates the asset entry.
|
void |
setAssetPriority(double assetPriority)
Sets the priority of an asset entry if this service context is being
passed as a parameter to a method which manipulates the asset entry.
|
void |
setAssetTagNames(String[] assetTagNames)
Sets an array of asset tag names to be applied to an asset entry if this
service context is being passed as a parameter to a method which
manipulates the asset entry.
|
void |
setAttribute(String name,
Serializable value)
Sets a mapping of a standard parameter's name to its serializable object.
|
void |
setAttributes(Map<String,Serializable> attributes)
Sets the map of the name/value pairs that are the standard parameters of
this service context.
|
void |
setCommand(String command)
Sets the value of the
Constants.CMD parameter used in most
Liferay forms for internal portlets. |
void |
setCompanyId(long companyId)
Sets the company ID of this service context's current portal instance.
|
void |
setCreateDate(Date createDate)
Sets the date when an entity was created if this service context is being
passed as a parameter to a method which creates an entity.
|
void |
setCurrentURL(String currentURL)
Sets the current URL of this service context
|
void |
setDeriveDefaultPermissions(boolean deriveDefaultPermissions) |
void |
setExpandoBridgeAttributes(Map<String,Serializable> expandoBridgeAttributes)
Sets an arbitrary number of attributes of an entity to be persisted.
|
void |
setFailOnPortalException(boolean failOnPortalException)
Sets whether portal exceptions should be handled as failures, possibly
halting processing, or if exceptions should be handled differently,
possibly allowing processing to continue in some manner.
|
void |
setFormDate(Date formDate)
Sets the date when an
aui:form was generated in this service
context. |
void |
setGroupPermissions(String[] groupPermissions)
Sets an array containing specific group permissions for a resource if
this service context is being passed as a parameter to a method which
manipulates the resource.
|
void |
setGuestPermissions(String[] guestPermissions)
Sets an array containing specific guest permissions for a resource if
this service context is being passed as a parameter to a method which
manipulates the resource.
|
void |
setHeaders(Map<String,String> headers)
Sets the map of request header name/value pairs of this service context.
|
void |
setIndexingEnabled(boolean indexingEnabled)
Sets whether the primary entity of this service context is to be
indexed/re-indexed.
|
void |
setLanguageId(String languageId)
Sets the language ID of the locale of this service context.
|
void |
setLayoutFullURL(String layoutFullURL)
Sets the complete URL of the current page for this service context.
|
void |
setLayoutURL(String layoutURL)
Sets the relative URL of the current page for this service context.
|
void |
setModelPermissions(ModelPermissions modelPermissions) |
void |
setModifiedDate(Date modifiedDate)
Sets the date when an entity was modified in this service context.
|
void |
setPathFriendlyURLPrivateGroup(String pathFriendlyURLPrivateGroup) |
void |
setPathFriendlyURLPrivateUser(String pathFriendlyURLPrivateUser) |
void |
setPathFriendlyURLPublic(String pathFriendlyURLPublic) |
void |
setPathMain(String pathMain)
Sets the main context path of the portal, concatenated with
/c . |
void |
setPlid(long plid)
Sets the portal layout ID of the current page in this service context.
|
void |
setPortalURL(String portalURL)
Sets the URL of this service context's portal, including the protocol,
domain, and non-default port relative to the company instance and any
virtual host.
|
void |
setPortletId(String portletId) |
void |
setPortletPreferencesIds(PortletPreferencesIds portletPreferencesIds)
Sets the portlet preferences IDs of the current portlet if this service
context is being passed as a parameter to a portlet.
|
void |
setRemoteAddr(String remoteAddr)
Sets the remote address of the user making the request in this service
context.
|
void |
setRemoteHost(String remoteHost)
Sets the remote host name of the user making the request in this service
context.
|
void |
setRequest(javax.servlet.http.HttpServletRequest request)
Sets the optional request used when instantiating this service context.
|
void |
setScopeGroupId(long scopeGroupId)
Sets the ID of the group corresponding to the current data scope of this
service context.
|
void |
setSignedIn(boolean signedIn)
Sets whether the sender of this service context's request is signed in.
|
void |
setTimeZone(TimeZone timeZone) |
void |
setUserDisplayURL(String userDisplayURL)
Sets the complete URL of this service context's current user's profile
page.
|
void |
setUserId(long userId)
Sets the ID of this service context's current user.
|
void |
setUuid(String uuid)
Sets the UUID of this service context's current entity.
|
void |
setWorkflowAction(int workflowAction)
Sets the workflow action to take if this service context is being passed
as parameter to a method that processes a workflow action.
|
String |
translate(String pattern,
Object... arguments) |
void |
validateModifiedDate(AuditedModel auditedModel,
Class<? extends PortalException> clazz) |
public ServiceContext()
public Object clone()
clone
in class Object
public void deriveDefaultPermissions(long repositoryId, String modelName) throws PortalException
PortalException
public long[] getAssetCategoryIds()
public long[] getAssetLinkEntryIds()
public double getAssetPriority()
public String[] getAssetTagNames()
public Serializable getAttribute(String name)
name
- the name of the standard parameterpublic Map<String,Serializable> getAttributes()
public String getCommand()
Constants.CMD
parameter used in most
Liferay forms for internal portlets.public long getCompanyId()
public Date getCreateDate()
public Date getCreateDate(Date defaultCreateDate)
defaultCreateDate
- an optional default create date to use if the
service context does not have a create datepublic String getCurrentURL()
public Map<String,Serializable> getExpandoBridgeAttributes()
These attributes only include fields that this service context does not possess by default.
public Date getFormDate()
aui:form
was generated in this
service context. The form date can be used in detecting situations in
which an entity has been modified while another client was editing that
entity.
Example:
Person1 and person2 start editing the same version of a Web Content article. Person1 publishes changes to the article first. When person2 attempts to publish changes to that article, the service implementation finds that a modification to that article has already been published some time after person2 started editing the article. Since the the article modification date was found to be later than the form date for person2, person2 could be alerted to the modification and make a backup copy of his edits before synchronizing with the published changes by person1.
public String[] getGroupPermissions()
public long getGuestOrUserId() throws PortalException
0
if there is no company in this service
contextPortalException
public String[] getGuestPermissions()
@JSON(include=false) public Map<String,String> getHeaders()
HttpHeaders
public String getLanguageId()
public String getLayoutFullURL()
public String getLayoutURL()
@JSON(include=false) public LiferayPortletRequest getLiferayPortletRequest()
@JSON(include=false) public LiferayPortletResponse getLiferayPortletResponse()
public Locale getLocale()
public ModelPermissions getModelPermissions()
public Date getModifiedDate()
public Date getModifiedDate(Date defaultModifiedDate)
defaultModifiedDate
- an optional default modified date to use if
this service context does not have a modified datepublic String getPathFriendlyURLPrivateGroup()
public String getPathFriendlyURLPrivateUser()
public String getPathFriendlyURLPublic()
public String getPathMain()
/c
.public long getPlid()
public String getPortalURL()
The URL returned does not include the port if a default port is used.
public String getPortletId()
PortletPreferencesIds
public PortletPreferencesIds getPortletPreferencesIds()
The PortletPreferencesIds
can be used to look up portlet
preferences of the current portlet.
PortletPreferencesIds
public String getRemoteAddr()
public String getRemoteHost()
public String getRootPortletId()
public Group getScopeGroup() throws PortalException
PortalException
public long getScopeGroupId()
Group
public ThemeDisplay getThemeDisplay()
public TimeZone getTimeZone()
public String getUserAgent()
HttpHeaders
public String getUserDisplayURL()
public long getUserId()
public String getUuid()
To ensure the same UUID is never used by two entities, the UUID is reset
to null
upon invoking this method.
public String getUuidWithoutReset()
public int getWorkflowAction()
public boolean isAddGroupPermissions()
true
if this service context is being passed as a
parameter to a method which manipulates a resource to which default group
permissions apply.true
if this service context is being passed as a
parameter to a method which manipulates a resource to which
default group permissions apply; false
otherwisepublic boolean isAddGuestPermissions()
true
if this service context is being passed as a
parameter to a method which manipulates a resource to which default guest
permissions apply.true
if this service context is being passed as a
parameter to a method which manipulates a resource to which
default guest permissions apply; false
otherwisepublic boolean isAssetEntryVisible()
public boolean isCommandAdd()
true
if this service context contains an add command
(i.e. has command value Constants.ADD
)true
if this service context contains an add
command; false
otherwisepublic boolean isCommandUpdate()
true
if this service context contains an update
command (i.e. has command value Constants.UPDATE
)true
if this service context contains an update
command; false
otherwisepublic boolean isDeriveDefaultPermissions()
public boolean isFailOnPortalException()
true
if portal exceptions should be handled as
failures, possibly halting processing, or false
if the
exceptions should be handled differently, possibly allowing processing to
continue in some manner. Services may check this flag to execute desired
behavior.
Batch invocation of such services (exposed as a JSON web services) can result in execution of all service invocations, in spite of portal exceptions.
If this flag is set to false
, services can implement logic
that allows processing to continue, while collecting information
regarding the exceptions for returning to the caller. For example, the
AssetVocabularyServiceImpl.deleteVocabularies(
long[], ServiceContext)
method uses the list it returns to give
information on vocabularies it fails to delete; it returns an empty list
if all deletions are successful.
true
if portal exceptions are to be handled as
failures; false
if portal exceptions can be handled
differently, possibly allowing processing to continue in some
mannerpublic boolean isIndexingEnabled()
true
the primary entity of this service context is
to be indexed/re-indexed; false
otherwisepublic boolean isSignedIn()
true
if the sender of this service context's request
is signed in.true
if the sender of this service context's request
is signed in; false
otherwisepublic void merge(ServiceContext serviceContext)
null
attributes, attributes greater than 0
, and fields (except
the request) with this service context object.serviceContext
- the service context object to be mergedpublic Serializable removeAttribute(String name)
name
- the name of the standard parameterpublic void setAddGroupPermissions(boolean addGroupPermissions)
addGroupPermissions
- indicates whether or not to apply default
group permissionspublic void setAddGuestPermissions(boolean addGuestPermissions)
addGuestPermissions
- indicates whether or not to apply default
guest permissionspublic void setAssetCategoryIds(long[] assetCategoryIds)
assetCategoryIds
- the primary keys of the asset categoriespublic void setAssetEntryVisible(boolean assetEntryVisible)
public void setAssetLinkEntryIds(long[] assetLinkEntryIds)
assetLinkEntryIds
- the primary keys of the asset entries to be
linked to an asset entrypublic void setAssetPriority(double assetPriority)
assetPriority
- the priority of an asset entrypublic void setAssetTagNames(String[] assetTagNames)
assetTagNames
- the tag names to be applied to an asset entrypublic void setAttribute(String name, Serializable value)
name
- the standard parameter name to associate with the valuevalue
- the serializable object to be associated with the namepublic void setAttributes(Map<String,Serializable> attributes)
attributes
- the map of the name/value pairs that are the standard
parameters of this service contextpublic void setCommand(String command)
Constants.CMD
parameter used in most
Liferay forms for internal portlets.command
- the value of the Constants.CMD
parameterpublic void setCompanyId(long companyId)
companyId
- the primary key of this service context's current portal
instancepublic void setCreateDate(Date createDate)
createDate
- the date the entity was createdpublic void setCurrentURL(String currentURL)
currentURL
- the current URL of this service contextpublic void setDeriveDefaultPermissions(boolean deriveDefaultPermissions)
public void setExpandoBridgeAttributes(Map<String,Serializable> expandoBridgeAttributes)
These attributes should only include fields that ServiceContext
does not possess by default.
expandoBridgeAttributes
- the expando bridge attributes (optionally
null
)public void setFailOnPortalException(boolean failOnPortalException)
failOnPortalException
- whether portal exceptions should be handled
as failures, or if portal exceptions should be handled
differently, possibly allowing processing to continue in some
mannerisFailOnPortalException()
public void setFormDate(Date formDate)
aui:form
was generated in this service
context. The form date can be used in detecting situations in which an
entity has been modified while another client was editing that entity.
Example:
Person1 and person2 start editing the same version of a Web Content article. Person1 publishes changes to the article first. When person2 attempts to publish changes to that article, the service implementation finds that a modification to that article has already been published some time after person2 started editing the article. Since the article modification date was found to be later than the form date for person2, person2 could be alerted to the modification and make a backup copy of his edits before synchronizing with the published changes by person1.
formDate
- the date that an aui:form
was generated for
this service context (optionally null
)public void setGroupPermissions(String[] groupPermissions)
groupPermissions
- the permissions (optionally null
)public void setGuestPermissions(String[] guestPermissions)
guestPermissions
- the guest permissions (optionally
null
)public void setHeaders(Map<String,String> headers)
headers
- map of request header name/value pairs of this service
contextHttpHeaders
public void setIndexingEnabled(boolean indexingEnabled)
The entity is only indexed/re-indexed if the method receiving this service context as a parameter does indexing.
indexingEnabled
- whether the primary entity of this service context
is to be indexed/re-indexed (default is true
)public void setLanguageId(String languageId)
languageId
- the language ID of the locale of this service context's
current userpublic void setLayoutFullURL(String layoutFullURL)
layoutFullURL
- the complete URL of the current page if a page
context can be determined for this service contextpublic void setLayoutURL(String layoutURL)
layoutURL
- the relative URL of the current page if a page context
can be determined for this service contextpublic void setModelPermissions(ModelPermissions modelPermissions)
public void setModifiedDate(Date modifiedDate)
modifiedDate
- the date when an entity was modified in this service
contextpublic void setPathFriendlyURLPrivateGroup(String pathFriendlyURLPrivateGroup)
public void setPathFriendlyURLPrivateUser(String pathFriendlyURLPrivateUser)
public void setPathFriendlyURLPublic(String pathFriendlyURLPublic)
public void setPathMain(String pathMain)
/c
.pathMain
- the main context path of the portalpublic void setPlid(long plid)
plid
- the portal layout ID of the current pagepublic void setPortalURL(String portalURL)
The URL should not include the port if a default port is used.
portalURL
- the portal URLpublic void setPortletId(String portletId)
public void setPortletPreferencesIds(PortletPreferencesIds portletPreferencesIds)
The PortletPreferencesIds
can be used to look up portlet
preferences of the current portlet.
portletPreferencesIds
- the portlet preferencesPortletPreferencesIds
public void setRemoteAddr(String remoteAddr)
remoteAddr
- the remote address of the user making the request in
this service contextpublic void setRemoteHost(String remoteHost)
remoteHost
- the remote host name of the user making the request in
this service contextpublic void setRequest(javax.servlet.http.HttpServletRequest request)
request
- the requestpublic void setScopeGroupId(long scopeGroupId)
scopeGroupId
- the ID of the group corresponding to the current data
scope of this service contextGroup
public void setSignedIn(boolean signedIn)
signedIn
- whether the sender of this service context's request is
signed inpublic void setTimeZone(TimeZone timeZone)
public void setUserDisplayURL(String userDisplayURL)
userDisplayURL
- the complete URL of the current user's profile pagepublic void setUserId(long userId)
userId
- the ID of the current userpublic void setUuid(String uuid)
uuid
- the UUID of the current entitypublic void setWorkflowAction(int workflowAction)
workflowAction
- workflow action to take (default is WorkflowConstants.ACTION_PUBLISH
)public String translate(String pattern, Object... arguments)
public void validateModifiedDate(AuditedModel auditedModel, Class<? extends PortalException> clazz) throws PortalException
PortalException