Package com.sap.cds.services
Interface EventContext
- All Known Subinterfaces:
ActionAccessEventContext,ActiveReadEventContext,ApplicationPreparedEventContext,ApplicationStoppedEventContext,CalcWhereConditionEventContext,CdsCreateEventContext,CdsDeleteEventContext,CdsReadEventContext,CdsUpdateEventContext,CdsUpsertEventContext,CloudEventMessageEventContext,ConfigChangeLogContext,DataAccessLogContext,DataModificationLogContext,DependenciesEventContext,DraftCancelEventContext,DraftCreateEventContext,DraftEditEventContext,DraftGcEventContext,DraftNewEventContext,DraftPatchEventContext,DraftPrepareEventContext,DraftReadEventContext,DraftSaveEventContext,EntityAccessEventContext,ErrorResponseEventContext,FunctionAccessEventContext,GetRestrictionEventContext,MessagingErrorEventContext,ModelChangedEventContext,OutboxMessageEventContext,PdfExportEventContext,ReadProviderTenantEventContext,ReadTenantsEventContext,SecurityLogContext,ServiceAccessEventContext,SubscribeEventContext,TenantOffboardedEventContext,TenantOnboardedEventContext,TopicMessageEventContext,UnauthorizedRequestEventContext,UnsubscribeEventContext,UpgradeEventContext
public interface EventContext
The
It gives access to objects defined by the global context of the event, for example the
Most importantly it gives access to the information about the actual event (
The
EventContext provides information about the event that is emitted via Service.emit(EventContext). It summarizes all information required by the handlers implementing the event and required by the framework to process the emitting of the
event. It gives access to objects defined by the global context of the event, for example the
CdsModel or the ServiceCatalog. Furthermore it gives access to objects which are
request-bound, like for example the UserInfo. Most importantly it gives access to the information about the actual event (
getEvent())
and the targeted service (getService()) and entity (getTarget()). The
EventContext interface is the super-interface of more specialized EventContext interfaces. Examples for these are CdsReadEventContext or CdsCreateEventContext. The generic interface provides access to all input and output parameters
of an event via the get(String) and put(String, Object) methods. However the
key and type of these parameters has to be known by the implementation. When using the
specialized interfaces this is taken care of. The as(Class) method can be used to
overlay an existing generic EventContext with a more specialized EventContext.-
Method Summary
Modifier and TypeMethodDescription<T extends EventContext>
TOverlays an existingEventContextwith a specialized EventContext interface (for exampleCdsReadEventContextorCdsCreateEventContext) The specialized EventContext provides typed access to the input and output parameters of the event.static <T extends EventContext>
TCreates a new specializedEventContextof concrete typeTstatic EventContextCreates a newEventContextReturns an input or output parameter, which was stored under the given key.Returns the underlyingCdsRuntime.getEvent()com.sap.cds.reflect.CdsModelgetModel()Returns the tenant-specificCdsModel.Returns theService(Consumption API) of the service, targeted by theEventContext.Returns theServiceCatalog, populated with all availableServiceinstances.com.sap.cds.reflect.CdsEntityReturns the Reflection APICdsEntity, for which theEventContextwas created.booleankeySet()Returns an unmodifiablesetcontaining the keys of all parameters.voidproceed()Proceeds with explicit execution of theOnhandler execution chain.voidStores an input or output parameter under a given key Whenever possible it is preferred to use specialized EventContext interfaces to guarantee correct and typed access.voidMarks theEventContextas completed.
-
Method Details
-
create
Creates a newEventContext- Parameters:
event- the name of the evententityName- the name of the entity- Returns:
- the
EventContext
-
create
Creates a new specializedEventContextof concrete typeT- Type Parameters:
T- the specializedEventContexttype- Parameters:
clazz- theClassof the specializedEventContexttypeentityName- the name of the entity- Returns:
- the specialized
EventContext
-
getCdsRuntime
CdsRuntime getCdsRuntime()Returns the underlyingCdsRuntime.- Returns:
- The
CdsRuntimeinstance.
-
getModel
com.sap.cds.reflect.CdsModel getModel()Returns the tenant-specificCdsModel. The tenant is determined based on the request-context and the tenant information available inUserInfo. If no tenant is specified, or if no tenant-specific model exists, the base model is returned.- Returns:
- the (tenant-specific)
CdsModel
-
getServiceCatalog
ServiceCatalog getServiceCatalog()Returns theServiceCatalog, populated with all availableServiceinstances.- Returns:
- the
ServiceCatalog
-
getParameterInfo
ParameterInfo getParameterInfo()- Returns:
- the request-dependent
ParameterInfo
-
getUserInfo
UserInfo getUserInfo()- Returns:
- the request-dependent
UserInfo
-
getAuthenticationInfo
AuthenticationInfo getAuthenticationInfo()- Returns:
- the request-dependent
AuthenticationInfo
-
getFeatureTogglesInfo
FeatureTogglesInfo getFeatureTogglesInfo()- Returns:
- the request-dependent
FeatureTogglesInfo
-
getMessages
Messages getMessages()- Returns:
- the
Messagescontainer for this request
-
getChangeSetContext
ChangeSetContext getChangeSetContext()- Returns:
- the currently active
ChangeSetContext
-
getService
Service getService()Returns theService(Consumption API) of the service, targeted by theEventContext. This is the service, on which theService.emit(EventContext)method (or specialized Consumption API) was called.- Returns:
- the
Service(Consumption API) of the service, targeted by theEventContext.
-
getEvent
String getEvent()- Returns:
- the name of the emitted event
-
getTarget
com.sap.cds.reflect.CdsEntity getTarget()Returns the Reflection APICdsEntity, for which theEventContextwas created. If theEventContextwas created without any entity information from theCdsModel,nullwill be returned.- Returns:
- the
CdsEntity, ornullif theEventContextwas created without entity information.
-
as
Overlays an existingEventContextwith a specialized EventContext interface (for exampleCdsReadEventContextorCdsCreateEventContext) The specialized EventContext provides typed access to the input and output parameters of the event. It operates directly on the originalEventContext. Therefore changes performed on the specialized EventContext instance, returned by this method, are written through to the original instance. In the same way changes to the originalEventContextaffect the specialized EventContext instance, returned by this method.- Type Parameters:
T- the type of the specialized EventContext- Parameters:
clazz- The interface representing the specialized EventContext- Returns:
- an instance of the specialized EventContext, providing typed access to this
EventContextinstance
-
get
Returns an input or output parameter, which was stored under the given key. Whenever possible it is preferred to use specialized EventContext interfaces to guarantee correct and typed access.- Parameters:
key- the key of the parameter- Returns:
- the parameter,
nullif there was no value stored under the given key.
-
put
Stores an input or output parameter under a given key Whenever possible it is preferred to use specialized EventContext interfaces to guarantee correct and typed access.- Parameters:
key- the key of the parametervalue- the parameter value
-
keySet
Returns an unmodifiablesetcontaining the keys of all parameters.- Returns:
- an unmodifiable
setcontaining the keys of all parameters. - Since:
- 1.17.0
- See Also:
-
setCompleted
void setCompleted()Marks theEventContextas completed. As soon as aEventContextis completed, theService.emit(EventContext)processing phases BEFORE and ON are finished. Setting anEventContextto completed, which is already completed has no effect. -
isCompleted
boolean isCompleted()- Returns:
true, ifsetCompleted()was called at least once.
-
proceed
void proceed()Proceeds with explicit execution of theOnhandler execution chain. It is typically used to:- Catch and handle exceptions thrown by underlying
Onhandlers. - Combine semantics of a
BeforeandAfterhandler into a single method, without overwriting the effectiveOnhandler.
Onhandlers will most likely modify theEventContextand callsetCompleted()internally. Triggering this method after the context has been completed already is a noop. Triggering this method from anBeforeorAfterhandler throws aServiceException. - Catch and handle exceptions thrown by underlying
-