Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: add link to more information on xml entity data file

...

  1. Create a new subdirectory by name entitydef in hot-deploy/practice/.
  2. Create new file by name  entitymodel.xml. This file will contain the defintions of entities which you want to define.
  3. For loading the defintion you need to do an entry in your ofbiz-component.xml file like:

    Code Block
    languagexml
    <entity-resource type="model" reader-name="main" loader="main" location="entitydef/entitymodel.xml"/>
    

    That implies that when ever you do a change you need to restart the server to have those changes in effect.
    At this place an important reading is at http://ofbiz.apache.org/docs/entity.html.
    You will rarely find this way to define new entity because you are already having entities there in OFBiz already defined which will be useful for the conduction of your business process. Though you may feel at some place to add more fields to an existing entity so how can you do that? The next  step will show you the way how you can extend an entity for your customized needs.
    Earlier we used to have one more file in same directory by name entitygroup.xml which not needed any more because code is checked in to the trunk for this.

...

  1. For extending an entity you can do in this manner in the entitydef/entitymodel.xml file of your custom application.

    Code Block
    languagexml
    <extend-entity entity-name="">
        <field name="" type=""/>
    </extend-entity>
    

    As an example of this you can refer entitymodel.xml file from party component.
    This is the simplest form it can be more complex. This will add up one more field to the entity you already have. Now it depends which field you want for your custom needs. Here you can also defined relation of this field with other entities you want. But before doing this you should search extesively may be you will be adding a field for a purpose and there is already a field which will serve the purpose, so be concisous about this. Also go for a extensive study of data model then do this.
    For entity engine configuration dont forget to read : Entity Engine Configuration Guide

...

  1. Create new folder in practice by name "data" and create a file in it by name PracticeData.xml.
  2. Now we are going to create the data for a user for this we have to prepare it in a specific order for a party like :

    Code Block
    languagexml
    <?xml version="1.0" encoding="UTF-8"?>
    <entity-engine-xml>
        <Party partyId="DemoUser" partyTypeId="PERSON"/>
        <Person partyId="DemoUser" firstName="Practice" lastName="Person"/>
        <PartyRole partyId="DemoUser" roleTypeId="VISITOR"/>
        <ContactMech contactMechId="5000" contactMechTypeId="EMAIL_ADDRESS" infoString="practice.person@gmail.com"/>
        <PartyContactMech partyId="DemoUser" contactMechId="5000" fromDate="2001-05-13 00:00:00.000" allowSolicitation="Y"/>
        <PartyContactMechPurpose partyId="DemoUser" contactMechId="5000" contactMechPurposeTypeId="PRIMARY_EMAIL" fromDate="2001-05-13 00:00:00.000"/>
    </entity-engine-xml>
    

    The purpose is to create a record for a party who is a person with a role of VISITOR and creating an email address which is a primary email address for that party.
    You can see Handling of External data#Preparexmlfile for more information on xml structure

  3. Now also add website data here which is as follows:

    Code Block
    languagexml
    <WebSite webSiteId="PRACTICE" siteName="Practice Application" visualThemeSetId="BACKOFFICE"/>
  4. This data is used for theme setup of a specific application and logged in user can change his theme for the back office application.
  5. Now we have to an entry in ofbiz-component.xml file :

    Code Block
    languagexml
    <entity-resource type="data" reader-name="demo" loader="main" location="data/PracticeData.xml"/>
    

    After doing this entry when you will run the command ant run-install to load demo data then the data from this file will be loaded as demo data and once you start the server you can see this record added for person by going to Person Form in practice application or you can prefer to go to https://localhost:8443/webtools/control/entitymaint and find each entity and check the records have gone in the database or not.

...