Search in sources :

Example 16 with DocumentRef

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

the class NuxeoDriveActions method canNavigateToCurrentSynchronizationRoot.

@Factory(value = "canNavigateToCurrentSynchronizationRoot")
public boolean canNavigateToCurrentSynchronizationRoot() {
    @SuppressWarnings("hiding") DocumentModel currentDocument = navigationContext.getCurrentDocument();
    if (currentDocument == null) {
        return false;
    }
    if (currentDocument.isTrashed()) {
        return false;
    }
    DocumentRef currentDocRef = currentDocument.getRef();
    DocumentModel currentSyncRoot = getCurrentSynchronizationRoot();
    if (currentSyncRoot == null) {
        return false;
    }
    return !currentDocRef.equals(currentSyncRoot.getRef());
}
Also used : DocumentRef(org.nuxeo.ecm.core.api.DocumentRef) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Factory(org.jboss.seam.annotations.Factory) LogFactory(org.apache.commons.logging.LogFactory)

Example 17 with DocumentRef

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

the class NuxeoDriveActions method canUnSynchronizeCurrentDocument.

@Factory(value = "canUnSynchronizeCurrentDocument")
public boolean canUnSynchronizeCurrentDocument() {
    @SuppressWarnings("hiding") DocumentModel currentDocument = navigationContext.getCurrentDocument();
    if (currentDocument == null) {
        return false;
    }
    if (!isSyncRootCandidate(currentDocument)) {
        return false;
    }
    DocumentRef currentDocRef = currentDocument.getRef();
    DocumentModel currentSyncRoot = getCurrentSynchronizationRoot();
    if (currentSyncRoot == null) {
        return false;
    }
    return currentDocRef.equals(currentSyncRoot.getRef());
}
Also used : DocumentRef(org.nuxeo.ecm.core.api.DocumentRef) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Factory(org.jboss.seam.annotations.Factory) LogFactory(org.apache.commons.logging.LogFactory)

Example 18 with DocumentRef

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

the class TestIntegrationTestOperations method testIntegrationTestsSetupAndTearDown.

