Search in sources :

Example 11 with Blob

use of org.nuxeo.ecm.automation.client.model.Blob in project nuxeo-drive-server by nuxeo.

the class TestFileSystemItemOperations method testFileSystemItemExists.

@Test
public void testFileSystemItemExists() throws Exception {
    // Non existing file system item
    Blob fileSystemItemExistsJSON = (Blob) clientSession.newRequest(NuxeoDriveFileSystemItemExists.ID).set("id", SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + "badId").execute();
    assertNotNull(fileSystemItemExistsJSON);
    String fileSystemItemExists = mapper.readValue(fileSystemItemExistsJSON.getStream(), String.class);
    assertEquals("false", fileSystemItemExists);
    // Existing file system item
    fileSystemItemExistsJSON = (Blob) clientSession.newRequest(NuxeoDriveFileSystemItemExists.ID).set("id", SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot1.getId()).execute();
    assertNotNull(fileSystemItemExistsJSON);
    fileSystemItemExists = mapper.readValue(fileSystemItemExistsJSON.getStream(), String.class);
    assertEquals("true", fileSystemItemExists);
    // Deleted file system item
    file1.followTransition("delete");
    // Need to flush VCS cache to be aware of changes in the session used by the file system item
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    fileSystemItemExistsJSON = (Blob) clientSession.newRequest(NuxeoDriveFileSystemItemExists.ID).set("id", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file1.getId()).execute();
    assertNotNull(fileSystemItemExistsJSON);
    fileSystemItemExists = mapper.readValue(fileSystemItemExistsJSON.getStream(), String.class);
    assertEquals("false", fileSystemItemExists);
}
Also used : Blob(org.nuxeo.ecm.automation.client.model.Blob) StringBlob(org.nuxeo.ecm.automation.client.model.StringBlob) Test(org.junit.Test)

Example 12 with Blob

use of org.nuxeo.ecm.automation.client.model.Blob in project nuxeo-drive-server by nuxeo.

the class TestFileSystemItemOperations method testRename.

@Test
public void testRename() throws Exception {
    // ------------------------------------------------------
    // File
    // ------------------------------------------------------
    Blob renamedFSItemJSON = (Blob) clientSession.newRequest(NuxeoDriveRename.ID).set("id", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file1.getId()).set("name", "Renamed file 1.odt").execute();
    assertNotNull(renamedFSItemJSON);
    DocumentBackedFileItem renamedFileItem = mapper.readValue(renamedFSItemJSON.getStream(), DocumentBackedFileItem.class);
    assertNotNull(renamedFileItem);
    assertEquals("Renamed file 1.odt", renamedFileItem.getName());
    // Need to flush VCS cache to be aware of changes in the session used by the file system item
    session.save();
    DocumentModel renamedFileDoc = session.getDocument(new IdRef(file1.getId()));
    assertEquals("file1", renamedFileDoc.getTitle());
    org.nuxeo.ecm.core.api.Blob renamedFileBlob = (org.nuxeo.ecm.core.api.Blob) renamedFileDoc.getPropertyValue("file:content");
    assertNotNull(renamedFileBlob);
    assertEquals("Renamed file 1.odt", renamedFileBlob.getFilename());
    assertEquals("nxfile/test/" + file1.getId() + "/blobholder:0/Renamed%20file%201.odt", renamedFileItem.getDownloadURL());
    assertEquals("MD5", renamedFileItem.getDigestAlgorithm());
    assertEquals(renamedFileBlob.getDigest(), renamedFileItem.getDigest());
    // ------------------------------------------------------
    // Folder
    // ------------------------------------------------------
    renamedFSItemJSON = (Blob) clientSession.newRequest(NuxeoDriveRename.ID).set("id", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolder1.getId()).set("name", "Renamed sub-folder 1").execute();
    assertNotNull(renamedFSItemJSON);
    DocumentBackedFolderItem renamedFolderItem = mapper.readValue(renamedFSItemJSON.getStream(), DocumentBackedFolderItem.class);
    assertNotNull(renamedFolderItem);
    assertEquals("Renamed sub-folder 1", renamedFolderItem.getName());
    // Need to flush VCS cache to be aware of changes in the session used by the file system item
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    DocumentModel renamedFolderDoc = session.getDocument(new IdRef(subFolder1.getId()));
    assertEquals("Renamed sub-folder 1", renamedFolderDoc.getTitle());
    // ------------------------------------------------------
    // Sync root
    // ------------------------------------------------------
    renamedFSItemJSON = (Blob) clientSession.newRequest(NuxeoDriveRename.ID).set("id", SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot1.getId()).set("name", "New name for sync root").execute();
    assertNotNull(renamedFSItemJSON);
    DefaultSyncRootFolderItem renamedSyncRootItem = mapper.readValue(renamedFSItemJSON.getStream(), DefaultSyncRootFolderItem.class);
    assertNotNull(renamedSyncRootItem);
    assertEquals("New name for sync root", renamedSyncRootItem.getName());
    // Need to flush VCS cache to be aware of changes in the session used by the file system item
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    DocumentModel renamedSyncRootDoc = session.getDocument(new IdRef(syncRoot1.getId()));
    assertEquals("New name for sync root", renamedSyncRootDoc.getTitle());
    // ------------------------------------------------------
    try {
        clientSession.newRequest(NuxeoDriveRename.ID).set("id", fileSystemItemAdapterService.getTopLevelFolderItemFactory().getTopLevelFolderItem(session.getPrincipal()).getId()).set("name", "New name for top level folder").execute();
        fail("Top level folder renaming shoud be unsupported.");
    } catch (Exception e) {
        assertEquals("Failed to invoke operation: NuxeoDrive.Rename", e.getMessage());
    }
}
Also used : Blob(org.nuxeo.ecm.automation.client.model.Blob) StringBlob(org.nuxeo.ecm.automation.client.model.StringBlob) DocumentBackedFileItem(org.nuxeo.drive.adapter.impl.DocumentBackedFileItem) DefaultSyncRootFolderItem(org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem) IdRef(org.nuxeo.ecm.core.api.IdRef) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) DocumentBackedFolderItem(org.nuxeo.drive.adapter.impl.DocumentBackedFolderItem) Test(org.junit.Test)

