Search in sources :

Example 46 with DocumentModel

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

the class TestGetChangeSummaryMultiRepo method testGetDocumentChangesSummary.

@Test
public void testGetDocumentChangesSummary() throws Exception {
    // Register 3 sync roots and create 3 documents: 2 in the 'test'
    // repository, 1 in the 'other' repository
    DocumentModel doc1;
    DocumentModel doc2;
    DocumentModel doc3;
    Principal administrator = session.getPrincipal();
    nuxeoDriveManager.registerSynchronizationRoot(administrator, folder1, session);
    nuxeoDriveManager.registerSynchronizationRoot(administrator, folder2, session);
    nuxeoDriveManager.registerSynchronizationRoot(administrator, folder3, otherSession);
    doc1 = session.createDocumentModel("/folder1", "doc1", "File");
    doc1.setPropertyValue("file:content", new StringBlob("The content of file 1."));
    doc1 = session.createDocument(doc1);
    doc2 = session.createDocumentModel("/folder2", "doc2", "File");
    doc2.setPropertyValue("file:content", new StringBlob("The content of file 2."));
    doc2 = session.createDocument(doc2);
    doc3 = otherSession.createDocumentModel("/folder3", "doc3", "File");
    doc3.setPropertyValue("file:content", new StringBlob("The content of file 3."));
    doc3 = otherSession.createDocument(doc3);
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    // Look in all repositories => should find 3 changes
    FileSystemChangeSummary changeSummary = getChangeSummary();
    List<FileSystemItemChange> docChanges = changeSummary.getFileSystemChanges();
    assertEquals(3, docChanges.size());
    Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
    expectedChanges.add(new SimpleFileSystemItemChange(doc1.getId(), "documentChanged", "test"));
    expectedChanges.add(new SimpleFileSystemItemChange(doc2.getId(), "documentChanged", "test"));
    expectedChanges.add(new SimpleFileSystemItemChange(doc3.getId(), "documentChanged", "other"));
    Set<SimpleFileSystemItemChange> changes = new HashSet<>();
    docChanges.forEach(docChange -> {
        changes.add(new SimpleFileSystemItemChange(docChange.getDocUuid(), docChange.getEventId(), docChange.getRepositoryId()));
        assertNotNull(docChange.getFileSystemItem());
    });
    assertTrue(CollectionUtils.isEqualCollection(expectedChanges, changes));
    assertEquals(Boolean.FALSE, changeSummary.getHasTooManyChanges());
    // Update documents
    doc1.setPropertyValue("dc:description", "Added description to doc1.");
    doc2.setPropertyValue("dc:description", "Added description to doc1.");
    doc3.setPropertyValue("dc:description", "Added description to doc1.");
    session.saveDocument(doc1);
    session.saveDocument(doc2);
    otherSession.saveDocument(doc3);
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    changeSummary = getChangeSummary();
    docChanges = changeSummary.getFileSystemChanges();
    assertEquals(3, docChanges.size());
}
Also used : FileSystemChangeSummary(org.nuxeo.drive.service.FileSystemChangeSummary) StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) SimpleFileSystemItemChange(org.nuxeo.drive.fixtures.SimpleFileSystemItemChange) FileSystemItemChange(org.nuxeo.drive.service.FileSystemItemChange) SimpleFileSystemItemChange(org.nuxeo.drive.fixtures.SimpleFileSystemItemChange) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Principal(java.security.Principal) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 47 with DocumentModel

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

the class NuxeoDriveActions method getCurrentSynchronizationRoot.

@Factory(value = CURRENT_SYNCHRONIZATION_ROOT, scope = ScopeType.EVENT)
public DocumentModel getCurrentSynchronizationRoot() {
    // Use the event context as request cache
    Context cache = Contexts.getEventContext();
    Boolean isUnderSync = (Boolean) cache.get(IS_UNDER_SYNCHRONIZATION_ROOT);
    if (isUnderSync == null) {
        NuxeoDriveManager driveManager = Framework.getService(NuxeoDriveManager.class);
        Set<IdRef> references = driveManager.getSynchronizationRootReferences(documentManager);
        DocumentModelList path = navigationContext.getCurrentPath();
        DocumentModel root = null;
        // considered the current synchronization root
        for (DocumentModel parent : path) {
            if (references.contains(parent.getRef())) {
                root = parent;
                break;
            }
        }
        cache.set(CURRENT_SYNCHRONIZATION_ROOT, root);
        cache.set(IS_UNDER_SYNCHRONIZATION_ROOT, root != null);
    }
    return (DocumentModel) cache.get(CURRENT_SYNCHRONIZATION_ROOT);
}
Also used : FacesContext(javax.faces.context.FacesContext) Context(org.jboss.seam.contexts.Context) DocumentModelList(org.nuxeo.ecm.core.api.DocumentModelList) IdRef(org.nuxeo.ecm.core.api.IdRef) NuxeoDriveManager(org.nuxeo.drive.service.NuxeoDriveManager) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Factory(org.jboss.seam.annotations.Factory) LogFactory(org.apache.commons.logging.LogFactory)

Example 48 with DocumentModel

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

the class NuxeoDriveActions method unsynchronizeCurrentDocument.

public void unsynchronizeCurrentDocument() {
    NuxeoDriveManager driveManager = Framework.getService(NuxeoDriveManager.class);
    Principal principal = documentManager.getPrincipal();
    DocumentModel syncRoot = navigationContext.getCurrentDocument();
    driveManager.unregisterSynchronizationRoot(principal, syncRoot, documentManager);
}
Also used : NuxeoDriveManager(org.nuxeo.drive.service.NuxeoDriveManager) Principal(java.security.Principal) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 49 with DocumentModel

use of org.nuxeo.ecm.core.api.DocumentModel 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 50 with DocumentModel

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

the class TestPermissionHierarchyFileSystemChanges method createFile.

protected DocumentModel createFile(CoreSession session, String path, String name, String type, String fileName, String content) {
    DocumentModel file = session.createDocumentModel(path, name, type);
    Blob blob = new StringBlob(content);
    blob.setFilename(fileName);
    file.setPropertyValue("file:content", (Serializable) blob);
    return session.createDocument(file);
}
Also used : StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) Blob(org.nuxeo.ecm.core.api.Blob) StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Aggregations

DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)128 Test (org.junit.Test)58 StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)26 CloseableCoreSession (org.nuxeo.ecm.core.api.CloseableCoreSession)25 FileSystemItemChange (org.nuxeo.drive.service.FileSystemItemChange)24 FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)22 PathRef (org.nuxeo.ecm.core.api.PathRef)21 IdRef (org.nuxeo.ecm.core.api.IdRef)18 HashSet (java.util.HashSet)17 Blob (org.nuxeo.ecm.core.api.Blob)17 DocumentRef (org.nuxeo.ecm.core.api.DocumentRef)17 ArrayList (java.util.ArrayList)16 FolderItem (org.nuxeo.drive.adapter.FolderItem)14 NuxeoException (org.nuxeo.ecm.core.api.NuxeoException)11 Principal (java.security.Principal)10 ACE (org.nuxeo.ecm.core.api.security.ACE)10 NuxeoDriveManager (org.nuxeo.drive.service.NuxeoDriveManager)9 FileItem (org.nuxeo.drive.adapter.FileItem)8 BlobHolder (org.nuxeo.ecm.core.api.blobholder.BlobHolder)8 HashMap (java.util.HashMap)7