NX How to determine if a part is checked out and by who using SOA

2021-10-06T23:26:12Z
NX for Design

Summary


Details

Is there a C++ example on how to use Teamcenter::Services::Core::ReservationService? 



Solution

Following is a SOA client C++ example in how to use the 
Teamcenter::Services::Core::ReservationService.


First is the header file followed by the C++ file. 


#pragma once


#include <vector> 
#include <string> 
#include <teamcenter/soa/common/autoptr.hxx>


// forward class declarations 
namespace Teamcenter 

 namespace Services 
 { 
 namespace Core 
 { 
 class ReservationService; 
 } 
 } 
 namespace Soa 
 { 
 namespace Client 
 { 
 namespace Model 
 { 
 class User; 
 class Folder; 
 class Item; 
 class ItemRevision; 
 }


 class ModelObject; 
 class ServiceData; 
 } 
 } 
}


class CheckInOut 

public: 
 CheckInOut();


 bool okToCheckOut(const 
Teamcenter::Soa::Common::AutoPtr<Teamcenter::Soa::Client::ModelObject>& obj); 
 bool okToCheckOut(const 
std::vector<Teamcenter::Soa::Common::AutoPtr<Teamcenter::Soa::Client::ModelObje 
ct>>& objList);


 bool checkOut(const 
Teamcenter::Soa::Common::AutoPtr<Teamcenter::Soa::Client::ModelObject>& obj, 
const std::string& comment, const std::string& changeID); 
 bool checkOut(const 
std::vector<Teamcenter::Soa::Common::AutoPtr<Teamcenter::Soa::Client::ModelObje 
ct>>& objList, const std::string& comment, const std::string& changeID);


 bool checkIn(const 
Teamcenter::Soa::Common::AutoPtr<Teamcenter::Soa::Client::ModelObject>& obj); 
 bool checkIn(const 
std::vector<Teamcenter::Soa::Common::AutoPtr<Teamcenter::Soa::Client::ModelObje 
ct>>& objList);


 bool cancelCheckout(const 
Teamcenter::Soa::Common::AutoPtr<Teamcenter::Soa::Client::ModelObject>& obj); 
 bool cancelCheckout(const 
std::vector<Teamcenter::Soa::Common::AutoPtr<Teamcenter::Soa::Client::ModelObje 
ct>>& objList);


protected: 
 bool ServiceDataError(const Teamcenter::Soa::Client::ServiceData& data);


private:


 Teamcenter::Services::Core::ReservationService* rvService; 
};


#include <teamcenter/hello/CheckInOut.h> 
#include <teamcenter/clientx/AppXSession.hxx>


#include <iostream>


#include <teamcenter/services/core/ReservationService.hxx>


using namespace std; 
using namespace Teamcenter::ClientX; 
using namespace Teamcenter::Soa::Client; 
using namespace Teamcenter::Soa::Client::Model; 
using namespace Teamcenter::Services::Core; 
using namespace Teamcenter::Soa::Common; 
using namespace Teamcenter::Services::Core::_2011_06;


CheckInOut::CheckInOut() 

 rvService = 
Teamcenter::Services::Core::ReservationService::getService(AppXSession::getConn 
ection()); 
}


bool CheckInOut::okToCheckOut(const AutoPtr<ModelObject>& obj) 

 vector<AutoPtr<ModelObject>> list;


 list.push_back(obj); 
 Reservation::OkToCheckoutResponse resp = rvService->okToCheckout(list);


 return ServiceDataError(resp.serviceData); 
}


bool CheckInOut::okToCheckOut(const vector<AutoPtr<ModelObject>>& objList) 

 Reservation::OkToCheckoutResponse resp = rvService->okToCheckout(objList);


 return ServiceDataError(resp.serviceData); 
}


bool CheckInOut::checkOut(const AutoPtr<ModelObject>& obj, const string& 
comment, const string& changeID) 

 vector<AutoPtr<ModelObject>> list;


 list.push_back(obj); 
 ServiceData sData = rvService->checkout(list, comment, changeID);


 return ServiceDataError(sData); 
}


bool CheckInOut::checkOut(const vector<AutoPtr<ModelObject>>& objList, const 
string& comment, const string& changeID) 

 ServiceData sData = rvService->checkout(objList, comment, changeID);


 return ServiceDataError(sData); 
}


bool CheckInOut::checkIn(const AutoPtr<ModelObject>& obj) 

 vector<AutoPtr<ModelObject>> list;


 list.push_back(obj); 
 ServiceData sData = rvService->checkin(list);


 return ServiceDataError(sData); 
}


bool CheckInOut::checkIn(const vector<AutoPtr<ModelObject>>& objList) 

 ServiceData sData = rvService->checkin(objList);


 return ServiceDataError(sData); 
}


bool CheckInOut::cancelCheckout(const AutoPtr<ModelObject>& obj) 

 vector<AutoPtr<ModelObject>> list;


 list.push_back(obj); 
 ServiceData sData = rvService->cancelCheckout(list);


 return ServiceDataError(sData); 
}


bool CheckInOut::cancelCheckout(const vector<AutoPtr<ModelObject>>& objList) 

 ServiceData sData = rvService->cancelCheckout(objList);


 return ServiceDataError(sData); 
}


bool CheckInOut::ServiceDataError(const ServiceData& data) 

 ErrorStackVector errors = data.getPartialErrors();


 if(!errors.empty()) 
 { 
 for(size_t i = 0; i < errors.size(); i++) 
 { 
 for(int ii = 0; ii < errors[i].getErrorValueCount(); ii++) 
 { 
 const ErrorValue& error = errors[i].getErrorValue(ii); 
 cout << "Code: " << error.code << " - " << error.message << endl; 
 } 
 } 
 
 return true; 
 } 
 
 return false; 




Notes and References





Hardware/Software Configuration

Platform: INTEL
OS: window
OS Version: 864
Product: NX
Application: NXMANAGER
Version: V10.0
Function: UGOPEN

Ref: 001-9038339

KB Article ID# PL8003169

Contents

SummaryDetails

Associated Components

Teamcenter Integration for NX