Example 13 with Blob

use of org.nuxeo.ecm.automation.client.model.Blob in project nuxeo-drive-server by nuxeo.

the class TestFileSystemItemOperations method testGetFileSystemItem.

@Test
public void testGetFileSystemItem() throws Exception {
    // Get top level folder
    String topLevelFolderItemId = fileSystemItemAdapterService.getTopLevelFolderItemFactory().getTopLevelFolderItem(session.getPrincipal()).getId();
    Blob fileSystemItemJSON = (Blob) clientSession.newRequest(NuxeoDriveGetFileSystemItem.ID).set("id", topLevelFolderItemId).execute();
    assertNotNull(fileSystemItemJSON);
    DefaultTopLevelFolderItem topLevelFolderItem = mapper.readValue(fileSystemItemJSON.getStream(), DefaultTopLevelFolderItem.class);
    assertNotNull(topLevelFolderItem);
    assertEquals(topLevelFolderItemId, topLevelFolderItem.getId());
    assertNull(topLevelFolderItem.getParentId());
    assertEquals("Nuxeo Drive", topLevelFolderItem.getName());
    assertTrue(topLevelFolderItem.isFolder());
    assertEquals("system", topLevelFolderItem.getCreator());
    assertEquals("system", topLevelFolderItem.getLastContributor());
    assertFalse(topLevelFolderItem.getCanRename());
    assertFalse(topLevelFolderItem.getCanDelete());
    assertFalse(topLevelFolderItem.getCanCreateChild());
    // Get sync root
    fileSystemItemJSON = (Blob) clientSession.newRequest(NuxeoDriveGetFileSystemItem.ID).set("id", SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot1.getId()).execute();
    assertNotNull(fileSystemItemJSON);
    DefaultSyncRootFolderItem syncRootFolderItem = mapper.readValue(fileSystemItemJSON.getStream(), DefaultSyncRootFolderItem.class);
    assertNotNull(syncRootFolderItem);
    assertEquals(SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot1.getId(), syncRootFolderItem.getId());
    assertTrue(syncRootFolderItem.getParentId().endsWith("DefaultTopLevelFolderItemFactory#"));
    assertEquals("folder1", syncRootFolderItem.getName());
    assertTrue(syncRootFolderItem.isFolder());
    assertEquals("Administrator", syncRootFolderItem.getCreator());
    assertEquals("Administrator", syncRootFolderItem.getLastContributor());
    assertTrue(syncRootFolderItem.getCanRename());
    assertTrue(syncRootFolderItem.getCanDelete());
    assertTrue(syncRootFolderItem.getCanCreateChild());
    // Get file in sync root
    fileSystemItemJSON = (Blob) clientSession.newRequest(NuxeoDriveGetFileSystemItem.ID).set("id", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file1.getId()).execute();
    assertNotNull(fileSystemItemJSON);
    DocumentBackedFileItem fileItem = mapper.readValue(fileSystemItemJSON.getStream(), DocumentBackedFileItem.class);
    assertNotNull(fileItem);
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file1.getId(), fileItem.getId());
    assertEquals(SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot1.getId(), fileItem.getParentId());
    assertEquals("First file.odt", fileItem.getName());
    assertFalse(fileItem.isFolder());
    assertEquals("Administrator", fileItem.getCreator());
    assertEquals("Administrator", fileItem.getLastContributor());
    assertTrue(fileItem.getCanRename());
    assertTrue(fileItem.getCanDelete());
    assertTrue(fileItem.getCanUpdate());
    assertEquals("nxfile/test/" + file1.getId() + "/blobholder:0/First%20file.odt", fileItem.getDownloadURL());
    assertEquals("MD5", fileItem.getDigestAlgorithm());
    assertEquals(((org.nuxeo.ecm.core.api.Blob) file1.getPropertyValue("file:content")).getDigest(), fileItem.getDigest());
    // Get deleted file
    file1.followTransition("delete");
    // Need to flush VCS cache to be aware of changes in the session used by the file system item
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    fileSystemItemJSON = (Blob) clientSession.newRequest(NuxeoDriveGetFileSystemItem.ID).set("id", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file1.getId()).execute();
    assertNotNull(fileSystemItemJSON);
    assertNull(mapper.readValue(fileSystemItemJSON.getStream(), Object.class));
}
Also used : Blob(org.nuxeo.ecm.automation.client.model.Blob) StringBlob(org.nuxeo.ecm.automation.client.model.StringBlob) DefaultTopLevelFolderItem(org.nuxeo.drive.adapter.impl.DefaultTopLevelFolderItem) DocumentBackedFileItem(org.nuxeo.drive.adapter.impl.DocumentBackedFileItem) DefaultSyncRootFolderItem(org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem) Test(org.junit.Test)

