...
Info | ||
---|---|---|
| ||
This tutorial is intended to be used with the latest version branch 15.12 of Apache OFBiz. For any questions or concerns, please use OFBiz User Mailing List. Details about the mailing lists are available here. |
...
Download Apache OFBiz Framework
If you haven't already checkout Apache OFBiz Framework on your machine, let's do it. Anyone can checkout or browse the source code in the OFBiz public Subversion (SVN) repository. If you don't have Subversion, to install it you can go here for instructions.
To checkout the source code, simply use the following command (if you are using a GUI client, configure it appropriately):
- For release : $ svn co http://svn.apache.org/repos/asf/ofbiz/branches/release15.12 ofbiz.15.12
For more details refer Apache OFBiz Source Repository page.
Running Apache OFBiz
- Using the command line, build and start OFBiz (with demo data), use command:
$ ./ant load-demo start (For linux/mac it will work, for Windows $OFBIZ_HOME/ant.bat come bundled with OFBiz for Windows) |
Above command will load demo data(Sample Data to run apps) comes with OFBiz in Derby Database, it comes configured with OFBiz.
- Direct your browser to http://localhost:8080/webtools and login with username "admin" and password "ofbiz" and look around a bit.
That's it, Apache OFBiz is now running on your system!!
Create Your First Application (Hello World...)
Introduction to Components
An OFBiz component is a folder, containing a special xml file, named “ofbiz-component.xml”, that describes the resources to be loaded and required by the component.
OFBiz itself is a set of components.
- framework components:These are lower level components that provides the technical layer and tools to the application components; the features provided by these components are typically the ones provided by any other development framework (data layer, business logic layer, transaction handling, data source pools, etc…)
- application components:These are generic business components required for ERP applications that can be extended/customized (product, order, party, manufacturing, accounting etc…); application components have access to the services and tools provided by the framework components and to the services published by other application component.
- special purpose components:These components are similar as applications components but meant for special purpose applications like ecommerce , google base integration , eBay integration etc.
- hot-deploy components:This is an empty component available for custom development. Custom components can extend/override, the resources published by all the other components.
Create the component
It's very easy to setup a new custom component in OFBiz in hot-deploy directory. Using command line you just need run the following command and answer questions which are being asked for naming your custom component, component resource, webapp and base permission as shown below:
$ ./ant create-component Buildfile: /home/ofbiz_dev/Apache_OFBiz/ofbiz- 15.12 /build.xml create-component: [input] Component name: (e.g. mycomponent) [Mandatory] ofbizdemo [input] Component resource name: (e.g. MyComponent) [Mandatory] OfbizDemo [input] Webapp name: (e.g. mycomponent) [Mandatory] ofbizdemo [input] Base permission: (e.g. MYCOMPONENT) [Mandatory] OFBIZDEMO [echo] The following hot-deploy component will be created: [echo] Name: ofbizdemo [echo] Resource Name: OfbizDemo [echo] Webapp Name: ofbizdemo [echo] Base permission: OFBIZDEMO [echo] Folder: /home/ofbiz_dev/Apache_OFBiz/ofbiz- 15.12 /hot-deploy/ofbizdemo [echo] [input] Confirm: (Y, [N], y, n) y |
Running your first application
Before running our first component, let's say 'Hello to the World'
Simply open $OFBIZ_HOME/hot-deploy/ofbizdemo/widget/OfbizDemoScreens.xml file from ofbizdemo component(you just created)
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<
screen
name
=
"main"
>
<
section
>
<
actions
>
<
set
field
=
"headerItem"
value
=
"main"
/>
<!-- this highlights the selected menu-item with name "main" -->
</
actions
>
<
widgets
>
<
decorator-screen
name
=
"OfbizDemoCommonDecorator"
location
=
"${parameters.mainDecoratorLocation}"
>
<
decorator-section
name
=
"body"
>
<
label
text
=
"Hello World!! :)"
/>
</
decorator-section
>
</
decorator-screen
>
</
widgets
>
</
section
>
</
screen
>
</
screens
>
We have only added the <label text="Hello World!! :)" />
- Now you will need to restart OFBiz by reloading data($ ./ant load-demo start). It's required as you have created a new component with some security data for you component (Setup by default in your component data directory as OfbizDemoSecurityGroupDemoData.xml) and as you will restart it, ofbizdemo component will also be loaded.
- As OFBiz restarted direct your browser to your application here http://localhost:8080/ofbizdemo
- You will be asked to login. Login with user: admin password: ofbiz.
- As you login you will see ofbizdemo application up with the hello world message you have put in screen as shown in below given image.
That's it, congratulations your first component is setup and running.
Creating First Database Entity (Table)
Defining entity
To create custom Entities/Tables in database, you simply need to provide entity definition in $OFBIZ_HOME/hot-deploy/ofbizdemo/entitydef/entitymodel.xml file of your ofbizdemo application. This file structure is already setup when you used ant target to setup your component. You simply need to go in and provide entity definition as shown below. Here we are going to add two new entities for ofbizdemo application.
<? xml version = "1.0" encoding = "UTF-8" ?> < title >Entity of an Open For Business Project Component</ title > < description >None</ description > < version >1.0</ version > < entity entity-name = "OfbizDemoType" package-name = "org.ofbiz.ofbizdemo" title = "OfbizDemo Type Entity" > < field name = "ofbizDemoTypeId" type = "id-ne" >< description >primary sequenced ID</ description ></ field > < field name = "description" type = "description" ></ field > < prim-key field = "ofbizDemoTypeId" /> </ entity > < entity entity-name = "OfbizDemo" package-name = "org.ofbiz.ofbizdemo" title = "OfbizDemo Entity" > < field name = "ofbizDemoId" type = "id-ne" >< description >primary sequenced ID</ description ></ field > < field name = "ofbizDemoTypeId" type = "id-ne" ></ field > < field name = "firstName" type = "name" ></ field > < field name = "lastName" type = "name" ></ field > < field name = "comments" type = "comment" ></ field > < prim-key field = "ofbizDemoId" /> < relation type = "one" fk-name = "ODEM_OD_TYPE_ID" rel-entity-name = "OfbizDemoType" > < key-map field-name = "ofbizDemoTypeId" /> </ relation > </ entity > </ entitymodel > |
Now have a look at $OFBIZ_HOME/hot-deploy/ofbizdemo/ofbiz-component.xml file. You already have resource entry made in it for loading these entities from their definitions to database when component loads. As shown below:
<entity-resource type= "model" reader-name= "main" loader= "main" location= "entitydef/entitymodel.xml" /> |
To check simply re-start OFBiz (Ctrl+C followed by "./ant start") and direct your browser to Entity Data Maintenance Tool here: https://localhost:8443/webtools/control/entitymaint and search for entities OfbizDemoType and OfbizDemo. You will see it as shown in below given image.
Preparing data for entity
As you have setup your custom entities, now is the time to prepare some sample xmldata for it. You can do it in data xmlfiles already setup under data directory of your component as $OFBIZ_HOME/hot-deploy/ofbizdemo/data/OfbizDemoTypeData.xml and $OFBIZ_HOME/hot-deploy/ofbizdemo/data/OfbizDemoDemoData.xml. Set it up as shown below:
OfbizDemoTypeData.xml
<? xml version = "1.0" encoding = "UTF-8" ?> < entity-engine-xml > < OfbizDemoType ofbizDemoTypeId = "INTERNAL" description = "Internal Demo - Office" /> < OfbizDemoType ofbizDemoTypeId = "EXTERNAL" description = "External Demo - On Site" /> </ entity-engine-xml > |
OfbizDemoDemoData.xml
<? xml version = "1.0" encoding = "UTF-8" ?> < entity-engine-xml > < OfbizDemo ofbizDemoId = "SAMPLE_DEMO_1" ofbizDemoTypeId = "INTERNAL" firstName = "Sample First 1" lastName = "Sample Last 1" comments = "This is test comment for first record." /> < OfbizDemo ofbizDemoId = "SAMPLE_DEMO_2" ofbizDemoTypeId = "INTERNAL" firstName = "Sample First 2" lastName = "Sample last 2" comments = "This is test comment for second record." /> < OfbizDemo ofbizDemoId = "SAMPLE_DEMO_3" ofbizDemoTypeId = "EXTERNAL" firstName = "Sample First 3" lastName = "Sample last 3" comments = "This is test comment for third record." /> < OfbizDemo ofbizDemoId = "SAMPLE_DEMO_4" ofbizDemoTypeId = "EXTERNAL" firstName = "Sample First 4" lastName = "Sample last 4" comments = "This is test comment for fourth record." /> </ entity-engine-xml > |
Now again have a look at $OFBIZ_HOME/hot-deploy/ofbizdemo/ofbiz-component.xml file. You already have resource entry made in it for loading data prepared in these files as:
Entry to be done in ofbiz-component.xml
< entity-resource type = "data" reader-name = "seed" loader = "main" location = "data/OfbizDemoTypeData.xml" /> < entity-resource type = "data" reader-name = "demo" loader = "main" location = "data/OfbizDemoDemoData.xml" />
|
Loading data in entity
At this moment to load this sample data into entities/tables defined you can either run "ant load-demo" on console or can directly go here in webtools to load entity xml https://localhost:8443/webtools/control/EntityImport.
Simply put your xml data in " Complete XML document (root tag: entity-engine-xml):" text area and hit "Import Text", as shown in below given image
As you will hit Import Text, it will load data and will show the result as shown below:
After completing the data load process again visit Entity Data Maintenance(https://localhost:8443/webtools/control/entitymaint) and check your entities, you will find this data here that you just loaded.
That's it, you have successfully imported the data in the entities, super easy, right!
Whats next?
If you have followed all the steps and developed practice application from this tutorial then this will help you in understanding other implementation in OFBiz. These things are basic foundation of working in OFBiz. Now you know, how you can start development in OFBiz. Don't leave behind the extra links provided in this tutorial as they will help you a lot in understanding the things which are given there in detail.
Here is another good reading can be of help is available at FAQ Tips Tricks Cookbook HowTo
Now the next thing comes in the way is the business processes which are really needed to be understood well for understanding OOTB process flow in OFBiz and OOTB data model, so for this, books are available at : OFBiz Related Books. Understanding well the OFBiz OOTB available data model and business processes will help in building better business solutions top of it.
...