Class CoreInstance


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

      • 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
      • 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
      • closeCoreSession

        @Deprecated
        public static void closeCoreSession​(CloseableCoreSession session)
        Deprecated.
        since 11.1, does nothing
        Does nothing.
        Since:
        5.9.3
      • 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