Search in sources :

Example 16 with OperationMethod

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

the class NuxeoDriveGenerateConflictedItemName method run.

@OperationMethod
public Blob run() throws IOException {
    String extension = "";
    if (name.contains(".")) {
        // Split on the last occurrence of . using a negative lookahead
        // regexp.
        String[] parts = name.split("\\.(?=[^\\.]+$)");
        name = parts[0];
        extension = "." + parts[1];
    }
    NuxeoPrincipal principal = (NuxeoPrincipal) ctx.getPrincipal();
    // fallback
    String userName = principal.getName();
    if (!StringUtils.isBlank(principal.getLastName()) && !StringUtils.isBlank(principal.getFirstName())) {
        // build more user friendly name from user info
        userName = principal.getFirstName() + " " + principal.getLastName();
    }
    Calendar userDate = Calendar.getInstance(NuxeoDriveManagerImpl.UTC);
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm");
    dateFormat.setCalendar(userDate);
    String formatedDate = dateFormat.format(userDate.getTime());
    String contextSection = String.format(" (%s - %s)", userName, formatedDate);
    String conflictedName = name + contextSection + extension;
    return Blobs.createJSONBlobFromValue(conflictedName);
}
Also used : Calendar(java.util.Calendar) NuxeoPrincipal(org.nuxeo.ecm.core.api.NuxeoPrincipal) SimpleDateFormat(java.text.SimpleDateFormat) OperationMethod(org.nuxeo.ecm.automation.core.annotations.OperationMethod)

Example 17 with OperationMethod

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

the class NuxeoDriveGetFileSystemItem method run.

@OperationMethod
public Blob run() throws IOException {
    FileSystemItemManager fileSystemItemManager = Framework.getService(FileSystemItemManager.class);
    FileSystemItem fsItem;
    if (parentId == null) {
        fsItem = fileSystemItemManager.getFileSystemItemById(id, ctx.getPrincipal());
    } else {
        fsItem = fileSystemItemManager.getFileSystemItemById(id, parentId, ctx.getPrincipal());
    }
    return Blobs.createJSONBlobFromValue(fsItem);
}
Also used : FileSystemItemManager(org.nuxeo.drive.service.FileSystemItemManager) FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) OperationMethod(org.nuxeo.ecm.automation.core.annotations.OperationMethod)

Example 18 with OperationMethod

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

the class NuxeoDriveGetTopLevelChildren method run.

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

Example 19 with OperationMethod

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

the class NuxeoDriveAttachBlob method run.

@OperationMethod
public Blob run(Blob blob) {
    BlobHolder bh = doc.getAdapter(BlobHolder.class);
    if (bh == null) {
        throw new NuxeoException(String.format("Document %s is not a BlobHolder, no blob can be attached to it.", doc.getId()));
    }
    bh.setBlob(blob);
    session.saveDocument(doc);
    return blob;
}
Also used : BlobHolder(org.nuxeo.ecm.core.api.blobholder.BlobHolder) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException) OperationMethod(org.nuxeo.ecm.automation.core.annotations.OperationMethod)

Example 20 with OperationMethod

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

the class NuxeoDriveCreateFolder method run.

@OperationMethod
public Blob run() throws IOException {
    FileSystemItemManager fileSystemItemManager = Framework.getService(FileSystemItemManager.class);
    FolderItem folderItem = fileSystemItemManager.createFolder(parentId, name, ctx.getPrincipal(), overwrite);
    return Blobs.createJSONBlobFromValue(folderItem);
}
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