首页 > 编程语言 >Sample Teamcenter SOA Java program : CreateOrUpdateBOMStructure

Sample Teamcenter SOA Java program : CreateOrUpdateBOMStructure

时间:2025-01-17 12:12:29浏览次数:1  
标签:SOA relStructInfos Java StructureManagementService creInfos Sample new childInfo

Sample Teamcenter SOA Java program : CreateOrUpdateBOMStructure

 

 

Solution

/* This example was tested with the SOA Java HelloTeamcenter example provided in the soa_client.zip file.

It assumes you have the HelloTeamcenter example working correctly. 

This example will demonstrate how to create a Part and BOM structure.

Add the following library to the project :TcSoaCadStrong_*.jar

Add the following code the the Hello.java to call/use the custom java code.

---------------------------------------------------------------

CreateOrUpdateBOMStructure cub = new CreateOrUpdateBOMStructure(loginResponse.user);

cub.createParts();

cub.createStructure();

------------------------------------------------------------ */

// CreateOrUpdateBOMStructure cub = new CreateOrUpdateBOMStructure(loginResponse.user);

// cub.createParts();

// cub.createStructure();

package com.gtac.bom;

import java.util.Calendar;

import com.gtac.clientx.AppXSession;

import com.teamcenter.schemas.soa._2006_03.exceptions.ServiceException;

import com.teamcenter.services.strong.cad.StructureManagementService;

import com.teamcenter.services.strong.core.ReservationService;

import com.teamcenter.services.strong.cad._2008_03.DataManagement.PartInfo3;

import com.teamcenter.services.strong.cad._2007_01.DataManagement.CreateOrUpdatePartsOutput;

import com.teamcenter.services.strong.cad._2007_01.DataManagement.DatasetOutput;

import com.teamcenter.services.strong.cad._2007_01.DataManagement.ItemInfo;

import com.teamcenter.services.strong.cad._2007_01.DataManagement.ItemRevInfo;

import com.teamcenter.services.strong.cad._2007_01.StructureManagement.RelOccInfo;

import com.teamcenter.services.strong.cad._2008_03.DataManagement.DatasetInfo3;

import com.teamcenter.services.strong.cad._2007_12.DataManagement.CreateOrUpdatePartsPref;

import com.teamcenter.services.strong.cad._2007_01.DataManagement.CreateOrUpdatePartsResponse;

import com.teamcenter.soa.client.model.ModelObject;

import com.teamcenter.soa.client.model.ServiceData;

import com.teamcenter.soa.client.model.strong.Dataset;

import com.teamcenter.soa.client.model.strong.Folder;

import com.teamcenter.soa.client.model.strong.ItemRevision;

import com.teamcenter.soa.client.model.strong.PSBOMViewRevision;

import com.teamcenter.soa.client.model.strong.User;

import com.teamcenter.soa.exceptions.NotLoadedException;

