uCosminexus Service Platform, Reception and Adapter Definition Guide

[Contents][Glossary][Index][Back][Next]

Appendix D.6 Sample for writing CSV data

The sample for writing CSV data uses a file adapter to write data retrieved by a DB adapter to a file in CSV format.

The following table lists the items that are input and output:

Table D-55 Input and output items (sample for writing CSV data)

Input or output item Content
Output file of file adapter service-platform-installation-directory\CSC\custom-adapter\File\sample\write_csv\write_csv_data.csv
Input table of DB adapter ADMIN.CSAFF_SAMPLE_WC#

#
Do not change the schema name.

Organization of this subsection
(1) Defining the file adapter
(2) Defining the business process
(3) Distributing the file adapter and business process deployment definitions
(4) Creating tables
(5) Creating request messages
(6) Executing the business process

(1) Defining the file adapter

(a) Adding and validating the file adapter

To add and validate a file adapter:

  1. From the Eclipse menu, select Window, Show View, and then Other.
    The Show View dialog box appears.
  2. Select HCSC-Definer and then HCSCTE View, and click OK.
    The Service Definition List appears in the tree view.
  3. Right-click the Service Definition List in the tree view, and select Add Service Adapter.
    The Service adapter definition addition wizard appears.
  4. From the Service component type: drop-down list, select File adapter.
  5. Click Next.
    The Service adapter definition addition (File Adapter) wizard appears.
  6. Enter the service name.
    Enter CSAFF_SAMPLE_WRITE_CSV as the service name.
  7. Click Finish.
    The necessary files are created, and stored in the repository. The Service adapter definition (standard) window appears.
  8. Enter settings in the Service adapter definition (standard) and Service adapter definition (details) windows.
    For details on the settings you need to enter, see File adapter settings (sample for writing CSV data).
  9. Review the definition contents, and then save the service adapter definition by selecting File and then Save from the Eclipse menu.
  10. Verify the file adapter settings.
    Select Verify from the pop-up list displayed when you right-click the Service Definition List in the tree view. The results appear in the Console View.

File adapter settings (sample for writing CSV data)
The table below shows the items you need to set in the Service adapter definition (standard) window when defining the file adapter for the sample for writing CSV data. You do not need to set items that do not appear in this table.

Table D-56 Settings in Service adapter definition (standard) window (sample for writing CSV data)

Category Item Value to set Requires setting
Service component control information Service name CSAFF_SAMPLE_WRITE_CSV Y
Service ID CSAFF_WC Y
Service type File adapter N
Address -- --
Maximum instances 0 Y
Operation Pattern: Binary file writing
Operation name: CSAFF_SAMPLE_WRITE_CSV
Y
Operation information Operation name CSAFF_SAMPLE_WRITE_CSV N
Communication model Sync Y
Request message Standard Use check box Use (select the check box) Y
Format ID SAMPLE_WRITE_CSV_Standard Y
Message format csaff_sample_write_csv_standard.xsd Y
Service component Format ID SAMPLE_WRITE_CSV_Request Y
Message format csaff_sample_write_csv.fdx Y
Data TransDefn File SAMPLE_WRITE_CSV_DT Y
Response message Standard Use check box Do not use (leave the check box cleared) Y
Service component Format ID SAMPLE_WRITE_CSV_Response Y
Message format adpff_result.xsd N

Legend:
Y: Must be set.
N: Check the content that is already displayed.
--: Do not set.

The table below shows the items you need to set in the Service adapter definition (details) window when defining the file adapter for the sample for writing CSV data. You do not need to set items that do not appear in this table.

Table D-57 Settings in Service adapter definition (details) window (sample for writing CSV data)

Category Item Value to set Requires setting
Service adapter control information Service adapter (EJB-JAR file) cscmsg_adpejb.jar N
Utility class (JAR file) adpffpc.jar N

Legend:
N: Check the content that is already displayed.

(b) Defining data transformation

Set the data transformation definition. The following figure shows the data transformation definition you need to set:

Figure D-11 Data-conversion definition screen for file adapter (sample for writing CSV data)

[Figure]

