cancel
Showing results for 
Search instead for 
Did you mean: 

How to add a new field to relations?

ioihanguren_
Star Contributor
Star Contributor

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,

1 ACCEPTED ANSWER

adam_bo_
Star Contributor
Star Contributor

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

View answer in original post

13 REPLIES 13

adam_bo_
Star Contributor
Star Contributor

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

ioihanguren_
Star Contributor
Star Contributor

Thank you very much, Adam!! You have been very helpful 🙂

ioihanguren_
Star Contributor
Star Contributor

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?

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.

Could you show us a structure of your bundle ?

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

adam_bo_
Star Contributor
Star Contributor

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.

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

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