How to add a property to all documents?

hi,

i m trying to extends all my documents with a new directory item (which looks like Subjects) and get rid of Coverage one.

so, i choose a custom dublincore schema that override default one, making a widget and extends the layout…but i get errors, almost everywhere.
May be it's not as simple as overriding dublincore ?
Do y have to register a new schema and extend all types of documents ?

thanks, jérémie

1 votes

1 answers

1703 views

ANSWER



Overriding dublincore is evil :)

Dublincore is the schema that store all the mandatory fields of Nuxeo Document. This is a standard schema, if you want to see a bit more on this point go there.

But that's not only for that. for maintenance of your code, if we update something on this part of our code, you will have to take care of our updates to push them into your code.

And last, but no least your error may happens because when you has overridden the schema you remove some fields but you didn't update the layout that wait for this field…

Anyway I hope, I convince you to not go to this way.

A better way is to:

  • Create your own schema
  • Override File and Folder docType definition to just add this new schema. As all documents extends that docTypes you must have all Doc Type implementing your schema.
  • Override the “dublincore” layout to add your widget (mmmh… ) or create your own layout and add it in all your document presentation definition.

To override the core type definition, I think you just have to do something like:

<require>org.nuxeo.ecm.core.CoreExtensions</require>
<extension target="org.nuxeo.ecm.core.schema.TypeService"
    point="configuration">
<doctype name="Folder" extends="Document">
  <schema name="myschema"/>
</doctype>

<doctype name="File" extends="Document">
  <schema name="myschema"/>
</doctype>
...

To override dublincore layout, you will have something like that:

<require>org.nuxeo.ecm.platform.forms.layouts.webapp</require>
<extension target="org.nuxeo.ecm.platform.forms.layout.WebLayoutManager"
    point="layouts">
    <layout name="dublincore">

I hope that will help you.

4 votes



ok, you convince me.

for the moment, i try the following registering a schema with one element adding my schema to the doctypes :

&lt;require&gt;org.nuxeo.ecm.core.CoreExtensions&lt;/require&gt;
&lt;extension target=&quot;org.nuxeo.ecm.core.schema.TypeService&quot; point=&quot;doctype&quot;&gt;
  &lt;doctype name=&quot;Folder&quot; extends=&quot;Document&quot;&gt;
     &lt;schema name=&quot;common&quot;/&gt;            
     &lt;schema name=&quot;dublincore&quot;/&gt;
     &lt;schema name=&quot;location&quot; /&gt;
     etc...
&lt;doctype name=&quot;File&quot; extends=&quot;Document&quot;&gt;
etc...

and, finally, adding a modified dublincore layout. but, i still have errors with workspace (the schema declared in folder was not found).
i think i will try the other method.

by the way, do i need to put the require thing directly above the extension point or in the manifest file ?

02/14/2012

Did you define your location schema:

&lt;extension target=&quot;org.nuxeo.ecm.core.schema.TypeService&quot;
      point=&quot;schema&quot;&gt;
    &lt;schema name=&quot;location&quot; prefix=&quot;location&quot; src=&quot;schema/location.xsd&quot;/&gt;
&lt;/extension&gt;
02/14/2012

here is the whole thing :

schema and doctype <pre><code> <extension target="org.nuxeo.ecm.core.schema.TypeService" point="schema">

&lt;schema name=&quot;location&quot; src=&quot;schemas/location.xsd&quot; prefix=&quot;lc&quot; /&gt;

</extension> <require>org.nuxeo.ecm.core.CoreExtensions</require> <extension target="org.nuxeo.ecm.core.schema.TypeService" point="doctype">

&lt;doctype name=&quot;Folder&quot; extends=&quot;Document&quot;&gt;
  &lt;schema name=&quot;common&quot;/&gt;           
  &lt;schema name=&quot;dublincore&quot;/&gt;
  &lt;schema name=&quot;location&quot; /&gt;
  &lt;facet name=&quot;Folderish&quot;/&gt;
  &lt;subtypes&gt;
    &lt;type&gt;Folder&lt;/type&gt;
    &lt;type&gt;File&lt;/type&gt;
    &lt;type&gt;Note&lt;/type&gt;
  &lt;/subtypes&gt;
