Home > Blog > [Monday Dev Heaven] Unleash Nuxeo Shell

[Monday Dev Heaven] Unleash Nuxeo Shell

Today I bring you the Nuxeo Shell. This is a wonderful toolbox for developers and administrators and I think it deserves more recognition.

Opening the Shell

Opening the Shell

Playing with the Shell

Using the Shell is quite easy when you have Nuxeo IDE. You need to be in the Nuxeo perspective and click on the little shell icon on the bottom left of the screen.

You can now type tab to see a list of the available commands. These commands are sorted by namespaces. Namespaces are command registries that you can register in the shell. A command registry helps bring inside the shell a new set of commands for a specific context without having name clash problems with already existing commands. It is also very useful because you have a different type of completion for each namespace. For instance, if you have selected the local namespace, hitting tab after ls will show you the list of files from your file system. If you have selected the remote namespace, it will display the list of documents on the Nuxeo server you are connected to.

So let’s start with the connect command:

[bash]connect http://localhost:8080/nuxeo/site/automation/ -u Administrator[/bash]

This command will prompt you for the password of the adminstrator user on the localhost:8080/nuxeo server.

Connect to the Shell

Connect to the Shell

If you type tab again, you’ll see that the command list has changed. There are a lot more of them. If you are a Unix shell user, it should feel like home. You’ll recognize some of them: cat, ls, mkdir, mv, cp, rm. They will of course apply to the server’s documents since you have selected the remote namespace. Let’s try the ls and then cat /default-domain command.

Cat command example

Cat command example

Do you need more information than what cat just gave you? Try help cat. Here is the description of the cat command, its syntax, options and arguments. This works with every command (you can also type cmds or commands to get the list of available commands). Try cat -all /default-domain, you’ll see much more information. Keep on playing with the commands, you’ll see you can do some pretty wicked things. Don’t hesitate to browse the index of all command sorted by namespace on our wiki.

Content Automation

So all the commands you typed in the remote namespace are using the Content Automation API. That’s right, you are using an http shell. This means I have two pieces of good news for you. The first is that you can call any existing operation or chain on the server. Just type use automation and you’ll get in the right namespace. If you type tab for completion, you’ll get the list of Operations and Operation Chains available on the server. If you don’t know hos to use them, here’s a quick trick. You can generate a help file for any name space using the following command: help -export [file] -ns [namespace]? This will give you the parameter name for each operation, for example. Then you’ll know how to run Document.Query:

[bash]
Administrator@localhost:/> use automation
remote -> automation
> Document.Query -query "Select * From File"

[/bash]

The second piece of good news is that those operations are really easy to deploy on your server using NuxeoIDE. I’ve created a CountWords operation that counts the number of words contained in a  document. You can check this out on a previous blog. It makes it quick and easy to test your operation directly from the IDE.

Groovy or MVEL script?

If you don’t have the IDE, you can still use the shell. It’s available from our nexus repository and has the exact same functionality as the one in the IDE. You’ll probably miss being able to quickly execute an operation and reload it on the server. Well, there is an alternative to this workflow. You can execute Groovy or MVEL script. Those of you who are familiar with NuxeoStudio probably already know MVEL. For those who don’t :

“MVEL is a powerful expression language for Java-based applications. It provides a plethora of features and is suited for everything from the smallest property binding and extraction, to full blown scripts.”

Here are two small example of what you can do:

This is a complete example of a script used by the perms command to get the ACLs available on a document:

[groovy]
import org.nuxeo.ecm.core.api.PathRef;
import org.nuxeo.ecm.core.api.IdRef;
import org.nuxeo.ecm.core.api.security.ACP;
import org.nuxeo.ecm.core.api.security.ACE;
import org.nuxeo.ecm.core.api.security.ACL;

def doc = null;
def aclname = Context["acl"];
def ref = Context["ref"];
if (ref.startsWith("/")) {
doc = Session.getDocument(new PathRef(ref));
} else {
doc = Session.getDocument(new IdRef(ref));
}
def acp = doc.getACP();
def result = null;
if (aclname != null) {
def acl = acp.getACL(aclname);
if (acl == null) {
result = "No Such ACL: ${aclname}. Available ACLS: ";
for (a in acp.getACLs()) {
result+=a.getName()+" ";
}
return result;
}
result = "{bold}${aclname}{bold}n";
for (ace in acl) {
result += "t${ace}n";
}
} else {
result = "";
for (acl in acp.getACLs()) {
result += "{bold}${acl.name}{bold}n";
for (ace in acl) {
result += "t${ace}n";
}
}
}