To define this data transformation:

  1. Display the data transformation (mapping) definition screen from the Adapter Definition screen.
    After displaying the data transformation (mapping) definition screen, the Select Root Element dialog box appears.
  2. Select the root elements for all logical schema names.
    The OK button becomes available.
  3. Click OK.
    The schemas of the selected root elements appear in tree format in the transformation-source schema tree viewer and the transformation-destination schema tree viewer.
  4. Perform mapping.
    Mapping involves the following tasks:
    • Placing and setting functions
      The following table shows the function settings:

      Table D-58 Function settings (sample for writing CSV data - File adapter)

      Function Function name Value to set
      loop loop1 Select Node record
      Set Node Condition Do not set
      loop loop2 Select Node column
      Set Node Condition Do not set
    • Setting inter-node mapping
      The following table shows the inter-node mapping settings:

      Table D-59 Mapping settings (sample for writing CSV data - File adapter)

      Source node Function Target node
      -- loop1 record
      -- loop2 data
      filename -- filename
      fileoption -- fileoption
      data -- data

      Legend:
      --: Not applicable.

  5. In the data transformation (mapping) definition screen, right-click an appropriate location in the transformation-source schema tree viewer, transformation-destination schema tree viewer, or mapping viewer, and select Validate.
    Validation takes place. You can ignore any warning messages that appear.
(c) Creating the file adapter runtime-environment property file

To create the file adapter runtime-environment property file:

  1. Open the sample file adapter runtime-environment property file in a text editor.
    The sample file adapter runtime-environment property file is service-platform-installation-directory\CSC\custom-adapter\File\sample\write_csv\CSAFF_WC.propertie.
  2. Add the following content to the file:
     
    fileaccess.path1 = service-platform-installation-directory\\CSC\\custom-adapter\\File\\sample\\write_csv
    character.code = MS932
    codetable.path = storage-path-for-code-conversion-table-(user-mapping-file)
    The storage path for user mapping files is as follows:
     
    service-platform-installation-directory\\CSC\\lib\\external\\table
     
  3. Save the file.
    The storage path for the file is as follows:
     
    service-platform-installation-directory\CSC\custom-adapter\File\config
     

(2) Defining the business process

The task of defining a business process involves adding a business process, defining the contents of the business process, and then validating the business process.

(a) Adding a business process

To add a business process:

  1. From the Eclipse menu, select Window, Show View, and then Other.
    The Show View dialog box appears.
  2. Select HCSC-Definer and then HCSCTE View, and click OK.
    The Service Definition List appears in the tree view.
  3. Right-click the Service Definition List in the tree view, and select Add Business Process.
    A dialog box appears in which you can add a business process definition.
  4. Enter the name of the business process, and select whether to make its status persistent (whether to save the execution status of the business process in the database).
    Enter CSAFF_SAMPLE_BP_WRITE_CSV as the business process name.
    Select yes for Status Persistence.
    Reference note
    Do not use a BPEL file.
  5. Click Finish.
    The necessary files are created, and stored in the repository. The Define Business Process window appears.
(b) Setting variables

Set the following variables:

Reference note
The sample business process does not use a correlation set.

To set the variables:

  1. On the canvas of the Define Business Process window, double-click the Variable-Correlation icon.
    The List Of Variables And Correlation Sets dialog box appears.
  2. Select Variable List from the list.
  3. Enter the variable name.
  4. From the Type: drop-down list, select XML.
  5. Perform whichever of the following operations is relevant for the variable you are defining:
    For CSAFF_DB_ResponseMessage, CSAFF_RequestMessage, and CSAFF_ResponseMessage
    In the Take In Message Format dialog box displayed by clicking the Take In button, specify the message format you want to use. For details on the settings you need to enter, see Variable settings (sample for writing CSV data).
    For CSAFF_BP_RequestMessage
    Click the ... button and select the csaff_sample_write_csv.xsd file.
    For CSAFF_DB_RequestMessage
    Click the ... button and select the csaff_sample_write_csv_db.xsd file.
  6. Click Add.
    The variable you added appears in the list of variables.
  7. Repeat steps 2 to 6 for each variable.
  8. Click OK.
    The variable settings are saved and the List Of Variables And Correlation Sets dialog box closes.

Variable settings (sample for writing CSV data)
The tables below show the settings for the CSAFF_DB_ResponseMessage, CSAFF_RequestMessage, and CSAFF_ResponseMessage variables. You do not need to set items that do not appear in this table.

Table D-60 Settings for CSAFF_DB_ResponseMessage (sample for writing CSV data)

Category Item Value to set
Service/Reception Service name CSAFF_SAMPLE_DB
Reception name --
Target for take in Operation name CSAFF_SAMPLE_DB
Message type Response message (Body)
-- Message format csaff_sample_sqlformat

