Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • If you have a direct access to an external database, the easiest method is to connect to it through the OFBiz Entity Engine.
  • If there is an external database but you don't have access to it, then we recommend the use of an ETL tool, Talend is our preferred. After evaluating few ETL tools - Pentaho Kettle, Jitterbit and Talend, we found out that the easiest way to integrate data in Ofbiz is to use Talend.
  • If there is not an external database, only flat files, then the best is to use ???

If you

...

First you create a Datasource in the entityengine.xml to connect to the legacy database.
Then use the https://localhost:8443/webtools/control/view/ModelInduceFromDb to create the entities from the legacy db.
It is recommended that you use ./ant create-component.  This will put the necessary structure for your component in hot-deploy
You do a view source of the resultant webpage, then copy and paste into hot-deploy/[ legacydb or what ever you want to call it ]/entitydef/entitymodel.xml

Next you need to clean up the entities that match your current DB.
you can use https://cwiki.apache.org/OFBIZ/ofbiz-tutorial-a-beginners-development-guide.html
as a reference.

Next assign those entities to a unique group-name by including them in an entity-group.xml file. Add the new group-name to the group-map element in entityengine.xml file.
Also in the entityengine.xml put in a delegator for your datasource named legacydb.

You can then access your external entities using the legacydb delegator.

Under the scripts directory you can write a mini language method that reads your entities and then transfers the fields of your entity to a map to call one of the OFBiz services to create entity records or use the methods to create new records at the entity level.

As time permits I will put in some skeleton code on how to do this. I used the simple method by Jacopo applications/product/script/org/ofbiz/product/olap/ProductDimensionServices.xml as guide

Note: the names are fictitious and meant to add clarity to what should be done.
NOTE: THIS IS A WORK IN PROGRESS, IT IS NOT FINISHED SO DON'T USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING.
Basically a service to walk through the entity you have

Code Block
    <simple-method method-name="walkthruyouentity" short-description="iterates thru you entity">
        <entity-condition entity-name="yourentity" list="nameofthelist"/>
        <iterate list="nameofthelist" entry="yourentity">
            <set-service-fields service-name="addtoofbizentity" map="parameters" to-map="inMap"/>
            <set field="inMap.fieldname" from-field="yourentity.fieldname"/>
<!-- note put in as may set fields as you need to pull you entities data -->
            <call-service service-name="addtoofbizentity" in-map-name="inMap"/>
            <clear-field field="inMap"/>
        </iterate>
    </simple-method>

Note these should be before the above one but for flow purposes of the document they are out of sequence.

Code Block
<simple-method method-name="addtoofbizentity" short-description="">
    <set-service-fields service-name="prepareyourentityData" map="parameters" to-map="inMap"/>
    <call-service service-name="prepareyourentityData" in-map-name="inMap">
        <result-to-field result-name="productDimension"/>
    </call-service>
    <clear-field field="inMap"/>
    <set-service-fields service-name="storeyourstoreserviceforthisdata" map="parameters" to-map="inMap"/>
    <set field="inMap.naturalKeyFields[]" value="productId"/>
    <set field="inMap.dimensionValue" from-field="productDimension"/>
    <call-service service-name="storeyourstoreserviceforthisdata" in-map-name="inMap"/>
</simple-method>

Finally a method to add any specific static data your entity does not have but the OFBiz entity does.
So speed up the process it checks to see if it has been added before. if not then add all the new data.
If not then just leaves the data necessary for an update.

Code Block
<simple-method method-name="prepareyourentityData" short-description="">
    <entity-one entity-name="ofbizentityyouwanttocheckifdataisavailible" value-field="nameofamap"/>
    <if-empty field="nameofamap">

    </if-empty>
    <check-errors/>
    <make-value value-field="productDimension" entity-name="ProductDimension"/>
    <set-nonpk-fields map="product" value-field="productDimension"/>

    <get-related-one value-field="product" relation-name="ProductType" to-value-field="productType"/>
    <set field="productDimension.productType" from-field="productType.description"/>

    <field-to-result field="productDimension"/>
</simple-method>

Coding a worker module to map to a service

If you don't have access to an external DB

It's easier to use Talend to extract data (you need to know at least the data structure of the DB) and send these data to OFBiz with xml-rpc

...