Skip to Content
0
Former Member
Nov 26, 2008 at 05:27 AM

Complex Message Mapping for a Lookup in PI 7.1

25 Views

Hi

I am having difficulty with a complex mapping in PI that I was wondering if someone could help me with.

The issue is that I am doing a Stock Lookup where you enter an item code and retrun an xml with all the stock for Warehouses, Local regions and Other regions.

The problem is with the Other Regions. I have done a mapping that produces a new Other Regions node for each store returned...

<?xml version="1.0" encoding="UTF-8"?>

<StockLookupResponse><Header><SessionID>Constant</SessionID></Header>

<OtherRegions><Region>Dunedin</Region><Stores><Branch>5115</Branch><Description>222 Waterloo Road</Description><StockLevel><AllocatedStock>2</AllocatedStock></StockLevel></Stores></OtherRegions>

<OtherRegions><Region>Dunedin</Region><Stores><Branch>5117</Branch><Description>1 Waterloo Road Dunedin</Description><StockLevel><AllocatedStock>26</AllocatedStock</StockLevel></Stores></OtherRegions>

<OtherRegions><Region>Christchurch</Region><Stores><Branch>5222</Branch><StockLevel><AllocatedStock>27</AllocatedStock></StockLevel></Stores></OtherRegions>

</StockLookupResponse>

What I need to do is create a single OtherRegions node for each region and then show the stores within this region like this

<?xml version="1.0" encoding="UTF-8"?>

<StockLookupResponse><Header><SessionID>Constant</SessionID></Header>

<OtherRegions><Region>Dunedin</Region>

<Stores><Branch>5115</Branch><Description>222 Waterloo Road Dunedin</Description><StockLevel><AllocatedStock>2</AllocatedStock></StockLevel></Stores>

<Stores><Branch>5117</Branch><Description>1 Waterloo Road Dunedin</Description><StockLevel><AllocatedStock>26</AllocatedStock</StockLevel></Stores>

</OtherRegions>

<OtherRegions><Region>Christchurch</Region><Stores><Branch>5222</Branch><StockLevel><AllocatedStock>27</AllocatedStock></StockLevel></Stores></OtherRegions>

</StockLookupResponse>

I have successfully created the OtherRegions node for each region but I only ever get one store return for each region. No matter what I do I cannot seem to get the full list of stores.

The sample XML coming in is

<?xml version="1.0" encoding="UTF-8"?>

<ns0:StockLookup_JDBC_response xmlns:ns0="urn:bridgestone:bpcs:logistics">

<StoredProceedureSelect_response>

<response_1>

<row>

<ITEM_CODE>484855A</ITEM_CODE>

<RECORD_TYPE>O</RECORD_TYPE>

<REGION_CODE>2</REGION_CODE>

<STORE_ID>5115</STORE_ID>

<LOCATION_CODE/>

<ON_HAND>555</ON_HAND>

</row>

<row>

<ITEM_CODE>484855A</ITEM_CODE>

<RECORD_TYPE>O</RECORD_TYPE>

<REGION_CODE>2</REGION_CODE>

<STORE_ID>5117</STORE_ID>

<WHS_FLAG>0</WHS_FLAG>

<ON_HAND>6</ON_HAND>

</row>

<row>

<ITEM_CODE>484855A</ITEM_CODE>

<RECORD_TYPE>O</RECORD_TYPE>

<REGION_CODE>6</REGION_CODE>

<STORE_ID>5222</STORE_ID>

<LOCATION_CODE/>

<ON_HAND>2</ON_HAND>

</row>

</response_1>

</StoredProceedureSelect_response>

</ns0:StockLookup_JDBC_response>

To get the Other regions to work I passed on the record type and region code into a UDF:

public void createOtherRegion(String[] recordType, String[] regionCode, ResultList result, Container container) throws StreamTransformationException{

String prevRegionCode = new String("");

for (int i = 0; i < recordType.length; i++)

{

if (!recordType<i>.equals("O"))

{

result.addValue(false);

}

else

{

if (prevRegionCode.equals(""))

{

result.addValue(true);

prevRegionCode = new String (regionCode<i>);

}

else if (prevRegionCode.equals(regionCode<i>))

result.addValue(false);

else

{

result.addValue(true);

prevRegionCode = new String (regionCode<i>);

}

}

}

}

This successfully create a new Other region and displays a single store within the region. Unfortunately by trying to map the STORE_ID to the Stores node (1.. unbounded) only one store is ever returned.

I have tried changing the context but it will only retrun one store.

Haas anyone else come across a similar problem? Any help appreciated.