Visualize Your Nuxeo Studio Configuration With StudioViz
Nuxeo Studio offers an enormous capability to configure and customize the Nuxeo Platform. After a quick learning curve, the users have the ability to do almost anything with Studio!
Sometimes this means you might end up creating multiple Document Types, Schemas, Content Views, Forms, Automation Chains, Scripting, etc. and end up with something very complex to understand for someone besides you. This is, in fact, something that happened to me when I started working on existing Studio projects. Often, when all I needed to do was just add a simple operation in an existing Automation Chain or add a field in a Content View, I had to navigate back and forth from the Document Type to the Content View and try to find the User Action Button definition to see which Automation Chain it’s pointing to. This was time consuming to say the least.
As you might have guessed, we decided to address it and make life easier for our Studio users!
During our annual discussion of the Nuxeo Roadmap, we talked about how to organize Nuxeo Studio so that it becomes even more intuitive. I proposed we use GraphViz to visualize the configuration in a graphical way and decided to dig a little bit deeper. As we all know “code always wins arguments”, I started working on a quick prototype as a side project and came up with StudioViz.
I divided the Studio configuration into 3 different parts:
-The Data Model representing Document Types, Schemas, and Facets
-The View for the Content Views, Tabs, and Forms related to Document Types
-The Business Rules containing the User Actions, Automation Chains, Scriptings, and Events.
This helps you visualize your studio configuration as promised :)
What would be even better is to be able to navigate to your Studio project directly from the graph. That’s easy too! GraphViz gives you the ability to add contextual links and that is what I did.
Now, anytime you want to make a modification on any part of your Studio configuration (for instance, add a new Operation in an Automation Chain, a new field in an existing Content View, etc.) you just have to click on the corresponding content of the graphic and you are automatically redirected to your Studio project! Configuring an existing Studio project is now a piece of cake ;)
Behind the Scene
Now that you have seen the result, let’s take a quick look at what went on behind the scene. First, I had to find a way of getting the data related to my Studio project. When you finish configuring your Studio project you upload it on your platform as a jar file.
So, I decided to create a Nuxeo plugin that reads the Studio configuration uploaded on the Nuxeo Platform and work on the data that you find in the extensions.xml file extracted from the jar.
JAXB: XML to Java
Once I extracted the XML, I had to convert it into Java Objects which is more convenient to navigate through. So I created an XSD file based on the XML and then generated the Java Objects via JAXB. JAXB (Java Architecture for XML Binding) is a tool that enables you to convert Java Objects to XML (Marshalling) and XML to Java Objects (Unmarshalling).
One last step was to unmarshal the XML to instantiate my Java objects like this:
JAXBContext jc = JAXBContext.newInstance("org.nuxeo.jaxb");
Unmarshaller unmarshaller = jc.createUnmarshaller();
Component component = (Component) unmarshaller.unmarshal(new File("mypath/extensions.xml"));
GraphViz: Boxes and Arrows
So now that I have the data and was able to instantiate the related Java Objects, I had to find a way to transform it into a graphical view with boxes and arrows. This is where GraphViz comes into play.
GraphViz is an open source program that enables you to generate a graphical view based on a text file describing nodes and links. I basically created an operation that does all the mapping and generates the graph.
This is just the cornerstone and a lot of features can be integrated into it, especially for the next generation of Studio UI. I am sure you’ll find it useful :)
You can find the StudioViz Nuxeo package here. You need to install GraphViz on the Nuxeo server, or locally if you run it as a localhost. This plugin is aligned with the Nuxeo Platform 8.1 version but will also work on the LTS 2015 as the UI is based on Web Components. Enjoy!