Access to add and change pages is restricted. See: https://cwiki.apache.org/confluence/display/OFBIZ/Wiki+access

 

If you have a legacy database that you want to import into OFBiz you can do this within OFBiz.

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

 

    <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.

 

<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.

 

<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

  • No labels