Example: Inserting and replacing price rule
Use the Data Load utility to load price rule data into the PRICERULE table. The Data Load utility provides two modes for loading price rule: insert and replace. Use the insert modes for a new price rule. Use the replace mode to update an existing price rule.
Do not use the insert mode if a price rule with the same price rule name, or if a uniqueId exists in database. In insert mode, if a price rule with the same price rule name or uniqueId exists in database, the record is not inserted. In the replace mode, if the price rule name or the uniqueId in the load file does not exist in database, the price rule is inserted.
This example uses a CSV file to demonstrate how to insert, replace, or delete your data. You can also create and use an XML formatted file to insert, replace, or delete your data. If you choose to create and use an XML formatted file, ensure that your XML elements use the same names as are used for CSV column names.
Prerequisites
Before you run this example, ensure that the following prerequisites are fulfilled:
- Make sure that the store exists.
CSV file with sample price rule data
In this example, the data source is a CSV file named PriceRule.csv. The file contains sample price rule data. Each column is delimited by a comma.Name | Description | State | Dependency | Format |
---|---|---|---|---|
PriceRule001 | This price rule is just for UT | 1 | TRUE | 1 |
PriceRule002 | This price rule is just for UT | 0 | FALSE | 0 |
- firstLineIsHeader
- true
- Indicates that the first line in the CSV file is treated as column name data, and it is not inserted into the database.
- false
- Indicates that the first line in the CSV file is data to be read and inserted into the database.
CSV column and XML element definitions
The
column order is defined in the price rule data load configuration
file. See the number
attribute in the <_config:Data>
element.
- Name
- (Required, String) The name of the price rule, the combination of name and storeIdentifier in the business context must be unique.
- Description
- (String) The description of the price rule.
- State
- (Required, Integer) The current state of the price rule. Valid values include: 0 = Draft, 1 = Ready, 2=Suspended, 3=Closed.
- Dependency
- (Required, Boolean) The Boolean flag to indicate whether the price rule is dependent or not.
- Format
- (Required, Integer) The type of the price rule. Valid values include: 0 = internal, 1 = external. The default value is 0.
Other optional fields not included in the example are:
- UniqueID
- (String) The reference number of the price rule. If this is provided, the PRICERULE.PRICERULE_ID is populated with the provided value. Or, the PRICERULE.PRICERULE_ID is one generated unique number.
- CreatedTime
- (Timestamp) The created time of the price rule.
- LastUpdateTime
- (Timestamp) The last update time of the price rule.
- Delete
- (String) Indicates whether to delete this record. This field takes
effect when dataLoadMode is "replace". If the value of this field
equals to deleteValue, the corresponding record is deleted. The default
deleteValue is 1. The deleteValue can be configured under
<DataMapping>
element in BusinessObjectConfigFile. - Field 1
- (String) Extension that is filed for String value, the maximum length is 254.
- Field 2
- (String) Extension that is filed for String value, the maximum length is 254.
- Field 3
- (String) Extension that is filed for String value, the maximum length is 254.
Business context data
The following code snippet from the wc-dataload-env.xml configuration file provides the business context data necessary for loading the price rule data:<_config:BusinessContext
storeIdentifier="AuroraESite"
catalogIdentifier="Extended Sites Catalog Asset Store"
languageId="-1"
currency="USD">
</_config:BusinessContext>
- storeIdentifier
- String: The identifier of the store to which this item belongs, such as AuroraESite. It is used if CSV file does not provide this information. The StoreIdentifier is used to retrieve the storeID.
- catalogIdentifier
- String: The catalog identifier. This parameter is used when the catalog identifier is not provided in the CSV file. If the catalogIdentifier is provided in the CSV file, it is used.
Mapping data
The following snippet from the sample configuration file demonstrates how to map each column of data in the source CSV file to a value.
<_config:DataReader
className="com.ibm.commerce.foundation.dataload.datareader.CSVReader"firstLineIsHeader="true">
<_config:Data>
<_config:column number="1" name="UniqueID" />
<_config:column number="2" name="Name" />
<_config:column number="3" name="Description" />
<_config:column number="4" name="State" />
<_config:column number="5" name="Dependent" />
<_config:column number="6" name="Format" />
<_config:column number="7" name="Version" />
<_config:column number="8" name="Field1" />
<_config:column number="9" name="Field2" />
<_config:column number="10" name="Field3" />
<_config:column number="11" name="CreatedTime"/>
<_config:column number="12" name="LastUpdateTime" />
<_config:column number="13" name="Delete" />
</_config:Data>
</_config:DataReader>
The following snippet from the sample configuration file demonstrates how to map each column of the data in the CSV file to a business object logical schema path. The attribute 'value' represents the name of a column of the CSV file, which is defined in the preceding configuration snippet. Each column in the CSV file must have a mapping to the logical schema path. If the optional fields are present in the CSV file, the mapping for them must be added.
<_config:DataMapping>
<_config:mapping xpath="PriceRuleIdentifier/UniqueID" value="UniqueID" />
<_config:mapping xpath="PriceRuleIdentifier/ExternalIdentifier/Name" value="Name" />
<_config:mapping xpath="Description" value="Description" />
<_config:mapping xpath="State" value="State" />
<_config:mapping xpath="Dependent" value="Dependent" />
<_config:mapping xpath="Format" value="Format" />
<_config:mapping xpath="Version" value="Version" />
<_config:mapping xpath="CreatedTime" value="CreatedTime"/>
<_config:mapping xpath="LastUpdateTime" value="LastUpdateTime"/>
<_config:mapping xpath="UserData/UserDataField[0]/FIELD1" value="Field1" />
<_config:mapping xpath="UserData/UserDataField[0]/FIELD2" value="Field2" />
<_config:mapping xpath="UserData/UserDataField[0]/FIELD3" value="Field3" />
<_config:mapping xpath="" value="Delete" deleteValue="1" />
</_config:DataMapping>
Business object mediator
The mediator class
name is com.ibm.commerce.price.dataload.mediator.PriceRuleMediator
.
The corresponding logical schema is defined in PriceRule.xsd
.