Teamcenter SOA Service : WorkFlow Submit And Complete with Form Attribute Modifcation

本文详细介绍了一种在Teamcenter环境中实现工作流自动化的方法,包括初始化工作流、提供输入及完成工作流的具体步骤。通过代码示例展示了如何使用Java进行工作流的创建、更新和完成操作,特别关注了附件管理和任务状态更新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem statement :

1) Initiate the workflow 
2) Interact with workflow to provide the input
3) Complete the workflow
At the end of this section you will be able to deal with workflow related activities in Teamcenter

Visual of what we wanted through code ...

String item_uid="E_Sh3sWzY95QJC#ABSEP#EuRh3sWzY95QJC#ABSEP#01fh3sWzY95QJC#ABSEP#0lUh3sWzY95QJC";

String[] arrObjectUID = item_uid.split("#ABSEP#");
int[] arrTypes = new int[arrObjectUID.length];
Arrays.fill(arrTypes, 1);
arrTypes[arrObjectUID.length-1]=3;//Reference Attachement

//One to One Relation between attachment and attachment types
//attachment type=1 //Target attachmetn
//attachment type=3 //Reference attachment
//Above statement says that last object defined in the item_uid string is attached in the workflow as //reference attachment

WorkflowService wfService = WorkflowService.getService(connection);

if(wfService==null)
{
  System.out.println("Unable to find WorkflowService.please try again");
}
//DataManagementService smService = DataManagementService.getService(connection);
for(int i=0;i<arrObjectUID.length;i++)
{
   System.out.println("arrObjectUID["+i+"]="+arrObjectUID[i]);
}
for(int i=0;i<arrTypes.length;i++)
{
   System.out.println("arrTypes["+i+"]="+arrTypes[i]);
}
ContextData contextData = new ContextData();
contextData.attachmentCount = arrObjectUID.length;
contextData.attachments = arrObjectUID;
contextData.attachmentTypes = arrTypes;
contextData.processTemplate = "Create XYZ Report";//"Simple Release";

System.out.println("Context data initialized");
InstanceInfo instanceResponse = wfService.createInstance(true, null, "TestGENERATION", null,"GENERATION DESC", contextData);
if(instanceResponse.serviceData.sizeOfPartialErrors() == 0)
   System.out.println("Process created Successfully");
else
{
  System.out.println("Error :"+instanceResponse.serviceData.getPartialError(0).getMessages());
  System.out.println("Error :"+instanceResponse.serviceData.getPartialError(0).getErrorValues());
}
ModelObject taskobject=instanceResponse.serviceData.getCreatedObject(0);
System.out.println("Task Object = "+taskobject.getClass());
DataManagementService dmServiceTI = DataManagementService.getService(connection);
Folder userinbox;
try
{
  String[] attributes = { "contents","object_name" };
  userinbox = (Folder)user.get_userinbox();//Get Inbox for User
  dmServiceTI.getProperties( new ModelObject[]{ userinbox }, attributes );
  //userinbox.get_contents();
  System.out.println("userinbox = "+userinbox);
  System.out.println("userinbox = "+userinbox.get_object_name());
  WorkspaceObject[] contents = null;
  WorkspaceObject UserInboxFolderList[]=null;
  WorkspaceObject[] tasks_to_perform=null;
 
  EPMTask epmtasks[]=null;
  ModelObject targetattachment[]=null;
  ModelObject referenceattachment[]=null;

  contents = userinbox.get_contents();//Get the Actual Inbox for user which we see in My Worklist
  dmServiceTI.getProperties( contents, attributes );
  for ( WorkspaceObject folder : contents )
  {
    System.out.println("Folder Name = " +folder.get_object_name());
    System.out.println("Folder Name = " +folder.getClass());
    TaskInbox taskinbox = ( TaskInbox )folder;
    dmServiceTI.getProperties( new ModelObject[] { taskinbox }, new String[]{ "tasks_to_perform" } );
 
    tasks_to_perform = taskinbox.get_tasks_to_perform();
    EPMDoTask dotask=(EPMDoTask) tasks_to_perform[0];
    dmServiceTI.getProperties( new ModelObject[]{dotask}, new String[]{ "root_target_attachments" } );
    targetattachment = dotask.get_root_target_attachments();

    for( ModelObject attachment : targetattachment )
    {

     if ( attachment instanceof Form )
      {
       HashMap hmformupdateattr = new HashMap();
       hmformupdateattr.put("rr_report_type", new String[]{ "RR Technical Instruction (PDF)" } );

       FormInfo[] inputsTIGenForm = new FormInfo[1];
       inputsTIGenForm[0] = new FormInfo();
       inputsTIGenForm[0].formObject = attachment;
       inputsTIGenForm[0].attributesMap = hmformupdateattr;
       inputsTIGenForm[0].saveDB = true;
       inputsTIGenForm[0].formType = "RR_CMEReports_Form";

       CreateOrUpdateFormsResponse response = dmServiceTI.createOrUpdateForms(inputsTIGenForm);

       processServiceDataForPartialErrors(response.serviceData);
       try {
       
       wfService.performAction(dotask , "SOA_EPM_complete_action" , ""  , null , "SOA_EPM_completed" , null );

       } catch (ServiceException e) {

        // TODO Auto-generated catch block

        e.printStackTrace();

      }
     }
    }
   }

 }
 catch (NotLoadedException e1)
 {
   e1.printStackTrace();
 }

