new vocabulary based on external database ?

Hello,

I declared a new data source in my custom bundle which points to an external database :

<extension target="org.nuxeo.runtime.datasource" point="datasources">
    <datasource name="jdbc/custom" driverClassName="${db.driverClassName}">
        <property name="url">${db.url}</property>
        <property name="user">${db.username}</property>
        <property name="password">${db.password}</property>
    </datasource>
</extension>

I want to know if it is possible to use this data source to add a new read only directory (id - value vocabulary) to my Nuxeo ?

May be using the SQLDirectoryFactory extension ?

Regards.

0 votes

1 answers

593 views

ANSWER



Hello,

I find the solution :)

Steps :

1/ add new datasource pointing to your database

<extension target="org.nuxeo.runtime.datasource" point="datasources">
    <datasource name="jdbc/mydb" driverClassName="${db.driverClassName}">
        <property name="url">${db.url}</property>
        <property name="user">${db.username}</property>
        <property name="password">${db.password}</property>
    </datasource>
</extension>

2/ create a VIEW with only columns : id / label / obsolete / ordering based on your table :

CREATE OR REPLACE FORCE VIEW "XXX"."NUXEO_CAR" ("id", "label", "obsolete", "ordering") AS 
SELECT CAR_ID AS "id", CAR_NAME AS "label", 0 AS "obsolete", 10000000 as "ordering"
FROM CAR_TABLE;

3/ add new SQLDirectoryFactory

<extension target="org.nuxeo.ecm.directory.sql.SQLDirectoryFactory" point="directories">
    <directory name="car">
        <schema>vocabulary</schema>
        <dataSource>jdbc/mydb</dataSource>
        <table>NUXEO_CAR</table>
        <readOnly>true</readOnly>
        <idField>id</idField>
        <autoincrementIdField>false</autoincrementIdField>
        <createTablePolicy>never</createTablePolicy>
        <dataLoadingPolicy>never_load</dataLoadingPolicy>
    </directory>
</extension>

4/ enjoy your “car” vocabulary :)

1 votes