Wednesday 14 December 2016

SOA Serivce Client : Get Unit Effective revision for Item

How to get Unit effective revision for Particular item?
What is unit effective revision?
Answer : The revision of Item which is effective for Particular Unit number
 Eg: Item_XZ
      |__ItemRevisionXZ1  Effective for unit 10
     |__ItemRevisionXZ2  Effective for unit 11

To get the Revision of Particular item for specified unit we must know the revision rule/ and we need to open bom window so that by configuring bom with specified revision rule and unit we will get effective item revision

Must Read->What is Unit Effectivity

//parentItem -> Whose effective revision we are looking for
//endItem -> End Item against which unit effectivity is set
public ItemRevision getEffectiveRevision(Connection connection,Item parentItem,Item endItem, String sRevRule,int unitEffectivity, Calendar date, boolean today) throws Exception
{
   CreateBOMWindowsInfo[] createBOMWindowsInfo = new CreateBOMWindowsInfo[1];
   createBOMWindowsInfo[0] = new CreateBOMWindowsInfo();
   BOMWindow[] bomWindows = null;
   BOMLine bomLine = null;
   DataManagementService dataManagementService = null;
   StructureManagementService cadSMService = null;
   if(parentItem==null){
  throw new eQMIException("Getting the configured revision: 002","Getting the configured revision - Parent item is null");
    }
   createBOMWindowsInfo[0].item = (Item) parentItem;
   if(sRevRule != null)
   {
 How to Get Revision Rule
        RevisionRule revisionRule =getRevisionRule(sRevRule,connection);
 if( revisionRule != null )
 {
      RevisionRuleConfigInfo revRuleConfigInfo = new RevisionRuleConfigInfo();
      revRuleConfigInfo.revRule = revisionRule;//Revision Rule object
     if(endItem!=null)
  revRuleConfigInfo.props.endItem = endItem;
           if(unitEffectivity!=-1)
  revRuleConfigInfo.props.unitNo = unitEffectivity;
   
    if(date!=null)
       revRuleConfigInfo.props.date = date;
   
          revRuleConfigInfo.props.today = today;//Boolean indicating todays date or specified data above to consider

    createBOMWindowsInfo[0].revRuleConfigInfo = revRuleConfigInfo;
       } else
       {
  System.out.println("The revision rule specified not found in Teamcenter : " + sRevRule);
 throw new Exception("Getting the configured revision: 005","Getting the configured revision - The configured revision rule '"+sRevRule+"' is not found in the Teamcenter");
      }
   }
  else
  {
    throw new Exception("Getting the configured revision: 006","Getting the configured revision - The revision rule is not configured in the properties");
  }
  dataManagementService = DataManagementService.getService(connection);
  cadSMService = com.teamcenter.services.strong.cad.StructureManagementService
  .getService(connection);
  CreateBOMWindowsResponse createBOMWindowsResponse = 
  cadSMService.createBOMWindows(createBOMWindowsInfo); //Create the BOM window with specified revision rule configuration
  if (createBOMWindowsResponse.serviceData.sizeOfPartialErrors() > 0)
  {
 String errorMsg="";
 for (int i = 0; i < createBOMWindowsResponse.serviceData.sizeOfPartialErrors(); i++)
 {
  errorMsg+=createBOMWindowsResponse.serviceData.getPartialError(i).getMessages();
  //System.out.println("Partial Error in Open BOMWindow = "+createBOMWindowsResponse.serviceData.getPartialError(i).getMessages()[0]);
 }
 throw new Exception("Getting the configured revision: 007","Getting the configured revision - "+errorMsg);
  }
  try{
 bomWindows = new BOMWindow[1];
 bomLine = createBOMWindowsResponse.output[0].bomLine; //This will be the configured line based on revision rule configuration
 bomWindows[0] = createBOMWindowsResponse.output[0].bomWindow;

 String[] arrAttributes = new String[] { "bl_revision"};
 ModelObject arrModelObjects[]= new ModelObject[1];
 arrModelObjects[0]=bomLine;
 dataManagementService.getProperties(arrModelObjects, arrAttributes);
 ModelObject configuredObject = bomLine.get_bl_revision();//Get the Revision object from BOMLine
 if(configuredObject!=null)
        {
  //Load the properties of object
   arrAttributes = new String[] { "item_revision_id","last_release_status"};
   ModelObject arrModelObjects1[]= new ModelObject[1];
   arrModelObjects1[0]=configuredObject;
   ServiceData sd = dataManagementService.getProperties(arrModelObjects1, arrAttributes);
   for (int j = 0; j < sd.sizeOfPlainObjects(); j++)
          {
     configuredObject = sd.getPlainObject(j);
      }
   ReleaseStatus lastReleaseStatus = 
          (ReleaseStatus) ((ItemRevision)configuredObject).get_last_release_status();
          //Load the property on Release Status object
   arrAttributes = new String[] { "name","effectivity_text"};
     arrModelObjects1 = new ModelObject[1];
      arrModelObjects1[0]=lastReleaseStatus;
     sd = dataManagementService.getProperties(arrModelObjects1, arrAttributes);
     for (int j = 0; j < sd.sizeOfPlainObjects(); j++) 
          {
      lastReleaseStatus = (ReleaseStatus) sd.getPlainObject(j);
          }
         System.out.println("effectivity_text="+lastReleaseStatus.get_effectivity_text());
         return (ItemRevision)configuredObject;
      }
    else
    {
 System.out.println("Item Revision not configured for Revision rule.= "+sRevRule+" and Unit Number = "+unitEffectivity);
    }
   }catch(Exception e)
    {
 throw new Exception("Getting the configured revision: 008","Getting the configured revision - "+e.getMessage());
    }
    finally{
  if(bomWindows != null && dataManagementService != null)
         cadSMService.closeBOMWindows(bomWindows);//close bom window
     }
 return null;
}

Explanation : Important API 
RevisionRule revisionRule =getRevisionRule(sRevRule,connection); RevisionRuleConfigInfo revRuleConfigInfo = new RevisionRuleConfigInfo();  
revRuleConfigInfo.revRule = revisionRule revRuleConfigInfo.props.endItem = endItem; revRuleConfigInfo.props.unitNo = unitEffectivity; revRuleConfigInfo.props.date = date; 
revRuleConfigInfo.props.today = today; createBOMWindowsInfo[0].revRuleConfigInfo = revRuleConfigInfo; CreateBOMWindowsResponse createBOMWindowsResponse = cadSMService.createBOMWindows(createBOMWindowsInfo);

No comments:

Post a Comment