How to add a new field to relations?

We are trying to add a new field (“quantity”) to relations.

We have created a new schema (“relation-extended”), and we have override Relation doctype adding this schema (in relation-extended-contrib.xml):

<component name="org.nuxeo.sample.relationextended">
  <require>org.nuxeo.ecm.core.CoreExtensions</require>

  <extension point="schema" target="org.nuxeo.ecm.core.schema.TypeService">
    <schema name="relation-extended" prefix="relext" src="schema/relationextended.xsd"/>
  </extension>

  <extension point="doctype" target="org.nuxeo.ecm.core.schema.TypeService">
    <doctype name="Relation"> <!-- no extends -->
      <schema name="relation"/>
      <schema name="dublincore"/>
      <schema name="relation-extended"/>
    </doctype>
  </extension>
</component>

This is the content of the new schema:

<xs:element name="quantity" type="xs:integer" default="1"/>

We have seen that it has created a new table in the database, with an ID and the field QUANTITY.

Afterwards, we followed http://doc.nuxeo.com/display/NXDOC/How+to+Override+a+Seam+Component how to:

  1. Created RelationExtendedActionsBean.java

        package org.nuxeo.sample;
    //Imports
    
    @Name("relationActions")
    @Scope(CONVERSATION)
    @Install(precedence = 100)
    public class RelationExtendedActionsBean extends RelationActionsBean {
      private static final long serialVersionUID = 1L;
    
        @Override
        public String addStatement() throws ClientException {
            return null;
        }
    }
    
  2. Added an empty seam.properties under the folder src/main/resources.

  3. Added required statements in deployment-fragment:

        <fragment version="1">
            <require>org.nuxeo.ecm.webapp.ui</require>
            <require>org.nuxeo.ecm.relations.web</require>  
            <install>
                <unzip from="${bundle.fileName}" to="/" prefix="web">
                    <include>web/nuxeo.war/**</include>
                </unzip>        
            </install>
        </fragment>
    

INFO logs are active in log4j.xml for Seam but we don't see our Seam component in the logs:

<category name="org.jboss.seam">
        <priority value="INFO" />
    </category>
        /***/
    <category name="org.jboss.seam.contexts.Contexts">
        <priority value="INFO" />
    </category>
    <category name="org.jboss.seam.contexts.Lifecycle">
        <priority value="INFO" />
    </category>

We don't see our component in the logs if we try to override an existing one, we just see it when we create a new Seam component using Nuxeo IDE:

2015-02-19 18:09:43,491 INFO  [http-bio-0.0.0.0-8080-exec-4] [org.jboss.seam.Component] Component: newRelation, scope: CONVERSATION, type: JAVA_BEAN, class: org.nuxeo.sample.NewRelationBean

We notice that it's not overriding, because it keeps creating the relation, and our addStatement does nothing. Also, the debugger doesn't stop in any breakpoint we put in our class.

The bundle structure is:

src/main/
    java/org/nuxeo/sample/
        RelationExtendedActionsBean.java
    resources/
        META-INF/
            MANIFEST.MF
        OSGI-INF/
            extensions/
                relation-extended-contrib.xml
            deployment-fragment.xml
        schema/
            relationextended.xsd
        web/nuxeo.war/
            create_relation.xhtml
        seam.properties

We are new in Nuxeo… What do you mean by registering our Seam bean? Do we miss a contribution to any extension point to register our Seam component? We just override create_relation.xhtml, do we need to override document_relations.xhtml?

Thank you in advance,

0 votes

4 answers

4432 views

ANSWER



You should add new fields to your version of create_relation.xhtml. After that you should add to your deployment-fragment.xml file a require statement:

<require>org.nuxeo.ecm.relations.web</require>

Then you should replace RelationActionsBean.java by your version. You can do this by adding a proper “precedence”.

@Name("relationActions")
@Scope(CONVERSATION)
@AutomaticDocumentBasedInvalidation
@Install(precedence = 100)
public class RelationActionsBean extends DocumentContextBoundActionBean

In RelationActionsBean.java it is necessary to change the addStatement method.

If you need a validation for your new fields then the RelationCreationBean.java should be also repleaced.

Adam

1 votes



I tried your example and the following one works.

The structure tree:

src/main/
    java/org/nuxeo/sample/
        RelationExtendedActionsBean.java
    resources/
        META-INF/
            MANIFEST.MF
        OSGI-INF/
            deployment-fragment.xml
        seam.properties

MANIFEST.MF:

Manifest-Version: 1.0
Bundle-Vendor: sample
Bundle-Version: 5.8
Bundle-ManifestVersion: 2
Bundle-Name: New TEST
Bundle-SymbolicName: org.nuxeo.sample.relations.test;singleton:=true
Bundle-Category: web,stateful

deployment-fragment.xml:

<?xml version="1.0"?>
<fragment version="1">
    <require>org.nuxeo.ecm.webapp.ui</require>
    <require>org.nuxeo.ecm.relations.web</require>  
</fragment>

RelationExtendedActionsBean.java:

package org.nuxeo.sample;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuxeo.ecm.platform.relations.web.listener.ejb.RelationActionsBean;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Install;   
import static org.jboss.seam.ScopeType.CONVERSATION;
import org.nuxeo.ecm.core.api.ClientException;

@Name("relationActions")
@Scope(CONVERSATION)
@Install(precedence = 100)
public class RelationExtendedActionsBean extends RelationActionsBean {
  private static final long serialVersionUID = 1L;
  private static final Log log = LogFactory.getLog(RelationExtendedActionsBean.class);

