Wednesday, 14 December 2016

SOA Service Client : Creating BOM

Creating BILL OF MATERIAL require
1) Opening BOMWINDOW
2) Adding Children
3) Saving BOM Window
4) Closing BOM Window

Opening BOMWINDOW
//To open BOMWindow we require object which will be topline after opening BOMWINDOW
//In Teamcenter we send object to Structure manager so that object is nothing but parentItemRev in below function
public ArrayList openBOMWindow(Connection connection,ItemRevision parentItemRev)
{

    ArrayList bomWindowandParentLine = new ArrayList(2);
    CreateBOMWindowsInfo[] createBOMWindowsInfo = new CreateBOMWindowsInfo[1];
    createBOMWindowsInfo[0] = new CreateBOMWindowsInfo();
    createBOMWindowsInfo[0].itemRev = (ItemRevision) parentItemRev;
    com.teamcenter.services.strong.cad.StructureManagementService cadSMService = 
    com.teamcenter.services.strong.cad.StructureManagementService
   .getService(connection);

    CreateBOMWindowsResponse createBOMWindowsResponse = 
    cadSMService.createBOMWindows(createBOMWindowsInfo);


    if (createBOMWindowsResponse.serviceData.sizeOfPartialErrors() > 0) 
    {
 for (int i = 0; i < createBOMWindowsResponse.serviceData
   .sizeOfPartialErrors(); i++) {

       System.out.println("Partial Error in Open BOMWindow = "+createBOMWindowsResponse.serviceData
 .getPartialError(i).getMessages()[0]);
 }
     }
     bomWindowandParentLine
     .add(createBOMWindowsResponse.output[0].bomWindow);//BOMWindow
      bomWindowandParentLine.add(createBOMWindowsResponse.output[0].bomLine);//TOPLine in BOMWINDOW
      return bomWindowandParentLine;
 }
ADD Children
//Assuming we have parent object and child objects

public void addAllChildrenInBOM(Connection tcConnection, ItemRevision parentObject, ItemRevision[] childObjects, ArrayList<LinkedHashMap<String, String>> alUpdateAttrs) throws Exception
 {
     ArrayList createBOMWindowsResponse = 
     openBOMWindow(tcConnection,parentObject);//Open BOMWindow
     BOMWindow[] bomWindows = new BOMWindow[]{(BOMWindow) createBOMWindowsResponse.get(0)};//Get the BOMWINDOW
     BOMLine parentBOMLine = 
    (BOMLine) createBOMWindowsResponse.get(1);//GET the Topline
     com.teamcenter.services.strong.core.DataManagementService dmService = 
     com.teamcenter.services.strong.core.DataManagementService.getService(tcConnection);

      //Set the Child bomline to be added and their properties
      ItemLineInfo[] itmLineInfoArr = 
      new ItemLineInfo[childObjects.length];
      for (int i = 0; i < childObjects.length; i++)
      {
       itmLineInfoArr[i] = new ItemLineInfo();
       itmLineInfoArr[i].itemRev = childObjects[i];//Add child object one by one
       if(alUpdateAttrs != null && alUpdateAttrs.size() > 0)
        {
             itmLineInfoArr[i].itemLineProperties 
             = alUpdateAttrs.get(i);/This is map of properties and their values
        }
       }
     AddOrUpdateChildrenToParentLineInfo[] addChToParInfoArr = 
     new AddOrUpdateChildrenToParentLineInfo[1];
     addChToParInfoArr[0] = new AddOrUpdateChildrenToParentLineInfo();
     addChToParInfoArr[0].items = itmLineInfoArr;
     addChToParInfoArr[0].parentLine = parentBOMLine;
     com.teamcenter.services.strong.bom.StructureManagementService bomSMService =
     com.teamcenter.services.strong.bom.StructureManagementService.getService(tcConnection);
     AddOrUpdateChildrenToParentLineResponse addUpdChToParResp = 
     bomSMService.addOrUpdateChildrenToParentLine(addChToParInfoArr);//Add children
     if (addUpdChToParResp.serviceData.sizeOfPartialErrors() > 0)
     {
       throw new Exception("Creating BOMLines : 003" ,"Creating BOMLines - "+addUpdChToParResp.serviceData.getPartialError(0).getMessages()[0]);
     }
     utils.saveBOMWindow(tcConnection, bomWindows[0]);
     utils.closeBOMWindow(tcConnection, bomWindows[0]);
     System.out.println("********************************** BOM Lines created successfully ********************************** ");
 }
 
SAVE BOMWINDOW //To save BOMWINDOW we need BOMWINDOW object
public void saveBOMWindow(Connection connection, BOMWindow bomWindow)
   {
      com.teamcenter.services.strong.cad.StructureManagementService cadSMService = 
      com.teamcenter.services.strong.cad.StructureManagementService.getService(connection);
      SaveBOMWindowsResponse saveResponse = 
      cadSMService.saveBOMWindows(new BOMWindow[]{bomWindow});

      if (saveResponse.serviceData.sizeOfPartialErrors() > 0)  
      {
       for (int i = 0; i < saveResponse.serviceData
      .sizeOfPartialErrors(); i++) 
      {
       System.out.println("Save BOMWindow Partial Error -- "+saveResponse.serviceData
      .getPartialError(i).getMessages()[0]);
       }

      }
   }
Close BOMWINDOW
//To close BOMWINDOW we need BOMWINDOW object

public void closeBOMWindow(Connection connection, BOMWindow bomWindow)
 {
  com.teamcenter.services.strong.cad.StructureManagementService cadSMService 
  = com.teamcenter.services.strong.cad.StructureManagementService
  .getService(connection);
   CloseBOMWindowsResponse response = null;
  if (cadSMService != null && bomWindow != null)
  {
    response = 
    cadSMService.closeBOMWindows(new BOMWindow[] { bomWindow });
  }
  if (response.serviceData.sizeOfPartialErrors() > 0) 
  {
    for (int i = 0; i < response.serviceData
   .sizeOfPartialErrors(); i++) 
   { 
    System.out.println("Close BOMWindow Partial Error -- "+response.serviceData
   .getPartialError(i).getMessages()[0]);
   }
  }
} 

Explanation : Important API
Open bomwindow ->CreateBOMWindowsResponse createBOMWindowsResponse =     cadSMService.createBOMWindows(createBOMWindowsInfo);
Add children -> com.teamcenter.services.strong.bom.StructureManagementService   bomSMService = com.teamcenter.services.strong.bom.StructureManagementService.getService(tcConnection);
        AddOrUpdateChildrenToParentLineResponse addUpdChToParResp = bomSMService.addOrUpdateChildrenToParentLine(addChToParInfoArr);//Add children
Save BomWindow -> SaveBOMWindowsResponse saveResponse = cadSMService.saveBOMWindows(new BOMWindow[]{bomWindow});
Close Bomwindow -> response = cadSMService.closeBOMWindows(new BOMWindow[] { bomWindow });
 

3 comments:

  1. Hi, can I create a BOMView with a specified PSViewType (different from the standard "view")? How can I do it? Thanks

    ReplyDelete
  2. I want to modify bomline attribute like as formular. Do I need to save parent bomview or other way ?

    ReplyDelete