2

I want to make a request with "dynamic" properties fetch from my Java app with nuxeo 8.10.

There is the declatation of my NuxeoDocument:

    <schema name="TestDocumentProperties" src="data/TestDocumentProperties.xsd" prefix="test" />
    <doctype name="TestDocument" extends="Document">
        <schema name="dublincore"/>
        <schema name="TestDocumentProperties"/>
    </doctype>

There is the schema:

<xs:schema ...>  
  <xs:element name="summary" type="xs:string"/>
  <xs:element name="content" type="xs:string"/>
</xs:schema>

There is a "Get" request to my Nuxeo server:

https:xxx/nuxeo/site/api/v1/search/lang/NXQL/execute?query=SELECT * FROM Document WHERE ecm:fulltext = 'test'&properties=TestDocumentProperties, dublincore

When i execute this request directly from my browser, the result contains all of the properties of "dublincore" and "TestDocumentProperties":

{
    "entity-type": "document",
    "type": "TestDocument",
    ...
    "properties": {
        "test:summary": "test text to search in summary",
        "test:content": "test text to search in content",
        "dc:description": null,
        "dc:language": null,
        "dc:coverage": null,
        "dc:valid": null,
        "dc:creator": "xxx",
        "dc:modified": "2017-12-13T16:28:38.44Z",
        ...
    },...
}

So, I want to execute a nuxeo nxql request from my Java application with the same parameter. Before, i execute only the request from my java app, without the "properties" parameter with this code:

return this.nuxeoClient.repository().query("SELECT * FROM Document WHERE ecm:fulltext = 'test'");

But with "query" method from repository, there isn't possible to specify the properties to fetch. So, today, i try with this code:

    Map<String, Object> parameters = new HashMap<>();
    parameters.put("query", "SELECT * FROM Document WHERE ecm:fulltext = 'test'");
    parameters.put("properties", "TestDocumentProperties, dublincore");
    return this.nuxeoClient.automation("Repository.Query").parameters(parameters).execute();

Unfortunately, the result isn't fetch correctly, i don't have the "dublincore" properties in my response but i have the "TestDocumentProperties". If i remove the "TestDocumentProperties" in the list of fetch properties parameters, there is no change to the response...

Can you help me to correct this code or indicate me an alternative ?

Thank's

julien dumortier
  • 1,303
  • 1
  • 13
  • 28
  • 1
    Try to set it via headers: .setHeader(Constants.HEADER_NX_SCHEMAS, "TestDocumentProperties,dublincore").parameters(parameters).execute(); – Jannes Botis Feb 19 '18 at 22:33
  • I already tested by modifying the header, it's works, but this method is only accessible from nuxeoClient (Singleton); there isn't accessible from the return of "automation" method. – julien dumortier Feb 20 '18 at 08:11
  • Glad it helped. It has been long since I have used it. – Jannes Botis Feb 20 '18 at 08:44

1 Answers1

1

According to the nuxeo doc, you can choose the schemas to return using setHeader(Constants.HEADER_NX_SCHEMAS) method:

return this.nuxeoClient.setHeader(Constants.HEADER_NX_SCHEMAS, "TestDocumentProperties,dublincore").automation("Repository.Query").parameters(parameters).execute();

For the properties. if I remember correctly, you can set specific properties to return:

parameters.put("properties", "dc:title,dc:description");

or maybe you need to do like this:

import org.nuxeo.ecm.automation.client.model.Document;
// Instantiate a new Document with the simple constructor
Document document = new Document("myDocument", "File");
document.set("dc:title", "My File");
document.set("dc:description", "My Description");
parameters.put("properties", document);

This latter I am not sure, hope it helps.

Jannes Botis
  • 11,154
  • 3
  • 21
  • 39