Search in sources :

Example 6 with DocumentRef

use of org.nuxeo.ecm.core.api.DocumentRef in project nuxeo-drive-server by nuxeo.

the class NuxeoDriveSetupIntegrationTests method createTestWorkspace.

protected void createTestWorkspace(String[] testUserNames) {
    // Create test workspace
    String testWorkspaceParentPath = NuxeoDriveIntegrationTestsHelper.getDefaultDomainPath(session) + "/" + NuxeoDriveIntegrationTestsHelper.TEST_WORKSPACE_PARENT_NAME;
    DocumentModel testWorkspace = session.createDocumentModel(testWorkspaceParentPath, TEST_WORKSPACE_NAME, "Workspace");
    testWorkspace.setPropertyValue("dc:title", TEST_WORKSPACE_TITLE);
    session.createDocument(testWorkspace);
    // Grant the given permission to the test users on the test workspace
    String testWorkspacePath = testWorkspaceParentPath + "/" + TEST_WORKSPACE_NAME;
    DocumentRef testWorkspaceDocRef = new PathRef(testWorkspacePath);
    ACP acp = session.getACP(testWorkspaceDocRef);
    ACL localACL = acp.getOrCreateACL(ACL.LOCAL_ACL);
    for (String testUserName : testUserNames) {
        localACL.add(new ACE(testUserName, permission, true));
    }
    session.setACP(testWorkspaceDocRef, acp, false);
}
Also used : ACE(org.nuxeo.ecm.core.api.security.ACE) DocumentRef(org.nuxeo.ecm.core.api.DocumentRef) PathRef(org.nuxeo.ecm.core.api.PathRef) ACL(org.nuxeo.ecm.core.api.security.ACL) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) ACP(org.nuxeo.ecm.core.api.security.ACP)

Example 7 with DocumentRef

use of org.nuxeo.ecm.core.api.DocumentRef in project nuxeo-drive-server by nuxeo.

the class NuxeoDriveIntegrationTestsHelper method cleanUp.

public static void cleanUp(CoreSession session) {
    // Delete test users and their personal workspace if exist
    UserManager userManager = Framework.getService(UserManager.class);
    DocumentModelList testUsers = userManager.searchUsers(TEST_USER_NAME_PREFIX);
    for (DocumentModel testUser : testUsers) {
        String testUserName = (String) testUser.getPropertyValue(userManager.getUserSchemaName() + ":" + userManager.getUserIdField());
        if (userManager.getPrincipal(testUserName) != null) {
            userManager.deleteUser(testUserName);
        }
        String testUserWorkspaceName = IdUtils.generateId(testUserName, "-", false, 30);
        String testUserWorkspacePath = getDefaultDomainPath(session) + "/" + USER_WORKSPACE_PARENT_NAME + "/" + testUserWorkspaceName;
        DocumentRef testUserWorkspaceRef = new PathRef(testUserWorkspacePath);
        if (session.exists(testUserWorkspaceRef)) {
            session.removeDocument(testUserWorkspaceRef);
            session.save();
        }
    }
    // Delete test workspace if exists
    String testWorkspacePath = getDefaultDomainPath(session) + "/" + TEST_WORKSPACE_PARENT_NAME + "/" + TEST_WORKSPACE_NAME;
    DocumentRef testWorkspaceDocRef = new PathRef(testWorkspacePath);
    if (session.exists(testWorkspaceDocRef)) {
        session.removeDocument(testWorkspaceDocRef);
        session.save();
    }
    // Invalidate user profile cache
    Framework.getService(UserProfileService.class).clearCache();
}
Also used : DocumentModelList(org.nuxeo.ecm.core.api.DocumentModelList) DocumentRef(org.nuxeo.ecm.core.api.DocumentRef) PathRef(org.nuxeo.ecm.core.api.PathRef) UserManager(org.nuxeo.ecm.platform.usermanager.UserManager) UserProfileService(org.nuxeo.ecm.user.center.profile.UserProfileService) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 8 with DocumentRef

use of org.nuxeo.ecm.core.api.DocumentRef in project nuxeo-drive-server by nuxeo.

the class DocumentBackedFolderItem method adaptDocuments.

/**
 * Adapts the given {@link DocumentModelList} as {@link FileSystemItem}s using a cache for the {@link FolderItem}
 * ancestors.
 */
