Sample Teamcenter SOA Java program : CreateOrUpdateBOMStructure

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();

}

}

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

}

posted @   张永全-PLM顾问  阅读(19)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示