@Test
public void testIntegrationTestsSetupAndTearDown() throws Exception {
    // ---------------------------------------------------------
    // Setup the integration tests environment as Administrator
    // ---------------------------------------------------------
    Blob testUserCredentialsBlob = (Blob) clientSession.newRequest(NuxeoDriveSetupIntegrationTests.ID).set("userNames", "joe,jack").set("permission", "ReadWrite").execute();
    assertNotNull(testUserCredentialsBlob);
    // Invalidate VCS cache
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    // Check test users
    String testUserCredentials = IOUtils.toString(testUserCredentialsBlob.getStream(), "UTF-8");
    assertNotNull(testUserCredentials);
    String[] testUserCrendentialsArray = StringUtils.split(testUserCredentials, ",");
    assertEquals(2, testUserCrendentialsArray.length);
    assertTrue(testUserCrendentialsArray[0].startsWith("drivejoe:"));
    assertTrue(testUserCrendentialsArray[1].startsWith("drivejack:"));
    // useMembersGroup is false by default
    NuxeoPrincipal joePrincipal = userManager.getPrincipal("drivejoe");
    assertNotNull(joePrincipal);
    assertFalse(joePrincipal.getGroups().contains("members"));
    NuxeoPrincipal jackPrincipal = userManager.getPrincipal("drivejack");
    assertNotNull(jackPrincipal);
    assertFalse(jackPrincipal.getGroups().contains("members"));
    // Check test workspace
    DocumentRef testWorkspaceRef = new PathRef(testWorkspacePath);
    DocumentModel testWorkspace = session.getDocument(testWorkspaceRef);
    assertEquals("Workspace", testWorkspace.getType());
    assertEquals("Nuxeo Drive Test Workspace", testWorkspace.getTitle());
    assertTrue(session.hasPermission(joePrincipal, testWorkspaceRef, SecurityConstants.WRITE));
    assertTrue(session.hasPermission(jackPrincipal, testWorkspaceRef, SecurityConstants.WRITE));
    // Create test users' personal workspaces for cleanup check
    userWorkspaceService.getUserPersonalWorkspace("drivejoe", session.getRootDocument());
    userWorkspaceService.getUserPersonalWorkspace("drivejack", session.getRootDocument());
    assertNotNull(session.getDocument(new PathRef(userWorkspaceParentPath + "/drivejoe")));
    assertNotNull(session.getDocument(new PathRef(userWorkspaceParentPath + "/drivejack")));
    // Save personal workspaces
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    // ----------------------------------------------------------------------
    // Setup the integration tests environment with other user names without
    // having teared it down previously => should start by cleaning it up
    // ----------------------------------------------------------------------
    testUserCredentialsBlob = (Blob) clientSession.newRequest(NuxeoDriveSetupIntegrationTests.ID).set("userNames", "sarah").set("useMembersGroup", true).set("permission", "ReadWrite").execute();
    assertNotNull(testUserCredentialsBlob);
    // Check cleanup
    assertNull(userManager.getPrincipal("drivejoe"));
    assertNull(userManager.getPrincipal("drivejack"));
    // Process invalidations
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    try {
        session.getDocument(new PathRef(userWorkspaceParentPath + "/drivejoe"));
        fail("User workspace should not exist.");
    } catch (DocumentNotFoundException e) {
        assertEquals(userWorkspaceParentPath + "/drivejoe", e.getMessage());
    }
    try {
        session.getDocument(new PathRef(userWorkspaceParentPath + "/drivejack"));
        fail("User workspace should not exist.");
    } catch (DocumentNotFoundException e) {
        assertEquals(userWorkspaceParentPath + "/drivejack", e.getMessage());
    }
    // Check test users
    testUserCredentials = IOUtils.toString(testUserCredentialsBlob.getStream(), "UTF-8");
    assertNotNull(testUserCredentials);
    testUserCrendentialsArray = StringUtils.split(testUserCredentials, ",");
    assertEquals(1, testUserCrendentialsArray.length);
    assertTrue(testUserCrendentialsArray[0].startsWith("drivesarah:"));
    NuxeoPrincipal sarahPrincipal = userManager.getPrincipal("drivesarah");
    assertNotNull(sarahPrincipal);
    assertTrue(sarahPrincipal.getGroups().contains("members"));
    // Check test workspace
    testWorkspace = session.getDocument(testWorkspaceRef);
    assertEquals("Nuxeo Drive Test Workspace", testWorkspace.getTitle());
    assertTrue(session.hasPermission(sarahPrincipal, testWorkspaceRef, SecurityConstants.WRITE));
    // Create test users' personal workspaces for cleanup check
    userWorkspaceService.getUserPersonalWorkspace("drivesarah", session.getRootDocument());
    assertNotNull(session.getDocument(new PathRef(userWorkspaceParentPath + "/drivesarah")));
    // Save personal workspaces
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    // ----------------------------------------------------------------------
    // Try to setup the integration tests environment as an unauthorized
    // user => should fail
    // ----------------------------------------------------------------------
    String sarahCredentials = testUserCrendentialsArray[0];
    String sarahPassword = sarahCredentials.substring(sarahCredentials.indexOf(':') + 1);
    Session unauthorizedSession = automationClient.getSession("drivesarah", sarahPassword);
    try {
        unauthorizedSession.newRequest(NuxeoDriveSetupIntegrationTests.ID).set("userNames", "john,bob").set("permission", "ReadWrite").execute();
        fail("NuxeoDrive.SetupIntegrationTests operation should not be callable by a non administrator.");
    } catch (Exception e) {
    // Expected
    }
    // ----------------------------------------------------------------------
    try {
        unauthorizedSession.newRequest(NuxeoDriveTearDownIntegrationTests.ID).execute();
        fail("NuxeoDrive.TearDownIntegrationTests operation should not be callable by a non administrator.");
    } catch (Exception e) {
    // Expected
    }
    // ----------------------------------------------------------------------
    // Tear down the integration tests environment as Administrator
    // ----------------------------------------------------------------------
    clientSession.newRequest(NuxeoDriveTearDownIntegrationTests.ID).execute();
    assertTrue(userManager.searchUsers("drive").isEmpty());
    // Process invalidations
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    try {
        session.getDocument(new PathRef(userWorkspaceParentPath + "/drivesarah"));
        fail("User workspace should not exist.");
    } catch (DocumentNotFoundException e) {
        assertEquals(userWorkspaceParentPath + "/drivesarah", e.getMessage());
    }
    assertFalse(session.exists(testWorkspaceRef));
}
Also used : Blob(org.nuxeo.ecm.automation.client.model.Blob) DocumentRef(org.nuxeo.ecm.core.api.DocumentRef) DocumentNotFoundException(org.nuxeo.ecm.core.api.DocumentNotFoundException) PathRef(org.nuxeo.ecm.core.api.PathRef) NuxeoPrincipal(org.nuxeo.ecm.core.api.NuxeoPrincipal) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) DocumentNotFoundException(org.nuxeo.ecm.core.api.DocumentNotFoundException) Session(org.nuxeo.ecm.automation.client.Session) CoreSession(org.nuxeo.ecm.core.api.CoreSession) Test(org.junit.Test)

