Nuxeo Flex Connector

Table of Contents

40.1. Overview
40.2. Development environment
40.3. Build and Deploy
40.3.1. Sample Overview
40.4. Dive In
40.4.1. Data Services Configuration
40.4.2. Your First Flex application
40.4.3. Granite DS configuration

The nuxeo-platform-flex addon provides a Flex Connector to use Nuxeo services and Nuxeo Seam components as Flex Remote Services.

40.1. Overview

The Nuxeo Flex Connector uses Granite Data Services wich is is a free, open source (LGPL), alternative to Adobe® LiveCycle® (Flex™ 2+) Data Services. GraniteDS provide a full support of AMF3/Remote Object for EJB3/Seam/Spring/Guice/Pojo technology. Since it is highly configurable, we added support for Nuxeo Runtime Services.

40.2. Development environment

You will need Flex and Air sdk to build the flex connector and its applications You can download those right here:

Check that your environment variable AIR_HOME and FLEX_HOME are setup correctly since Maven uses them to build your project.

Like all nuxeo project, you will need mercurial, maven and ant.

40.3. Build and Deploy

First, you have to get the sources on Mercurial.

  hg clone http://hg.nuxeo.org/addons/nuxeo-platform-flex
    

Next step is building those sources with maven and deploy it on your server. Configure your build.properties file so ant knows your server's location.

  ant install
    

This will run mvn install to build the project and ant copy to deploy the packages on your server.

By now you should have your connector deployed. Let's jump in the sample directory where you will find different simple examples. Run ant install to deploy them on your server. Next is a small overview of those samples. Start JBoss and go to http://localhost:8080/nuxeo/ to test them.

40.3.1. Sample Overview

  • Actions sample Take a look at all actions register for the selected Document.

  • Browser sample Browse through nuxeo Document and take a look a their properties.

  • DocumentAPI sample Modify a Document's property.

  • Facet Explorer sample Calls the SchemaManager Service to get Document Types implementing the given facet. Here to show the use of Nuxeo Runtime Service. This is a list of usual facet to test this sample: Folderish, Versionable, Orderable, Downloadable, Publishable, HiddenInNavigation, BrowseViaSearch.

  • Flex-login sample Log in Nuxeo Server and see the list of availables samples.

  • Simple sample Ping the server and play with Document properties

  • Tree sample Browse through Nuxeo documents with a simple navigation tree.

  • Users sample Search and Modify a User

  • Vocabularies sample Navigate through Nuxeo's Vocabularies.

40.4. Dive In

In this chapter, we'll see how to configure and call data services from Flex.

40.4.1. Data Services Configuration

Granite DS requires services configuration on both client and server side. To avoid painfull duplication of code, the connector provide two default factories and a default channel. If you are use to GraniteDS, you might wonder how the server side configuration is loaded. This is explained in Granite Configuration chapter.

Default Nuxeo Factory

There are two Different Factory, one to get Seam component and one to get Nuxeo services.

     <factories>
         <factory id="seamFactory" class="org.nuxeo.ecm.platform.ui.granite.factory.NuxeoSeamServiceFactory" / >
         <factory id="nxRuntimeFactory" class="org.nuxeo.ecm.platform.ui.granite.factory.NuxeoRuntimeServiceFactory" / >
     </factories >
      

Default channel

This is the default channel you have to use in your service-config.xml

    <channels >
         <channel-definition id="nx-amf" class="mx.messaging.channels.AMFChannel" >
             <endpoint
                uri="http://{server.name}:{server.port}/nuxeo/nuxeo-amf/amf"
                class="flex.messaging.endpoints.AMFEndpoint"/ >
         </channel-definition >
         <!--server.port and server.name are resolved dynamically at run time-- >
     </channels >
      

Services configuration is lighter on server side and same as usual on client side.