protected List<FileSystemItem> adaptDocuments(DocumentModelList docs, CoreSession session) {
    Map<DocumentRef, FolderItem> ancestorCache = new HashMap<>();
    if (log.isTraceEnabled()) {
        log.trace(String.format("Caching current FolderItem for doc %s: %s", docPath, getPath()));
    }
    ancestorCache.put(new IdRef(docId), this);
    List<FileSystemItem> descendants = new ArrayList<>(docs.size());
    for (DocumentModel doc : docs) {
        FolderItem parent = populateAncestorCache(ancestorCache, doc, session, false);
        if (parent == null) {
            if (log.isDebugEnabled()) {
                log.debug(String.format("Cannot adapt parent document of %s as a FileSystemItem, skipping descendant document", doc.getPathAsString()));
                continue;
            }
        }
        // NXP-19442: Avoid useless and costly call to DocumentModel#getLockInfo
        FileSystemItem descendant = getFileSystemItemAdapterService().getFileSystemItem(doc, parent, false, false, false);
        if (descendant != null) {
            if (descendant.isFolder()) {
                if (log.isTraceEnabled()) {
                    log.trace(String.format("Caching descendant FolderItem for doc %s: %s", doc.getPathAsString(), descendant.getPath()));
                }
                ancestorCache.put(doc.getRef(), (FolderItem) descendant);
            }
            descendants.add(descendant);
        }
    }
    return descendants;
}
Also used : FolderItem(org.nuxeo.drive.adapter.FolderItem) FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) DocumentRef(org.nuxeo.ecm.core.api.DocumentRef) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IdRef(org.nuxeo.ecm.core.api.IdRef) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 9 with DocumentRef

use of org.nuxeo.ecm.core.api.DocumentRef in project nuxeo-drive-server by nuxeo.

the class DocumentBackedFolderItem method populateAncestorCache.

protected FolderItem populateAncestorCache(Map<DocumentRef, FolderItem> cache, DocumentModel doc, CoreSession session, boolean cacheItem) {
    DocumentRef parentDocRef = session.getParentDocumentRef(doc.getRef());
    if (parentDocRef == null) {
        throw new RootlessItemException("Reached repository root");
    }
    FolderItem parentItem = cache.get(parentDocRef);
    if (parentItem != null) {
        if (log.isTraceEnabled()) {
            log.trace(String.format("Found parent FolderItem in cache for doc %s: %s", doc.getPathAsString(), parentItem.getPath()));
        }
        return getFolderItem(cache, doc, parentItem, cacheItem);
    }
    if (log.isTraceEnabled()) {
        log.trace(String.format("No parent FolderItem found in cache for doc %s, computing ancestor cache", doc.getPathAsString()));
    }
    DocumentModel parentDoc;
    try {
        parentDoc = session.getDocument(parentDocRef);
    } catch (DocumentSecurityException e) {
        throw new RootlessItemException(String.format("User %s has no READ access on parent of document %s (%s).", principal.getName(), doc.getPathAsString(), doc.getId()), e);
    }
    parentItem = populateAncestorCache(cache, parentDoc, session, true);
    if (parentItem == null) {
        return null;
    }
    return getFolderItem(cache, doc, parentItem, cacheItem);
}
Also used : FolderItem(org.nuxeo.drive.adapter.FolderItem) DocumentRef(org.nuxeo.ecm.core.api.DocumentRef) RootlessItemException(org.nuxeo.drive.adapter.RootlessItemException) DocumentSecurityException(org.nuxeo.ecm.core.api.DocumentSecurityException) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 10 with DocumentRef

use of org.nuxeo.ecm.core.api.DocumentRef in project nuxeo-drive-server by nuxeo.

the class AbstractDocumentBackedFileSystemItem method canMove.

@Override
public boolean canMove(FolderItem dest) {
    // Check source doc deletion
    if (!canDelete) {
        return false;
    }
    // Check add children on destination doc
    AbstractDocumentBackedFileSystemItem docBackedDest = (AbstractDocumentBackedFileSystemItem) dest;
    String destRepoName = docBackedDest.getRepositoryName();
    DocumentRef destDocRef = new IdRef(docBackedDest.getDocId());
    String sessionRepo = repositoryName;
    // session bound to the destination repository
    if (!repositoryName.equals(destRepoName)) {
        sessionRepo = destRepoName;
    }
    try (CloseableCoreSession session = CoreInstance.openCoreSession(sessionRepo, principal)) {
        if (!session.hasPermission(destDocRef, SecurityConstants.ADD_CHILDREN)) {
            return false;
        }
        return true;
    }
}
Also used : DocumentRef(org.nuxeo.ecm.core.api.DocumentRef) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) IdRef(org.nuxeo.ecm.core.api.IdRef)

Aggregations

DocumentRef (org.nuxeo.ecm.core.api.DocumentRef)20 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)17 PathRef (org.nuxeo.ecm.core.api.PathRef)8 Test (org.junit.Test)6 IdRef (org.nuxeo.ecm.core.api.IdRef)6 ArrayList (java.util.ArrayList)3 FolderItem (org.nuxeo.drive.adapter.FolderItem)3 CloseableCoreSession (org.nuxeo.ecm.core.api.CloseableCoreSession)3 HashMap (java.util.HashMap)2 LogFactory (org.apache.commons.logging.LogFactory)2 Factory (org.jboss.seam.annotations.Factory)2 Path (org.nuxeo.common.utils.Path)2 FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)2 FileSystemItemChange (org.nuxeo.drive.service.FileSystemItemChange)2 CollectionManager (org.nuxeo.ecm.collections.api.CollectionManager)2 Blob (org.nuxeo.ecm.core.api.Blob)2 CoreSession (org.nuxeo.ecm.core.api.CoreSession)2 StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)2 Serializable (java.io.Serializable)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1