Automation chain with parametrized Query
Hi, I'm inside an automation chain and I need to get the current user's private workspace. The trouble is that user names are in the form: username@domain.com, and the private workspace is named like 'username-domain-com'. How can I write a query replacing both “@” and “.” from the current user's name with “-“?
SELECT * FROM Document WHERE ecm:path='/default-domain/UserWorkspaces/@{CurrentUser.name}'
is evaluated as
SELECT * FROM Document WHERE ecm:path='/default-domain/UserWorkspaces/myUser@domain.com'
but I need it to come out as
SELECT * FROM Document WHERE ecm:path='/default-domain/UserWorkspaces/myUser-domain-com'
if you really need this feature on your old version of Nuxeo, and if you have little development skills you can:
create a nuxeo plugin with Nuxeo IDE, it's really easy.
Create a new operation given a void as input and Document as output
declare a variable that will receive the username
@Param(name = "username", widget = Constants.W_TEXT) protected String username;
And in your operation method, just get the userworkspace service
UserWorkspaceService uws = Framework.getLocalService(UserWorkspaceService.class);
I let you check how to get the workspace from it :)
Hope will help you
Other solution: you can use a “Run Script” operation before and produce your string using some MVEL expressions, mostly the String API (the same you have on java :http://docs.oracle.com/javase/6/docs/api/java/lang/String.html). You can use replace, match, …. and work on your string.
An exemple of script put in a Run Script (that doesn't do what you aim at though, just an exemple):
org.nuxeo.ecm.core.api.Blob myBlob=Document.getProperty(“file:content”); Context[“extension”]=“none”; Context[“filename”] = myBlob.getFilename(); String[] splitedFilename=Context[“filename”].split(“\.“); Context[“extension”]=“none”;if (splitedFilename.length>=2){Context[“extension”]=splitedFilename[splitedFilename.length-1]};