Working with OpenXava

This page contains resources designed to assist you in working with OpenXava.



Installation and Configuration

ABL requires the use of Hibernate, either native or JPA, so you must configure OpenXava accordingly.  General instructions are below.  

Note: for specific instructions for the BusLogicDemo OpenXava application, click here.

Define your annotated Domain Objects as shown below:



Configure Hibernate/JPA as shown below:
  1. Configure persistence.xml to 
    1. Identity the Data Source to be used (line 13)
    2. Register ABL as the event listener(line 19)
  2. Configure the Data Source location in context.xml


Basic App Definition

Application construction is unchanged.  Once you define / configure your JPA Beans, you can define the default application.xml file as shown below.  Using this default means you do not need to define html/jsp files, or controllers.



Enable Logging

To ensure you get important logic logging:
  1. Include log4j in your web/WEB-INF/lib folder
  2. Include properties/log4j.properties


Constraint Exception Handling

The screen shot below illustrates the code to translates ABL com.autobizlogic.abl.businesslogicengine.constraintexcp.ConstraintException into javax.validation.ConstraintViolationException, as expected by OpenXava, by using the ExceptionFactoryClass configuration provided by ABL



Commit Configuration

You must also alter the properties/xava.properties file entry to be as shown below:
mapFacadeAutoCommit=true


Naviox - menu and user login

You can obtain naviox to provide application menus, and provide user authentication.  In addition to the provided documentation, please note:
  1. Note that on first execution, Naviox will create several tables such as OXUSERS, OXROLES etc.  These will be created in your application's data source.
  2. Take care to merge Naviox files into your project as shown at right (in particular, it is not a separate project, as in project > properties > build path > Projects Eclipse)
    1. The concept is that you already have a fully created, running OpenXava project, into which you want to inject Naviox
  3. The Naviox instructions refer to UpdateOX - note this is a target inside build.xml (located in your project root)
  4. After merging and running UpdateOX, you may need to refresh and clean your project.
  5. Early per-GA Naviox releases had issues with defining new users; as a temporary workaround, make com.openxava.naviox.model.User#encrypt(source) return source, and dropping the OX** tables in your database to force their recreation on the next run 
An example is shown below.  It's rather simple and elegant:
  1. The Module list (on the left) can be opened and closed
  2. The Horizontal Menu (at the top) is built automatically as users execute desired modules


Refresh after Update

Business Logic makes updates to attributes per derivation rules.  In the demo, for example, altering a PurchaseOrder's Paid flag will adjust the Customer's balance.  Recall we had to click the Refresh button to see these effects.

So that End Users can see the results of such changes automatically, you may wish to refresh after updates.  One way is to define an application.xml as show below:




Note in particular the indicated lines:

    <default-module>          

        <controller name="TypicalNotResetOnSave"/>        

    </default-module>


and

     <controller name="TypicalNotResetOnSave">

        <extends controller="Typical"/>

        <action name="save" mode="detail"

            class="org.openxava.actions.SaveAction"

            image="save.gif"

            by-default="if-possible"

            keystroke="F3">            

            <set property="resetAfter" value="false"/>

        </action>                

    </controller>   



Data Loader

You may find it convenient to develop and test with a version of HQLDB that supports in-memory operation, with options to create the database tables when you open the database.  This section describes how you can use this to simplify test data management.

You may find the idea of a database that disappears when it is closed is at first quite odd.  But, it can be very useful in testing when combined with a DataLoader that initializes the database every time the application starts up:
  • Development - when you run your app, you can be sure of the initial database state.  Updates from prior test runs are no longer a concern

  • Test Suites - you can ensure that each step in a Test Suite is unaffected by preceding tests

  • Logic aware - the DataLoader implementation below loads data through Hibernate/JPA, which thus reflects your business logic.  This means that new derivations are reflected when you restart the application.  It also means your data is checked for correctness because all the constraints are run!
You can configure OpenXava to load your test data illustrated below, and described in the following sub-sections:



DataServer Configuration

Configure your servers/context.xml like this:

<Resource
    name="jdbc/BusLogicOXDS" 
    auth="Container" 
    type="javax.sql.DataSource"
    maxActive="20" 
    maxIdle="5"
    maxWait="10000"
    username="sa"
    password=""
    driverClassName="org.hsqldb.jdbcDriver"
    url="jdbc:hsqldb:mem:memdb"
/>


The critical part here is the last line: mem instructs HSQL to use an in-memory database, and memdb is just an arbitrary name for that database.

Persistence configured to create tables

As shown in the screen shot above, update your persistence/META-INF/persistence.xml file to include the following:

<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>

<property name="hibernate.hbm2ddl.auto" value="create" />



web/WEB-INF updates
First, create your servlets.xml,and enter its contents as follows:

<servlet>
    <servlet-name>dataLoadServlet</servlet-name>      
    <servlet-class>buslogicox.dataload.DataLoaderServlet</servlet-class>
    <load-on-startup>100</load-on-startup>
    <init-param>
          <param-name>entityForDataCheck</param-name>
          <param-value>Customer</param-value>
     </init-param>
</servlet>

<servlet-mapping>
    <servlet-name>module</servlet-name>
    <url-pattern>/BusLogicOX/modules/*</url-pattern>
</servlet-mapping>


The parameter (entityForDataCheck) is optional but can be set to the name of a persistent entity. If it is set, the data loader will check whether the database already has data for this entity, and if it does, it will not load any more data.

You must also execute the deployWar (default) target of your project's build.xml.  This will update web.xml (which should normally not be edited directly).

Update lib and classpath

The DataLoader requires these jars:
  1. Place them in web/WEB-INF/lib, and 
  2. Add commons-beanutils and gson to your class path (Select your project, Properties > Java Build Path > Libraries > Add Jars...)

Provide DataLoaderServlet and DataLoader

You must also provide an implementation of the src/buslogicox/dataload/DataLoaderServlet and DataLoader.  You can obtain implementations used in the BusLogicOX Tutorial here:
  1. Create a package called buslogicox.dataload
  2. Copy the unzipped files into this package

Provide Data

The sample DataLoaderServlet reads input data from a json file, as shown in the screen shot above.
  1. Click here to download the sample data (and images) 
  2. Unzip and paste under your projects' persistence folder (verify the folder structure matches the screen shot illustrated above)

You can use the BusLogicOX Tutorial to explore these procedures.



ċ
constraintexcp.zip
(6k)
Val Huber,
Jul 7, 2012, 3:17 PM
ċ
log4j.properties
(1k)
Val Huber,
Jul 26, 2012, 9:10 AM
ċ
persistence.buslogicox.dataload.zip
(17k)
Val Huber,
Jul 22, 2012, 4:46 PM
ċ
src.buslogicox.dataload.zip
(3k)
Val Huber,
Jul 20, 2012, 8:53 AM
ċ
web.WEB_INF.lib.zip
(800k)
Val Huber,
Jul 24, 2012, 9:30 PM
Comments