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