    @Override
    public String addStatement() throws ClientException {
        log.debug("test add statement");
        return null;
    }
}

You can try it.

1 votes



We have tried exactly the same, but it didn't work. It creates relations as always, and in the logs (server.log) the only line related to RelationActions is this:

2015-02-25 09:40:56,891 INFO [localhost-startStop-1] [org.jboss.seam.Component] Component: relationActions, scope: CONVERSATION, type: JAVA_BEAN, class: org.nuxeo.ecm.platform.relations.web.listener.ejb.RelationActionsBean

So, we think it loads the default RelationActionsBean.

We are using Nuxeo IDE 1.2.3.R12x_v20141113_1414 in Eclipse Luna, with SDK for the Nuxeo Platform 6.0-HF01.

We have deployed other projects and it has worked.

Are you using a different configuration, SDK version, etc.?

Thank you again.

02/25/2015

I have used Eclipse Luna without Nuxeo IDE and Nuxeo 5.8 HF 21.

Your problem is in SEAM and loading of bundle, so I reduced the bundle to the beam class. Also check MANIFEST.MF. In some cases Nuxeo doesn't load bundle if there is a problem with CR and LF characters.

02/25/2015

Yes, we also have reduced the bundle to the bean class, we have copied your code exactly. And we think that it's not a MANIFEST.MF problem, because we see in the logs that the bundle is deployed:

=== Reloaded Projects on Target Server ===

= Project: relations-test

2015-02-26 18:20:06,620 INFO [Dev Bundles Loader] [org.nuxeo.runtime.reload.ReloadComponent] Before undeploy bundle with name 'org.nuxeo.sample.relations.test'.

= Component Loading Status: Pending: 0 / Unstarted: 0 / Total: 538

2015-02-26 18:20:06,622 INFO [Dev Bundles Loader] [org.nuxeo.runtime.reload.ReloadComponent] Undeploy done.

= Component Loading Status: Pending: 0 / Unstarted: 0 / Total: 538

2015-02-26 18:20:06,622 INFO [Dev Bundles Loader] [org.nuxeo.runtime.reload.ReloadComponent] Flush Seam components 2015-02-26 18:20:07,107 INFO [Dev Bundles Loader] [org.nuxeo.runtime.reload.ReloadComponent] Flush the JAAS cache

2015-02-26 18:20:07,109 INFO [Dev Bundles Loader] [org.nuxeo.runtime.reload.ReloadComponent] Before deploy bundle for file at '/home/ioihanguren/Documents/Nuxeo IDE/relations-test/bin/devbundle/main'

= Component Loading Status: Pending: 0 / Unstarted: 0 / Total: 538

2015-02-26 18:20:07,109 INFO [Dev Bundles Loader] [org.nuxeo.runtime.reload.ReloadComponent] Deploy done for bundle with name 'org.nuxeo.sample.relations.test'.

= Component Loading Status: Pending: 0 / Unstarted: 0 / Total: 538

2015-02-26 18:20:07,109 INFO [Dev Bundles Loader] [org.nuxeo.runtime.reload.ReloadComponent] Install web resources 2015-02-26 18:20:07,109 INFO [Dev Bundles Loader] [org.nuxeo.runtime.reload.ReloadComponent] Reload Seam components 2015-02-26 18:20:07,157 INFO [Dev Bundles Loader] [org.nuxeo.runtime.reload.ReloadComponent] Reload runtime properties

We have also tried with Nuxeo 5.8, with the same results.

Can it be something related with Nuxeo IDE?

We really appreciate your efforts :)

02/26/2015

I don't think that this is the Nuxeo IDE.

It depends on the precedence and the name paremeters. It looks like Seam doesn't see your code in general or your precedence is lower than an other class with the same name paremeter in the system.

02/27/2015

Thank you Adam,

we will try to check what is wrong with Seam and if we don't find anything we will post another question specific to Seam.

03/02/2015

We have tried creating a JAR and copying to the plugins folder and it works, so we think it is something related with the IDE or the SDK. We have posted another question: http://answers.nuxeo.com/questions/11497/problem-overriding-a-seam-component-using-nuxeo-ide
03/09/2015


Hello again,

We have followed the steps you told us. But we still have some problems. We are not able to override RelationActionsBean.java

We have created the class RelationExtendedActionsBean.java following this how-to: http://doc.nuxeo.com/display/NXDOC/How+to+Override+a+Seam+Component

package com.my.package.relations;

//Imports

@Name("relationActions")
@Scope(CONVERSATION)
@Install(precedence = 100)
public class RelationExtendedActionsBean extends RelationActionsBean {

      private static final long serialVersionUID = 1L;

      @Override
      public String addStatement() throws ClientException {
          return null;
      }
}

We notice that it's not overriding, because it keeps creating the relation, and our addStatement does nothing. Also, the debugger doesn't stop in any breakpoint we put in our class. And we don't see any line in the logs saying that our Seam component has loaded.

We have tried with different precedences: Install.MOCK, 100, etc.

Are we missing something?

0 votes



This is not an answer. Please just edit your original question with what you tried, and add a comment to the given answer to say what you changed.

Did you correctly register your Seam bean? Do you have an empty seam.properties like described in the doc? What are the startup logs (activate INFO logs for Seam)?

02/19/2015

Could you show us a structure of your bundle ?
02/19/2015

Sorry Florent, we have reformulated the question with all the steps we have followed.

Adam, we also added the complete structure of our bundle.

Thanks!

02/20/2015


Thank you very much, Adam!! You have been very helpful :)

0 votes