Tutorials > Contracts > Extend the existing contract model
Update WebSphere Commerce Accelerator to use the new term and condition
Once you have created new terms and conditions, you can update WebSphere Commerce Accelerator so that it can be used to create new contracts that include those new terms and conditions.
Procedure
- Create the new JavaScript file
The first step to updating the WebSphere Commerce Accelerator to use new terms and conditions is to create a new JavaScript file for them. For reference, you can refer to the following sample file:
- WC_INSTAL../images/locale/screensnap/samples/contract/Extensions.js
- WCDE_INSTALL/\samples\contract\Extensions.js
To use this sample file, copy it to the following directory (overwrite the file if it already exists):
- WC_eardi../images/locale/screensnap/CommerceAccelerator.war/javascript/tools/contract
- workspace_dir\CommerceAccelerator\Web Content\javascript\tools\contract
In the JavaScript file, create a JavaScript object to store the data for the new term and condition. This is shown in the following code snip, which already exists in the sample file:
function ContractMyTCModel() { this.tcReferenceNumber = ""; this.policyReferenceNumber = ""; this.attr1 = ""; this.attr2 = ""; this.policyList = new Array(); this.selectedPolicyIndex = "0"; }
You should also create a new JavaScript object to submit the new term and condition. This must be done in a manner consistent with the extensions that you made to the XSD files. This is shown in the following code snip, which already exists in the sample file:
function submitMyTC(contract) { var tcModel = get("ContractMyTCModel"); if (tcModel != null) { var myTC = new Object(); myTC.attr1 = tcModel.attr1; myTC.attr2 = tcModel.attr2; myTC.ProductSetPolicyRef = new Object(); myTC.ProductSetPolicyRef.policyName = tcModel.policyList[ tcModel.selectedPolicyIndex].policyName; myTC.ProductSetPolicyRef.StoreRef = new Object(); myTC.ProductSetPolicyRef.StoreRef.name = tcModel.policyList[ tcModel.selectedPolicyIndex].storeIdentity; myTC.ProductSetPolicyRef.StoreRef.Owner = new Object(); myTC.ProductSetPolicyRef.StoreRef.Owner = tcModel.policyList[ tcModel.selectedPolicyIndex].member; if (tcModel.tcReferenceNumber != "") { // Change the term and condition myTC.action = "update"; myTC.referenceNumber = tcModel.tcReferenceNumber; } else { // Create a new term and condition myTC.action = "new"; } contract.MySubTC = myTC; } return true; }
- Create the new JSP template
The next step is to create a new JSP template that includes an HTML section in which the user can enter information required by the new term and condition. For reference, you can refer to the following sample file:
- WC_INSTAL../images/locale/screensnap/samples/contract/ContractMyTC.jsp
- WC_INSTALL\samples\contract\ContractMyTC.jsp
- WCDE_INSTALL/\samples\contract\ContractMyTC.jsp
To use this sample file, copy it to the following directory:
- WC_eardi../images/locale/screensnap/CommerceAccelerator.war/tools/contract
- WC_EAR\CommerceAccelerator.war\tools\contract
- workspace_dir\CommerceAccelerator\Web Content\tools\contract
The following code snip from the sample JSP file shows the HTML section that can be used for MyTC.
<!-- /////////// // HTML SECTION /////////// --> <BODY onLoad="onLoad()" class="content"> <H1> <%= contractsRB.get("MyTCHeading") %> </H1> <FORM NAME="MyTCForm"> <label for="MyTCAttr1Label"><%= contractsRB.get("MyTCAttr1Label") %></label> <BR> <INPUT id="MyTCAttr1Label" type=text name=Attr1 value="" size=10 maxlength=10> <BR> <label for="MyTCAttr2Label"><%= contractsRB.get("MyTCAttr2Label") %></label> <BR> <INPUT id="MyTCAttr2Label" type=text name=Attr2 value="" size=10 maxlength=10> <BR> <label for="MyTCPolicyLabel"><%= contractsRB.get("MyTCPolicyLabel") %></label> <BR> <SELECT id="MyTCPolicyLabel" NAME="PolicyList" SIZE="1"> </SELECT> </FORM>
- Create the new data bean
In this step, you create a new data bean that loads the necessary data from the MySubTC access bean.
- Select File > Import... . In the Import wizard:
- Select Java EE > J2EE Utility Jar, and click Next.
- From the EAR Project drop-down, choose WC and click Next.
- For the External Jar Directory, click Browse... and navigate to the WC_EAR directory and click OK.
- Select Enablement-RelationshipManagementLogic.jar and click Finish. The project is created.
- Right-click the Enablement-RelationshipManagementLogic project and select Properties. The Project Properties dialog opens.
- Choose Targeted Runtimes from the left list.
- On the right panel, select WebSphere Application Server v7.0.
- Click OK to close the dialog.
- Right-click the Enablement-RelationshipManagementLogic project and select New > Class. The Java Class wizard opens.
- For the Package field, type com.ibm.commerce.tools.contract.beans.
- For the Name field, type MyTCDataBean.
- Click Finish. The class is created.
- Replace the class implementation with the following:
public class MyTCDataBean extends com.ibm.commerce.contract.objects.MySubTCAccessBean implements com.ibm.commerce.beans.SmartDataBean, com.ibm.commerce.security.Delegator { private Long contractId; private Integer languageId; private boolean hasMyTC = false; private com.ibm.commerce.command.CommandContext commandContext; private com.ibm.commerce.datatype.TypedProperty requestProperties; /** * MyTCDataBean default constructor. */ public MyTCDataBean() { super(); } /** * MyTCDataBean constructor. */ public MyTCDataBean(Long newContractId, Integer newLanguageId) { contractId = newContractId; languageId = newLanguageId; } public boolean getHasMyTC() { return hasMyTC; } /** * Populates the attributes from TermConditionAccessBean. */ public void populate() throws Exception { java.util.Enumeration myTCEnum = new com.ibm.commerce.contract.objects.TermConditionAccessBean().findByTradingAndTCSubType( contractId, "MySubTC"); if (myTCEnum != null) { if (myTCEnum.hasMoreElements()) { // assume a contract only has one MyTC for this example setEJBRef(((com.ibm.commerce.contract.objects.TermConditionAccessBean) myTCEnum.nextElement()).getEJBRef()); refreshCopyHelper(); hasMyTC = true; } } } public com.ibm.commerce.command.CommandContext getCommandContext() { return commandContext; } public void setCommandContext(com.ibm.commerce.command.CommandContext newCommandContext) { commandContext = newCommandContext; } public com.ibm.commerce.datatype.TypedProperty getRequestProperties() { return requestProperties; } public void setRequestProperties(com.ibm.commerce.datatype.TypedProperty newRequestProperties) throws Exception { requestProperties = newRequestProperties; } public com.ibm.commerce.security.Protectable getDelegate() throws Exception { return null; } }
- Register the new view
Register the newly created view in the Struts configuration files.
- In the Enterprise Explorer view, expand CommerceAccelerator > WebContent > WEB-INF and double-click on the struts-config.xml file to open it.
- Create the action mappings.
- In the Action Mappings section, click Add. A new entry will be created with a default name highlighted so that it can be overwritten.
- Type "/ContractMyTCPanelView" and press enter.
- In the Type field, enter "com.ibm.commerce.struts.BaseAction".
- Again, in the Action Mappings section, click Add. A new entry will be created with a default name highlighted so that it can be overwritten.
- Type "/MySubTCDeployCmd" and press enter.
- In the Type field, enter "com.ibm.commerce.struts.BaseAction".
- In the Parameter field, enter "com.mycompany.mycommands.MySubTCDeployCmd".
- Create the global forward.
- Click the Global Forwards tab at the bottom and create a new forward by clicking Add. A new entry will be created with a default name highlighted so that it can be overwritten.
- Type "ContractMyTCPanelView" and press enter.
- In the Forward Attributes section in the Path field, enter "com.ibm.commerce.struts.BaseAction".
- In the Forward Mapping Extensions section click Add to create a new attribute.
- Set the Attribute column to "property".
- Set the Key/Property column to "resourceClassName".
- Set the Value column to "com.ibm.commerce.tools.command.ToolsForwardViewCommandImpl".
- In the Forward Mapping Extensions section in the Class Name field, enter "com.ibm.commerce.struts.ECActionForward".
- Save the work.
- Update the ContractRB_locale.properties file
- Navigate to the following file:
- WC_eardi../images/locale/screensnap/properties/com/ibm/commerce/tools/contract/properties/ContractRB_locale.properties
- WC_EAR\properties\com\ibm\commerce\tools\contract\properties\ContractRB_locale.properties
- workspace_dir\WC\properties\com\ibm\commerce\tools\contract\properties\ContractRB_locale.properties
- Add the following information to the file:
MyTCHeading=My TC attr1Empty=Attribute One must be entered. attr2Empty=Attribute Two must be entered. attr1TooLong=Attribute One is too long. attr2TooLong=Attribute Two is too long. MyTCAttr1Label=Attribute One (required) MyTCAttr2Label=Attribute Two (required) MyTCPolicyLabel=Policy
- Edit the ContractNotebook.xml file
- Navigate to the following file:
- WC_eardi../images/locale/screensnap/xml/tools/contract/ContractNotebook.xml
- WC_EAR\xml\tools\contract\ContractNotebook.xml
- workspace_dir\WC\xml\tools\contract\ContractNotebook.xml
- Add the following after the last <panel> tag and before the first <jsFile>.
<panel name="MyTCHeading" url="ContractMyTCPanelView" parameters="contractId,accountId" helpKey="MC.contract.MyTCPanel.Help" />
- Import the new contract using the new term and condition
As an alternative to updating the WebSphere Commerce tools to use a new term and condition, you can use the contract import command to import a new contract that includes this new term and condition. After importing, the relevant section in the Contract.xml file appears as follows:
<MySubTC attr1="abc" attr2="123"> <ProductSetPolicyRef policyName="Product Set 1"> <StoreRef name="StoreGroup1"> <Owner> <OrganizationRef distinguishName="o=Root Organization"/> </Owner> </StoreRef> </ProductSetPolicyRef> </MySubTC>
Previous topic: Create an access bean and deploying
Next topic: Invoke the new business policy