Example 14 with Blob

use of org.nuxeo.ecm.automation.client.model.Blob in project nuxeo-drive-server by nuxeo.

the class TestFileSystemItemOperations method testCreateFile.

@Test
public void testCreateFile() throws Exception {
    StringBlob blob = new StringBlob("This is the content of a new file.");
    blob.setFileName("New file.odt");
    Blob newFileJSON = (Blob) clientSession.newRequest(NuxeoDriveCreateFile.ID).set("parentId", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolder1.getId()).setInput(blob).execute();
    assertNotNull(newFileJSON);
    DocumentBackedFileItem newFile = mapper.readValue(newFileJSON.getStream(), DocumentBackedFileItem.class);
    assertNotNull(newFile);
    // Need to flush VCS cache to be aware of changes in the session used by the file system item
    session.save();
    DocumentModel newFileDoc = session.getDocument(new PathRef("/folder1/subFolder1/New file.odt"));
    assertEquals("File", newFileDoc.getType());
    assertEquals("New file.odt", newFileDoc.getTitle());
    org.nuxeo.ecm.core.api.Blob newFileBlob = (org.nuxeo.ecm.core.api.Blob) newFileDoc.getPropertyValue("file:content");
    assertNotNull(newFileBlob);
    assertEquals("New file.odt", newFileBlob.getFilename());
    assertEquals("This is the content of a new file.", newFileBlob.getString());
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + newFileDoc.getId(), newFile.getId());
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolder1.getId(), newFile.getParentId());
    assertEquals("New file.odt", newFile.getName());
    assertFalse(newFile.isFolder());
    assertEquals("Administrator", newFile.getCreator());
    assertEquals("Administrator", newFile.getLastContributor());
    assertTrue(newFile.getCanRename());
    assertTrue(newFile.getCanDelete());
    assertTrue(newFile.getCanUpdate());
    assertEquals("nxfile/test/" + newFileDoc.getId() + "/blobholder:0/New%20file.odt", newFile.getDownloadURL());
    assertEquals("MD5", newFile.getDigestAlgorithm());
    assertEquals(newFileBlob.getDigest(), newFile.getDigest());
}
Also used : Blob(org.nuxeo.ecm.automation.client.model.Blob) StringBlob(org.nuxeo.ecm.automation.client.model.StringBlob) PathRef(org.nuxeo.ecm.core.api.PathRef) StringBlob(org.nuxeo.ecm.automation.client.model.StringBlob) DocumentBackedFileItem(org.nuxeo.drive.adapter.impl.DocumentBackedFileItem) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Example 15 with Blob

