Wednesday 14 December 2016

SOA Service Client : Pack / Unpack BOM

How to Pack/Unpack BoM

 CreateBOMWindowsResponse createBOMWindowsResponse = createBOMWindows2(modObjParent);

 BOMWindow[] bomWindows = getBOMWindows(createBOMWindowsResponse);
 BOMLine parentBOMLine = getParentBOMLine(createBOMWindowsResponse);
 List<BOMLine> arrChildBOMLines = getChildren(parentBOMLine, plugin);

 System.out.println( "Children BOMLines : " + arrChildBOMLines);
//Expand child lines one by one.
if(arrChildBOMLines != null && arrChildBOMLines.size() > 0)
{
    for (int cnt = 0; cnt < arrChildBOMLines.size(); cnt++)
    {
        if(arrChildBOMLines.get(cnt) instanceof BOMLine)
         {  
          //Get child bomlines
          BOMLine bline = (BOMLine)arrChildBOMLines.get(cnt);
          boolean bIsBomLinePacked = false;
          try           {
               bIsBomLinePacked = bline.get_bl_is_packed();
          } 
         catch (NotLoadedException e)
          {
             System.out.println("get_bl_is_packed attribute not loaded fetching from Tc="+ e);
             bIsBomLinePacked = (Boolean) plugin.getObjectAttribute(bline,"bl_is_packed", null);
          }
         System.out.println("Value for get_bl_is_packed :  " + bIsBomLinePacked);
         if(bIsBomLinePacked)
          {
            System.out.println("BOM Line is packed, unpacking the complete BOMLine");

           //com.teamcenter.services.strong.structuremanagement.StructureService
           StructureService strucService = StructureService.getService(connection);
           ServiceData response = strucService.packOrUnpack(new BOMLine[] { bline } , 3);
           if(response.sizeOfPartialErrors() == 0)
           System.out.println("unpacking successfull ");
         }
       }
    } 
}
Explanation :
StructureService strucService = StructureService.getService(connection);
ServiceData response = strucService.packOrUnpack(new BOMLine[] { bline } , 3);
packOrUnpack method parameters are ->1st Parameter) lines - The lines that need to be packed. If pack all option is selected, the children of the lines will be packed.2nd Parameter)flag - 0:pack the lines 1:unpack the lines 2:pack all lines 3:unpack all lines

No comments:

Post a Comment