Legend:
--: Not applicable.

Table D-61 Settings for CSAFF_RequestMessage (sample for writing CSV data)

Category Item Value to set
Service/Reception Service name CSAFF_SAMPLE_WRITE_CSV
Reception name --
Target for take in Operation name CSAFF_SAMPLE_WRITE_CSV
Message type Request message (Body)
-- Message format csaff_sample_write_csv_standard

Legend:
--: Not applicable.

Table D-62 Settings for CSAFF_ResponseMessage (sample for writing CSV data)

Category Item Value to set
Service/Reception Service name CSAFF_SAMPLE_WRITE_CSV
Reception name --
Target for take in Operation name CSAFF_SAMPLE_WRITE_CSV
Message type Response message (Body)
-- Message format adpff_result

Legend:
--: Not applicable.

(c) Setting up activities

The following describes how to arrange and define the activities in the figure below, define the data transformations, and connect the activities.

Figure D-12 Overall view of business process definition (sample for writing CSV data)

[Figure]

Arranging and defining activities

In the sample for writing CSV data, set up the activities shown in the following table.

Table D-63 List of activities (sample for writing CSV data)

Activity Activity name Description
Reception CSAFF_SAMPLE_BP_WRITE_CSV Receives messages into the business process.
Reply CSAFF_SAMPLE_BP_WRITE_CSV_RSP Issues a response from the business process.
Invoke Service InvokeFileAadapter Invokes the file adapter.
Invoke Service InvokeDBAdapter Invokes the DB adapter.
Data transformation CreateFileAdapterRequestMessage Transforms a response message from the DB adapter to a request message for the file adapter.
Data transformation CreateDBAdapterRequestMessage Transforms the request message of the business process to a request message for the DB adapter.

To position and set up an activity:

  1. In the palette, click the basic or structure activity you want to place on the canvas.
    The activity you clicked is selected.
  2. Click the appropriate location on the canvas.
    The selected activity is placed on the canvas. You can reposition the activity by dragging it with your mouse.
  3. Double-click the activity on the canvas.
    A dialog box appears in which you can enter settings for the activity you double-clicked.
  4. Enter the necessary information in the dialog box.
    For details on the information you need to set, see Activity settings (sample for writing CSV data).
  5. Click OK.
    The dialog box for the activity closes.
  6. Repeat steps 1 to 5 for each activity.

Activity settings (sample for writing CSV data)
The tables below show the settings for the business process activities used in the sample for writing CSV data. You do not need to set items that do not appear in this table.

Table D-64 Settings for CSAFF_SAMPLE_BP_WRITE_CSV

Item Value to set
Activity name CSAFF_SAMPLE_BP_WRITE_CSV
Operation name CSAFF_SAMPLE_BP_WRITE_CSV
Body allocated variable CSAFF_BP_RequestMessage
Communication model Sync
Instance generation Yes

Table D-65 Settings for CSAFF_SAMPLE_BP_WRITE_CSV_RSP

Item Value to set
Activity name CSAFF_SAMPLE_BP_WRITE_CSV_RSP
Operation name CSAFF_SAMPLE_BP_WRITE_CSV
Body allocated variable CSAFF_ResponseMessage

Table D-66 Settings for InvokeFileAadapter (sample for writing CSV data)

Item Value to set
Activity name InvokeFileAadapter
Service name CSAFF_SAMPLE_WRITE_CSV
Operation name CSAFF_SAMPLE_WRITE_CSV
Communication model Sync
Request message Body allocated variable CSAFF_RequestMessage
Response message Body allocated variable CSAFF_ResponseMessage

Table D-67 Settings for InvokeDBAdapter (sample for writing CSV data)

Item Value to set
Activity name InvokeDBAdapter
Service name CSAFF_SAMPLE_DB
Operation name CSAFF_SAMPLE_DB
Communication model Sync
Request message Body allocated variable CSAFF_DB_RequestMessage
Response message Body allocated variable CSAFF_DB_ResponseMessage

Table D-68 Settings for CreateFileAdapterRequestMessage (sample for writing CSV data)

Item Value to set
Activity name CreateFileAdapterRequestMessage
Source Variables CSAFF_BP_RequestMessage
CSAFF_DB_ResponseMessage
Destination Variable CSAFF_RequestMessage
Data TransDefn File SAMPLE_WRITE_CSV_DT2

