Monday, November 10, 2014

Merge documents

Below are the services and adapters that will help user to merge or concatenate two documents into one document in Sterling Integrator.

MergeDocument Service: This Service has been introduced to merge or concatenate two documents into one document. It takes two primary documents as input, and the resulting document will be placed in primary document.

<process name="Test_MergeDocumentProcess">

                <sequence name="main">
                                <!-- To pick/collect 1st file named file101.txt -->
                                <operation name="File System Adapter">
                                                <participant name="FileSystemAdapterInstance"/>
                                                <output message="FileSystemInputMessage">
                                                                <assign to="." from="*"/>
                                                                <assign to="Action">FS_COLLECT</assign>
                                                                <assign to="deleteAfterCollect">false</assign>
                                                                <assign to="filter">file101.txt</assign>
                                                </output>
                                                <input message="inmsg">
                                                                <assign to="." from="*"/>
                                                </input>
                                </operation>
                                <!-- Assign the primary document to process data i.e.doc1  -->
                                <assign to="variables/doc1" from="PrimaryDocument/@SCIObjectID"/>
                                <!-- To pick/collect 2nd file named file202.txt -->
                                <operation name="File System Adapter">
                                                <participant name="FileSystemAdapterInstance"/>
                                                <output message="FileSystemInputMessage">
                                                                <assign to="." from="*"/>
                                                                <assign to="Action">FS_COLLECT</assign>
                                                                <assign to="deleteAfterCollect">false</assign>
                                                                <assign to="filter">file202.txt</assign>
                                                </output>
                                                <input message="inmsg">
                                                                <assign to="." from="*"/>
                                                </input>
                                </operation>
                                <!-- Assign the primary document to process data i.e.doc2  -->
                                <assign to="variables/doc2" from="PrimaryDocument/@SCIObjectID"/>
                                <!-- MergeDocument service takes the 1st file from doc1 and 2nd file from doc2, merges the contents of 2nd file at the end of 1st file -->
                                <operation name="MergeDocument">
                                                <participant name="MergeDocumentInstance"/>
                                                <output message="MergeDocumentInputMessage">
                                                                <assign to="." from="*"/>
                                                                <assign to="document1" from="'doc1'"/>
                                                                <assign to="document2" from="'doc2'"/>
                                                </output>
                                                <input message="inmsg">
                                                                <assign to="." from="*"/>
                                                </input>
                                </operation>
                </sequence>
</process>


Let’s say the content of 1st file is ‘File name is file101.txt’, and 2nd file content is ‘File name is file202.txt’. The resulted document content will be ‘File name is file101.txt File name is file202.txt.

File system adapter: File system adapter (FSA) can also be used to merge documents. This is a preferred way of merging documents when writing or reading files from disk (file system) is allowed. When FSA used to merge documents it can be done two ways.
  1. During Extracting: In order to merge documents during document extraction (writing files to disk), below parameters need to be configured.
    • appendOnExtract – Set to ‘Yes’, this configuration will allows user to append data to the existing file, instead of creating new one. As it’s going to append to the existing file the file name must be unique. Configure ‘assignedFilename’ parameter to give specific file name to file.
  2. During Collecting: In order to merge documents during document collection (reading files to disk), below parameters need to be configured.
    • concatenateFiles – Set to ‘Yes’, this configuration will allows user to concatenate files during collecting multiple files. The contents of all non-zero byte files will be concatenated to a single file and placed as the primary document. This parameter configuration will work when FSA is configured in non-bootstrap mode and the parameter ‘collectMultiple’ is set to ‘Yes’.

2 comments:

  1. can we merge like 9 documents into 1 single file , the files that are being downloaded from the server by writing a for loop?

    ReplyDelete
  2. can we merge like 9 documents into 1 single file , the files that are being downloaded from the server by writing a for loop?

    ReplyDelete