Search in sources :

Example 6 with NuxeoDriveManager

use of org.nuxeo.drive.service.NuxeoDriveManager 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 7 with NuxeoDriveManager

use of org.nuxeo.drive.service.NuxeoDriveManager in project nuxeo-drive-server by nuxeo.

the class NuxeoDriveActions method getSynchronizationRoots.

public DocumentModelList getSynchronizationRoots() {
    DocumentModelList syncRoots = new DocumentModelListImpl();
    NuxeoDriveManager driveManager = Framework.getService(NuxeoDriveManager.class);
    Set<IdRef> syncRootRefs = driveManager.getSynchronizationRootReferences(documentManager);
    for (IdRef syncRootRef : syncRootRefs) {
        syncRoots.add(documentManager.getDocument(syncRootRef));
    }
    return syncRoots;
}
Also used : DocumentModelListImpl(org.nuxeo.ecm.core.api.impl.DocumentModelListImpl) DocumentModelList(org.nuxeo.ecm.core.api.DocumentModelList) IdRef(org.nuxeo.ecm.core.api.IdRef) NuxeoDriveManager(org.nuxeo.drive.service.NuxeoDriveManager)

Example 8 with NuxeoDriveManager

use of org.nuxeo.drive.service.NuxeoDriveManager 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 9 with NuxeoDriveManager

use of org.nuxeo.drive.service.NuxeoDriveManager in project nuxeo-drive-server by nuxeo.

the class NuxeoDriveGetRootsOperation method run.

@OperationMethod
public DocumentModelList run() {
    // By default get synchronization roots from all repositories, except if
    // a specific repository name is passed as a request header
    boolean allRepositories = true;
    HttpServletRequest request = (HttpServletRequest) ctx.get("request");
    if (request != null) {
        String respositoryName = request.getHeader(RenderingContext.REPOSITORY_NAME_REQUEST_HEADER);
        if (!StringUtils.isEmpty(respositoryName)) {
            allRepositories = false;
        }
    }
    NuxeoDriveManager driveManager = Framework.getService(NuxeoDriveManager.class);
    Map<String, SynchronizationRoots> roots = driveManager.getSynchronizationRoots(ctx.getPrincipal());
    DocumentModelList rootDocumentModels = new DocumentModelListImpl();
    for (Map.Entry<String, SynchronizationRoots> rootsEntry : roots.entrySet()) {
        if (session.getRepositoryName().equals(rootsEntry.getKey())) {
            Set<IdRef> references = rootsEntry.getValue().getRefs();
            rootDocumentModels.addAll(session.getDocuments(references.toArray(new DocumentRef[references.size()])));
        } else {
            if (allRepositories) {
                // XXX: do we really need to implement this now?
                throw new RuntimeException("Multi repo roots not yet implemented");
            }
        }
    }
    return rootDocumentModels;
}
Also used : DocumentModelListImpl(org.nuxeo.ecm.core.api.impl.DocumentModelListImpl) SynchronizationRoots(org.nuxeo.drive.service.SynchronizationRoots) IdRef(org.nuxeo.ecm.core.api.IdRef) HttpServletRequest(javax.servlet.http.HttpServletRequest) DocumentModelList(org.nuxeo.ecm.core.api.DocumentModelList) Map(java.util.Map) NuxeoDriveManager(org.nuxeo.drive.service.NuxeoDriveManager) OperationMethod(org.nuxeo.ecm.automation.core.annotations.OperationMethod)

Example 10 with NuxeoDriveManager

use of org.nuxeo.drive.service.NuxeoDriveManager in project nuxeo-drive-server by nuxeo.

the class NuxeoDriveGetChangeSummary method run.

@OperationMethod
public Blob run() throws IOException {
    NuxeoDriveManager driveManager = Framework.getService(NuxeoDriveManager.class);
    Map<String, Set<IdRef>> lastActiveRootRefs = RootDefinitionsHelper.parseRootDefinitions(lastSyncActiveRootDefinitions);
    FileSystemChangeSummary docChangeSummary;
    if (lastSyncDate >= 0) {
        docChangeSummary = driveManager.getChangeSummary(ctx.getPrincipal(), lastActiveRootRefs, lastSyncDate);
    } else {
        docChangeSummary = driveManager.getChangeSummaryIntegerBounds(ctx.getPrincipal(), lastActiveRootRefs, lowerBound);
    }
    return Blobs.createJSONBlobFromValue(docChangeSummary);
}
Also used : Set(java.util.Set) FileSystemChangeSummary(org.nuxeo.drive.service.FileSystemChangeSummary) NuxeoDriveManager(org.nuxeo.drive.service.NuxeoDriveManager) OperationMethod(org.nuxeo.ecm.automation.core.annotations.OperationMethod)

Aggregations

NuxeoDriveManager (org.nuxeo.drive.service.NuxeoDriveManager)14 Principal (java.security.Principal)6 IdRef (org.nuxeo.ecm.core.api.IdRef)4 OperationMethod (org.nuxeo.ecm.automation.core.annotations.OperationMethod)3 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)3 DocumentModelList (org.nuxeo.ecm.core.api.DocumentModelList)3 SynchronizationRoots (org.nuxeo.drive.service.SynchronizationRoots)2 Blob (org.nuxeo.ecm.core.api.Blob)2 DocumentModelListImpl (org.nuxeo.ecm.core.api.impl.DocumentModelListImpl)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Set (java.util.Set)1 FacesContext (javax.faces.context.FacesContext)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 LogFactory (org.apache.commons.logging.LogFactory)1 Factory (org.jboss.seam.annotations.Factory)1 Context (org.jboss.seam.contexts.Context)1 FileSystemChangeSummary (org.nuxeo.drive.service.FileSystemChangeSummary)1 FileSystemItemChange (org.nuxeo.drive.service.FileSystemItemChange)1 TooManyChangesException (org.nuxeo.drive.service.TooManyChangesException)1