Example 19 with DocumentRef

use of org.nuxeo.ecm.core.api.DocumentRef in project nuxeo-filesystem-connectors by nuxeo.

the class SimpleBackend method resolveLocation.

@Override
public DocumentModel resolveLocation(String location) {
    Path resolvedLocation = parseLocation(location);
    DocumentModel doc = null;
    doc = getPathCache().get(resolvedLocation.toString());
    if (doc != null) {
        return doc;
    }
    DocumentRef docRef = new PathRef(resolvedLocation.toString());
    if (exists(docRef)) {
        doc = getSession().getDocument(docRef);
    } else {
        String encodedPath = urlEncode(resolvedLocation.toString());
        if (!resolvedLocation.toString().equals(encodedPath)) {
            DocumentRef encodedPathRef = new PathRef(encodedPath);
            if (exists(encodedPathRef)) {
                doc = getSession().getDocument(encodedPathRef);
            }
        }
        if (doc == null) {
            String filename = resolvedLocation.lastSegment();
            Path parentLocation = resolvedLocation.removeLastSegments(1);
            // first try with spaces (for create New Folder)
            String folderName = filename;
            DocumentRef folderRef = new PathRef(parentLocation.append(folderName).toString());
            if (exists(folderRef)) {
                doc = getSession().getDocument(folderRef);
            }
            // look for a child
            DocumentModel parentDocument = resolveParent(parentLocation.toString());
            if (parentDocument == null) {
                // parent doesn't exist, no use looking for a child
                return null;
            }
            List<DocumentModel> children = getChildren(parentDocument.getRef());
            for (DocumentModel child : children) {
                BlobHolder bh = child.getAdapter(BlobHolder.class);
                if (bh != null) {
                    Blob blob = bh.getBlob();
                    if (blob != null) {
                        try {
                            String blobFilename = blob.getFilename();
                            if (filename.equals(blobFilename)) {
                                doc = child;
                                break;
                            } else if (urlEncode(filename).equals(blobFilename)) {
                                doc = child;
                                break;
                            } else if (URLEncoder.encode(filename, "UTF-8").equals(blobFilename)) {
                                doc = child;
                                break;
                            } else if (encode(blobFilename.getBytes(), "ISO-8859-1").equals(filename)) {
                                doc = child;
                                break;
                            }
                        } catch (UnsupportedEncodingException e) {
                            // cannot happen for UTF-8
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
        }
    }
    getPathCache().put(resolvedLocation.toString(), doc);
    return doc;
}
Also used : Path(org.nuxeo.common.utils.Path) Blob(org.nuxeo.ecm.core.api.Blob) DocumentRef(org.nuxeo.ecm.core.api.DocumentRef) PathRef(org.nuxeo.ecm.core.api.PathRef) BlobHolder(org.nuxeo.ecm.core.api.blobholder.BlobHolder) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 20 with DocumentRef

use of org.nuxeo.ecm.core.api.DocumentRef in project nuxeo-filesystem-connectors by nuxeo.

the class SimpleBackend method resolveParent.

protected DocumentModel resolveParent(String location) {
    DocumentModel doc = null;
    doc = getPathCache().get(location.toString());
    if (doc != null) {
        return doc;
    }
    DocumentRef docRef = new PathRef(location.toString());
    if (exists(docRef)) {
        doc = getSession().getDocument(docRef);
    } else {
        Path locationPath = new Path(location);
        String filename = locationPath.lastSegment();
        Path parentLocation = locationPath.removeLastSegments(1);
        // first try with spaces (for create New Folder)
        String folderName = filename;
        DocumentRef folderRef = new PathRef(parentLocation.append(folderName).toString());
        if (exists(folderRef)) {
            doc = getSession().getDocument(folderRef);
        }
    }
    getPathCache().put(location.toString(), doc);
    return doc;
}
Also used : Path(org.nuxeo.common.utils.Path) DocumentRef(org.nuxeo.ecm.core.api.DocumentRef) PathRef(org.nuxeo.ecm.core.api.PathRef) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

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