Tuesday, June 23, 2015

Useful Oracle File Adapter's JCA configurations.

JCA configuration to debatch a file.

<adapter-config name="DebatchAdapter"
adapter="File Adapter" wsdlLocation="DebatchAdapter.wsdl" xmlns="http://platform.integration.oracle/blocks/adapter/fw/metadata">
 
  <connection-factory location="eis/HAFileAdapter" UIincludeWildcard="Test*.OUT"/>
  <endpoint-activation portType="Read_ptt" operation="Read">
    <activation-spec className="oracle.tip.adapter.file.inbound.ScalableFileActivationSpec">
      <property name="DeleteFile" value="true"/>
      <property name="MinimumAge" value="60"/>
      <property name="LogicalArchiveDirectory" value="TestFileArchiveDirectory"/>
      <property name="LogicalDirectory" value="TestFileInputDirectory"/>
      <property name="Recursive" value="false"/>
      <property name="PublishSize" value="3000"/>
      <property name="PollingFrequency" value="60"/>
      <property name="IncludeFiles" value="Test.*\.OUT"/>
      <property name="MaxRaiseSize" value="1"/>
      <property name="SingleThreadModel" value="true"/>
      <property name="UseHeaders" value="false"/>
    </activation-spec>
  </endpoint-activation>
</adapter-config>

Here location="eis/HAFileAdapter" indicates that the debatching happens in a cluster environment.
observe the className is changed as oracle.tip.adapter.file.inbound.ScalableFileActivationSpec instead of oracle.tip.adapter.file.inbound.FileActivationSpec which is default.

====================
Writing CSV file with header line.

When writing CSV using file adapter and if you want the header line to be published in the output CSV file then make sure that XSD corresponding to the file structure defined in the format builder of the File Adapter should not contain following lines.
nxsd:hasHeader="true"
nxsd:headerLines="1"

These attributes when populated within <xsd:schema> element basically skip the header row in the CSV file.
====================
JCA File Adapter's SynchRead configuration to read the file in the middle of a process and MOVE it to a particular folder.

<adapter-config name="TestFileSynchRead" adapter="File Adapter"
wsdlLocation="TestFileSynchRead.wsdl" xmlns="http://platform.integration.oracle/blocks/adapter/fw/metadata">
 
  <connection-factory location="eis/HAFileAdapter"/>
  <endpoint-interaction portType="SynchRead_ptt" operation="SynchRead">
    <interaction-spec className="oracle.tip.adapter.file.outbound.FileIoInteractionSpec">
      <property name="SourcePhysicalDirectory" value="/test/in"/>
      <property name="SourceFileName" value="Test.CSV"/>
      <property name="TargetPhysicalDirectory" value="/test/out"/>
      <property name="TargetFileName" value="Test.CSV"/>
      <property name="Type" value="MOVE"/>
    </interaction-spec>
  </endpoint-interaction>
</adapter-config>

If you just want the file to be copied then change the property Type value to COPY as below.
property name="Type" value="COPY"
Observe the file interaction spec is oracle.tip.adapter.file.outbound.FileIoInteractionSpec.

In OSB, JCA properties can be set in transport header as below.


Monday, March 16, 2015

Creating an attribute within an element using OSB XQuery 11g


For example we have an xml document as follow.

<root>
<invoiceNumber></invoiceNumber>
</root>

Based on above input I want to create one attribute in side an element say,  <testelemnet>.

Following is the code snippet to achieve the required output.

<testelemnet>
{
if (data($getTaxData/invoiceNumber) = '')
then attribute documentNumber {"SALES"}
else
attribute documentNumber {data($getTaxData/invoiceNumber)}
}
</testelemnet>

 Output is as follow.

<testelement documentNumber ="SALES"/>

 Note : If there is an attribute documentNumber  within <testelemnet> an error will be raised due to the duplication of the attribute names.

Wednesday, February 4, 2015

Replacing $ in amount and calculating the sum of amount using OSB XQuery


XQuery Code Snippet:

let $in :=
<test>
{
for $repeat in $input/repeat
let $amount := $repeat/amount
return
<amount1>{fn:replace($amount,"\quot;,'')}</amount1>
}
</test>
return
sum($in/amount1)

Sample Input:

<input>
<repeat>
<amount>$100</amount>
</repeat>
<repeat>
<amount>100</amount>
</repeat>
</input>

Result : 200.0

P.S. An alternative to this lengthy approach will be updated as early as possible in this post.

Tuesday, January 20, 2015

Creating XML structure in a recursive using xquery in OSB

Following code snippet generates the desired XML structure in a recursive way.

let $range := 50 div 10
return
let $i in (1 to xs:integer($range))
return
<root>
<boo>
{$input/MyElement/text()}
</boo>
</root>

This snippet generates the XML in the structure <root><boo>sample text</boo></root> for 5 times.

Above snippet can be used in the xquery expression builder of assign ,replace actions on the OSB proxy service or can be used in the xquery transformation.

In this snippet we can make the "50 div 10" dynamic using the xquery variables. 

Ex : $dividend div $divisor

And $input in the element <boo></boo> can be a variable which holds the XML structure from which we can extract the text.