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'
0 votes

3 answers

1558 views

ANSWER



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

0 votes



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]};

0 votes



FYI in the next version ofNuxeo (5.4.3 or whatever it's named) a UserWorkspace.Get operation has been added that will help you once you upgrade (cf NXP-7638).

0 votes