ANOTHER WAY

SessionService service2 = SessionService.getService( connection );

ObjectPropertyPolicy objPropPolicy = new ObjectPropertyPolicy();
PolicyType policyType = new PolicyType( "EPMTask", new String[]{ "real_state", "object_name", "parent_task" } );
objPropPolicy.addType( policyType );
service2.setObjectPropertyPolicy( objPropPolicy );

DataManagementService dmServiceTI = DataManagementService.getService(connection);
ModelObject targetattachment[]=null;

System.out.println("Inside submit_to_workflow");
String item_uid="E_Sh3sWzY95QJC#ABSEP#EuRh3sWzY95QJC#ABSEP#01fh3sWzY95QJC#ABSEP#0lUh3sWzY95QJC";

String[] arrObjectUID = item_uid.split("#ABSEP#");
int[] arrTypes = new int[arrObjectUID.length];
Arrays.fill(arrTypes, 1);
arrTypes[arrObjectUID.length-1] = 3;//Reference Attachement
WorkflowService wfService = WorkflowService.getService(connection);

if(wfService==null)
{
  System.out.println("Unable to find WorkflowService.please try again");
}
//DataManagementService smService = DataManagementService.getService(connection);
for(int i=0;i<arrObjectUID.length;i++)
{
   System.out.println("arrObjectUID["+i+"]="+arrObjectUID[i]);
}
for(int i=0;i<arrTypes.length;i++)
{
   System.out.println("arrTypes["+i+"]="+arrTypes[i]);
}
ContextData contextData = new ContextData();
contextData.attachmentCount = arrObjectUID.length;
contextData.attachments = arrObjectUID;
contextData.attachmentTypes = arrTypes;
contextData.processTemplate = "Create XYZ Report";//"Simple Release";
System.out.println("Context data initialized");
InstanceInfo instanceResponse = wfService.createInstance(true, null, "TestGENERATION", null,"GENERATION DESC", contextData);

EPMTask taskToForward = null;
if(instanceResponse.serviceData.sizeOfPartialErrors() == 0)
{
  System.out.println("Process created Successfully");
  int sizeOfUpdatedObjects = instanceResponse.serviceData.sizeOfUpdatedObjects();
  for (int i = 0; i < sizeOfUpdatedObjects; i++)
  {
     ModelObject updatedObject = instanceResponse.serviceData.getUpdatedObject( i );
     try
     {
      if ( updatedObject instanceof EPMTask )
      {

       String sName = updatedObject.getPropertyObject( "object_name" ).getStringValue();
       String sParent = updatedObject.getPropertyObject( "parent_task" ).getDisplayableValue();

       if ( sName.equalsIgnoreCase( "Select Report Type" )

         && sParent.equalsIgnoreCase( "Select CAPP Report Type for Op" ) )
       {
        taskToForward = (EPMTask) updatedObject;
        System.out.println( "taskToForward.get_real_state() - " + taskToForward.get_real_state() );
        break;
      }
     }
   }
   catch (NotLoadedException e) {

      // TODO Auto-generated catch block

      e.printStackTrace();

  }
 }
}
else
{
       System.out.println("Error :"+instanceResponse.serviceData.getPartialError(0).getMessages());
       System.out.println("Error :"+instanceResponse.serviceData.getPartialError(0).getErrorValues());

}
try
{
    Job wrkjob=(Job) instanceResponse.serviceData.getCreatedObject(0);
    EPMTask root_task=null;
    dmServiceTI.getProperties( new ModelObject[]{wrkjob}, new String[]{ "root_task" } );
    root_task = wrkjob.get_root_task();
    dmServiceTI.getProperties( new ModelObject[]{root_task}, new String[]{ "target_attachments" } );
    targetattachment=root_task.get_target_attachments();

     for( ModelObject attachment : targetattachment )
     {//Here We are going to update the form
      if ( attachment instanceof Form )
      {
       HashMap hmformupdateattr = new HashMap();
       //LOV type attribute
       hmformupdateattr.put("rr_report_type", new String[]{ "RR Technical Instruction (PDF)" } );
       
       FormInfo[] inputsTIGenForm = new FormInfo[1];
       inputsTIGenForm[0] = new FormInfo();
       inputsTIGenForm[0].formObject = attachment;
       inputsTIGenForm[0].attributesMap = hmformupdateattr;
       inputsTIGenForm[0].saveDB = true;
       inputsTIGenForm[0].formType = "RR_CMEReports_Form";

       CreateOrUpdateFormsResponse response = dmServiceTI.createOrUpdateForms(inputsTIGenForm);
       processServiceDataForPartialErrors(response.serviceData);

       //dmServiceTI.refreshObjects( new ModelObject[]{ taskToForward } );
       System.out.println( "taskToForward.get_real_state() - " + taskToForward.get_real_state() );
       //Here we are going to complete the task using api
       ServiceData performAction = wfService.performAction( taskToForward, "SOA_EPM_complete_action" , ""  , null , "SOA_EPM_completed" , null );
       System.out.println( performAction );

      }
     }
 }
 catch (NotLoadedException e2)
 {
   // TODO Auto-generated catch block
   e2.printStackTrace();
  }
  catch (ServiceException e)
  {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值