Archive for the ‘Friday Q&A’ tag
[Q&A Friday] How to add tagging capability during drag’n'drop
Here’s a question that comes back often, asked by bruce: How to add tag capability during drag’n’drop?. Since Thierry added HTML5 drag’n’drop to the Nuxeo Platform, it’s possible to fill in metadata right after the import, and apply them to all the imported documents. But I understand it can be frustrating not being able to add tags. And fortunately the drag’n’drop service for content capture is extensible. The full code sample is available on GitHub.
So here’s how it works. When dragging files in a content view for at least 2 seconds, you’ll be prompted with a Select import operation choice. Those select operations are actually actions. It means you can add as any as you want through the action extension point. These actions have a specific behavior.
The ID of the action must, for instance, be the ID of the operation or the operation chain that …
[Q&A Friday] How to Access a Resource Bundle with MVEL in Content Automation
There’s an interesting question today from milonette, asking how to access labels with MVEL. Sometimes the Content Automation API doesn’t provide everything you need out of the box, hence the question. But the good news is this API is extensible.
While some functions are already available in the automation context, there is currently nothing to access the resource bundles. We’ll need to add our own function into it. This is quite easy to do. First we need to write the new function we need, then we’ll write an operation that adds this function to the content automation context.
Our localized function needs different parameters. We want the locale, the name of the resource bundle, the key of our message and some optional parameters. Here’s a simple implementation:
Now that I have my function, I need to create an operation that will make this available within the automation context:…
[Q&A Friday] Remotely Searching for a Document Using Tags
Today dedacosta asks if it’s possible to search documents remotely using tags. First let’s talk about tags.
The tag service uses two important concepts: a tag object, and a tagging action. Both are represented as Nuxeo documents.
A tag is a document type representing the tag itself (but not its association to specific documents). It contains the usual dublincore schema, and in addition has a specific tag schema containing a tag:label string field.
A tagging is a relation type representing the action of tagging a given document with a tag. (A relation type is a document type extending the default relation document type; it works like a normal document type except that it’s not found by NXQL queries on document). The important fields of a tagging document are relation:source which is the document ID, relation:target which is the tag ID, and dc:creator which is the user doing the
…
[Q&A Friday] How to Retrieve the List of All Possible Subject Values Using Content Automation
Today we have a question from thexman who asks how he can retrieve the list of all possible subject values with content automation. His first thought was to use NXQL, Nuxeo’s query language, which makes perfect sense when you are searching for something. Unfortunately, NXQL is used to search the content of documents, and all the subject values are not stored as documents. The values proposed by Nuxeo when choosing a subject are all stored on what we call a directory. Here’s a definition taken straight from our documentation:
In Nuxeo EP, a directory is a source of (mostly) table-like data that lives outside of the VCS document storage database. A directory is typically a connection to an external data source that is also accessed by processes other than Nuxeo EP itself (therefore allowing shared management and usage).
A vocabulary is a specialized directory with only a few
…
[Q&A Friday] How to Retrieve Custom Metadata with Content Automation
Here’s a question that comes up often: When you retrieve a document using content automation, how do you retrieve custom metadata? This question comes up often mostly because content automation is the preferred way of interacting with Nuxeo from another application. People use it on mobile, directly from Javascript, from another Java app, the PHP client, the python client (Nuxeo Drive is a good example of that), etc.
Now back to the question, how do you retrieve other metadata? The question was about the Android connector but it applies to content automation. The short answer: We have special headers. Here’s the definition straight from the documentation:
This header can be used whenever a document will be returned by the server. The header is forcing the server to fill the returned document up with data from schemas that match the X-NXDocumentProperties filter. So, X-NXDocumentProperties is a filter of schemas.
…
[Q&A Friday] Automatic Creation of User Workspaces
Today we’re answering a question about user workspaces. How can you create them automatically? First, if you don’t know what a personal workspace is, here’s a definition taken from our documentation:
Personal workspaces can only be accessed by their owner, by default. You can of course share the access to your personal workspace with other users. Personal workspaces are accessible in the header of the application.
What you need to know to answer that is that those personal workspaces are usually created lazily. It means they are created the first time something tries to access it. So the solution Ron proposed is to access the user personal workspace each time he successfully logged in.
You can access it using the following Java code:
But, to do that, everybody would have to log in. If you still need to create all of them automatically, the good news is that …
[Q&A Friday] How Do We Search for Accented Characters in Note Content?
Here’s a question from patrek; you might have seen him a lot on Nuxeo Answers: How do we search for accented characters in Note content?
If you are not familiar with Nuxeo you have to know that the Note document type is used to store text. This text can be plain text, XML, HTML or markdown. When you store a note in HTML, the accented characters you type are converted to HTML entities. For instance if you type ‘é‘, it will be stored as ‘é. And if it’s stored as ‘é‘, it will be indexed as such. Which means that if you search for it, you’ll have to type ‘é‘ in the search field instead of ‘é‘. This is no good for most of the normal users; they want to type ‘é‘ just like they did when …
[Q&A Friday] Can an external web service call be included in an automation chain?
Here’s a common question: Can an external web service call be included in an automation chain?
There are many uses cases to this. You may want to integrate with an existing application or simply retrieve some metadata from a single web service. This can be a good way to enrich metadata about a specific kind of document. Let’s say, for instance, that you are managing a book collection in Nuxeo. Every book as an ID called ISBN, which stands for International Standard Book Number. It’s a unique numeric commercial book identifier. Using this ID, you can retrieve more information about the book. The openlibrary.org website has a REST API that gives you information from an ISBN. So, all you have to do to use this in an automation chain is to create an operation that makes a call to this API. As Vlad answered, we have some documentation for …
[Q&A Friday] Relative date usage in Nuxeo Studio
Here’s a question about relative date usage in Nuxeo Studio: How do I pass a date, relative to the current date, into a Query Filter?
This is interesting as sometimes you might want to retrieve all documents with an expiration date before today plus 30 days. Or maybe you want to retrieve every document created thirty days ago. You obviously can’t hardcode the date so you have to use something like a @{CurrentDate} object.
Content Automation
If you’re in the content automation context, it’s really straight forward. Most of the operation parameters support the MVEl scripting language. So you have access to any objects like @{CurrentDate}.
Here’s a query that returns the documents that will expire in the next 10 days:
While this retrieves all the documents that have been expired at least 10 days:
Content Views
Unfortunately, this won’t work in a content view. The problem …
[Q&A Friday] How to deploy a contribution on a per method basis?
Today we have a question from Edgar who asks if it’s possible to deploy a contribution on per method basis? I like this question because the use of the Deploy annotation can be misleading. Here’s why: You can put this annotation on a method and it won’t do anything, which is deeply disturbing to me. That’s because method annotations are never looked for in our JUnit runner (One day I’ll have to fix the target of those annotations).
So if you cannot use the Deploy and LocalDeploy annotations on your method, the question is: How do you deploy bundles or contributions inside them? Well, the proper way to do this is to use the test harness you can inject in your test using the @Inject annotation.
Injection is one of the most important part of our test framework. But, it’s not easy to know what you can/cannot inject. To …