Seam Component

  • client side

    <services>
            <service
                id="flexDocumentManager"
                class="flex.messaging.services.RemotingService"
                messageTypes="flex.messaging.messages.RemotingMessage">
                <destination id="flexDocumentManager">
                <channels>      
                    <channel ref="nx-amf"/>
                </channels>
                    <properties>
                        <factory>seamFactory</factory>
                        <source>flexDocumentManager</source>
                    </properties>    
                </destination>
            </service>
        </services>
              
  • sever side

    Here is the minimum configuration to register your service using NxGraniteConfigService extension point:

     <extension target="org.nuxeo.ecm.platform.ui.granite.config.NxGraniteConfigService" point="services">	
            <seam id="myID" />
     </extension>
              

    The id is the default service id. They will be used as the destination name if not specified. The id will be use a the default Seam component Name if not specified.

    A complete service declaration would look like this:

     <extension target="org.nuxeo.ecm.platform.ui.granite.config.NxGraniteConfigService" point="services">	
            <seam id="myID" destinationId="myDestinationId" source="mySeamComponentName"/>
     </extension>
              

Runtime Services

  • client side

    <services>
            <service
                id="schemaManager"
                class="flex.messaging.services.RemotingService"
                messageTypes="flex.messaging.messages.RemotingMessage">
                <destination id="schemaManager">
                <channels>      
                    <channel ref="nx-amf"/>
                </channels>
                    <properties>
                        <factory>nxruntimeFactory</factory>
                        <class>org.nuxeo.ecm.core.schema.SchemaManager</class>
                    </properties>
                </destination>
            </service>
        </services>
  • server side

    Here is the minimum configuration to register your service using NxGraniteConfigService extension point:

    <extension target="org.nuxeo.ecm.platform.ui.granite.config.NxGraniteConfigService" point="services">	
            <runtime id="myID" class="my.package.MyClass" />
     </extension>

    The id is the default service id. They will be used as the destination name if not specified.

    A complete service declaration would look like this:

    <extension target="org.nuxeo.ecm.platform.ui.granite.config.NxGraniteConfigService" point="services">	
            <runtime id="myID" destinationId="myDestinationId" class="my.package.MyRuntimeServiceClass" />
    </extension>
              

40.4.2. Your First Flex application

This the code of the facet explorer sample. The RemoteOject tag is binded to the schemaManager service by the destination attribute. For more information about the other tags, see Flex Documentation here : http://livedocs.adobe.com/flex/3/langref/index.html

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"   xmlns:word="*">    
        <mx:RemoteObject id="schemaManager" destination="schemaManager"/>
        <mx:Panel title="Nuxeo Facet explorer"
            paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">
            <mx:VBox>
              <mx:TextInput id="facet" maxChars="30" text="Folderish"/>
              <mx:Button label="get Document Type" 
                click="schemaManager.getDocumentTypeNamesForFacet(facet.text)"/>
              <mx:List id="typeList" height="100%" width="100%" 
                dataProvider="{schemaManager.getDocumentTypeNamesForFacet.lastResult}" />
            </mx:VBox>
      </mx:Panel>
</mx:Application>  

40.4.3. Granite DS configuration

  • Externalizer

    If you want to use Nuxeo API, you will need a mapping between Java Object and Action Script Object. GraniteDS provides pluggable externalizer for your different Object. It aims to (de)serialize the different fields of ypur objects. For more information, see GraniteDS documentation here : http://www.graniteds.org/confluence/display/DOC/2.+Externalizers

  • InvocationListener

    You might need more controil on mapping. For instance, the DocumentModel object in Nuxeo is rather complicated. So we have a FlexDocumentModel object wich is a simplified version of DocumentModel. The mapping between those two java objects is done in the NuxeoInvocationListener. It listens to each service invocation method call. Then we can switch from FlexDocumentModel to DocumentModel or the other way around. For more information on InvocationListener, see GraniteDS documentation here: http://www.graniteds.org/confluence/display/DOC/8.+Miscanellous+Options