Class OperationContext


  • public class OperationContext
    extends Object

    This class permits to give details about operation actions (save action for now), especially the user who is the trigger of the operation. It is usually used from service method implementation. It is used by JPA Silverpeas API to set the technical entity information on:

    • entity create
    • entity update

    As each operation in Silverpeas is relative to a thread, such an operation context is then attached to the thread that processes the operation. So, the operation context can be get by any processing actors within the same thread without being worried on the context transmission between them.

    Author:
    Yohann Chastagnier
    • Method Detail

      • fromUser

        public static OperationContext fromUser​(String userId)
        Creates an instance from the given identifier which aims a user. If an operation context already exists for the current thread, then sets it with the specified user and returns it.
        Parameters:
        userId - the unique identifier of the user at the source of the operation.
        Returns:
        a new OperationContext for the specified user identifier.
      • fromUser

        public static OperationContext fromUser​(User user)
        Creates an instance from the given user. If an operation context already exists for the current thread, then sets it with the specified user and returns it.
        Parameters:
        user - the user at the source of the operation.
        Returns:
        a new OperationContext for the specified user.
      • fromCurrentRequester

        public static OperationContext fromCurrentRequester()
        Creates an instance from the current requester (User.getCurrentRequester()). If an operation context exists for the current thread, then returns it. Otherwise, constructs a new one from the current requester of the operation (if any). If there is no user set, then set it with the current requester before returning it.
        Returns:
        a new OperationContext for the current user.
      • getFromCache

        public static OperationContext getFromCache()
        Get the current OperationContext instance from a cache (thread cache (request cache exactly)). The call of this method is automatically done by technical JPA tools.
        Returns:
        the current OperationContext instance from the cache.
      • statesOf

        public static boolean statesOf​(OperationContext.State... states)
        Indicates if the given states are well set into context.
        Parameters:
        states - the states to verify.
        Returns:
        true if the specified states exists into the context, false otherwise.
      • withUser

        public OperationContext withUser​(User user)
        Sets the user associated to the save operation.
        Parameters:
        user - the user to set.
        Returns:
        itself.
      • setUpdatingInCaseOfCreation

        public OperationContext setUpdatingInCaseOfCreation()
        Calling this method to indicates that the current data update is performed in a case of a creation. Indeed, in some cases, the creation of a resource into database is done by a chaining of inserts and updates.
        Returns:
        itselft.
      • isUpdatingInCaseOfCreation

        public boolean isUpdatingInCaseOfCreation()
        Indicates if the date update is performed in a case of creation.
        Returns:
        true if the date is updated, false otherwise.
      • setUpdatingInCaseOfCreation

        public OperationContext setUpdatingInCaseOfCreation​(boolean updatingInCaseOfCreation)
        Calling this method to indicates that the current data update is performed in a case of a creation or not. Indeed, in some cases, the creation of a resource into database is done by a chaining of inserts and updates.
        Parameters:
        updatingInCaseOfCreation - true to specify that the update is performed in a case of data creation.
        Returns:
        itself
      • getUser

        public User getUser()
        Gets the user behind the operation.
        Returns:
        the user concerned by the operation.
      • getPersistenceOperation

        public <T extends PersistenceOperation> T getPersistenceOperation​(Class<T> operationType)
        Gets the current active persistence operation from this context.
        Type Parameters:
        T - the concrete type of the implementation of PersistenceOperation class.
        Parameters:
        operationType - the type of the expected persistence operation.
        Returns:
        a persistence operation matching the expected type. Null if no such type exists.