use of org.nuxeo.ecm.automation.client.model.Blob in project nuxeo-drive-server by nuxeo.

the class TestFileSystemItemOperations method testGetTopLevelChildren.

@Test
public void testGetTopLevelChildren() throws Exception {
    Blob topLevelFolderJSON = (Blob) clientSession.newRequest(NuxeoDriveGetTopLevelFolder.ID).execute();
    assertNotNull(topLevelFolderJSON);
    // Check children
    FolderItem topLevelFolder = mapper.readValue(topLevelFolderJSON.getStream(), new TypeReference<DefaultTopLevelFolderItem>() {
    });
    Blob topLevelChildrenJSON = (Blob) clientSession.newRequest(NuxeoDriveGetChildren.ID).set("id", topLevelFolder.getId()).execute();
    List<DefaultSyncRootFolderItem> topLevelChildren = mapper.readValue(topLevelChildrenJSON.getStream(), new TypeReference<List<DefaultSyncRootFolderItem>>() {
    });
    assertNotNull(topLevelChildren);
    assertEquals(2, topLevelChildren.size());
    DefaultSyncRootFolderItem child = topLevelChildren.get(0);
    assertEquals(SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot1.getId(), child.getId());
    assertTrue(child.getParentId().endsWith("DefaultTopLevelFolderItemFactory#"));
    assertEquals("folder1", child.getName());
    assertTrue(child.isFolder());
    assertEquals("Administrator", child.getCreator());
    assertEquals("Administrator", child.getLastContributor());
    assertTrue(child.getCanRename());
    assertTrue(child.getCanDelete());
    assertTrue(child.getCanCreateChild());
    child = topLevelChildren.get(1);
    assertEquals(SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot2.getId(), child.getId());
    assertTrue(child.getParentId().endsWith("DefaultTopLevelFolderItemFactory#"));
    assertEquals("folder2", child.getName());
    assertTrue(child.isFolder());
    assertEquals("Administrator", child.getCreator());
    assertEquals("Administrator", child.getLastContributor());
    assertTrue(child.getCanRename());
    assertTrue(child.getCanDelete());
    assertTrue(child.getCanCreateChild());
    // Check descendants
    assertFalse(topLevelFolder.getCanScrollDescendants());
    try {
        clientSession.newRequest(NuxeoDriveScrollDescendants.ID).set("id", topLevelFolder.getId()).set("batchSize", 10).execute();
        fail("Scrolling through the descendants of the default top level folder item should be unsupported.");
    } catch (Exception e) {
        assertEquals("Failed to invoke operation: NuxeoDrive.ScrollDescendants", e.getMessage());
    }
}
Also used : Blob(org.nuxeo.ecm.automation.client.model.Blob) StringBlob(org.nuxeo.ecm.automation.client.model.StringBlob) DefaultSyncRootFolderItem(org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem) DocumentBackedFolderItem(org.nuxeo.drive.adapter.impl.DocumentBackedFolderItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) DefaultTopLevelFolderItem(org.nuxeo.drive.adapter.impl.DefaultTopLevelFolderItem) DefaultTopLevelFolderItem(org.nuxeo.drive.adapter.impl.DefaultTopLevelFolderItem) DefaultSyncRootFolderItem(org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem) List(java.util.List) ScrollFileSystemItemList(org.nuxeo.drive.adapter.ScrollFileSystemItemList) Test(org.junit.Test)

Aggregations

Blob (org.nuxeo.ecm.automation.client.model.Blob)18 Test (org.junit.Test)16 StringBlob (org.nuxeo.ecm.automation.client.model.StringBlob)12 DocumentBackedFileItem (org.nuxeo.drive.adapter.impl.DocumentBackedFileItem)9 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)9 DefaultSyncRootFolderItem (org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem)6 DocumentBackedFolderItem (org.nuxeo.drive.adapter.impl.DocumentBackedFolderItem)6 List (java.util.List)5 Session (org.nuxeo.ecm.automation.client.Session)5 CoreSession (org.nuxeo.ecm.core.api.CoreSession)5 TypeReference (com.fasterxml.jackson.core.type.TypeReference)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 FolderItem (org.nuxeo.drive.adapter.FolderItem)3 ScrollFileSystemItemList (org.nuxeo.drive.adapter.ScrollFileSystemItemList)3 DefaultTopLevelFolderItem (org.nuxeo.drive.adapter.impl.DefaultTopLevelFolderItem)3 IdRef (org.nuxeo.ecm.core.api.IdRef)3 PathRef (org.nuxeo.ecm.core.api.PathRef)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 IOException (java.io.IOException)2