return result;
[/groovy]

And here is the MVEL example:

[groovy]
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]
};
[/groovy]

The different variables available in Nuxeo are explained on the wiki. If you already know NuxeoStudio, it’s exactly the same.

Pretty cool, huh?

Now batch that script!

Some of the scripts we do sometimes need to be ran at a particular time. So instead of using the shell in an interactive mode, we use the batch mode. There are three different batch modes:

1. Run commands from a file
2. Run commands from standard input
3. Run commands specified on the command line – this is a convenient way to run a short list of commands

Here’s how you do it:

[bash]java -cp nuxeo-shell.jar org.nuxeo.shell.Main -f my_batch_file[/bash]

my_batch_file contains the different commands you need to run. Here’s a sample from the documentation:

[bash]
# connect to local server using the Administrator account.
connect -u Administrator -p Administrator http://localhost:8080/nuxeo/site/automation

# we are now in the repository root. Go to /default-domain/workspaces
cd /default-domain/workspaces

# list the content of the workspaces root – as document UIDs
ls -uid
[/bash]

You’ll find examples for the two other modes on the wiki. Now you can use cron to execute your script at any time you want :)

Still not enough? Extend the shell.

If you have enjoyed what you read, and want to dive further in the shell, you need to read the Extending the Shell page on the wiki. And if you need examples, you can always check out the sources on GitHub. We love pull requests so don’t hesitate :)

Nuxeo Document Management
Document
Management
with the
Nuxeo Platform Watch the webinar >
  • jcarsique

    The Nuxeo Shell is available in many forms (you mentioned two of them):
    – in Eclipse as a plugin,
    – in command line, using the JAR,
    – in the Admin Center as an applet,
    – in the Nuxeo Control Panel GUI (aka NuxeoCtl).

  • http://www.cuclapita.com Bonuses

    I simply want to mention I am beginner to weblog and certainly loved this blog. Probably I’m planning to bookmark your blog . You amazingly come with beneficial well written articles. With thanks for sharing your web-site.

  • http://www.evottaparadise.com get more info
  • http://www.sexovisa.com/16/teniendo-sexo-con-una-camarera-guarra/ good post
  • http://home.by.me/es/perfil/ansbdssaw viagra sklep

    Hello, i read your blog from time to time and i own a similar one and i was just wondering if you get a lot of spam remarks? If so how do you protect against it, any plugin or anything you can recommend? I get so much lately it’s driving me mad so any support is very much appreciated.

  • http://www.albumsexo.com/15/follando-por-el-culo-a-una-rubia-tetona/ browse link
  • http://www.hot-porn-site.com/62/colegiala-rubia-corriendose-de-gusto/ follow this article
  • http://kotburger.pl/user/benek71 Wróżka

    Lecz dobro zależy na zasługę; albo ów przypadek podług kolei przypadków przestrzeganie lub nieokrzesany http://moz.com/community/users/3996499 Skutki i poczciwość i darować Albowiem najrealniejsza Istność absolutnie konieczna jest przeciw dobrotliwości i utraty

  • http://www.plumppornstars.com/22/haciendo-gemir-a-una-morena-depilada/ check it out

    I simply want to say I am just newbie to blogging and seriously savored your web site. More than likely I’m going to bookmark your website . You absolutely have incredible articles. Bless you for revealing your web-site.

  • http://www.celebratehealth.org Romelia Zoellner

    Somebody essentially assist to make significantly posts I might state. This is the very first time I frequented your web page and to this point? I surprised with the analysis you made to make this actual submit incredible. Wonderful process

  • http://www.startupconnecticut.org Kandy Schellhorn

    I was very happy to find this site. I want to to thank you for ones time just for this wonderful read!! I definitely appreciated every little bit of it and I have you book marked to see new stuff in your web site.

  • Pingback: My Homepage()

  • Pingback: عقارات للبيع في تركيا()

  • Pingback: phentermine 37.5 tablets()