use of org.nuxeo.ecm.core.api.NuxeoException 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.ecm.core.api.NuxeoException in project nuxeo-drive-server by nuxeo.
the class PermissionSyncRootFactory method getParentItem.
/*------------------ AbstractSyncRootFolderItemFactory ------------------*/
@Override
protected FolderItem getParentItem(DocumentModel doc) {
Principal principal = doc.getCoreSession().getPrincipal();
String docCreator = (String) doc.getPropertyValue("dc:creator");
if (principal.getName().equals(docCreator)) {
FolderItem parent = getFileSystemAdapterService().getVirtualFolderItemFactory(userSyncRootParentFactoryName).getVirtualFolderItem(principal);
if (parent == null) {
throw new NuxeoException(String.format("Cannot find the parent of document %s: virtual folder from factory %s.", doc.getId(), userSyncRootParentFactoryName));
}
return parent;
} else {
FolderItem parent = getFileSystemAdapterService().getVirtualFolderItemFactory(sharedSyncRootParentFactoryName).getVirtualFolderItem(principal);
if (parent == null) {
throw new NuxeoException(String.format("Cannot find the parent of document %s: virtual folder from factory %s.", doc.getId(), sharedSyncRootParentFactoryName));
}
return parent;
}
}
use of org.nuxeo.ecm.core.api.NuxeoException in project nuxeo-drive-server by nuxeo.
the class SharedSyncRootParentFactory method getVirtualFolderItem.
@Override
public FolderItem getVirtualFolderItem(Principal principal) {
FileSystemItemManager fileSystemItemManager = Framework.getService(FileSystemItemManager.class);
FolderItem topLevelFolder = fileSystemItemManager.getTopLevelFolder(principal);
if (topLevelFolder == null) {
throw new NuxeoException("Found no top level folder item. Please check your contribution to the following extension point: <extension target=\"org.nuxeo.drive.service.FileSystemItemAdapterService\" point=\"topLevelFolderItemFactory\">.");
}
return new SharedSyncRootParentFolderItem(getName(), principal, topLevelFolder.getId(), topLevelFolder.getPath(), folderName);
}
use of org.nuxeo.ecm.core.api.NuxeoException in project nuxeo-drive-server by nuxeo.
the class UserWorkspaceSyncRootFactory method getParentItem.
/*------------------ AbstractSyncRootFolderItemFactory ------------------*/
@Override
protected FolderItem getParentItem(DocumentModel doc) {
Principal principal = doc.getCoreSession().getPrincipal();
FolderItem parent = getFileSystemAdapterService().getVirtualFolderItemFactory(syncRootParentFactoryName).getVirtualFolderItem(principal);
if (parent == null) {
throw new NuxeoException(String.format("Cannot find the parent of document %s: virtual folder from factory %s.", doc.getId(), syncRootParentFactoryName));
}
return parent;
}
use of org.nuxeo.ecm.core.api.NuxeoException 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;
}
Aggregations