use of org.nuxeo.ecm.core.api.CoreSession in project nuxeo-drive-server by nuxeo.
the class NuxeoDriveGroupUpdateListener method handleUpdatedGroups.
protected void handleUpdatedGroups(List<String> groupNames) {
RepositoryManager repositoryManager = Framework.getService(RepositoryManager.class);
for (String repositoryName : repositoryManager.getRepositoryNames()) {
CoreInstance.doPrivileged(repositoryName, (CoreSession session) -> {
DocumentModelList impactedDocuments = getImpactedDocuments(session, groupNames);
impactedDocuments.forEach(doc -> fireGroupUpdatedEvent(session, doc));
});
}
}
use of org.nuxeo.ecm.core.api.CoreSession in project nuxeo-drive-server by nuxeo.
the class NuxeoDriveSyncRootCopyListener method handleEvent.
@Override
public void handleEvent(Event event) {
if (Framework.getService(ConfigurationService.class).isBooleanPropertyFalse(RESET_SYNC_ROOTS_ON_COPY_CONFIGURATION_PROPERTY)) {
return;
}
EventContext context = event.getContext();
if (!(context instanceof DocumentEventContext)) {
return;
}
DocumentModel doc = ((DocumentEventContext) context).getSourceDocument();
CoreSession session = context.getCoreSession();
DocumentModelList syncRoots = getSyncRoots(doc, session);
for (DocumentModel syncRoot : syncRoots) {
syncRoot.setPropertyValue(NuxeoDriveManagerImpl.DRIVE_SUBSCRIPTIONS_PROPERTY, null);
syncRoot.putContextData("source", "drive");
syncRoot.putContextData(CoreSession.SOURCE, "drive");
session.saveDocument(syncRoot);
}
}
use of org.nuxeo.ecm.core.api.CoreSession in project nuxeo-drive-server by nuxeo.
the class FileSystemItemManagerImpl method getSession.
@Deprecated
@Override
public CoreSession getSession(String repositoryName, Principal principal) {
final String sessionKey = repositoryName + "/" + principal.getName();
CoreSession session = openedSessions.get().get(sessionKey);
if (session == null) {
Map<String, Serializable> context = new HashMap<String, Serializable>();
context.put("principal", (Serializable) principal);
final CloseableCoreSession newSession = CoreInstance.openCoreSession(repositoryName, principal);
openedSessions.get().put(sessionKey, newSession);
try {
Transaction t = TransactionHelper.lookupTransactionManager().getTransaction();
if (t == null) {
throw new RuntimeException("FileSystemItemManagerImpl requires an active transaction.");
}
t.registerSynchronization(new SessionCloser(newSession, sessionKey));
} catch (SystemException | NamingException | RollbackException e) {
throw new NuxeoException(e);
}
session = newSession;
}
return session;
}
use of org.nuxeo.ecm.core.api.CoreSession in project nuxeo-drive-server by nuxeo.
the class PermissionSyncRootFactory method isFileSystemItem.
/**
* Checks if the given {@link DocumentModel} is adaptable as a {@link FileSystemItem}. The permission
* synchronization root factory considers that a {@link DocumentModel} is adaptable as a {@link FileSystemItem} if:
* <ul>
* <li>It is Folderish</li>
* <li>AND it is not a version nor a proxy</li>
* <li>AND it is not HiddenInNavigation</li>
* <li>AND it is not in the trash, unless {@code includeDeleted} is true</li>
* <li>AND it is a synchronization root registered for the current user, unless {@code relaxSyncRootConstraint} is
* true</li>
* <li>AND the current user has the {@link #getRequiredPermission()} permission on the document</li>
* </ul>
*/
@Override
public boolean isFileSystemItem(DocumentModel doc, boolean includeDeleted, boolean relaxSyncRootConstraint) {
// Check required permission
CoreSession session = doc.getCoreSession();
boolean hasRequiredPermission = session.hasPermission(doc.getRef(), requiredPermission);
if (!hasRequiredPermission) {
if (log.isDebugEnabled()) {
log.debug(String.format("Required permission %s is not granted on document %s to user %s, it cannot be adapted as a FileSystemItem.", requiredPermission, doc.getId(), session.getPrincipal().getName()));
}
return false;
}
return super.isFileSystemItem(doc, includeDeleted, relaxSyncRootConstraint) && hasRequiredPermission;
}
use of org.nuxeo.ecm.core.api.CoreSession in project nuxeo-drive-server by nuxeo.
the class NuxeoDriveSyncRootVersioningListener method handleEvent.
@Override
public void handleEvent(Event event) {
EventContext context = event.getContext();
DocumentRef checkedInVersionRef = (DocumentRef) context.getProperty("checkedInVersionRef");
if (checkedInVersionRef == null) {
return;
}
CoreSession session = context.getCoreSession();
DocumentModel doc = session.getDocument(checkedInVersionRef);
if (!(doc.isVersion() && doc.hasFacet(NuxeoDriveManagerImpl.NUXEO_DRIVE_FACET))) {
return;
}
doc.setPropertyValue(NuxeoDriveManagerImpl.DRIVE_SUBSCRIPTIONS_PROPERTY, null);
doc.putContextData(CoreSession.ALLOW_VERSION_WRITE, Boolean.TRUE);
doc.putContextData("source", "drive");
doc.putContextData(CoreSession.SOURCE, "drive");
session.saveDocument(doc);
}
Aggregations