Table D-69 Settings for CreateDBAdapterRequestMessage (sample for writing CSV data)

Item Value to set
Activity name CreateDBAdapterRequestMessage
Source Variables CSAFF_BP_RequestMessage
Destination Variable CSAFF_DB_RequestMessage
Data TransDefn File SAMPLE_WRITE_CSV_DT1
Setting the data transformation definition for the CreateDBAdapterRequestMessage activity

Set the data transformation definition for the CreateDBAdapterRequestMessage activity. The following figure shows the data transformation definition you need to set:

Figure D-13 Data conversion definition window for CreateDBAdapterRequestMessage activity (sample for writing CSV data)

[Figure]

To set the data transformation definition for the CreateDBAdapterRequestMessage activity:

  1. Display the data transformation (mapping) definition screen from the CreateDBAdapterRequestMessage activity.
    After displaying the data transformation (mapping) definition screen, the Select Root Element dialog box appears.
  2. Select the root elements for all logical schema names.
    The OK button becomes available.
  3. Click OK.
    The schemas of the selected root elements appear in tree format in the transformation-source schema tree viewer and the transformation-destination schema tree viewer.
  4. Perform mapping.
    Mapping involves the following tasks:
    • Placing and setting functions
      The following table shows the function settings:

      Table D-70 Function settings (sample for writing CSV data - CreateDBAdapterRequestMessage activity)

      Function Function name Value to set
      const const1 Constant type String
      Value PRODUCT_CODE
      const const2 Constant type String
      Value =
    • Setting inter-node mapping
      The following table shows the inter-node mapping settings:

      Table D-71 Mapping settings (sample for writing CSV data - CreateDBAdapterRequestMessage activity)

      Source node Function Target node
      -- const1 val1
      -- const2 val2
      PRODUCT_CODE -- val3

      Legend:
      --: Not applicable.

  5. In the data transformation (mapping) definition screen, right-click an appropriate location in the transformation-source schema tree viewer, transformation-destination schema tree viewer, or mapping viewer, and select Validate.
    Validation takes place.
Setting the data transformation definition for the CreateFileAdapterRequestMessage activity

Set the data transformation definition for the CreateFileAdapterRequestMessage activity. The following figure shows the data transformation definition you need to set:

Figure D-14 Data conversion definition window for CreateFileAdapterRequestMessage activity (sample for writing CSV data)

[Figure]

To set the data transformation definition for the CreateFileAdapterRequestMessage activity:

  1. Display the data transformation (mapping) definition screen from the CreateFileAdapterRequestMessage activity.
    After displaying the data transformation (mapping) definition screen, the Select Root Element dialog box appears.
  2. Select the root elements for all logical schema names.
    The OK button becomes available.
  3. Click OK.
    The schemas of the selected root elements appear in tree format in the transformation-source schema tree viewer and the transformation-destination schema tree viewer.
  4. Perform mapping.
    Mapping involves the following tasks:
    • Placing and setting functions
      The following table shows the function settings:

      Table D-72 Function settings (sample for writing CSV data - CreateFileAdapterRequestMessage activity)

      Function Function name Value to set
      loop loop1 Select Node DBA_ResultSet#
      Set Node Condition Do not set
      loop loop2 Select Node DBA_ResultColumn#
      Set Node Condition Do not set

      #
      DBA_ResultSet and DBA_ResultColumn use the information under the WRITE_CSV node.

    • Setting inter-node mapping
      The following table shows the inter-node mapping settings:

      Table D-73 Mapping settings (sample for writing CSV data - CreateFileAdapterRequestMessage activity)

      Source node Function Target node
      -- loop1 record
      -- loop2 column
      filename -- filename
      fileoption -- fileoption
      DBA_ResultColumn# -- data

      Legend:
      --: Not applicable.

      #
      DBA_ResultColumn uses information under the WRITE_CSV node.

  5. In the data transformation (mapping) definition screen, right-click an appropriate location in the transformation-source schema tree viewer, transformation-destination schema tree viewer, or mapping viewer, and select Validate.
    Validation takes place.
Connecting activities

In the sample for writing CSV data, connect the activities as shown in the following table.

Table D-74 Activity connections (sample for writing CSV data)

