Search in sources :

Example 1 with OperationMethod

use of org.nuxeo.ecm.automation.core.annotations.OperationMethod in project nuxeo-drive-server by nuxeo.

the class NuxeoDriveCreateFile method run.

@OperationMethod
public Blob run(Blob blob) throws ParseException, IOException {
    FileSystemItemManager fileSystemItemManager = Framework.getService(FileSystemItemManager.class);
    // correctly if there is non ascii characters in it.
    if (StringUtils.isNotBlank(name)) {
        blob.setFilename(name);
    }
    NuxeoDriveOperationHelper.normalizeMimeTypeAndEncoding(blob);
    FileItem fileItem = fileSystemItemManager.createFile(parentId, blob, ctx.getPrincipal(), overwrite);
    return Blobs.createJSONBlobFromValue(fileItem);
}
Also used : FileItem(org.nuxeo.drive.adapter.FileItem) FileSystemItemManager(org.nuxeo.drive.service.FileSystemItemManager) OperationMethod(org.nuxeo.ecm.automation.core.annotations.OperationMethod)

Example 2 with OperationMethod

use of org.nuxeo.ecm.automation.core.annotations.OperationMethod in project nuxeo-drive-server by nuxeo.

the class NuxeoDriveRename method run.

@OperationMethod
public Blob run() throws InvalidOperationException, IOException {
    FileSystemItemManager fileSystemItemManager = Framework.getService(FileSystemItemManager.class);
    FileSystemItem fsItem;
    try {
        fsItem = fileSystemItemManager.rename(id, name, ctx.getPrincipal());
    } catch (UnsupportedOperationException e) {
        throw new InvalidOperationException(e);
    }
    return Blobs.createJSONBlobFromValue(fsItem);
}
Also used : FileSystemItemManager(org.nuxeo.drive.service.FileSystemItemManager) FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) InvalidOperationException(org.nuxeo.ecm.automation.InvalidOperationException) OperationMethod(org.nuxeo.ecm.automation.core.annotations.OperationMethod)

Example 3 with OperationMethod

use of org.nuxeo.ecm.automation.core.annotations.OperationMethod in project nuxeo-drive-server by nuxeo.

the class NuxeoDriveSetActiveFactories method run.

@OperationMethod
public boolean run() throws Exception {
    NuxeoDriveIntegrationTestsHelper.checkOperationAllowed();
    String contrib;
    if ("userworkspace".equals(profile)) {
        contrib = "/OSGI-INF/nuxeodrive-hierarchy-userworkspace-contrib.xml";
    } else if ("permission".equals(profile)) {
        contrib = "/OSGI-INF/nuxeodrive-hierarchy-permission-contrib.xml";
    } else {
        log.warn(String.format("No active file system item factory contribution for profile '%s'.", profile));
        return false;
    }
    URL url = NuxeoDriveSetActiveFactories.class.getResource(contrib);
    try {
        if (enable) {
            Framework.getRuntime().getContext().deploy(url);
        } else {
            Framework.getRuntime().getContext().undeploy(url);
        }
    } finally {
        Framework.getRuntime().getComponentManager().unstash();
    }
    FileSystemItemAdapterServiceImpl fileSystemItemAdapterService = (FileSystemItemAdapterServiceImpl) Framework.getService(FileSystemItemAdapterService.class);
    fileSystemItemAdapterService.setActiveFactories();
    return true;
}
Also used : FileSystemItemAdapterService(org.nuxeo.drive.service.FileSystemItemAdapterService) FileSystemItemAdapterServiceImpl(org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl) URL(java.net.URL) OperationMethod(org.nuxeo.ecm.automation.core.annotations.OperationMethod)

Example 4 with OperationMethod

use of org.nuxeo.ecm.automation.core.annotations.OperationMethod 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 5 with OperationMethod

use of org.nuxeo.ecm.automation.core.annotations.OperationMethod in project nuxeo-drive-server by nuxeo.

the class NuxeoDriveGetTopLevelFolder method run.

@OperationMethod
public Blob run() throws IOException {
    FileSystemItemManager fileSystemItemManager = Framework.getService(FileSystemItemManager.class);
    FolderItem topLevelFolder = fileSystemItemManager.getTopLevelFolder(ctx.getPrincipal());
    return Blobs.createJSONBlobFromValue(topLevelFolder);
}
Also used : FileSystemItemManager(org.nuxeo.drive.service.FileSystemItemManager) FolderItem(org.nuxeo.drive.adapter.FolderItem) OperationMethod(org.nuxeo.ecm.automation.core.annotations.OperationMethod)

Aggregations

OperationMethod (org.nuxeo.ecm.automation.core.annotations.OperationMethod)20 FileSystemItemManager (org.nuxeo.drive.service.FileSystemItemManager)12 FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)5 NuxeoDriveManager (org.nuxeo.drive.service.NuxeoDriveManager)3 FileItem (org.nuxeo.drive.adapter.FileItem)2 FolderItem (org.nuxeo.drive.adapter.FolderItem)2 FileSystemItemAdapterService (org.nuxeo.drive.service.FileSystemItemAdapterService)2 InvalidOperationException (org.nuxeo.ecm.automation.InvalidOperationException)2 URL (java.net.URL)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 Map (java.util.Map)1 Set (java.util.Set)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 RootlessItemException (org.nuxeo.drive.adapter.RootlessItemException)1 ScrollFileSystemItemList (org.nuxeo.drive.adapter.ScrollFileSystemItemList)1 FileSystemChangeSummary (org.nuxeo.drive.service.FileSystemChangeSummary)1 SynchronizationRoots (org.nuxeo.drive.service.SynchronizationRoots)1 VersioningFileSystemItemFactory (org.nuxeo.drive.service.VersioningFileSystemItemFactory)1 FileSystemItemAdapterServiceImpl (org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl)1