Class CoreInstance

java.lang.Object
org.nuxeo.ecm.core.api.CoreInstance

public class CoreInstance extends Object
The CoreInstance is the main access point to a CoreSession.
  • Method Details

    • getCoreSession

      public static CoreSession getCoreSession(String repositoryName)
      Gets a CoreSession for the currently logged-in user.
      Parameters:
      repositoryName - the repository name, or null for the default repository
      Returns:
      the session
      Since:
      11.1
    • getCoreSession

      public static CoreSession getCoreSession(String repositoryName, String username)
      MUST ONLY BE USED IN UNIT TESTS to get a CoreSession for the given user.
      Parameters:
      repositoryName - the repository name, or null for the default repository
      username - the user name
      Returns:
      the session
      Since:
      11.1
    • getCoreSessionSystem

      public static CoreSession getCoreSessionSystem(String repositoryName)
      Gets a CoreSession for a system user.
      Parameters:
      repositoryName - the repository name, or null for the default repository
      Returns:
      the session
      Since:
      11.1
    • getCoreSessionSystem

      public static CoreSession getCoreSessionSystem(String repositoryName, String originatingUsername)
      Gets a CoreSession for a system user with an optional originating username.
      Parameters:
      repositoryName - the repository name, or null for the default repository
      originatingUsername - the originating username to set on the SystemPrincipal
      Returns:
      the session
      Since:
      11.1
    • getCoreSession

      public static CoreSession getCoreSession(String repositoryName, NuxeoPrincipal principal)
      Gets a CoreSession for the given principal.
      Parameters:
      repositoryName - the repository name, or null for the default repository
      principal - the principal
      Returns:
      the session
      Since:
      11.1
    • openCoreSession

      @Deprecated public static CloseableCoreSession openCoreSession(String repositoryName)
      Deprecated.
      since 11.1, use getCoreSession(String) instead
      Opens a CoreSession for the currently logged-in user.
      Parameters:
      repositoryName - the repository name, or null for the default repository
      Returns:
      the session
      Since:
      5.9.3
    • openCoreSession

      @Deprecated public static CloseableCoreSession openCoreSession(String repositoryName, String username)
      Deprecated.
      since 11.1, use getCoreSession(String, String) instead
      MUST ONLY BE USED IN UNIT TESTS to open a CoreSession for the given user.
      Parameters:
      repositoryName - the repository name, or null for the default repository
      username - the user name
      Returns:
      the session
      Since:
      5.9.3
    • openCoreSessionSystem

      @Deprecated public static CloseableCoreSession openCoreSessionSystem(String repositoryName)
      Deprecated.
      since 11.1, use getCoreSessionSystem(String) instead
      Opens a CoreSession for a system user.
      Parameters:
      repositoryName - the repository name, or null for the default repository
      Returns:
      the session
      Since:
      5.9.3
    • openCoreSessionSystem

      @Deprecated public static CloseableCoreSession openCoreSessionSystem(String repositoryName, String originatingUsername)
      Deprecated.
      since 11.1, use getCoreSessionSystem(String, String) instead
      Opens a CoreSession for a system user with an optional originating username.
      Parameters:
      repositoryName - the repository name, or null for the default repository
      originatingUsername - the originating username to set on the SystemPrincipal
      Returns:
      the session
      Since:
      8.1
    • openCoreSession

      @Deprecated public static CloseableCoreSession openCoreSession(String repositoryName, NuxeoPrincipal principal)
      Deprecated.
      Opens a CoreSession for the given principal.
      Parameters:
      repositoryName - the repository name, or null for the default repository
      principal - the principal
      Returns:
      the session
      Since:
      5.9.3
    • closeCoreSession

      @Deprecated public static void closeCoreSession(CloseableCoreSession session)
      Deprecated.
      since 11.1, does nothing
      Does nothing.
      Since:
      5.9.3
    • getPrincipal

      protected static NuxeoPrincipal getPrincipal(String username)
    • getCurrentPrincipalName

      protected static String getCurrentPrincipalName()
      Gets the name of the currently logged-in principal.
      Returns:
      the principal name, or null if there was no login
      Since:
      8.4
    • doPrivileged

      public static <R> R doPrivileged(String repositoryName, Function<CoreSession,R> function)
      Runs the given Function with a system CoreSession while logged in as a system user.
      Type Parameters:
      R - the function return type
      Parameters:
      repositoryName - the repository name for the CoreSession
      function - the function taking a system CoreSession and returning a result of type <R>
      Returns:
      the result of the function
      Since:
      8.4
    • doPrivileged

      public static <R> R doPrivileged(CoreSession session, Function<CoreSession,R> function)
      Runs the given Function with a system CoreSession while logged in as a system user.
      Type Parameters:
      R - the function return type
      Parameters:
      session - an existing session
      function - the function taking a system CoreSession and returning a result of type <R>
      Returns:
      the result of the function
      Since:
      8.4
    • doPrivileged

      public static void doPrivileged(String repositoryName, Consumer<CoreSession> consumer)
      Runs the given Consumer with a system CoreSession while logged in as a system user.
      Parameters:
      repositoryName - the repository name for the CoreSession
      consumer - the consumer taking a system CoreSession
      Since:
      8.4
    • doPrivileged

      public static void doPrivileged(CoreSession session, Consumer<CoreSession> consumer)
      Runs the given Consumer with a system CoreSession while logged in as a system user.
      Parameters:
      session - an existing session
      consumer - the consumer taking a system CoreSession
      Since:
      8.4