Tutorials > Program model > Create new business logic

< Previous


Load the completed tutorial code

You can load the completed tutorial code into the WebSphere Commerce development environment instead of completing each step in the tutorial.

The following types of assets must be loaded:

Before loading the completed tutorial code, have published a store based on the consumer direct sample store.

The completed tutorial code is provided in the newbusinesslogic_completedsource.zip file, contained within the WCSample.zip file.


Procedure

  1. Update the development database

    Before updating the development database, determine the store entity ID for the store to which you are deploying the customized logic. The following SQL statement can be used to determine this value:

    select STOREENT_ID from STOREENT where IDENTIFIER='ConsumerDirect_name'
    

    where ConsumerDirect_name is the name of the consumer direct store.

  2. Open WebSphere Commerce Developer and open the Java EE Perspective, Enterprise Explorer view.

  3. Update the struts-config-ext.xml file to register the view and controller command:

    1. Navigate to Stores > WebContent > WEB-INF.

    2. Right-click the struts-config-ext.xml file and select Open With > Struts Configuration File Editor.

    3. In the Action Mappings tab:

      1. In the Actions Mappings section, click Add. Delete the default path value /action1 and enter /MyNewView.

      2. In the Action Mapping attributes section, in the Type field, enter com.ibm.commerce.struts.BaseAction.

      The editor should look similar to the following screen capture:

    4. Enter values for the new view:

      1. In the Global Forwards tab, click Add. Delete the default name success and enter MyNewView.

      2. In the Forward Attributes section, in the Path field, enter /MyNewJSPTemplate.jsp.

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

      The editor should look like the following screen capture:

  4. Register the interface in the struts-config-ext.xml file:

    1. In the Action Mappings tab, in the Action Mappings section, click Add. Delete the default path value /action1 and enter /MyNewControllerCmd.

    2. In the Action Mapping attributes section, in the Type field, enter com.ibm.commerce.struts.BaseAction.

    3. In the Action Mapping attributes section, in the Parameter field, enter com.ibm.commerce.sample.commands.MyNewControllerCmd. The parameter field contains the interface name of the business logic to execute.

    4. Save the changes and close the file.

  5. Update the registry component named Struts Configuration:

    1. Open the Administration Console and select Site on the Administration Console Site/Store Selection page.

    2. From the Configuration menu, click Registry. A list of registry components for the site displays.

    3. Select the check box for the Struts Configuration registry component and click Update. The Registry window reloads listing the status for the selected components as "Updating."

    4. Click Refresh to reload the Registry window. When updating is complete, the status column reads "Updated."

  6. Register the new controller command in the CMDREG table:

    Update the development database with information about the new controller command created in this tutorial.

    Register MyNewControllerCmd in the CMDREG table:

    1. Open a browser and type the following URL: http://localhost/webapp/wcs/admin/servlet/db.jsp.

    2. Enter the following SQL statement:

    3. insert into CMDREG (STOREENT_ID, INTERFACENAME, DESCRIPTION,     CLASSNAME, TARGET)
       values (CD_storeent_ID,     'com.ibm.commerce.sample.commands.MyNewControllerCmd',         'This is a new controller command for the business logic tutorial.',          'com.ibm.commerce.sample.commands.MyNewControllerCmdImpl','Local');
      

    4. where CD_storeent_ID is the unique identifier for the store that is based on the consumer direct sample store.

    5. Click Submit Query to run the SQL statement.

  7. Create the XBONUS table

    In this step, you will create the XBONUS table in the database used by the WebSphere Commerce development environment.

    1. Ensure the test environment is started.

    2. Open a browser and type the following URL: http://localhost/webapp/wcs/admin/servlet/db.jsp.

    3. In the input box, enter the following SQL statement:

      create table XBONUS (MEMBERID BIGINT NOT NULL,           
      BONUSPOINT INTEGER NOT NULL, OPTCOUNTER SMALLINT NOT NULL,            
      constraint p_xbonus primary key (MEMBERID),           
      constraint f_xbonus foreign key (MEMBERID)
                references users (users_id) on delete cascade);
      


      create table XBONUS (MEMBERID NUMBER NOT NULL, 
              BONUSPOINT INTEGER NOT NULL, OPTCOUNTER SMALLINT NOT NULL,            constraint p_xbonus primary key (MEMBERID), 
              constraint f_xbonus foreign key (MEMBERID) 
              references users (users_id) on delete cascade);
      

    4. Click Submit Query. You should see a message that the statement resulted in 0 updates.

  8. Load access control policies on the WebSphere Commerce development environment

    In this step, you load the access control policies for the new resources onto the WebSphere Commerce development environment.

    Update the access control policies to reflect the values specific to the WebSphere Commerce development environment:

    1. Determine the member ID value for the consumer direct store:

      1. Open the following URL: http://localhost/webapp/wcs/admin/servlet/db.jsp

      2. Run the following query:

         select member_id from storeent where storeent_id=CD_storeent_ID
        

        where CD_storeent_ID is the store entity ID for the consumer direct store. For example, you can enter:

        select member_id from storeent where storeent_id=10001
        

        Make note of the member ID value: ________________________

    2. Extract the following four files from newbusinesslogic_completedsource.zip to WC_EAR\xml\policies\xml

      • MyNewViewACPolicy.xml

      • MyNewControllerCmdACPolicy.xml

      • SampleACPolicy_template.xml

      • SampleACPolicy_template_en_US.xml

    3. Use a text editor, open the SampleACPolicy_template.xml file and replace ConsumerDirectMemberId with the member ID value for the consumer direct store. Save the modified file as SampleACPolicy.xml.

    4. Use a text editor, open the SampleACPolicy_template_en_US.xml file and replace ConsumerDirectMemberId with the member ID value for the consumer direct store. Save the modified file as SampleACPolicy_en_US.xml.

    Load the access control policies:

    1. At a command prompt, navigate to the following directory: WCDE_INSTALL/\bin

    2. Issue the acpload command, which has the following form:

      acpload targetDB dbuser dbpassword inputXMLFile schema_name
      

      Where:

      targetDB

      is the name of the development database.

      dbuser

      is the name of the database user.

      dbpassword

      is the password for the database user.

      inputXMLFile

      is the XML file containing the access control policy specification. In this case, specify MyNewViewACPolicy.xml.

      schema_name

      is

      • the database user who created the database and owns the schema

      • the user who owns the tables

      The following is an example of the command, with variables specified:

      acpload Demo_Dev db2admin db2admin MyNewViewACPolicy.xml DB2ADMIN
      

    3. Load the access control policy description in the SampleACPolicy_en_US.xml file by running the acpnlsload command:

      acpnlsload db_name db_user db_password inputXMLFile schema_name
      

      For example, you can issue the following command:

      acpnlsload Demo_dev user password SampleACPolicy_en_US.xml DBUSER
      

    4. Stop the WebSphere Commerce Test Server then issue the following acpload commands:

      1. acpload MyNewViewACPolicy.xml

      2. acpload MyNewControllerCmdACPolicy.xml

      3. acpload SampleACPolicy.xml

    5. Issue the following acpnlsload command: acpnlsload SampleACPolicy_en_US.xml

    6. Check for errors in the log files. Note that errors might not appear on the command line.

      1. Check the acpnlsload.log and messages.txt files...

        • WCDE_userdir/instances/acpnlsload.log

        • WCDE_userdir/instances/instance/logs/messages.txt

      2. Check the acpnlsload.log and messages.txt files...

      3. Any error files generated in WC_eardi../images/locale/screensnap/xml/policies/xml directory.

  9. Update store assets in the WebSphere Commerce development environment

    To update the store assets:

    1. In the , navigate to Stores > WebContent > ConsumerDirect_name.

    2. From the ConsumerDirect_name folder's pop-up menu, select Import

    3. SelectGeneral > Archive File and click Next.

    4. Enter or browse to the file newbusinesslogic_completedsource.zip in the From archive file list.

    5. Click Deselect All.

    6. Select the MyNewJSPTemplate.jsp file and click Finish.

    7. Navigate to Stores > Java Resources > src > ConsumerDirect_name

    8. From the ConsumerDirect_name folder's pop-up menu, select Import.

    9. Select General > Archive File and click Next.

    10. Select or browse to the file newbusinesslogic_completedsource.zip in the From archive file list.

    11. Click Deselect All.

    12. Select the TutorialNLS_en_US.properties and TutorialNLS.properties files.

    13. Click Finish.

    Your Stores project now contains the following three new files:

    • Web Content\ConsumerDirect_name\MyNewJSPTemplate.jsp

    • Java Resources\src\ConsumerDirect_name\TutorialNLS_en_US.properties

    • Java Resources\src\ConsumerDirect_name\TutorialNLS.properties

  10. Import the EJB JAR file into the workspace

    Import the JAR file that contains the new Bonus EJB bean created in this tutorial.

    To import the Bonus EJB bean:

    1. In the filesystem, navigate to newbusinesslogic_completedsource.zip and extract the WebSphereCommerceServerExtensionsData.jar file to a temporary directory.

    2. In the Enterprise Explorer view, navigate to WebSphereCommerceServerExtensionsData project.

    3. From the project's pop-up menu, select Import > Import, select General > Archive File and click Next.

    4. In the From archive file field, enter or browse to the location of WebSphereCommerceServerExtensionsData.jar.

    5. In the Into folder field, select WebSphereCommerceServerExtensionsData/ejbModule.

    6. Select Overwrite existing resources without warning.

    7. Click Finish. An error may appear in the tasks view, but will be resolved in a later step when you generate deployed code.

    8. Delete the default database mapping and Map the XBONUS table to the entity bean

    9. Set the optimistic predicate value of the optcounter field:

      1. In the Mapping Editor, the Map.mapxmi file should still be open. If it is not open, select and open it from the following location: WebSphereCommerceServerExtensionsData > ejbModule > META-INF > backends > DB2UDBNT_V95_1

      2. In the Overview section, in the Enterprise Beans pane, select optcounter : short.

      3. Select the Properties view, and select true from the OptimisticPredicate list. Your screen should resemble the following screen capture:

    10. Check the value of the JNDI name in the deployment descriptor:

      1. Expand EJB Projects > WebSphereCommerceServerExtensionsData > Deployment Descriptor : > WebSphereCommerceServerExtensionsData > Entity Beans > Bonus.

      2. Double-click the Bonus bean to open its deployment descriptor.

      3. In the EJB Deployment Descriptor Editor, in the Overview tab, scroll down to the JNDI - CMP Connection Factory Binding section and in the JNDI name field enter the value that matches the database type:

        • jdbc/WebSphere Commerce Cloudscape DataSource demo

        • jdbc/WebSphere Commerce DB2 DataSource demo

        • jdbc/WebSphere Commerce iSeries DataSource demo

        • jdbc/WebSphere Commerce Oracle DataSource demo

    11. Generate deployed code:

      1. Select the WebSphereCommerceServerExtensionsData project.

      2. From the project's pop-up menu, select Java EE > Prepare for Deployment.

  11. Import the command and data bean

    Import the command and data bean that are created in this tutorial:

    1. Extract WebSphereCommerceServerExtensionsLogic.jar from the newbusinesslogic_completedsource.zip file.

    2. Navigate to WebSphereCommerceServerExtensionsLogic > src directory.

    3. From the src directory's pop-up menu, select Import. Select General > Archive File and click Next.

    4. In the From archive file field, enter or browse to the location of WebSphereCommerceServerExtensionsLogic.jar.

    5. Click Deselect All and select only the com folder.

    6. The Into folder field should contain a value similar to the following path: WebSphereCommerceServerExtensionsLogic/src

    7. Select Overwrite existing resources without warning.

    8. Click Finish.

    9. The resulting project should look similar to the following image:

  12. Test the tutorial code

    In this step, you verify that the code was imported successfully.

    1. Restart the WebSphere Commerce Test Server.

    2. Open a Web browser and enter the URL to launch the store.

    3. Register a new user:

      1. Click Register or Log In.

      2. Click Register again to create a new customer.

      3. In the registration form, enter appropriate values into all of the mandatory fields. For example, in the login id field, enter my_login_Id. Make note of the value for the login ID address: _________________________.

      4. Once the values have been entered, click Submit.

    4. Once the login has completed, enter the following URL in the same browser:

      http://hostname/webapp/wcs/stores/servlet/MyNewControllerCmd?
         input1=user_login&input2=1000
      

      where hostname is the host name and user_login is the login id for the user that you created in step 2. A page displays that contains all of the previous output parameters as well as a new form that allows you to update the balance of bonus points for the user.

    5. Now, enter the user's e-mail address into the Logon ID field and in the Bonus Point field, enter 500. Click Submit. You are presented with a page similar to the following one that shows that the balance of bonus points is updated.

< Previous


+

Search Tips   |   Advanced Search