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);
}
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();
}
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;
}
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);
}
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;
}
}
Aggregations