use of org.nuxeo.drive.service.NuxeoDriveManager in project nuxeo-drive-server by nuxeo.
the class AuditChangeFinder method getFileSystemChanges.
protected List<FileSystemItemChange> getFileSystemChanges(CoreSession session, Set<IdRef> lastActiveRootRefs, SynchronizationRoots activeRoots, Set<String> collectionSyncRootMemberIds, long lowerBound, long upperBound, boolean integerBounds, int limit) throws TooManyChangesException {
String principalName = session.getPrincipal().getName();
List<FileSystemItemChange> changes = new ArrayList<FileSystemItemChange>();
// Note: lastActiveRootRefs is not used: we could remove it from the
// public API
// and from the client as well but it might be useful to optimize future
// alternative implementations FileSystemChangeFinder component so it
// might
// be better to leave it part of the public API as currently.
// Find changes from the log under active roots or events that are
// linked to the un-registration or deletion of formerly synchronized
// roots
List<LogEntry> entries = queryAuditEntries(session, activeRoots, collectionSyncRootMemberIds, lowerBound, upperBound, integerBounds, limit);
// query with the actual active roots.
for (LogEntry entry : entries) {
if (NuxeoDriveEvents.EVENT_CATEGORY.equals(entry.getCategory())) {
if (log.isDebugEnabled()) {
log.debug(String.format("Detected sync root change for user '%s' in audit log:" + " invalidating the root cache and refetching the changes.", principalName));
}
NuxeoDriveManager driveManager = Framework.getService(NuxeoDriveManager.class);
driveManager.invalidateSynchronizationRootsCache(principalName);
driveManager.invalidateCollectionSyncRootMemberCache(principalName);
Map<String, SynchronizationRoots> synchronizationRoots = driveManager.getSynchronizationRoots(session.getPrincipal());
SynchronizationRoots updatedActiveRoots = synchronizationRoots.get(session.getRepositoryName());
Set<String> updatedCollectionSyncRootMemberIds = driveManager.getCollectionSyncRootMemberIds(session.getPrincipal()).get(session.getRepositoryName());
entries = queryAuditEntries(session, updatedActiveRoots, updatedCollectionSyncRootMemberIds, lowerBound, upperBound, integerBounds, limit);
break;
}
}
if (entries.size() >= limit) {
throw new TooManyChangesException("Too many changes found in the audit logs.");
}
for (LogEntry entry : entries) {
if (log.isDebugEnabled()) {
log.debug(String.format("Handling log entry %s", entry));
}
FileSystemItemChange change = null;
DocumentRef docRef = new IdRef(entry.getDocUUID());
ExtendedInfo fsIdInfo = entry.getExtendedInfos().get("fileSystemItemId");
if (fsIdInfo != null) {
// been updated, we just know the FileSystemItem id and name.
if (log.isDebugEnabled()) {
log.debug(String.format("Found extended info in audit log entry: document has been deleted, moved," + " is an unregistered synchronization root or its security has been updated," + " we just know the FileSystemItem id and name."));
}
boolean isChangeSet = false;
// current user still has access to the document.
if (!"deleted".equals(entry.getEventId()) && session.exists(docRef)) {
change = getFileSystemItemChange(session, docRef, entry, fsIdInfo.getValue(String.class));
if (change != null) {
if (NuxeoDriveEvents.MOVED_EVENT.equals(entry.getEventId())) {
// virtual event.
if (log.isDebugEnabled()) {
log.debug(String.format("Document %s (%s) has been moved to another synchronzation root, not adding entry to the change summary.", entry.getDocPath(), docRef));
}
continue;
}
isChangeSet = true;
}
}
if (!isChangeSet) {
// FileSystemItem id and name to the FileSystemItemChange entry.
if (log.isDebugEnabled()) {
log.debug(String.format("Document %s (%s) doesn't exist or is not adaptable as a FileSystemItem, only providing the FileSystemItem id and name to the FileSystemItemChange entry.", entry.getDocPath(), docRef));
}
String fsId = fsIdInfo.getValue(String.class);
String eventId;
if (NuxeoDriveEvents.MOVED_EVENT.equals(entry.getEventId())) {
// Move to a non synchronization root
eventId = NuxeoDriveEvents.DELETED_EVENT;
} else {
// Deletion, unregistration or security update
eventId = entry.getEventId();
}
change = new FileSystemItemChangeImpl(eventId, entry.getEventDate().getTime(), entry.getRepositoryId(), entry.getDocUUID(), fsId, null);
}
if (log.isDebugEnabled()) {
log.debug(String.format("Adding FileSystemItemChange entry to the change summary: %s", change));
}
changes.add(change);
} else {
// unregistered synchronization root nor a security update denying access to the current user.
if (log.isDebugEnabled()) {
log.debug(String.format("No extended info found in audit log entry %s (%s): this is not a deleted document, a moved document," + " an unregistered synchronization root nor a security update denying access to the current user.", entry.getDocPath(), docRef));
}
if (!session.exists(docRef)) {
if (log.isDebugEnabled()) {
log.debug(String.format("Document %s (%s) doesn't exist, not adding entry to the change summary.", entry.getDocPath(), docRef));
}
// try to propagate this event.
continue;
}
// Let's try to adapt the document as a FileSystemItem to
// provide it to the FileSystemItemChange entry.
change = getFileSystemItemChange(session, docRef, entry, null);
if (change == null) {
// Non-adaptable documents are ignored
if (log.isDebugEnabled()) {
log.debug(String.format("Document %s (%s) is not adaptable as a FileSystemItem, not adding any entry to the change summary.", entry.getDocPath(), docRef));
}
} else {
if (log.isDebugEnabled()) {
log.debug(String.format("Adding FileSystemItemChange entry to the change summary: %s", change));
}
changes.add(change);
}
}
}
return changes;
}
use of org.nuxeo.drive.service.NuxeoDriveManager in project nuxeo-drive-server by nuxeo.
the class DefaultFileSystemItemFactory method isFileSystemItem.
/**
* The default factory considers that a {@link DocumentModel} is adaptable as a {@link FileSystemItem} if:
* <ul>
* <li>It is not a version</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 Folderish or it can be adapted as a {@link BlobHolder} with a blob</li>
* <li>AND its blob is not backed by an extended blob provider</li>
* <li>AND it is not a synchronization root registered for the current user, unless {@code relaxSyncRootConstraint}
* is true</li>
* </ul>
*/
@Override
public boolean isFileSystemItem(DocumentModel doc, boolean includeDeleted, boolean relaxSyncRootConstraint) {
// Check version
if (doc.isVersion()) {
if (log.isDebugEnabled()) {
log.debug(String.format("Document %s is a version, it cannot be adapted as a FileSystemItem.", doc.getId()));
}
return false;
}
// Check Collections
if (CollectionConstants.COLLECTIONS_TYPE.equals(doc.getType())) {
if (log.isDebugEnabled()) {
log.debug(String.format("Document %s is the collection root folder (type=%s, path=%s), it cannot be adapted as a FileSystemItem.", doc.getId(), CollectionConstants.COLLECTIONS_TYPE, doc.getPathAsString()));
}
return false;
}
// Check HiddenInNavigation
if (doc.hasFacet("HiddenInNavigation")) {
if (log.isDebugEnabled()) {
log.debug(String.format("Document %s is HiddenInNavigation, it cannot be adapted as a FileSystemItem.", doc.getId()));
}
return false;
}
// Check if document is in the trash
if (!includeDeleted && doc.isTrashed()) {
if (log.isDebugEnabled()) {
log.debug(String.format("Document %s is trashed, it cannot be adapted as a FileSystemItem.", doc.getId()));
}
return false;
}
// Try to fetch blob
Blob blob = null;
try {
blob = getBlob(doc);
} catch (NuxeoException e) {
log.error(String.format("Error while fetching blob for document %s, it cannot be adapted as a FileSystemItem.", doc.getId()), e);
return false;
}
// Check Folderish or BlobHolder with a blob
if (!doc.isFolder() && blob == null) {
if (log.isDebugEnabled()) {
log.debug(String.format("Document %s is not Folderish nor a BlobHolder with a blob, it cannot be adapted as a FileSystemItem.", doc.getId()));
}
return false;
}
// Check for blobs backed by extended blob providers (ex: Google Drive)
if (!doc.isFolder()) {
BlobManager blobManager = Framework.getService(BlobManager.class);
BlobProvider blobProvider = blobManager.getBlobProvider(blob);
if (blobProvider != null && (!blobProvider.supportsUserUpdate() || blobProvider.getBinaryManager() == null)) {
if (log.isDebugEnabled()) {
log.debug(String.format("Blob for Document %s is backed by a BlobProvider preventing updates, it cannot be adapted as a FileSystemItem.", doc.getId()));
}
return false;
}
}
if (!relaxSyncRootConstraint && doc.isFolder()) {
// Check not a synchronization root registered for the current user
NuxeoDriveManager nuxeoDriveManager = Framework.getService(NuxeoDriveManager.class);
Principal principal = doc.getCoreSession().getPrincipal();
boolean isSyncRoot = nuxeoDriveManager.isSynchronizationRoot(principal, doc);
if (isSyncRoot) {
if (log.isDebugEnabled()) {
log.debug(String.format("Document %s is a registered synchronization root for user %s, it cannot be adapted as a DefaultFileSystemItem.", doc.getId(), principal.getName()));
}
return false;
}
}
return true;
}
use of org.nuxeo.drive.service.NuxeoDriveManager in project nuxeo-drive-server by nuxeo.
the class NuxeoDriveCacheInvalidationListener method handleEvent.
@Override
public void handleEvent(Event event) {
DocumentEventContext docCtx;
if (event.getContext() instanceof DocumentEventContext) {
docCtx = (DocumentEventContext) event.getContext();
} else {
// not interested in event that are not related to documents
return;
}
String transition = (String) docCtx.getProperty(LifeCycleConstants.TRANSTION_EVENT_OPTION_TRANSITION);
if (transition != null && !(LifeCycleConstants.DELETE_TRANSITION.equals(transition) || LifeCycleConstants.UNDELETE_TRANSITION.equals(transition))) {
// document deletion
return;
}
NuxeoDriveManager driveManager = Framework.getService(NuxeoDriveManager.class);
if (CollectionConstants.ADDED_TO_COLLECTION.equals(event.getName()) || CollectionConstants.REMOVED_FROM_COLLECTION.equals(event.getName())) {
driveManager.invalidateCollectionSyncRootMemberCache();
} else {
driveManager.handleFolderDeletion((IdRef) docCtx.getSourceDocument().getRef());
}
}
use of org.nuxeo.drive.service.NuxeoDriveManager in project nuxeo-drive-server by nuxeo.
the class CollectionSyncRootFolderItemFactory method isFileSystemItem.
/**
* The factory considers that a {@link DocumentModel} is adaptable as a {@link FileSystemItem} if:
* <ul>
* <li>It is a Collection</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>
* </ul>
*/
@Override
public boolean isFileSystemItem(DocumentModel doc, boolean includeDeleted, boolean relaxSyncRootConstraint) {
// Check Collection
if (!Framework.getService(CollectionManager.class).isCollection(doc)) {
if (log.isDebugEnabled()) {
log.debug(String.format("Document %s is not a Collection, it cannot be adapted as a FileSystemItem.", doc.getId()));
}
return false;
}
// Check HiddenInNavigation
if (doc.hasFacet("HiddenInNavigation")) {
if (log.isDebugEnabled()) {
log.debug(String.format("Document %s is HiddenInNavigation, it cannot be adapted as a FileSystemItem.", doc.getId()));
}
return false;
}
// Check is document is in the trash
if (!includeDeleted && doc.isTrashed()) {
if (log.isDebugEnabled()) {
log.debug(String.format("Document %s is in the trash, it cannot be adapted as a FileSystemItem.", doc.getId()));
}
return false;
}
if (!relaxSyncRootConstraint) {
// Check synchronization root registered for the current user
NuxeoDriveManager nuxeoDriveManager = Framework.getService(NuxeoDriveManager.class);
Principal principal = doc.getCoreSession().getPrincipal();
boolean isSyncRoot = nuxeoDriveManager.isSynchronizationRoot(principal, doc);
if (!isSyncRoot) {
if (log.isDebugEnabled()) {
log.debug(String.format("Document %s is not a registered synchronization root for user %s, it cannot be adapted as a FileSystemItem.", doc.getId(), principal.getName()));
}
return false;
}
}
return true;
}
use of org.nuxeo.drive.service.NuxeoDriveManager in project nuxeo-drive-server by nuxeo.
the class AbstractSyncRootFolderItemFactory method isFileSystemItem.
/**
* The 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>
* </ul>
*/
@Override
public boolean isFileSystemItem(DocumentModel doc, boolean includeDeleted, boolean relaxSyncRootConstraint) {
// Check Folderish
if (!doc.isFolder()) {
if (log.isDebugEnabled()) {
log.debug(String.format("Document %s is not Folderish, it cannot be adapted as a FileSystemItem.", doc.getId()));
}
return false;
}
// Check version
if (doc.isVersion()) {
if (log.isDebugEnabled()) {
log.debug(String.format("Document %s is a version, it cannot be adapted as a FileSystemItem.", doc.getId()));
}
return false;
}
// Check proxy
if (doc.isProxy()) {
if (log.isDebugEnabled()) {
log.debug(String.format("Document %s is a proxy, it cannot be adapted as a FileSystemItem.", doc.getId()));
}
return false;
}
// Check HiddenInNavigation
if (doc.hasFacet("HiddenInNavigation")) {
if (log.isDebugEnabled()) {
log.debug(String.format("Document %s is HiddenInNavigation, it cannot be adapted as a FileSystemItem.", doc.getId()));
}
return false;
}
// Check if document is in the trash
if (!includeDeleted && doc.isTrashed()) {
if (log.isDebugEnabled()) {
log.debug(String.format("Document %s is in the trash, it cannot be adapted as a FileSystemItem.", doc.getId()));
}
return false;
}
if (!relaxSyncRootConstraint) {
// Check synchronization root registered for the current user
NuxeoDriveManager nuxeoDriveManager = Framework.getService(NuxeoDriveManager.class);
Principal principal = doc.getCoreSession().getPrincipal();
boolean isSyncRoot = nuxeoDriveManager.isSynchronizationRoot(principal, doc);
if (!isSyncRoot) {
if (log.isDebugEnabled()) {
log.debug(String.format("Document %s is not a registered synchronization root for user %s, it cannot be adapted as a FileSystemItem.", doc.getId(), principal.getName()));
}
return false;
}
}
return true;
}
Aggregations