public class CreateOrUpdateBOMStructure {

private com.teamcenter.services.strong.core.DataManagementService dmService;

private com.teamcenter.services.strong.cad.DataManagementService cadDmService;

private StructureManagementService structureService;

private ReservationService reservationService;

private Folder newstuffFolder;

private ItemRevision absOccAsmItemRev = null;

private ItemRevision plateAsmItemRev = null;

private ItemRevision plateItemRev = null;

private Dataset plateDataset = null;

private Dataset plateHoleDateset = null;

/**************************************************************************/

public CreateOrUpdateBOMStructure(User user)

{

dmService = com.teamcenter.services.strong.core.DataManagementService.getService(AppXSession.getConnection());

cadDmService = com.teamcenter.services.strong.cad.DataManagementService.getService(AppXSession.getConnection());

structureService = StructureManagementService.getService(AppXSession.getConnection());

reservationService = ReservationService.getService(AppXSession.getConnection());

try

{

newstuffFolder = user.get_newstuff_folder();

}

catch(NotLoadedException e)

{

e.printStackTrace();

}

}

/**************************************************************************/

public boolean createParts()

{

PartInfo3[] creInfos = new PartInfo3[3];

creInfos[0] = new PartInfo3();

creInfos[0].itemInput = new ItemInfo();

creInfos[0].clientId = "AbsOccAssembly";

creInfos[0].itemInput.name = "Abs Occ Assembly";

creInfos[0].itemInput.folder = newstuffFolder;

creInfos[0].itemRevInput = new ItemRevInfo();

creInfos[1] = new PartInfo3();

creInfos[1].itemInput = new ItemInfo();

creInfos[1].clientId = "PlateAssembly";

creInfos[1].itemInput.name = "Plate Assembly";

creInfos[1].itemInput.folder = newstuffFolder;

creInfos[1].itemRevInput = new ItemRevInfo();

creInfos[2] = new PartInfo3();

creInfos[2].itemInput = new ItemInfo();

creInfos[2].clientId = "Plate";

creInfos[2].itemInput.name = "Plate";

creInfos[2].itemInput.folder = newstuffFolder;

creInfos[2].itemRevInput = new ItemRevInfo();

creInfos[2].datasetInput = new DatasetInfo3[2];

creInfos[2].datasetInput[0] = new DatasetInfo3();

creInfos[2].datasetInput[0].clientId = "PlateDataset";

creInfos[2].datasetInput[0].name = "Plate";

creInfos[2].datasetInput[0].type = "DirectModel";

creInfos[2].datasetInput[0].itemRevRelationName = "IMAN_Rendering";

creInfos[2].datasetInput[0].description = "Plate";

creInfos[2].datasetInput[0].mapAttributesWithoutDataset = false;

creInfos[2].datasetInput[0].lastModifiedOfDataset = Calendar.getInstance();

creInfos[2].datasetInput[1] = new DatasetInfo3();

creInfos[2].datasetInput[1].clientId = "PlateHoleDataset";

creInfos[2].datasetInput[1].name = "Plate with hole";

creInfos[2].datasetInput[1].type = "DirectModel";

creInfos[2].datasetInput[1].itemRevRelationName = "IMAN_reference";

creInfos[2].datasetInput[1].description = "Plate with hole";

creInfos[2].datasetInput[1].mapAttributesWithoutDataset = false;

creInfos[2].datasetInput[1].lastModifiedOfDataset = Calendar.getInstance();

CreateOrUpdatePartsResponse creResp = cadDmService.createOrUpdateParts(creInfos, new CreateOrUpdatePartsPref());

if(creInfos.length == creResp.output.length)

{

for(CreateOrUpdatePartsOutput partsOut : creResp.output)

{

if(partsOut.clientId.equals("AbsOccAssembly"))

absOccAsmItemRev = partsOut.itemRev;

else if(partsOut.clientId.equals("PlateAssembly"))

plateAsmItemRev = partsOut.itemRev;

else if(partsOut.clientId.equals("Plate"))

{

plateItemRev = partsOut.itemRev;

for(DatasetOutput datasetOut : partsOut.datasetOutput)

{

if(datasetOut.clientId.equals("PlateDataset"))

plateDataset = datasetOut.dataset;

else if(datasetOut.clientId.equals("PlateHoleDataset"))

plateHoleDateset = datasetOut.dataset;

else

return false;

}

}

else

return false;

}

return true;

}

return false;

}

/**************************************************************************/

public void createStructure()

{

if(absOccAsmItemRev == null || plateAsmItemRev == null

|| plateItemRev == null || plateDataset == null

|| plateHoleDateset == null)

return;

try

{

StructureManagementService.CreateOrUpdateRelativeStructureInfo2[] relStructInfos = new StructureManagementService.CreateOrUpdateRelativeStructureInfo2[2];

relStructInfos[0] = new StructureManagementService.CreateOrUpdateRelativeStructureInfo2();

relStructInfos[0].parent = plateAsmItemRev;

relStructInfos[0].precise = false;

relStructInfos[0].childInfo = new StructureManagementService.RelativeStructureChildInfo[2];

relStructInfos[0].childInfo[0] = new StructureManagementService.RelativeStructureChildInfo();

relStructInfos[0].childInfo[0].child = plateItemRev;

relStructInfos[0].childInfo[0].occInfo = new RelOccInfo();

relStructInfos[0].childInfo[0].occInfo.attrsToSet = new StructureManagementService.AttributesInfo[1];

relStructInfos[0].childInfo[0].occInfo.attrsToSet[0] = new StructureManagementService.AttributesInfo();

relStructInfos[0].childInfo[0].occInfo.attrsToSet[0].name = "bl_sequence_no";

relStructInfos[0].childInfo[0].occInfo.attrsToSet[0].value = "10";

relStructInfos[0].childInfo[0].occInfo.occTransform = new double[]{ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };

relStructInfos[0].childInfo[1] = new StructureManagementService.RelativeStructureChildInfo();

relStructInfos[0].childInfo[1].child = plateItemRev;

relStructInfos[0].childInfo[1].occInfo = new RelOccInfo();

relStructInfos[0].childInfo[1].occInfo.attrsToSet = new StructureManagementService.AttributesInfo[1];

relStructInfos[0].childInfo[1].occInfo.attrsToSet[0] = new StructureManagementService.AttributesInfo();

relStructInfos[0].childInfo[1].occInfo.attrsToSet[0].name = "bl_sequence_no";

relStructInfos[0].childInfo[1].occInfo.attrsToSet[0].value = "20";

relStructInfos[0].childInfo[1].occInfo.occTransform = new double[]{ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0.11, 0, 0, 1 };

relStructInfos[1] = new StructureManagementService.CreateOrUpdateRelativeStructureInfo2();

relStructInfos[1].parent = absOccAsmItemRev;

relStructInfos[1].precise = false;

relStructInfos[1].childInfo = new StructureManagementService.RelativeStructureChildInfo[1];

relStructInfos[1].childInfo[0] = new StructureManagementService.RelativeStructureChildInfo();

relStructInfos[1].childInfo[0].child = plateAsmItemRev;

relStructInfos[1].childInfo[0].occInfo = new RelOccInfo();

relStructInfos[1].childInfo[0].occInfo.attrsToSet = new StructureManagementService.AttributesInfo[1];

relStructInfos[1].childInfo[0].occInfo.attrsToSet[0] = new StructureManagementService.AttributesInfo();

relStructInfos[1].childInfo[0].occInfo.attrsToSet[0].name = "bl_sequence_no";

relStructInfos[1].childInfo[0].occInfo.attrsToSet[0].value = "10";

relStructInfos[1].childInfo[0].occInfo.occTransform = new double[]{ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };

StructureManagementService.CreateOrUpdateRelativeStructurePref2 relStructPref = new StructureManagementService.CreateOrUpdateRelativeStructurePref2();

com.teamcenter.services.strong.cad._2007_01.StructureManagement.CreateOrUpdateRelativeStructureResponse relStructResp2 = structureService.createOrUpdateRelativeStructure(relStructInfos, "", true, relStructPref);

if(checkOutAsmBVR())

{

StructureManagementService.CreateOrUpdateAbsoluteStructurePref2 absStructPref = new StructureManagementService.CreateOrUpdateAbsoluteStructurePref2();

absStructPref.cadOccIdAttrName = "bl_sequence_no";

StructureManagementService.CreateOrUpdateAbsoluteStructureInfo2[] absStructInfos = new StructureManagementService.CreateOrUpdateAbsoluteStructureInfo2[1];

absStructInfos[0] = new StructureManagementService.CreateOrUpdateAbsoluteStructureInfo2();

absStructInfos[0].contextItemRev = absOccAsmItemRev;

absStructInfos[0].bvrAbsOccInfo = new StructureManagementService.AbsOccInfo[1];

absStructInfos[0].bvrAbsOccInfo[0] = new StructureManagementService.AbsOccInfo();

absStructInfos[0].bvrAbsOccInfo[0].cadOccIdPath = new String[]{ "10", "10" };

absStructInfos[0].bvrAbsOccInfo[0].absOccData = new StructureManagementService.AbsOccDataInfo();

absStructInfos[0].bvrAbsOccInfo[0].absOccData.attachments = new StructureManagementService.AbsOccAttachment[1];

absStructInfos[0].bvrAbsOccInfo[0].absOccData.attachments[0] = new StructureManagementService.AbsOccAttachment();

absStructInfos[0].bvrAbsOccInfo[0].absOccData.attachments[0].dataset = plateDataset;

absStructInfos[0].bvrAbsOccInfo[0].absOccData.attachments[0].relationTypeName = "IMAN_Rendering";

absStructInfos[0].bvrAbsOccInfo[0].absOccData.occTransform = new double[]{ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0.11, 0, 1 };

StructureManagementService.CreateOrUpdateAbsoluteStructureResponse absStructResp = structureService.createOrUpdateAbsoluteStructure(absStructInfos, "", true, absStructPref);

StructureManagementService.CreateOrUpdateAbsoluteStructureInfo2[] absStructInfos2 = new StructureManagementService.CreateOrUpdateAbsoluteStructureInfo2[1];

absStructInfos2[0] = new StructureManagementService.CreateOrUpdateAbsoluteStructureInfo2();

absStructInfos2[0].contextItemRev = absOccAsmItemRev;

absStructInfos2[0].bvrAbsOccInfo = new StructureManagementService.AbsOccInfo[1];

absStructInfos2[0].bvrAbsOccInfo[0] = new StructureManagementService.AbsOccInfo();

absStructInfos2[0].bvrAbsOccInfo[0].cadOccIdPath = new String[]{ "10", "20" };

absStructInfos2[0].bvrAbsOccInfo[0].absOccData = new StructureManagementService.AbsOccDataInfo();

absStructInfos2[0].bvrAbsOccInfo[0].absOccData.attachments = new StructureManagementService.AbsOccAttachment[1];

absStructInfos2[0].bvrAbsOccInfo[0].absOccData.attachments[0] = new StructureManagementService.AbsOccAttachment();

absStructInfos2[0].bvrAbsOccInfo[0].absOccData.attachments[0].dataset = plateHoleDateset;

absStructInfos2[0].bvrAbsOccInfo[0].absOccData.attachments[0].relationTypeName = "IMAN_reference";

absStructInfos2[0].bvrAbsOccInfo[0].absOccData.occTransform = new double[]{ 1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0.11, 0, 0, 1 };

StructureManagementService.CreateOrUpdateAbsoluteStructureResponse absStructResp2 = structureService.createOrUpdateAbsoluteStructure(absStructInfos2, "", true, absStructPref);

checkInAsmBVR();

}

else

System.out.println("Error: Unable to check out absOccAsmItemRev");

}

catch(ServiceException e)

{

e.printStackTrace();

}

}

/**************************************************************************/

protected boolean checkOutAsmBVR()

{

dmService.getProperties(new ModelObject[]{ absOccAsmItemRev }, new String[]{ "structure_revisions" });

try

{

PSBOMViewRevision[] absOccAsmBVRs = absOccAsmItemRev.get_structure_revisions();

if(absOccAsmBVRs.length > 0)

{

ServiceData sd = reservationService.checkout(absOccAsmBVRs, "CheckOut for createOrUpdateAbsoluteStructure", "");

if(sd.sizeOfUpdatedObjects() > 0)

return true;

}

}

catch(NotLoadedException e)

{

e.printStackTrace();

}

return false;

}

/**************************************************************************/

protected void checkInAsmBVR()

{

try

{

PSBOMViewRevision[] absOccAsmBVRs = absOccAsmItemRev.get_structure_revisions();

if(absOccAsmBVRs.length > 0)

{

ServiceData sd = reservationService.checkin(absOccAsmBVRs);

}

}

catch(NotLoadedException e)

{

e.printStackTrace();

}

}

/**************************************************************************/

}

