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

  1. 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:

    To use this sample file, copy it to the following directory (overwrite the file if it already exists):

    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;     }
        
    

  2. 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:

    To use this sample file, copy it to the following directory:

    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>     
    

  3. Create the new data bean

    In this step, you create a new data bean that loads the necessary data from the MySubTC access bean.

    1. Select File > Import... . In the Import wizard:

      1. Select Java EE > J2EE Utility Jar, and click Next.

      2. From the EAR Project drop-down, choose WC and click Next.

      3. For the External Jar Directory, click Browse... and navigate to the WC_EAR directory and click OK.

      4. Select Enablement-RelationshipManagementLogic.jar and click Finish. The project is created.

      5. Right-click the Enablement-RelationshipManagementLogic project and select Properties. The Project Properties dialog opens.

      6. Choose Targeted Runtimes from the left list.

      7. On the right panel, select WebSphere Application Server v7.0.

      8. Click OK to close the dialog.

    2. Right-click the Enablement-RelationshipManagementLogic project and select New > Class. The Java Class wizard opens.

    3. For the Package field, type com.ibm.commerce.tools.contract.beans.

    4. For the Name field, type MyTCDataBean.

    5. Click Finish. The class is created.

    6. 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;         }
          }
                  
      

  4. Register the new view

    Register the newly created view in the Struts configuration files.

    1. In the Enterprise Explorer view, expand CommerceAccelerator > WebContent > WEB-INF and double-click on the struts-config.xml file to open it.

    2. Create the action mappings.

      1. In the Action Mappings section, click Add. A new entry will be created with a default name highlighted so that it can be overwritten.

      2. Type "/ContractMyTCPanelView" and press enter.

      3. In the Type field, enter "com.ibm.commerce.struts.BaseAction".

      4. 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.

      5. Type "/MySubTCDeployCmd" and press enter.

      6. In the Type field, enter "com.ibm.commerce.struts.BaseAction".

      7. In the Parameter field, enter "com.mycompany.mycommands.MySubTCDeployCmd".

    3. Create the global forward.

      1. 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.

      2. Type "ContractMyTCPanelView" and press enter.

      3. In the Forward Attributes section in the Path field, enter "com.ibm.commerce.struts.BaseAction".

      4. In the Forward Mapping Extensions section click Add to create a new attribute.

        1. Set the Attribute column to "property".

        2. Set the Key/Property column to "resourceClassName".

        3. Set the Value column to "com.ibm.commerce.tools.command.ToolsForwardViewCommandImpl".

      5. In the Forward Mapping Extensions section in the Class Name field, enter "com.ibm.commerce.struts.ECActionForward".

    4. Save the work.

  5. Update the ContractRB_locale.properties file

    1. Navigate to the following file:

    2. 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 
                  
      

  6. Edit the ContractNotebook.xml file

    1. Navigate to the following file:

    2. 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" />             
      

  7. 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


+

Search Tips   |   Advanced Search