Wednesday 14 December 2016

SOA Service Client : Revision Rule and Object Property Policy

Object property policy is used to define what default properties are to be loaded when object is returned from Teamcenter Policy files are available at location TC_DATA/soa/policies/policyName.xml

Revision rules are used to expand BOM
How you get revision rule from Teamcenter by name ?

 //strRevisionRule -> Revision Rule name

 //Revision Rules 'object_name' property must get loaded when we query revision rules from Teamcenter

 //So we use Object property policy

 private RevisionRule getRevisionRule(String strRevisionRule, Connection soaConnection )  throws Exception
 {
   if( strRevisionRule != null )
    {
      String strTcSource = "RevisionRule";//Class of Revision Rule
      try {
            TcSOAUtil utilObj = new TcSOAUtil();
            //ObjectPropertyPolicy available in package 
            //com.teamcenter.soa.common
             ObjectPropertyPolicy objectPropertyPolicy = 
             new ObjectPropertyPolicy();
             PolicyType policyType = 
             new PolicyType( strTcSource, new String[]{"object_name"});           
             //Statement says I need object_name property on 
             //RevisionRule class object

             objectPropertyPolicy.addType( policyType );
             //SessionService available in package  
             //com.teamcenter.services.strong.core     
             SessionService sessionService = 
             SessionService.getService( soaConnection );
            sessionService.setObjectPropertyPolicy( objectPropertyPolicy );
             //Set object property policy
           }
         catch (Exception e)
          {
            throw new Exception(e.getMessage());
          }  
          //StructureManagementService available in package
          //com.teamcenter.services.strong.cad
          StructureManagementService managementService =
          StructureManagementService.getService( soaConnection );
          try
          {
            //getRevisionRules API used to get all the 
            //available revision rule
             GetRevisionRulesResponse revisionRules 
             = managementService.getRevisionRules();
             RevisionRuleInfo[] revisionRuleInfos = revisionRules.output;
             if( revisionRuleInfos != null )
             {
                for ( RevisionRuleInfo revisionRuleInfo : revisionRuleInfos )
                {
                  if( revisionRuleInfo.revRule.get_object_name().equals( strRevisionRule ) )
                    return revisionRuleInfo.revRule;
                   //Actual revision rule which is require
                }

              }
           }
          catch ( Exception e )
          {
           throw new Exception(e.getMessage());
          }
        }
       return null;
    }
Explanation : Important API
GetRevisionRulesResponse revisionRules = managementService.getRevisionRules();

No comments:

Post a Comment