Package org.nuxeo.ecm.core.api
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 Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voidcloseCoreSession(CloseableCoreSession session)Deprecated.since 11.1, does nothingstatic voiddoPrivileged(String repositoryName, Consumer<CoreSession> consumer)Runs the givenConsumerwith a systemCoreSessionwhile logged in as a system user.static <R> RdoPrivileged(String repositoryName, Function<CoreSession,R> function)Runs the givenFunctionwith a systemCoreSessionwhile logged in as a system user.static voiddoPrivileged(CoreSession session, Consumer<CoreSession> consumer)Runs the givenConsumerwith a systemCoreSessionwhile logged in as a system user.static <R> RdoPrivileged(CoreSession session, Function<CoreSession,R> function)Runs the givenFunctionwith a systemCoreSessionwhile logged in as a system user.static CoreSessiongetCoreSession(String repositoryName)Gets aCoreSessionfor the currently logged-in user.static CoreSessiongetCoreSession(String repositoryName, String username)MUST ONLY BE USED IN UNIT TESTS to get aCoreSessionfor the given user.static CoreSessiongetCoreSession(String repositoryName, NuxeoPrincipal principal)Gets aCoreSessionfor the given principal.static CoreSessiongetCoreSessionSystem(String repositoryName)Gets aCoreSessionfor a system user.static CoreSessiongetCoreSessionSystem(String repositoryName, String originatingUsername)Gets aCoreSessionfor a system user with an optional originating username.protected static StringgetCurrentPrincipalName()Gets the name of the currently logged-in principal.protected static NuxeoPrincipalgetPrincipal(String username)static CloseableCoreSessionopenCoreSession(String repositoryName)Deprecated.since 11.1, usegetCoreSession(String)insteadstatic CloseableCoreSessionopenCoreSession(String repositoryName, String username)Deprecated.since 11.1, usegetCoreSession(String, String)insteadstatic CloseableCoreSessionopenCoreSession(String repositoryName, NuxeoPrincipal principal)Deprecated.since 11.1, usegetCoreSession(String, NuxeoPrincipal)insteadstatic CloseableCoreSessionopenCoreSessionSystem(String repositoryName)Deprecated.since 11.1, usegetCoreSessionSystem(String)insteadstatic CloseableCoreSessionopenCoreSessionSystem(String repositoryName, String originatingUsername)Deprecated.since 11.1, usegetCoreSessionSystem(String, String)instead
-
-
-
Method Detail
-
getCoreSession
public static CoreSession getCoreSession(String repositoryName)
Gets aCoreSessionfor the currently logged-in user.- Parameters:
repositoryName- the repository name, ornullfor 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 aCoreSessionfor the given user.- Parameters:
repositoryName- the repository name, ornullfor the default repositoryusername- the user name- Returns:
- the session
- Since:
- 11.1
-
getCoreSessionSystem
public static CoreSession getCoreSessionSystem(String repositoryName)
Gets aCoreSessionfor a system user.- Parameters:
repositoryName- the repository name, ornullfor the default repository- Returns:
- the session
- Since:
- 11.1
-
getCoreSessionSystem
public static CoreSession getCoreSessionSystem(String repositoryName, String originatingUsername)
Gets aCoreSessionfor a system user with an optional originating username.- Parameters:
repositoryName- the repository name, ornullfor the default repositoryoriginatingUsername- the originating username to set on the SystemPrincipal- Returns:
- the session
- Since:
- 11.1
-
getCoreSession
public static CoreSession getCoreSession(String repositoryName, NuxeoPrincipal principal)
Gets aCoreSessionfor the given principal.- Parameters:
repositoryName- the repository name, ornullfor the default repositoryprincipal- the principal- Returns:
- the session
- Since:
- 11.1
-
openCoreSession
@Deprecated public static CloseableCoreSession openCoreSession(String repositoryName)
Deprecated.since 11.1, usegetCoreSession(String)insteadOpens aCoreSessionfor the currently logged-in user.- Parameters:
repositoryName- the repository name, ornullfor the default repository- Returns:
- the session
- Since:
- 5.9.3
-
openCoreSession
@Deprecated public static CloseableCoreSession openCoreSession(String repositoryName, String username)
Deprecated.since 11.1, usegetCoreSession(String, String)insteadMUST ONLY BE USED IN UNIT TESTS to open aCoreSessionfor the given user.- Parameters:
repositoryName- the repository name, ornullfor the default repositoryusername- the user name- Returns:
- the session
- Since:
- 5.9.3
-
openCoreSessionSystem
@Deprecated public static CloseableCoreSession openCoreSessionSystem(String repositoryName)
Deprecated.since 11.1, usegetCoreSessionSystem(String)insteadOpens aCoreSessionfor a system user.- Parameters:
repositoryName- the repository name, ornullfor the default repository- Returns:
- the session
- Since:
- 5.9.3
-
openCoreSessionSystem
@Deprecated public static CloseableCoreSession openCoreSessionSystem(String repositoryName, String originatingUsername)
Deprecated.since 11.1, usegetCoreSessionSystem(String, String)insteadOpens aCoreSessionfor a system user with an optional originating username.- Parameters:
repositoryName- the repository name, ornullfor the default repositoryoriginatingUsername- 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.since 11.1, usegetCoreSession(String, NuxeoPrincipal)insteadOpens aCoreSessionfor the given principal.- Parameters:
repositoryName- the repository name, ornullfor the default repositoryprincipal- the principal- Returns:
- the session
- Since:
- 5.9.3
-
closeCoreSession
@Deprecated public static void closeCoreSession(CloseableCoreSession session)
Deprecated.since 11.1, does nothingDoes 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
nullif there was no login - Since:
- 8.4
-
doPrivileged
public static <R> R doPrivileged(String repositoryName, Function<CoreSession,R> function)
Runs the givenFunctionwith a systemCoreSessionwhile logged in as a system user.- Type Parameters:
R- the function return type- Parameters:
repositoryName- the repository name for theCoreSessionfunction- the function taking a systemCoreSessionand 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 givenFunctionwith a systemCoreSessionwhile logged in as a system user.- Type Parameters:
R- the function return type- Parameters:
session- an existing sessionfunction- the function taking a systemCoreSessionand 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 givenConsumerwith a systemCoreSessionwhile logged in as a system user.- Parameters:
repositoryName- the repository name for theCoreSessionconsumer- the consumer taking a systemCoreSession- Since:
- 8.4
-
doPrivileged
public static void doPrivileged(CoreSession session, Consumer<CoreSession> consumer)
Runs the givenConsumerwith a systemCoreSessionwhile logged in as a system user.- Parameters:
session- an existing sessionconsumer- the consumer taking a systemCoreSession- Since:
- 8.4
-
-