/** * Opens a {@link CoreSession} for a system user. * <p> * The session must be closed using {@link CloseableCoreSession#close}. * * @param repositoryName the repository name, or {@code null} for the default repository * @return the session * @since 5.9.3 */ public static CloseableCoreSession openCoreSessionSystem(String repositoryName) { return openCoreSession(repositoryName, new SystemPrincipal(null)); }
/** * May be called by implementing classes to open a System session on the repository. * * @since 8.1 */ public void openSystemSession() { session = CoreInstance.openCoreSessionSystem(repositoryName, originatingUsername); }
/** * Opens a {@link CoreSession} for the currently logged-in user. * <p> * The session must be closed using {@link CloseableCoreSession#close}. * * @param repositoryName the repository name, or {@code null} for the default repository * @return the session * @since 5.9.3 */ public static CloseableCoreSession openCoreSession(String repositoryName) { return openCoreSession(repositoryName, getPrincipal(null)); }
protected void copyTags(CoreSession session, String srcDocId, String dstDocId, boolean removeExistingTags) { CoreInstance.doPrivileged(session, s -> { doCopyTags(s, srcDocId, dstDocId, removeExistingTags); }); }
protected String probeRepository(String repositoryName) { return TransactionHelper.runInTransaction(() -> CoreInstance.doPrivileged(repositoryName, this::probeSession)); }
/** * MUST ONLY BE USED IN UNIT TESTS to open a {@link CoreSession} for the given user. * <p> * The session must be closed using {@link CloseableCoreSession#close}. * * @param repositoryName the repository name, or {@code null} for the default repository * @param username the user name * @return the session * @since 5.9.3 */ public static CloseableCoreSession openCoreSession(String repositoryName, String username) { return openCoreSession(repositoryName, getPrincipal(username)); }
/** * Opens a {@link CoreSession} for a system user with an optional originating username. * <p> * The session must be closed using {@link CloseableCoreSession#close}. * * @param repositoryName the repository name, or {@code null} for the default repository * @param originatingUsername the originating username to set on the SystemPrincipal * @return the session * @since 8.1 */ public static CloseableCoreSession openCoreSessionSystem(String repositoryName, String originatingUsername) { return openCoreSession(repositoryName, new SystemPrincipal(originatingUsername)); }
@Override public Set<String> getTags(CoreSession session, String docId) { return CoreInstance.doPrivileged(session, (CoreSession s) -> doGetTags(s, docId)); }
/** * Make sure we open the repository, to initialize its connection manager. */ protected void activateRepository(String repositoryName) { try (CloseableCoreSession session = CoreInstance.openCoreSessionSystem(repositoryName)) { // do nothing, just open and close } }
private Object readResolve() throws ObjectStreamException { // we need a transaction for this boolean started = false; if (!TransactionHelper.isTransactionActiveOrMarkedRollback()) { started = TransactionHelper.startTransaction(); } try { try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) { referent = session.getDocument(ref); referent.detach(true); return referent; } } catch (RuntimeException cause) { InvalidObjectException error = new InvalidObjectException( "Cannot refetch " + ref + " from " + repositoryName); error.initCause(cause); throw error; } finally { if (started) { TransactionHelper.commitOrRollbackTransaction(); } } }
protected void migrateRepository(String repositoryName) { TransactionHelper.runInTransaction(() -> CoreInstance.doPrivileged(repositoryName, this::migrateSession)); }
/** * May be called by implementing classes to open a session on the given repository. * * @param repositoryName the repository name * @return the session (also available in {@code session} field) * @deprecated since 8.1. Use {@link #openSystemSession()} to open a session on the configured repository name, * otherwise use {@link CoreInstance#openCoreSessionSystem(String)}. */ @Deprecated public CoreSession initSession(String repositoryName) { session = CoreInstance.openCoreSessionSystem(repositoryName, originatingUsername); return session; }
try (CloseableCoreSession closeableCoreSession = CoreInstance.openCoreSession(repositoryName)) { session = closeableCoreSession; run();
@Override public List<DocumentModel> getSubscribedDocuments(String prefixedPrincipalName, String repositoryName) { String nxql = "SELECT * FROM Document WHERE ecm:mixinType = '" + SubscriptionAdapter.NOTIFIABLE_FACET + "' " + "AND ecm:isVersion = 0 " + "AND notif:notifications/*/subscribers/* = " + NXQL.escapeString(prefixedPrincipalName); return CoreInstance.doPrivileged(repositoryName, (CoreSession s) -> s.query(nxql).stream().map(NotificationService::detachDocumentModel).collect( toList())); }
public CloseableCoreSession openCoreSessionSystem() { return CoreInstance.openCoreSessionSystem(getRepositoryName()); }
protected CloseableCoreSession createSession(HttpServletRequest request, String repoName) { if (request.getUserPrincipal() == null) { throw new java.lang.IllegalStateException("Not authenticated user is trying to get a core session"); } return CoreInstance.openCoreSession(repoName); }
@Override @SuppressWarnings("unchecked") public List<Annotation> getAnnotations(CoreSession session, String documentId, String xpath) { return CoreInstance.doPrivileged(session, s -> { PageProviderService ppService = Framework.getService(PageProviderService.class); Map<String, Serializable> props = Collections.singletonMap( CoreQueryAndFetchPageProvider.CORE_SESSION_PROPERTY, (Serializable) s); List<DocumentModel> annotationList = // ((PageProvider<DocumentModel>) ppService.getPageProvider(GET_ANNOTATIONS_FOR_DOC_PAGEPROVIDER_NAME, null, null, null, props, documentId, xpath)).getCurrentPage(); return annotationList.stream().map(AnnotationImpl::new).collect(Collectors.toList()); }); }
protected CoreSession getReconnectedCoreSession(String repoName, String originatingUsername) { if (reconnectedCoreSession == null) { try { loginCtx = Framework.login(); } catch (LoginException e) { log.error("Cannot log in", e); return null; } reconnectedCoreSession = CoreInstance.openCoreSessionSystem(repoName, originatingUsername); } else { // Sanity Check if (!reconnectedCoreSession.getRepositoryName().equals(repoName)) { if (repoName != null) { throw new IllegalStateException("Can no reconnected a Bundle tied to several Core instances !"); } } } return reconnectedCoreSession; }
public CloseableCoreSession openCoreSession(NuxeoPrincipal principal) { return CoreInstance.openCoreSession(getRepositoryName(), principal); }
@Override public List<String> getTagDocumentIds(CoreSession session, String label) { String cleanLabel = cleanLabel(label, true, false); return CoreInstance.doPrivileged(session, (CoreSession s) -> doGetTagDocumentIds(s, cleanLabel)); }