private static void createECNObject() { // The create input for the ChangeNotice Item Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateInput itemCreateIn = new Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateInput(); itemCreateIn.BoName = "A9_AutoCN"; itemCreateIn.StringProps.Add("object_name", "Name of A9_AutoCN"); itemCreateIn.StringProps.Add("object_desc", "Description of A9_AutoCN"); // The create input for the ChangeNoticeRevision Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateInput revisionCreateIn = new Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateInput(); revisionCreateIn.BoName = "A9_AutoCNRevision"; //revisionCreateIn.StringProps.Add("item_revision_id", "A"); DateTime currentdate = DateTime.Now; DateTime SyncStartdate = new DateTime(currentdate.Year, currentdate.Month, currentdate.Day, currentdate.Hour, currentdate.Minute, currentdate.Second); String SyncStartdateStr = SyncStartdate.ToString("yyyyMMMddHHmmsssss"); //Calendar cal = Calendar..getInstance(); //cal.SetTime(new Date()); DateTime dateValue = Teamcenter.Soa.Client.Model.Property.ParseDate(currentdate.ToString()); revisionCreateIn.DateProps.Add("a9_EstImpDate", dateValue); // Tie the Revision CreateInput to the Item CreateInput itemCreateIn.CompoundCreateInput.Add("revision", new Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateInput[] { revisionCreateIn }); // The data for the createObjects call Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateIn cnCreateIn = new Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateIn(); cnCreateIn.ClientId = "Create ECN-10000"; cnCreateIn.Data = itemCreateIn; CreateResponse createResponse = dmService.CreateObjects(new Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateIn[] { cnCreateIn }); if (createResponse.ServiceData.sizeOfPartialErrors() > 0) { //logErrors(createResponse.serviceData); } else { //for (DataManagement.CreateOut createOut : createResponse.output) //{ // logger.info("Response for client ID " + createOut.clientId); // for (ModelObject modelObject : createOut.objects) // { // logger.info("Created Object " + modelObject.getTypeObject().getName() + " : " + modelObject.getUid()); // } //} } }
private CreateItemsOutput[] createECNItems(ItemIdsAndInitialRevisionIds[] itemIds, string itemType) // throws ServiceException { // Get the service stub DataManagementService dmService = DataManagementService.getService(Session.getConnection()); // Populate form type GetItemCreationRelatedInfoResponse relatedResponse = dmService.GetItemCreationRelatedInfo(itemType, null); String[] formTypes = new String[0]; if (relatedResponse.ServiceData.sizeOfPartialErrors() > 0) { throw new ServiceException("DataManagementService.getItemCretionRelatedInfo returned a partial error."); } formTypes = new String[relatedResponse.FormAttrs.Length]; for (int i = 0; i < relatedResponse.FormAttrs.Length; i++) { FormAttributesInfo attrInfo = relatedResponse.FormAttrs[i]; formTypes[i] = attrInfo.FormType; } ItemProperties[] itemProps = new ItemProperties[itemIds.Length]; for (int i = 0; i < itemIds.Length; i++) { CreateIn itemInput = new CreateIn(); itemInput.Data.BoName = "A9_AutoCN"; VecStruct PropValueVec1 = new VecStruct(); PropValueVec1.StringVec = new String[] { "Synopsis_name" }; itemInput.Data.StringProps.Add("object_name", PropValueVec1); CreateInput itemRevisionInput = new CreateInput(); itemRevisionInput.BoName = "A9_AutoCNRevision"; VecStruct PropValueVec2 = new VecStruct(); PropValueVec2.StringVec = new String[] { "test revision desc" }; itemRevisionInput.StringProps.Add("object_desc", PropValueVec2); DateTime currentdate = DateTime.Now; DateTime SyncStartdate = new DateTime(currentdate.Year, currentdate.Month, currentdate.Day, currentdate.Hour, currentdate.Minute, currentdate.Second); String SyncStartdateStr = SyncStartdate.ToString("yyyyMMMddHHmmsssss"); VecStruct PropValueVec4 = new VecStruct(); PropValueVec4.StringVec = new String[] { SyncStartdateStr }; itemRevisionInput.DateProps.Add("a9_EstImpDate", PropValueVec4); itemInput.Data.CompoundCreateInput.Add("revision", itemRevisionInput); CreateIn[] itemInputarray = new CreateIn[1]; itemInputarray[0] = itemInput; CreateResponse cresponse = dmService.CreateObjects(itemInputarray); if (cresponse.ServiceData.sizeOfPartialErrors() > 0) { throw new ServiceException("DataManagementService.CreateObjects returned a partial error." + cresponse.ServiceData.GetPartialError(0)); } //--------------------------------------------------------------------------------- //// Create form in cache for form property population //ModelObject[] forms = createForms(itemIds[i].NewItemId, formTypes[0], // itemIds[i].NewRevId, formTypes[1], // null, false); //ItemProperties itemProperty = new ItemProperties(); //itemProperty.ClientId = "AppX-Test"; //itemProperty.ItemId = itemIds[i].NewItemId; //itemProperty.RevId = itemIds[i].NewRevId; //itemProperty.Name = "AppX-Test"; //itemProperty.Type = itemType; //itemProperty.Description = "Test Item for the SOA AppX sample application."; //itemProperty.Uom = ""; //// Retrieve one of form attribute value from Item master form. //ServiceData serviceData = dmService.GetProperties(forms, new String[] { "project_id" }); //if (serviceData.sizeOfPartialErrors() > 0) // throw new ServiceException("DataManagementService.getProperties returned a partial error."); //Property property = null; //try //{ // property = forms[0].GetProperty("project_id"); //} //catch (NotLoadedException /*ex*/) { } //// Only if value is null, we set new value //if (property == null || property.StringValue == null || property.StringValue.Length == 0) //{ // itemProperty.ExtendedAttributes = new ExtendedAttributes[1]; // ExtendedAttributes theExtendedAttr = new ExtendedAttributes(); // theExtendedAttr.Attributes = new Hashtable(); // theExtendedAttr.ObjectType = formTypes[0]; // theExtendedAttr.Attributes["project_id"] = "project_id"; // itemProperty.ExtendedAttributes[0] = theExtendedAttr; //} //itemProps[i] = itemProperty; } //// ***************************** //// Execute the service operation //// ***************************** //CreateItemsResponse response = dmService.CreateItems(itemProps, null, ""); //// before control is returned the ChangedHandler will be called with //// newly created Item and ItemRevisions //// The AppXPartialErrorListener is logging the partial errors returned //// In this simple example if any partial errors occur we will throw a //// ServiceException //if (response.ServiceData.sizeOfPartialErrors() > 0) // throw new ServiceException("DataManagementService.createItems returned a partial error."); CreateItemsResponse response = null; return(response.Output); }
public static CreateObjectOutput CreateObjectinTCAndReturnTCItemIdAndRev(CreateObjectParameters[] createObjectParList, String ItemTypeName, String ItemRevisionName) { String item_id = ""; String revision_id = ""; InitializeProces(); // The create input for the ChangeNotice Item Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateInput itemCreateIn = new Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateInput(); itemCreateIn.BoName = ItemTypeName; //itemCreateIn.BoName = "A9_AutoCN"; // The create input for the ChangeNoticeRevision Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateInput revisionCreateIn = new Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateInput(); revisionCreateIn.BoName = ItemRevisionName; //revisionCreateIn.BoName = "A9_AutoCNRevision"; foreach (CreateObjectParameters createObjectPar in createObjectParList) { String propType = createObjectPar.propType; String propOn = createObjectPar.propOn; switch (propType.ToLower()) { case "string": if (propOn == "Item") { itemCreateIn.StringProps.Add(createObjectPar.propName, createObjectPar.propValue); } else { revisionCreateIn.StringProps.Add(createObjectPar.propName, createObjectPar.propValue); } break; case "date": DateTime dateValue = Teamcenter.Soa.Client.Model.Property.ParseDate(createObjectPar.propValue); if (propOn == "Item") { itemCreateIn.DateProps.Add(createObjectPar.propName, dateValue); } else { revisionCreateIn.DateProps.Add(createObjectPar.propName, dateValue); } break; } } // Tie the Revision CreateInput to the Item CreateInput itemCreateIn.CompoundCreateInput.Add("revision", new Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateInput[] { revisionCreateIn }); // The data for the createObjects call Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateIn cnCreateIn = new Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateIn(); cnCreateIn.ClientId = "One"; cnCreateIn.Data = itemCreateIn; CreateResponse createResponse = dmService.CreateObjects(new Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateIn[] { cnCreateIn }); if (createResponse.ServiceData.sizeOfPartialErrors() > 0) { //createResponse.ServiceData.; } else { //Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateOut[] createOut = createResponse.Output; foreach (Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateOut createOut in createResponse.Output) { //createOut.ClientId Console.WriteLine("Response for client ID " + createOut.ClientId); foreach (ModelObject modelObject in createOut.Objects) { //modelObject. //Console.WriteLine(); String[] uids = new String[1]; uids[0] = modelObject.Uid; ServiceData sd = dmService.LoadObjects(uids); ModelObject[] foundObjs = new ModelObject[sd.sizeOfPlainObjects()]; for (int k = 0; k < sd.sizeOfPlainObjects(); k++) { foundObjs[k] = sd.GetPlainObject(k); if (foundObjs[k].SoaType.ClassName == ItemRevisionName) { dmService.GetProperties(foundObjs, new String[] { "item_id" }); item_id = foundObjs[k].GetPropertyDisplayableValue("item_id"); dmService.GetProperties(foundObjs, new String[] { "item_revision_id" }); revision_id = foundObjs[k].GetPropertyDisplayableValue("item_revision_id"); } } } } } CreateObjectOutput createObjectOutput = new CreateObjectOutput(item_id, revision_id); return(createObjectOutput); }