标签:SOA,relStructInfos,Java,StructureManagementService,creInfos,Sample,new,childInfo
From: https://www.cnblogs.com/PLM-Teamcenter/p/18676668

相关文章

  • 大数据学习记录,Java基础(6)
    集合Java集合框架体系Java集合可分为Collection和Map两种体系:Collection接口:单列数据,定义了存取一组对象的方法的集合List:元素有序、可重复的集合Set:元素无序、不可重复的集合Map接口:双列数据,保存具有映射关系“key-value对”的集合Collection接口的方法add......
  • 大数据学习记录,Java基础(5)
    常用类objectobject类是Java中所有类的共同父类Object类的方法1.toString()默认情况下,toString()返回的是“对象的运行时类型@对象的hashCode值的十六进制形式"如果我们直接System.out.println(对象),默认会自动调用这个对象的toString(),打印的是地址值可以根据需要在用......
  • 基于JAVA中的spring框架和jsp实现驾驶知识学习和评测系统项目【附项目源码+论文说明】
    摘要在21世纪这个信息高度发达,并且高速流通的时代,计算机的普及以及计算机网络技术的应用,让大量普通人能够有机会接触到比以往更多的知识。作为一个以传播知识为主要职能的机构——学校,建立一个自己的精品课程网站是十分必要的事情,这不仅能使更多的人享用宝贵的教育资料源,同时......
  • 大数据学习记录,Java基础(5)
    常用类objectobject类是Java中所有类的共同父类Object类的方法1.toString()默认情况下,toString()返回的是“对象的运行时类型@对象的hashCode值的十六进制形式"如果我们直接System.out.println(对象),默认会自动调用这个对象的toString(),打印的是地址值可以根据需要......
  • 大数据学习记录,Java基础(6)
    集合Java集合框架体系Java集合可分为Collection和Map两种体系:Collection接口:单列数据,定义了存取一组对象的方法的集合List:元素有序、可重复的集合Set:元素无序、不可重复的集合Map接口:双列数据,保存具有映射关系“key-value对”的集合Collection接口的方......
  • 基于JAVA中的spring框架和jsp实现大学生综合测评系统项目【内附项目源码+论文说明】
    摘要大学生综合测评系统是一款以大学生德智体等综合成绩进行评测的系统, 其开发基于B/S模式的网上评测的实现,采用的是JSP+sqlserver数据库为主要模式。在线评测平台是凌架于互联网系统上的一个评测平台,是地面评测系统的一种延伸和互补,也是实现无纸化评测的主要工具。当下在......
  • Java中String类常用的各种方法
    Java中String类常见的方法以下介绍字符串常见的几个方法。介绍String类在Java中,String类是一个代表字符串的类,具有以下特性:不可变性:String对象一旦被创建就是不可变的,即它们的值在创建后不能被更改。任何对String对象的修改操作实际上会创建一个新的String对象。......
  • Java百万数据导出Excel性能优化[读(并发)写分离/流式查询]
    参考:https://www.zhihu.com/tardis/bd/art/533753443?source_id=1001 Java百万数据导出Excel性能优化[读(并发)写分离/流式查询]结果测试:104万数据,导出excel用时由59秒优化到19秒问题列表:1、导出过程中会较多占用CPU、内存、磁盘,需全局对Excel导出限流,防止同时对大量数......
  • JAVA开源免费项目 基于Vue和SpringBoot的城镇保障性住房管理系统(附源码)
    本文项目编号T122,文末自助获取源码\color{red}{T122,文末自助获取源码}......
  • JAVA开源免费项目 基于Vue和SpringBoot的多维分类的知识管理系统(附源码)
    本文项目编号T121,文末自助获取源码\color{red}{T121,文末自助获取源码}......