&lt;/doctype&gt;    
&lt;doctype name=&quot;File&quot; extends=&quot;Document&quot;&gt;
  &lt;schema name=&quot;common&quot;/&gt;
  &lt;schema name=&quot;file&quot;/&gt;
  &lt;schema name=&quot;dublincore&quot;/&gt;
  &lt;schema name=&quot;uid&quot;/&gt;
  &lt;schema name=&quot;files&quot;/&gt;
  &lt;schema name=&quot;location&quot;/&gt;
  &lt;facet name=&quot;Downloadable&quot;/&gt;
  &lt;facet name=&quot;Versionable&quot;/&gt;
  &lt;facet name=&quot;Publishable&quot;/&gt;
  &lt;facet name=&quot;Commentable&quot;/&gt;
  &lt;facet name=&quot;HasRelatedText&quot;/&gt;
&lt;/doctype&gt;

</code></pre>

widget : <pre><code>

&lt;extension target=&quot;org.nuxeo.ecm.platform.forms.layout.WebLayoutManager&quot;
point=&quot;widgets&quot;&gt;
    &lt;widget name=&quot;location&quot; type=&quot;template&quot;&gt;
        &lt;labels&gt;
            &lt;label mode=&quot;any&quot;&gt;Localisation&lt;/label&gt;
        &lt;/labels&gt;
        &lt;helpLabels&gt;
            &lt;label mode=&quot;edit&quot;&gt;si besoin d&apos;aide&lt;/label&gt;
        &lt;/helpLabels&gt;
        &lt;translated&gt;false&lt;/translated&gt;
        &lt;fields&gt;
            &lt;field&gt;lc:locations&lt;/field&gt;
        &lt;/fields&gt;
        &lt;properties mode=&quot;any&quot;&gt;
            &lt;property name=&quot;template&quot;&gt;/widgets/subject_widget.xhtml&lt;/property&gt;
        &lt;/properties&gt;
    &lt;/widget&gt;    
&lt;/extension&gt;    

</code></pre>

and layout : <pre><code>

&lt;require&gt;org.nuxeo.ecm.platform.forms.layouts.webapp&lt;/require&gt;
&lt;extension target=&quot;org.nuxeo.ecm.platform.forms.layout.WebLayoutManager&quot;
point=&quot;layouts&quot;&gt;

&lt;layout name=&quot;dublincore&quot;&gt;
  &lt;templates&gt;
    &lt;template mode=&quot;any&quot;&gt;/layouts/layout_default_template.xhtml&lt;/template&gt;
  &lt;/templates&gt;
  &lt;rows&gt;
    &lt;row&gt;
      &lt;widget&gt;nature&lt;/widget&gt;
    &lt;/row&gt;
    &lt;row&gt;
      &lt;widget&gt;subjects&lt;/widget&gt;
    &lt;/row&gt;
    &lt;row&gt;
      &lt;widget&gt;location&lt;/widget&gt;
    &lt;/row&gt;
    &lt;row&gt;
      &lt;widget&gt;rights&lt;/widget&gt;
    &lt;/row&gt;
    &lt;row&gt;
      &lt;widget&gt;source&lt;/widget&gt;
    &lt;/row&gt;
    &lt;row&gt;
      &lt;widget&gt;created&lt;/widget&gt;
    &lt;/row&gt;
    &lt;row&gt;
      &lt;widget&gt;modified&lt;/widget&gt;
    &lt;/row&gt;
    &lt;row&gt;
      &lt;widget&gt;format&lt;/widget&gt;
    &lt;/row&gt;
    &lt;row&gt;
      &lt;widget&gt;language&lt;/widget&gt;
    &lt;/row&gt;
    &lt;row&gt;
      &lt;widget&gt;expired&lt;/widget&gt;
    &lt;/row&gt;
    &lt;row&gt;
      &lt;widget&gt;author&lt;/widget&gt;
    &lt;/row&gt;
    &lt;row&gt;
      &lt;widget&gt;contributors&lt;/widget&gt;
    &lt;/row&gt;
    &lt;row&gt;
      &lt;widget&gt;lastContributor&lt;/widget&gt;
    &lt;/row&gt;
  &lt;/rows&gt;
&lt;/layout&gt;        
&lt;/extension&gt;

</code></pre>

02/14/2012

All seems good can you please give us some information of your error. Please refer to this answer item if you don't know how.
02/25/2012