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