In one of our previous blog post (JUnit Tests in OFBiz – Data Setup and Execution) we outlined data setup best practices for manual and automated testing. Today, we’ll explore additional data categories and discuss how to distinguish them in the codebase, and also how to distinguish them while loading them into the database from XML.
When implementing an application on top of Apache OFBiz, the ability to effectively use the OFBiz Data Reader feature offers important advantages:
- Data categorization manages data as it grows, streamlining the process for developers.
- Deployment challenges related to data are reduced.
From a broader perspective, application data may fall into these categories:
- Data required for core functioning and for running the system
- Data required for the first-time setup
- Data specific to business i.e. required in production
- Data required for testing, demo or simulation.
Now let’s take a look at how this data categorization works in OFBiz.
Apache OFBiz data setup default
Let’s get started with the basic data setup for Apache OFBiz. To load data in a fresh copy you can run the following command:
$ ./ant load-demo
This command will load all the data meant for generic OFBiz development, testing, demonstration, etc.
For loading any specific type of data you can use the following command data-reader:
$ ./ant load-readers -Ddata-readers=seed,seed-initial,demo
Here you can specify the name of the reader of the data you want to load. Below is the description of each of the data-readers:
seed: This reader is used for loading the basic application data/minimum data that is required to run any application. It is created and maintained along with the code and should be loaded into the database when the code is updated. It should not be changed or removed in the application database without first having done so in the seed data XML files (for example, data like RoleType data, “CUSTOMER, BILL_TO_CUSTOME, or StatusItem data such as “ORDER_APPROVED”, “ORDER_CANCELLED” and Enumeration data). So whenever you need to remove or update the seed data from the database, you should update data in XML file as well.
seed-initial: This reader is used for data that is only required for the first-time system setup e.g. data for SequenceValueItem and/or JobSandbox entities. It is to be maintained along with sources like other seed data. So you need to be sure to load this type of data in production systems only for the first time.
Here is an example of this type of data. By preparing the data in JobSandbox entity you can schedule services that are loaded when you are deploying the system for the first time for execution. So if you load seed-initial data again in further deployments, the system may function less effectively due to multiple records for the same job. This can happen because when scheduled services are loaded again, the system may start running, and it may perform jobs that you don’t want it to perform again. Here is an example from accounting/ofbiz-component.xml. You can find additional examples of this type of data file in OOTB OFBiz.
<entity-resource type="data" reader-name="seed-initial" loader="main" location="data/AccountingScheduledServiceData.xml"/>
demo: This reader is used for data which is used for setting up development, testing, simulation or a demonstration environment.
Data preparation and setup for various instances
We have now examined the proper procedure for loading data for Apache OFBiz to run. However, there can be certain other scenarios and data categories that can be essential in the software development life cycle. Here are some examples of various data sets which play an important role (such as data for Staging, QA, and Testing, Demo, and Production instance).
If you are creating your own component, you can use the above-mentioned reader procedures for data preparation for custom components. But if there is a case in which you need to manage separate data for a testing instance and a production instance, OR if you want to load only custom data and not the data that comes with OOTB OFBiz, you can follow the practices outlined below.
Setting up custom data readers
OFBiz has the capability for real-time data reader identification and for loading data for the particular newly defined reader for data file entry in ofbiz-component.xml. Creation of the custom data reader is one of the best ways to use the data categorization efficiently in OFBiz. Please click here to get more details on this feature committed by HotWax Media VP of Technology, Jacopo Cappellato.
With this feature, you can easily define a new reader for data categorization in the ofbiz-component.xml file for data that is required to be loaded only in the production system. Here are some examples:
<entity-resource type="data" reader-name="ext-prod" loader="main" location="data/CustomSeedData.xml"/>
and load data with the command:
$ ./ant load-readers -Ddata-readers=ext-prod
without the need to add/define the reader “ext-prod” into the entityengine.xml file.
Data for custom applications
For developing and deploying custom applications you might choose to skip OFBiz “demo” data. In this case, you only need to load basic data i.e. seed, or seed-initial with custom data defined for the application.
With seed, or seed-initial data you can load custom data required for a hot-deploy custom component with the readers detailed below:
ext: This reader is used for the external data, which is a custom component, specific, general data that is to be used in the production system.
ext-seed-initial: This reader can be used for custom seed initial(first-time data) for hot-deploy component. It is to be maintained along with source like other seed data, but only to be loaded initially and not updated when the system is updated (except manually reviewing each line).
ext-seed: This reader can be used for seed data for custom application, though seed is a good fit if you don’t want to define a new reader. It helps when we want to load only our custom seed data each time we reload. It should be created and maintained along with the code and should be loaded into the database when the code is updated. It should not be changed or removed in the database without first having done so in the seed data XML files, to avoid data conflicts.
ext-test: with this reader the data needed as input to unit tests has to be modeled under the OFBiz “ext-test” data-reader.
Data for production instance
The data on real/production instance is the live set and is very crucial. It includes the business data, marketing data and the most important application data. Here is how you can define and load the production data:
ext-prod: This reader can be used for data that is specific to the production instance. In most cases it will be the configuration data (e.g. data for Payment Gateway configuration which differ from test/staging/local instance for urls to be used in a different environment). Having different readers for this type of configuration data automates the process for deployment so that you don’t need to manage it manually.
Data for staging instance
The staging instance differs from the production instance. For example, some configurations are different in the staging environment (e.g. Payment Gateway configuration).
ext-stag: This reader can be used for configuration data that is required for set-up only, and for testing purposes.
Using these practices you can set up data like this:
<entity-resource type="data" reader-name="ext-stag" loader="main" location="data/CustomComponentStagingConfigData.xml"/> <entity-resource type="data" reader-name="ext-prod" loader="main" location="data/CustomComponentProductionConfigData.xml"/>
Data for demo and testing
As mentioned in our blog post JUnit Tests in OFBiz – Data Setup and Execution it is a good practice to combine your demonstration data, manual testing data and automated unit testing data, and to use it cohesively. With OOTB OFBiz, this type of data should be modeled under the “demo” data-reader, while for custom OFBiz-based development this data can be modeled under the “ext-test” data-reader.
In conclusion, it’s all about using data in a smart and efficient manner. For additional details, please refer to the Apache OFBiz Technical Production Setup Guide.
Put the power of Apache OFBiz to work for your business
HotWax Systems is the leading global innovator of flexible enterprise commerce solutions powered by Apache OFBiz. Contact us today to learn more about how to put the power of OFBiz to work for your business.