miércoles, 24 de febrero de 2010

Creating a new module (OpenTaps)

Welcome to my new blog, I hope Blogger offers a better interface and tools than Roller, so, let's get started with a new series of OpenTaps entries, this will be a little more focused on customizing an existing instance of Opentaps, while trying to guarantee some code independence so you can gracefully upgrade to new versions without much trouble.

Just a little quick introduction, the customization I'm making is for my family business, which is a seed trading company, so while its business model is quite common, it has a few differences that make it interesting and a nice example to use for our exercises.

So, first of all, we are going to work with the Product module, we don't want to directly modify it so we will make a new module based on it, to do this, we will make a folder in the hot-deploy directory, and for this example we will name it citsaProduct:

On it, we will create the following new files and folders:
  • ofbiz-component.xml -> This file contains all our main configuration of our new module, basically where to load the services, webapps, data, etc.
  • build.xml -> This file contains the Ant configuration to compile and build our module, for now, copy the build.xml from the application/party module, and it should be enough
  • src (folder) -> Our java sources will be located here, although for now it will be empty
  • data (folder) -> Here we will put our custom seed data, in a later blog post I'll show how to create a small app to quickly create this data from a spreadsheet file
  • entitydef (folder) -> Here we will put the configuration of our new and custom data entities
So, first of all we have to edit our ofbiz-component.xml file, for now lets put the following content:

<?xml version="1.0" encoding="UTF-8" ?>
<ofbiz-component name="citsaProduct"
<resource-loader name="main" type="component"/>
<classpath location="build/classes/*" type="dir"/>
<classpath location="config" type="dir"/>

The resource-loader tag helps us have a common base from where to look for the files that we configure here

The classpath tag will tell the Ofbiz Framework (in which OpenTaps is based on) where to find java classes, jars and other configuration files and put them in the classpath.

We also have to tell the Ofbiz Framework to load the module at application start, so we need to modify the file hot-deploy/component-load.xml

<component-loader xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<load-component component-location="opentaps-common"/>
<load-component component-location="crmsfa"/>
<!-- Some more components here.... -->
<!-- CITSA -->
<load-component component-location="citsaProduct"/>
So you should be able to run startofbiz.sh and look in the logs for an entry like this:

2010-02-11 16:04:30,113 (main) [ ComponentContainer.java:218:INFO ] Loading component : [citsaProduct]

So that means that our module is loading

0 comentarios:

Publicar un comentario