// dial_ws_selection_imp.cxx // Define functions for the DIAL selection service. #include #include "../gsoap/dial_ws_selectionH.h" #include "dataset_util/XmlElement.h" #include "dataset_util/Text.h" #include "dataset_util/ThreadCredential.h" #include "dataset_catalog/GenericSelectionCatalog.h" #include "dial_ws/GsoapRegistry.h" #include "dial_ws/DialWs.h" #include "dial_webcat/register_catalog_web_pages.h" using std::string; using std::endl; using std::vector; using std::map; using dset::GenericSelectionCatalog; using dial::GsoapRegistry; using dial::DialWs; using namespace dial_ws_selection; extern SOAP_NMAC struct Namespace dial_ws_selection_namespaces[]; typedef GenericSelectionCatalog::Name Name; typedef GenericSelectionCatalog::NameList NameList; typedef GenericSelectionCatalog::Attributes Attributes; typedef map RepMap; typedef dial_ws_selection::dial__Attribute dial__Attribute; typedef vector AttributeList; //********************************************************************** // Helper functions. //********************************************************************** namespace { //********************************************************************** // Initialization. // This function is called when the service is started. int init() { return 0; } int init_http() { // Register web pages. dial::register_catalog_web_pages(); // Append to home page. Text hpi; string indent = "
  "; hpi.append("

This is a DIAL selection catalog service"); // Application selection catalog. if ( DialWs::web_page("application_selection").size() ) { hpi.append( "

Application selection catalog"); } // Task selection catalog. if ( DialWs::web_page("task_selection").size() ) { hpi.append( "

Task selection catalog"); } // Application selection catalog. if ( DialWs::web_page("dataset_selection").size() ) { hpi.append( "

