Friday, 30 December 2016

Teamcenter SOA Service : Manufacturing Process Planner : Operation and Activity Creation and Attachment of Activity and Form

Problem Statement : 1) Attach Form Object To Activity OR Activity To RootActivity
//APIs are same only Object provided to APIs are different

How to do this task in Teamcenter ? refer link
1) Attach Form Object to Activity
  Left Object - Activity
  Right Object - Form Object

Assumption here is we have top line of Process under which we have operation ,beneath operation we have activity attached.Add form to that activity.
From top Line we will get Operation Line and from that operation line we will get root activity and from root activity we will get activity to which we want form to be attached.

//Create Form Object
CreateIn[] createIn = new CreateIn[1];
createIn[0] = new CreateIn();
createIn[0].data.stringProps.put( "object_name", "TestRRActivity12302016123" );
createIn[0].data.stringProps.put( "object_desc", "jTestRRActivity12302016 desc123" );
createIn[0].data.boName = "Activity Form";
CreateResponse createObjectsForm = null;

try {

createObjectsForm = dataManagementService1.createObjects( createIn );

} catch (ServiceException e) {

e.printStackTrace();

} // create form object end
//Attach Form Object To Activity

BOMLine operationline3=getchildlines("TCK71000006461/A-TestMeOp1VOption (Engineering)",topLineObject,dataManagementService1);//get Operation line

getAttachmentLines(operationline3, connection);//get Activity to which form is to be attached

MEActivityFolderInfo[] Activityfolderinfo=new MEActivityFolderInfo[1];
Activityfolderinfo[0]=new MEActivityFolderInfo();
Activityfolderinfo[0].activity=activityLineObject;//MEActivity to which we want to attach form
Activityfolderinfo[0].contents=new WorkspaceObject[]{(WorkspaceObject) createObjectsForm.output[0].objects[0]};//Form object<-createObjectsForm.output[0].objects[0]

dataManagementService.createOrUpdateMEActivityFolders(Activityfolderinfo);
 2) Attach Activity To Root Activity Of Operation(i.e What we say in Teamcenter is attach activity to operation but it is actually attached to root activity of operation)
Left Object - RootActivity  of Operation
Right Object - Activity

Assumption here is we have top line of Process under which we have operation under which there is default root activity to which we want to attach activity.
From top Line we will get Operation Line and from that operation line we will get root activity to that root activity we will attach activity.

//Create Activity Object
CreateIn[] createIn2 = new CreateIn[1];
createIn2[0] = new CreateIn();
createIn2[0].data.stringProps.put( "object_name", "Test10" );
createIn2[0].data.stringProps.put( "object_desc", "Test10 desc" );
createIn2[0].data.boName = "MEActivity";
CreateResponse createObjectsActivity= null;

try {

  createObjectsActivity = dataManagementService1.createObjects( createIn2 );

} catch (ServiceException e) {

e.printStackTrace();

} // create Activity object end
//Attach Activity Object To Root Activity
BOMLine operationline3=getchildlines("TCK71000006461/A-TestMeOp1VOption (Engineering)",topLineObject,dataManagementService1);//Get OPeration line
getAttachmentLines(operationline3, connection);//provide root line

MEActivityFolderInfo[] Activityfolderinfo=new MEActivityFolderInfo[1];
Activityfolderinfo[0]=new MEActivityFolderInfo();
Activityfolderinfo[0].activity=rootactivityLineObject;//Root Activity
Activityfolderinfo[0].contents=new WorkspaceObject[]{(WorkspaceObject)createObjectsActivity.output[0].objects[0]}; //MEActivity object

dataManagementService.createOrUpdateMEActivityFolders(Activityfolderinfo);

//Return the child line based on filter

 private BOMLine getchildlines(String filter_formattedtitletext,BOMLine topLineObject,com.teamcenter.services.strong.core.DataManagementService dataManagementService)
 {

  ModelObject[] allChildLines;

  try {

    dataManagementService.getProperties( new ModelObject[] { topLineObject }, new String[]{ "bl_child_lines" } );

   allChildLines = topLineObject.get_bl_child_lines();

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

    BOMLine bomLine = (BOMLine) allChildLines[i];
    dataManagementService.getProperties( new ModelObject[] { bomLine }, new String[]{ "bl_formatted_title" } );

    String formated_title = bomLine.get_bl_formatted_title();

    if ( formated_title.equalsIgnoreCase(filter_formattedtitletext))
    {
     return bomLine;
    }
    System.out.println( bomLine.get_bl_formatted_title() );
   }

  } catch (NotLoadedException e) {

   e.printStackTrace();
  }
  return null;
}

//provide Root activity and ActivityLine object
 
MEActivity activityLineObject;
MEActivity rootactivityLineObject;

private void getAttachmentLines( BOMLine bopLine, Connection connection ) throws NotLoadedException
 {
  Mfg0BvrOperation mfg0BVROperation = (Mfg0BvrOperation)bopLine;

  DataManagementService dataManagementService = DataManagementService.getService( connection );
  dataManagementService.getProperties( new ModelObject[] { bopLine }, new String[]{ "bl_me_activity_lines" } );

  CfgActivityLine activityLine = (CfgActivityLine) mfg0BVROperation.get_bl_me_activity_lines();

  dataManagementService.getProperties( new ModelObject[] { activityLine }, new String[]{ "me_cl_object_name","me_cl_object_desc","me_cl_source" } );
  rootactivityLineObject=(MEActivity) activityLine.get_me_cl_source();
  dataManagementService.getProperties( new ModelObject[] { activityLine }, new String[]{ "me_cl_child_lines" } );
  ModelObject[] activityContents = activityLine.get_me_cl_child_lines();

  for ( int i = 0; i < activityContents.length; i++ )
  {
    CfgActivityLine cfgActivityLine =  (CfgActivityLine) activityContents[0];
    dataManagementService.getProperties( new ModelObject[] { cfgActivityLine }, new String[]{ "me_cl_object_name","me_cl_object_desc","me_cl_source" } );
    activityLineObject = (MEActivity) cfgActivityLine.get_me_cl_source();
    System.out.println("Activity Object Name ="+cfgActivityLine.get_me_cl_object_name());
    System.out.println("Activity Object Desc ="+cfgActivityLine.get_me_cl_object_desc());
  }
}

No comments:

Post a Comment