Connection-source activity Connection-target activity
Start CSAFF_SAMPLE_BP_WRITE_CSV
CSAFF_SAMPLE_BP_WRITE_CSV CreateDBAdapterRequestMessage
CreateDBAdapterRequestMessage InvokeDBAdapter
InvokeDBAdapter CreateFileAdapterRequestMessage
CreateFileAdapterRequestMessage InvokeFileAadapter
InvokeFileAadapter CSAFF_SAMPLE_BP_WRITE_CSV_RSP
CSAFF_SAMPLE_BP_WRITE_CSV_RSP Finish

To connect the activities:

  1. On the palette, click Connection.
    Connection mode is selected.
    When you align your cursor with an activity that can be specified as a connection source, the background color of the activity changes.
  2. On the canvas, click the activity that you want to serve as the connection source.
    The activity is set as the connection source.
    If you then align your cursor with another activity, the background color of the activity changes if it can be specified as a connection target.
  3. On the canvas, click the activity that you want to serve as the connection target.
    The activity you selected as the connection source is connected to the activity you selected as the connection target.
(d) Saving and validating the business process

To save and validate the business process:

  1. Review the definition contents, and then save file adapter settings by selecting File and then Save from the Eclipse menu.
    In properties view, set CSAFF_B5 as the service ID of the business process.
  2. Validate the business process settings.
    Select Verify from the pop-up list displayed when you right-click the Service Definition List in the tree view. The results appear in Console View.

(3) Distributing the file adapter and business process deployment definitions

Deploy the file adapter and business process and start them on the server.

To distribute the file adapter and business process deployment definitions:

  1. Right-click the Service Definition List in the tree view, and select Deploy all services to server and start.
    If the file adapter or business process fails to start, a dialog box appears describing the nature of the error. Look up the message ID displayed in the error details and take the appropriate action.

    If you are not logged in, the Account Verification window appears. In this case, perform step 2.
  2. Enter admin in the User ID field and the Password field, and then click OK.
    A message indicating that account verification is in progress appears, followed by a message indicating whether it was successful.

(4) Creating tables

Create the table the sample business process will access in the database.

Open HiRDB SQL Executer and execute the following SQL statement:

CREATE TABLE CSAFF_SAMPLE_WC
(ORDER_NO INT,
 CUSTOMER_CODE CHAR(5),
 PRODUCT_CODE CHAR(4),
 ORDER_COUNT INT);
INSERT INTO CSAFF_SAMPLE_WC VALUES(1001,'AA001','1001',5);
INSERT INTO CSAFF_SAMPLE_WC VALUES(1002,'AB002','1001',1);
INSERT INTO CSAFF_SAMPLE_WC VALUES(1003,'AA001','1102',3);
INSERT INTO CSAFF_SAMPLE_WC VALUES(1004,'XA005','1103',1);
INSERT INTO CSAFF_SAMPLE_WC VALUES(1005,'AA001','1105',1);
Note
Use ADMIN as the user ID.

(5) Creating request messages

The following describes how to create a request message by editing the sample request message used when executing the business process.

  1. Open the sample request message file in a text editor.
    The sample request message file is service-platform-installation-directory\CSC\custom-adapter\File\sample\write_csv\write_csv_message.csv.
  2. Add the part in italics below:
    <?xml version="1.0" encoding="UTF-8"?>
    <WriteData>
      <filename>service-platform-installation-directory\CSC\custom-adapter\File\sample\write_csv\write_csv_data.csv</filename>
      <fileoption>mode=new</fileoption>
      <PRODUCT_CODE>1001</PRODUCT_CODE>
    </WriteData>
  3. Save the file.

(6) Executing the business process

To execute the sample, start the business process from the service requester.

The flow of service requester processing is as follows:

  1. Service requester execution
    The request message of the business process is used as the request message of the file adapter without transformation.
  2. DB adapter execution
    Data that matches the conditions specified in the request message is acquired from the database.
  3. Create file adapter message
    The response message from the DB adapter is transformed to a request message for the file adapter.
  4. File adapter execution
    The file specified in the request message is output.
  5. Service requester termination
    The response message from the file adapter is used without transformation as the response message of the business process.

To execute the service requester:

  1. Navigate to service-platform-installation-directory\CSC\custom-adapter\File\sample\bin.
  2. Execute request.bat.
    Execute request.bat in the following format:
    request write_csv service-platform-installation-directory\CSC\custom-adapter\File\sample\write_csv\write_csv_message.xml

Reference note
The data is output to the following file:
service-platform-installation-directory\CSC\custom-adapter\File\sample\write_csv\write_csv_data.csv