Dataset selection catalog"); } DialWs::insert_home_page(hpi); return 0; } //********************************************************************** // Registration. // The "selection" service is associated with the listed // initialization function, gsoap server function and gsoap namespace. int dial_ws_sel_reg = dial::GsoapRegistry::insert( "selection", init, dial_ws_selection_serve, dial_ws_selection_namespaces ); int dial_ws__ereg = dial::GsoapRegistry::insert( "selection_http", init_http, GsoapRegistry::server("base"), GsoapRegistry::nspace("base") ); //********************************************************************** // Function to create and cache selection catalogs. GenericSelectionCatalog* findrep(string type, string conn) { static RepMap reps; string repname = type + " " + conn; RepMap::const_iterator irep = reps.find(repname); if ( irep != reps.end() ) { return irep->second; } DialWs::lout() << "Establishing new connection" << endl; DialWs::lout() << " Type: " << type << endl; DialWs::lout() << " Conn: " << conn << endl; GenericSelectionCatalog* pcat = GenericSelectionCatalog::create(type, conn); if ( pcat == 0 ) { DialWs::lout() << "Unable to find catalog" << endl; } else { reps[repname] = pcat; } return pcat; } } // end unnamed namespace //********************************************************************** // Common server functions. //********************************************************************** // Validity. int dial_ws_selection::dial__is_valid(soap*, bool& stat) { DialWs::lout() << ">>>Received service validity request " << endl; DialWs::lout() << "Return true" << endl; stat = true; return SOAP_OK; } //********************************************************************** // Termination. int dial_ws_selection::dial__terminate(soap* psoap, int& stat) { DialWs::lout() << ">>>Received request for termination " << endl; const char* emsg1 = "Error in DIAL terminate request"; // Check authorization. if ( ThreadCredential().owner() == "" ) { return soap_sender_fault(psoap, emsg1, "Credential owner not defined."); } DialWs::terminate() = true; stat = 0; return SOAP_OK; } //********************************************************************** // Local server functions. //********************************************************************** // Validity. int dial_ws_selection:: dial__selection_is_valid(soap*, string type, string conn, bool& stat) { DialWs::lout() << ">>>Received catalog validity request" << endl; DialWs::lout() << "Type: " << type << endl; DialWs::lout() << "Connection: " << conn << endl; GenericSelectionCatalog* pcat = findrep(type, conn); if ( pcat == 0 ) { stat = false; } else { DialWs::lout() << "Checking catalog validity" << endl; stat = pcat->is_valid(); } if ( stat ) { DialWs::lout() << "Return true" << endl; } else { DialWs::lout() << "Return false" << endl; } return SOAP_OK; } //********************************************************************** // ID encoding. int dial_ws_selection::dial__selection_id_encoding( soap* psoap, string type, string conn, string& msg) { DialWs::lout() << ">>>Received ID encoding request" << endl; DialWs::lout() << "Type: " << type << endl; DialWs::lout() << "Connection: " << conn << endl; const char* emsg1 = "Error in DIAL ID encoding request"; GenericSelectionCatalog* pcat = findrep(type, conn); if ( pcat == 0 ) { return soap_receiver_fault(psoap, emsg1, "Unknown catalog"); } msg = pcat->id_encoding(); DialWs::lout() << "Response is " << msg << endl; return SOAP_OK; } //********************************************************************** // Schema. int dial_ws_selection::dial__selection_schema( soap* psoap, string type, string conn, dial__StringVectorResponse& sch) { DialWs::lout() << ">>>Received schema request" << endl; DialWs::lout() << "Type: " << type << endl; DialWs::lout() << "Connection: " << conn << endl; const char* emsg1 = "Error in DIAL ID encoding request"; GenericSelectionCatalog* pcat = findrep(type, conn); if ( pcat == 0 ) { return soap_receiver_fault(psoap, emsg1, "Unknown catalog"); } static NameList cols; cols = pcat->schema(); sch.pvec = &cols; DialWs::lout() << "Field count is " << cols.size() << endl; return SOAP_OK; } //********************************************************************** // Has name. int dial_ws_selection::dial__selection_has_name( soap* psoap, string type, string conn, string name, bool& res) { DialWs::lout() << ">>>Received request for has name" << endl; DialWs::lout() << "Type: " << type << endl; DialWs::lout() << "Connection: " << conn << endl; DialWs::lout() << "Name: " << name << endl; const char* emsg1 = "Error in DIAL ID encoding request"; GenericSelectionCatalog* pcat = findrep(type, conn); if ( pcat == 0 ) { return soap_receiver_fault(psoap, emsg1, "Unknown catalog"); } res = pcat->has_name(name); if ( res ) { DialWs::lout() << "Response is true" << endl; } else { DialWs::lout() << "Response is false" << endl; } return SOAP_OK; } //********************************************************************** // Attributes. int dial_ws_selection::dial__selection_attributes( soap* psoap, string type, string conn, string name, dial__AttributeVectorResponse& ratts) { DialWs::lout() << ">>>Received request for attributes" << endl; DialWs::lout() << "Type: " << type << endl; DialWs::lout() << "Connection: " << conn << endl; DialWs::lout() << "Name: " << name << endl; const char* emsg1 = "Error in DIAL ID encoding request"; GenericSelectionCatalog* pcat = findrep(type, conn); if ( pcat == 0 ) { return soap_receiver_fault(psoap, emsg1, "Unknown catalog"); } Attributes atts = pcat->attributes(name); static AttributeList vatts; vatts = AttributeList(atts.size()); size_t ivatt = 0; for ( Attributes::const_iterator iatt=atts.begin(); iatt!=atts.end(); ++iatt ) { vatts[ivatt].name = iatt->first; vatts[ivatt].value = iatt->second; ++ivatt; } ratts.pvec = &vatts; DialWs::lout() << "Field count is " << atts.size() << endl; return SOAP_OK; } //********************************************************************** // ID. int dial_ws_selection::dial__selection_id( soap* psoap, string type, string conn, string name, string& sid) { DialWs::lout() << ">>>Received ID request" << endl; DialWs::lout() << "Type: " << type << endl; DialWs::lout() << "Connection: " << conn << endl; DialWs::lout() << "Name: " << name << endl; const char* emsg1 = "Error in DIAL ID encoding request"; GenericSelectionCatalog* pcat = findrep(type, conn); if ( pcat == 0 ) { return soap_receiver_fault(psoap, emsg1, "Unknown catalog"); } sid = pcat->id(name); DialWs::lout() << "Response is " << sid << endl; return SOAP_OK; } //********************************************************************** // Size. int dial_ws_selection::dial__selection_size( soap* psoap, string type, string conn, int& res) { DialWs::lout() << ">>>Received size request" << endl; DialWs::lout() << "Type: " << type << endl; DialWs::lout() << "Connection: " << conn << endl; const char* emsg1 = "Error in DIAL ID encoding request"; GenericSelectionCatalog* pcat = findrep(type, conn); if ( pcat == 0 ) { return soap_receiver_fault(psoap, emsg1, "Unknown catalog"); } res = pcat->size(); DialWs::lout() << "Size is " << res << endl; return SOAP_OK; } //********************************************************************** // Query. int dial_ws_selection::dial__selection_query( soap* psoap, string type, string conn, string query, int maxent, dial__StringVectorResponse& res) { DialWs::lout() << ">>>Received query" << endl; DialWs::lout() << "Type: " << type << endl; DialWs::lout() << "Connection: " << conn << endl; DialWs::lout() << "Query: " << query << endl; DialWs::lout() << "Max: " << maxent << endl; const char* emsg1 = "Error in DIAL ID encoding request"; GenericSelectionCatalog* pcat = findrep(type, conn); if ( pcat == 0 ) { return soap_receiver_fault(psoap, emsg1, "Unknown catalog"); } static NameList names; names = pcat->query(query, maxent); res.pvec = &names; DialWs::lout() << "Number selected is " << names.size() << endl; return SOAP_OK; } //********************************************************************** // Query count. int dial_ws_selection::dial__selection_query_count( soap* psoap, string type, string conn, string query, int& res) { DialWs::lout() << ">>>Received query count request" << endl; DialWs::lout() << "Type: " << type << endl; DialWs::lout() << "Connection: " << conn << endl; DialWs::lout() << "Query: " << query << endl; const char* emsg1 = "Error in DIAL ID encoding request"; GenericSelectionCatalog* pcat = findrep(type, conn); if ( pcat == 0 ) { return soap_receiver_fault(psoap, emsg1, "Unknown catalog"); } res = pcat->query_count(query); DialWs::lout() << "Number selected is " << res << endl; return SOAP_OK; } //********************************************************************** // Insert. int dial_ws_selection::dial__selection_insert( soap* psoap, string type, string conn, string name, dial__AttributeVector* pgatts, int& res) { DialWs::lout() << ">>>Insert" << endl; DialWs::lout() << "Type: " << type << endl; DialWs::lout() << "Connection: " << conn << endl; DialWs::lout() << "Name: " << name << endl; const char* emsg1 = "Error in DIAL ID encoding request"; GenericSelectionCatalog* pcat = findrep(type, conn); if ( pcat == 0 ) { return soap_receiver_fault(psoap, emsg1, "Unknown catalog"); } // Check authorization. if ( ThreadCredential().owner() == "" ) { return soap_sender_fault(psoap, emsg1, "Credential owner not defined."); } Attributes atts; for ( size_t iatt=0; iattpvec->size(); ++ iatt ) { string name = (*pgatts->pvec)[iatt].name; string value = (*pgatts->pvec)[iatt].value; atts[name] = value; } res = pcat->insert(name, atts); DialWs::lout() << "Return status is " << res << endl; return SOAP_OK; } //********************************************************************** // Update. int dial_ws_selection::dial__selection_update( soap* psoap, string type, string conn, string name, dial__AttributeVector* pgatts, int& res) { DialWs::lout() << ">>>Update" << endl; DialWs::lout() << "Type: " << type << endl; DialWs::lout() << "Connection: " << conn << endl; DialWs::lout() << "Name: " << name << endl; const char* emsg1 = "Error in DIAL ID encoding request"; GenericSelectionCatalog* pcat = findrep(type, conn); if ( pcat == 0 ) { return soap_receiver_fault(psoap, emsg1, "Unknown catalog"); } // Check authorization. if ( ThreadCredential().owner() == "" ) { return soap_sender_fault(psoap, emsg1, "Credential owner not defined."); } Attributes atts; for ( size_t iatt=0; iattpvec->size(); ++ iatt ) { string name = (*pgatts->pvec)[iatt].name; string value = (*pgatts->pvec)[iatt].value; atts[name] = value; } res = pcat->update(name, atts); DialWs::lout() << "Return status is " << res << endl; return SOAP_OK; } //********************************************************************** // Remove. int dial_ws_selection::dial__selection_remove( soap* psoap, string type, string conn, string name, int& res) { DialWs::lout() << ">>>Update" << endl; DialWs::lout() << "Type: " << type << endl; DialWs::lout() << "Connection: " << conn << endl; DialWs::lout() << "Name: " << name << endl; const char* emsg1 = "Error in DIAL ID encoding request"; GenericSelectionCatalog* pcat = findrep(type, conn); if ( pcat == 0 ) { return soap_receiver_fault(psoap, emsg1, "Unknown catalog"); } // Check authorization. if ( ThreadCredential().owner() == "" ) { return soap_sender_fault(psoap, emsg1, "Credential owner not defined."); } res = pcat->remove(name); DialWs::lout() << "Return status is " << res << endl; return SOAP_OK; } //**********************************************************************