Search in sources :

Example 1 with DocumentModelListImpl

use of org.nuxeo.ecm.core.api.impl.DocumentModelListImpl 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 2 with DocumentModelListImpl

use of org.nuxeo.ecm.core.api.impl.DocumentModelListImpl 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)

Aggregations

NuxeoDriveManager (org.nuxeo.drive.service.NuxeoDriveManager)2 DocumentModelList (org.nuxeo.ecm.core.api.DocumentModelList)2 IdRef (org.nuxeo.ecm.core.api.IdRef)2 DocumentModelListImpl (org.nuxeo.ecm.core.api.impl.DocumentModelListImpl)2 Map (java.util.Map)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 SynchronizationRoots (org.nuxeo.drive.service.SynchronizationRoots)1 OperationMethod (org.nuxeo.ecm.automation.core.annotations.OperationMethod)1