Next >Tutorial: Creating a BOD service module
In this tutorial, you develop a project service module. The services provided by the module are Get and Change. As a part of creating the service module, you design the logical model (a noun) and physical model (a database schema) based on your business requirement.The Project BOD service module stores and retrieves data, and provides logic to perform operations on a business object or logical model, referred to as a noun. The noun that we define in this tutorial is called the Project noun.
This tutorial provides one example, however we can use the methods described to implement any business logic.
Previous versions of WebSphere Commerce relied upon the Specification and Description Language (SDL) for creating service modules. Since Version 9 uses the Java Persistence API, this tutorial shows how to use BOD to call the JPA in WebSphere Commerce. In order to reduce complexity and emphasize how JPA operations work in Version 9, the tutorial will define a single table and noun. Any service that uses an XML schema requires a logical model definition. For WebSphere Commerce, the logical model is represented as nouns and noun parts. Nouns are the business objects in your application. Noun parts are parts of those objects that are given distinct names so that they can be handled independently of the noun. Nouns define the name of each data element in the logical model, and assign that name to a data type. This data type can be a primitive XML schema type such as a boolean, or it can be a complex type that is constructed of data elements. For example, ProjectExternalIdentifierType contains Name (represented by a string type) and StoreIdentifier (represented as a _wcf:StoreIdentifierType). _wcf:StoreIdentifierType is a predefined complex type construct that can be shared among all of the nouns. It is defined in the IdentifierTypes.xsd file. WebSphere Commerce provides some predefined complex type constructs, which are shared among all of the nouns. To use the common predefined type constructs, you need to import the file in the Project.xsd file. The following code sample shows how to import these type constructs.
<import namespace="http://www.ibm.com/xmlns/prod/commerce/9/foundation" schemaLocation="../../../../IBM/Commerce/Resources/Components/IdentifierTypes.xsd" />
Note: To reduce complexity, WebSphere Commerce uses its own simplified nouns, defined types, and primitive XML schema types, rather than using the nouns and base types provided by OAGIS.
The service module created in this tutorial contains one noun: Project. For this tutorial, these Project nouns are predefined for you. The Project.xsd file, which defines the nouns, is provided as part of the ProjectServices.zip sample file.
For this tutorial, the definitions of the noun contain information that is listed in the table for each noun. The tables list the access profiles that include the information. Data included in the Summary profile are shown in the summary view, and data included in the Details profile are shown in the details view.
Project noun The Project noun represents the logical data model of the new service module created. The definition of this logical model is a key development step as this model is exposed to any client that uses the Project service. The model is also extensively used in the BOD programming model for the business logic layer of WebSphere Commerce. The following diagram shows the schema definition for the Project noun: The following diagrams show the structure for Project noun: To manage the Project noun information created in this tutorial, you implement Get, and Change services for the new service module.
- Get services
- We can use the Get service to retrieve Project noun information that is based on an XPath search expression. This tutorial demonstrates how to support the following XPath expressions:
Find Project by Project UniqueID: /Project[ProjectIdentifier[(UniqueID='10001')]]
Change services The Change service updates project information for a Project noun. The Change service can update the projectName(we can wrote add and delete service by yourself).
Learning objectives
After completing this tutorial, you should be familiar with the following concepts:
- The WebSphere Commerce BOD command framework
- Extension and customization tasks.
- Logical model definitions.
- The Java Emitter Template.
- Service Data Objects.
- Eclipse Modeling Framework.
- The JPA Framework
- The Business Object Mediator.
After completing this tutorial, you should be able to perform the following tasks:
- Create an extended sites store with a custom catalog.
- Review the Project noun.
- Customize the physical layer.
- Generate the base code for our Project service module.
- Add language-specific exception messages to the properties files.
- Import mediators.
- Configure the data service layer for the Project service module.
Time required
Expect this tutorial to take two hours to complete. The tutorial takes longer if you explore concepts related to this tutorial.
Skill level
This tutorial is intended for advanced WebSphere Commerce developers who are responsible for creating and customizing WebSphere Commerce services. To complete this tutorial, ensure that we are familiar with the following terms and concepts:
- Java programming language
- XPath
- XSD
- Web services
- XML
- WebSphere Commerce services
- JPA Framework
- Nouns
- Relational databases
- SQL
System requirements
Before starting this tutorial, completed the following tasks:
- Installing the Java Emitter Template (JET) package
- Set up the development environment for creating WebSphere Commerce services
Tutorial resources
To complete this tutorial, the following resources are used. Ensure that you download and extract the following compress file to a temporary directory, such as C:\Temp before you begin this tutorial:
Note: If we are completing this tutorial as a prerequisite for the Management Center customization tutorial, "Adding a tool to the Management Center", we can import the projects within the following Recipe_service_source.zip compressed file into the development environment.
These files include the source code for the completed BOD service module for the sample recipe services. To learn more about creating a service module, however, we are recommended to complete the tutorial in full instead of importing these projects.
If you do import these projects, we must still complete the step to update the build dependencies for the service module. See Generating the Project service module projects.
Lessons in this tutorial
- Defining the database schema
In this step, you customize the physical layer by adding tables to contain recipe information in the WebSphere Commerce database schema.- Generating the Project service module projects
The Java Emitter Template (JET) is an Eclipse-enabled template engine for generating applications based on model-driven architecture transformations. By defining an XML file that describes your module, the JET plug-in for Rational Application Developer (RAD) can generate the basic WebSphere Commerce service module code for you. Afterward, we can complete the module by completing your specific business logic to start directly with the service module implementation. You do not need to spend hours with the setup and configuration of a service module.- Generating the SDOs for the Project noun
In this lesson, you generate the Service Data Objects (SDOs) that implement the logical data model of your Project and ProjectCollection nouns. SDOs are Java objects that represent the nouns in your logical model. Use the Eclipse Modeling Framework (EMF) to generate these SDOs from your noun definitions.- Implementing the persistence layer for the WebSphere Commerce BOD programming model
The BOD programming model provides a JPA framework to replace the DSL in V9. In this lesson, you use the JPA framework to generate service data objects.- Adding language-specific exception messages
In this lesson, you add language-specific exception messages to the properties files used by the mediators and commands. You write the mediator and command code in a later lesson.- Configure the data service layer for the Project service module
In this lesson, you configure the data service layer for the Project service module, through XML to provide the necessary mappings.- Implementing the business logic layer
The business logic layer contains the commands used in this tutorial. To save time, you are importing these commands directly from the provided tutorial code.- Implementing the client library
The primary purpose of the client library is to simplify and eliminate code on the client. The client library is essentially a Java layer to help Java applications integrate with your service architecture, with no additional code generation required. The client library already has support for session and authentication and provides Java based clients a standardized mechanism to create the logical SDO objects to represent service requests.- Implementing access control
Resources that web services act upon are actually nouns that are represented by generated SDOs. This lesson contains a brief overview of how access control policy works for BOD service modules.- Validating the Project service module with JUnit
After you apply the WebSphere Commerce service module pattern, a Project-UnitTests project is created as a place to put JUnit tests for the services createdd.