Interface EventContext

All Known Subinterfaces:
ActionAccessEventContext, ApplicationPreparedEventContext, ApplicationStoppedEventContext, CalcWhereConditionEventContext, CdsCreateEventContext, CdsDeleteEventContext, CdsReadEventContext, CdsUpdateEventContext, CdsUpsertEventContext, CloudEventMessageEventContext, ConfigChangeLogContext, DataAccessLogContext, DataModificationLogContext, DependenciesEventContext, DraftCancelEventContext, DraftCreateEventContext, DraftEditEventContext, DraftGcEventContext, DraftNewEventContext, DraftPatchEventContext, DraftPrepareEventContext, DraftSaveEventContext, EntityAccessEventContext, ErrorResponseEventContext, FunctionAccessEventContext, GetRestrictionEventContext, MessagingErrorEventContext, ModelChangedEventContext, OutboxMessageEventContext, PdfExportEventContext, ReadProviderTenantEventContext, ReadTenantsEventContext, SecurityLogContext, ServiceAccessEventContext, SubscribeEventContext, TopicMessageEventContext, UnsubscribeEventContext, UpgradeEventContext

public interface EventContext
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 Details

    • create

      static EventContext create(String event, String entityName)
      Creates a new EventContext
      Parameters:
      event - the name of the event
      entityName - the name of the entity
      Returns:
      the EventContext
    • create

      static <T extends EventContext> T create(Class<T> clazz, String entityName)
      Creates a new specialized EventContext of concrete type T
      Type Parameters:
      T - the specialized EventContext type
      Parameters:
      clazz - the Class of the specialized EventContext type
      entityName - the name of the entity
      Returns:
      the specialized EventContext
    • getCdsRuntime

      CdsRuntime getCdsRuntime()
      Returns the underlying CdsRuntime.
      Returns:
      The CdsRuntime instance.
    • getModel

      com.sap.cds.reflect.CdsModel getModel()
      Returns the tenant-specific CdsModel. The tenant is determined based on the request-context and the tenant information available in UserInfo. 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 the ServiceCatalog, populated with all available Service instances.
      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 Messages container for this request
    • getChangeSetContext

      ChangeSetContext getChangeSetContext()
      Returns:
      the currently active ChangeSetContext
    • getService

      Service getService()
      Returns the Service (Consumption API) of the service, targeted by the EventContext. This is the service, on which the Service.emit(EventContext) method (or specialized Consumption API) was called.
      Returns:
      the Service (Consumption API) of the service, targeted by the EventContext.
    • getEvent

      String getEvent()
      Returns:
      the name of the emitted event
    • getTarget

      com.sap.cds.reflect.CdsEntity getTarget()
      Returns the Reflection API CdsEntity, for which the EventContext was created. If the EventContext was created without any entity information from the CdsModel, null will be returned.
      Returns:
      the CdsEntity, or null if the EventContext was created without entity information.
    • as

      <T extends EventContext> T as(Class<T> clazz)
      Overlays an existing EventContext with a specialized EventContext interface (for example CdsReadEventContext or CdsCreateEventContext) The specialized EventContext provides typed access to the input and output parameters of the event. It operates directly on the original EventContext. 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 original EventContext affect 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 EventContext instance
    • get

      Object get(String key)
      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, null if there was no value stored under the given key.
    • put

      void put(String key, Object value)
      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 parameter
      value - the parameter value
    • keySet

      Set<String> keySet()
      Returns an unmodifiable set containing the keys of all parameters.
      Returns:
      an unmodifiable set containing the keys of all parameters.
      Since:
      1.17.0
      See Also:
    • setCompleted

      void setCompleted()
      Marks the EventContext as completed. As soon as a EventContext is completed, the Service.emit(EventContext) processing phases BEFORE and ON are finished. Setting an EventContext to completed, which is already completed has no effect.
    • isCompleted

      boolean isCompleted()
      Returns:
      true, if setCompleted() was called at least once.