Contribute to "File" core DocumentType to add extra metadata
hi @ all,
I'm tring to add extra data to “File” core DocumentType. To achive this i have created a schema with extra informations. like:
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://nuxeo.com/schemas/com/nuxeo/myproject/metadata/extra/"
xmlns:nxs="http://nuxeo.com/schemas/com/nuxeo/myproject/metadata/extra/"
>
<xs:element name="test1" type="xs:string"/>
<xs:element name="test2" type="xs:string"/>
</xs:schema>
And added a contrib xml file for extend “schema” and “doctype”:
<extension target="org.nuxeo.ecm.core.schema.TypeService" point="schema">
<schema name="extra" src="schemas/extra.xsd" prefix="extra" />
</extension>
<extension target="org.nuxeo.ecm.core.schema.TypeService" point="doctype">
<doctype name="File" extends="Document">
<schema name="common"/>
<schema name="uid"/>
<schema name="dublincore"/>
<schema name="file"/>
<schema name="file_schema"/>
<schema name="files"/>
<schema name="extra"/>
<facet name="Versionable"/>
</doctype>
</extension>
Also, i have created a new table to add extra metadata and i have added the contrib in the xml file:
<extension target="org.nuxeo.ecm.directory.sql.SQLDirectoryFactory" point="directories">
<directory name="myextrametadata">
<schema>vocabulary</schema>
<dataSource>java:/nxsqldirectory</dataSource>
<cacheTimeout>3600</cacheTimeout>
<cacheMaxSize>1000</cacheMaxSize>
<table>my_extrametadata</table>
<idField>id</idField>
<autoincrementIdField>true</autoincrementIdField>
<dataFile>directories/myextrametadata-def.csv</dataFile>
<createTablePolicy>on_missing_columns</createTablePolicy>
</directory>
</extension>
I want to add extra metadata that no one (using webinterface) can use, but that can be usable by me via nuxeo automation client. Using a call like:
PropertyMap props = new PropertyMap();
props.set("dc:title","MyTest");
props.set("dc:description", "Descr of my Test");
props.set("extra:test1", "myextrainfo");
nuxeosession.newRequest("Document.Create").setInput(new PathRef(workspacepath)).set("type", "File").set("name", "MyTest").set("properties", props).execute();
But when i try to create a “File” into workspace via Web user interface i have a runtime error with this full stacktrace:
To make more readable the post i have pasted the stacktrace here: http://pastebin.com/7pCzE26Z
Can you help me? There is a way to “extend” metadata for Document Type “File” ? What's my fault?
Thank you!!!
I have followed this nuxeo official howto: http://doc.nuxeo.com/display/NXDOC/How-to+configure+document+types%2C+actions+and+operation+chains#How-toconfiguredocumenttypes,actionsandoperationchains-Extensionofmetadata
Ok, I tried your base schema and doc contribs on a test 5.6 system and they worked.
schema file:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://nuxeo.com/schemas/com/nuxeo/myproject/metadata/extra/"
xmlns:extra="http://nuxeo.com/schemas/com/nuxeo/myproject/metadata/extra/">
<xs:element name="test1" type="xs:string" />
<xs:element name="test2" type="xs:string" />
</xs:schema>
And the schema/doc contrib:
<?xml version="1.0" encoding="UTF-8"?>
<component name="test">
<require>org.nuxeo.ecm.directory.types</require>
<require>org.nuxeo.runtime.started</require>
<extension target="org.nuxeo.ecm.core.schema.TypeService" point="schema">
<schema name="extra" src="data/schemas/extra.xsd" prefix="extra" />
</extension>
<extension target="org.nuxeo.ecm.core.schema.TypeService" point="doctype">
<doctype name="File" extends="Document">
<schema name="common" />
<schema name="uid" />
<schema name="dublincore" />
<schema name="file" />
<schema name="files" />
<schema name="extra" />
<facet name="Versionable" />
</doctype>
</extension>
</component>
I had to remove the “file_schema” schema because I dont have that defined. I created a new File doc and confirmed in Postgres that the extra table is created. So if your contribs look like those above then they are not the issue.
I haven't followed either of these examples but I customize File on almost every Nuxeo project so I know that customizing File does work. Do you see any useful errors in the server startup log? Have you turned on additional startup logging (in Nuxeo server in the lib/log4j.xml file uncomment the following… [had to create this as an answer because the XML wouldn't show up in Comment]
<!-- Uncomment for fragments pre-processing -->
<!--
<category name="org.nuxeo.runtime.deployment.preprocessor">
<priority value="INFO" />
</category>
-->
and
<!-- Uncomment for components registration info -->
<!--
<category name="org.nuxeo.runtime.model.impl">
<priority value="INFO" />
</category>
-->
=== Reloaded Projects on Target Server ===
= Project: test-doc-definition
2012-10-19 17:35:47,539 INFO [org.nuxeo.runtime.reload.ReloadComponent] Before undeploy bundle with name 'com.test.docdefinition'.
= Component Loading Status: Pending: 0 / Unstarted: 0 / Total: 372
2012-10-19 17:35:47,541 INFO [org.nuxeo.runtime.model.impl.ComponentManagerImpl] Unregistering component: service:com.test.docdefinition
2012-10-19 17:35:47,544 INFO [org.nuxeo.runtime.reload.ReloadComponent] Undeploy done.
= Component Loading Status: Pending: 0 / Unstarted: 0 / Total: 371
2012-10-19 17:35:47,545 INFO [org.nuxeo.runtime.reload.ReloadComponent] Flush the JAAS cache
2012-10-19 17:35:48,585 INFO [org.nuxeo.runtime.reload.ReloadComponent] Before deploy bundle for file at '/home/yayo/Documents/proj/test-doc-definition/bin/main'
= Component Loading Status: Pending: 0 / Unstarted: 0 / Total: 371
2012-10-19 17:35:48,591 INFO [org.nuxeo.runtime.model.impl.ComponentManagerImpl] Registering component: service:com.test.docdefinition 2012-10-19 17:35:48,592 INFO [org.nuxeo.runtime.model.impl.ComponentRegistry] Registering component: service:com.test.docdefinition 2012-10-19 17:35:48,592 INFO [org.nuxeo.runtime.model.impl.RegistrationInfoImpl] Component activated: service:com.test.docdefinition
2012-10-19 17:35:48,606 INFO [org.nuxeo.runtime.reload.ReloadComponent] Deploy done for bundle with name 'com.test.docdefinition'.
= Component Loading Status: Pending: 0 / Unstarted: 0 / Total: 372
2012-10-19 17:35:48,607 INFO [org.nuxeo.runtime.reload.ReloadComponent] Install web resources 2012-10-19 17:35:48,607 INFO [org.nuxeo.runtime.reload.ReloadComponent] Reload runtime properties
Same error and same problem every time.
Thanks
Ok, confirm that now works for me! So thank you for your time, you are my guru now! :)
I don't know why but i think that in the last part of my test i have missed the “files” schema and all other works broke against this problem. In the meanwhile i have decided to create another File Type but, in my latest test, i have tried to extend “File” (based on my first question) and all works fine :) So:
- Duble check every time that all core schema are imported
- Enable extra logging
- Enable
- When you have an exception like this, you miss something [1]
- Bruce is always right :)
Thank you!
[1]
Caused by: org.nuxeo.ecm.core.api.WrappedException: Exception: java.lang.NullPointerException. message: null
at org.nuxeo.ecm.core.api.impl.DataModelImpl.getSchema(DataModelImpl.java:86)
at org.nuxeo.ecm.core.api.impl.DocumentModelImpl.addDataModel(DocumentModelImpl.java:569)