use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class TestPermissionHierarchyFileSystemChanges method testRegisteredSyncRootChildChange.
@Test
public void testRegisteredSyncRootChildChange() throws InterruptedException {
commitAndWaitForAsyncCompletion();
DocumentModel folderA;
DocumentModel folderC;
// Create the tree structure
try {
createFolderTree(session1, userWorkspace1.getPathAsString(), 5);
folderA = session1.getChild(userWorkspace1.getRef(), "Folder A");
DocumentModel folderB = session1.getChild(folderA.getRef(), "Folder B");
folderC = session1.getChild(folderB.getRef(), "Folder C");
setPermission(session1, folderA, "user2", SecurityConstants.EVERYTHING, true);
setPermission(session1, folderC, "user2", SecurityConstants.READ, true);
} finally {
commitAndWaitForAsyncCompletion();
}
lastEventLogId = nuxeoDriveManager.getChangeFinder().getUpperBound();
// Register FolderA as a synchronization root for user2
try {
nuxeoDriveManager.registerSynchronizationRoot(session2.getPrincipal(), folderA, session2);
assertTrue(nuxeoDriveManager.getSynchronizationRootReferences(session2).contains(new IdRef(folderA.getId())));
} finally {
commitAndWaitForAsyncCompletion();
}
// Check file system item change
try {
List<FileSystemItemChange> changes = getChanges(principal2);
assertEquals(1, changes.size());
FileSystemItemChange change = changes.get(0);
assertEquals("rootRegistered", change.getEventId());
assertEquals("Folder A", change.getFileSystemItemName());
assertNotNull(change.getFileSystemItem());
} finally {
commitAndWaitForAsyncCompletion();
}
try {
resetPermissions(session1, folderA.getRef(), "user2");
} finally {
commitAndWaitForAsyncCompletion();
}
// Check file system item change
try {
List<FileSystemItemChange> changes = getChanges(principal2);
assertEquals(1, changes.size());
FileSystemItemChange change = changes.get(0);
assertEquals("securityUpdated", change.getEventId());
assertNull(change.getFileSystemItemName());
assertNull(change.getFileSystemItem());
} finally {
commitAndWaitForAsyncCompletion();
}
// Register Folder C as a synchronization root for user2
try {
nuxeoDriveManager.registerSynchronizationRoot(session2.getPrincipal(), folderC, session2);
assertFalse(nuxeoDriveManager.getSynchronizationRootReferences(session2).contains(new IdRef(folderA.getId())));
assertTrue(nuxeoDriveManager.getSynchronizationRootReferences(session2).contains(new IdRef(folderC.getId())));
} finally {
commitAndWaitForAsyncCompletion();
}
// Check file system item change
try {
assertEquals(1, session2.getChildren(folderC.getRef()).size());
List<FileSystemItemChange> changes = getChanges(principal2);
assertEquals(1, changes.size());
FileSystemItemChange change = changes.get(0);
assertEquals("rootRegistered", change.getEventId());
assertEquals("Folder C", change.getFileSystemItemName());
assertNotNull(change.getFileSystemItem());
} finally {
commitAndWaitForAsyncCompletion();
}
}
use of org.nuxeo.ecm.core.api.DocumentModel 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();
}
use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class TestESSyncRootFolderItem method buildTree.
protected void buildTree(String parentPath, int maxLevel, int level, int fileCount, int folderCount) {
if (level > maxLevel) {
return;
}
for (int i = 0; i < fileCount; i++) {
String name = "file-" + level + "-" + i;
DocumentModel file = session.createDocumentModel(parentPath, name, "File");
file.setPropertyValue("dc:title", name);
Blob blob = new StringBlob("Content of Joe's file.");
blob.setFilename("Joe.odt");
file.setPropertyValue("file:content", (Serializable) blob);
session.createDocument(file);
}
for (int i = 0; i < folderCount; i++) {
String name = "folder-" + level + "-" + i;
DocumentModel folder = session.createDocumentModel(parentPath, name, "Folder");
folder.setPropertyValue("dc:title", name);
session.createDocument(folder);
buildTree(parentPath + "/" + name, maxLevel, level + 1, fileCount, folderCount);
}
}
use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class MockChangeFinder method getDocumentChanges.
protected List<FileSystemItemChange> getDocumentChanges(CoreSession session, String query, int limit) throws TooManyChangesException {
List<FileSystemItemChange> docChanges = new ArrayList<FileSystemItemChange>();
DocumentModelList queryResult = session.query(query, limit);
if (queryResult.size() >= limit) {
throw new TooManyChangesException("Too many document changes found in the repository.");
}
for (DocumentModel doc : queryResult) {
String repositoryId = session.getRepositoryName();
String eventId = "documentChanged";
long eventDate = ((Calendar) doc.getPropertyValue("dc:modified")).getTimeInMillis();
String docUuid = doc.getId();
FileSystemItem fsItem = doc.getAdapter(FileSystemItem.class);
if (fsItem != null) {
docChanges.add(new FileSystemItemChangeImpl(eventId, eventDate, repositoryId, docUuid, fsItem));
}
}
return docChanges;
}
use of org.nuxeo.ecm.core.api.DocumentModel 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;
}
Aggregations