webservice.cpp
Go to the documentation of this file.
00001 /*************************************************************************** 00002 file : $URL: http://svn.code.sf.net/p/frepple/code/trunk/modules/webservice/webservice.cpp $ 00003 version : $LastChangedRevision: 1713 $ $LastChangedBy: jdetaeye $ 00004 date : $LastChangedDate: 2012-07-18 11:46:01 +0200 (Wed, 18 Jul 2012) $ 00005 ***************************************************************************/ 00006 00007 /*************************************************************************** 00008 * * 00009 * Copyright (C) 2007-2012 by Johan De Taeye, frePPLe bvba * 00010 * * 00011 * This library is free software; you can redistribute it and/or modify it * 00012 * under the terms of the GNU Affero General Public License as published * 00013 * by the Free Software Foundation; either version 3 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 * This library is distributed in the hope that it will be useful, * 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00019 * GNU Affero General Public License for more details. * 00020 * * 00021 * You should have received a copy of the GNU Affero General Public * 00022 * License along with this program. * 00023 * If not, see <http://www.gnu.org/licenses/>. * 00024 * * 00025 ***************************************************************************/ 00026 00027 #include "module.h" 00028 #include "frepple.nsmap" 00029 00030 00031 /** Implementation of the webservice method to return demand information. */ 00032 SOAP_FMAC5 int SOAP_FMAC6 frepple__demand(struct soap* soap, char *name, struct frepple__DemandInfoResponse &result) 00033 { 00034 // Search for the demand 00035 if (!name) 00036 return soap_sender_fault(soap, "Missing demand name", "NULL demand name passed"); 00037 Demand* i = Demand::find(name); 00038 if (!i) 00039 { 00040 ostringstream msg; 00041 msg << "The demand with name '" << name << "' couldn't be found"; 00042 return soap_sender_fault(soap, "Demand not found", msg.str().c_str()); 00043 } 00044 00045 // Retrieve demand data 00046 result._return.name = const_cast<char*>(i->getName().c_str()); 00047 if (i->getItem()) 00048 result._return.item = const_cast<char*>(i->getItem()->getName().c_str()); 00049 result._return.priority = i->getPriority(); 00050 result._return.quantity = i->getQuantity(); 00051 result._return.due = i->getDue().getTicks(); 00052 return SOAP_OK; 00053 } 00054 00055 00056 /** Implementation of the webservice method to post XML data. */ 00057 SOAP_FMAC5 int SOAP_FMAC6 frepple__post(struct soap* soap, char *data, struct frepple__PostResponse &result) 00058 { 00059 try 00060 { 00061 CommandReadXMLString(data, true, false).commit(); 00062 } 00063 catch (const DataException& e) 00064 {return soap_sender_fault(soap, "Data Exception", e.what());} 00065 catch (const LogicException& e) 00066 {return soap_sender_fault(soap, "Logic Exception", e.what());} 00067 catch (const RuntimeException& e) 00068 {return soap_sender_fault(soap, "Runtime Exception", e.what());} 00069 catch (...) 00070 {return soap_sender_fault(soap, "Exception", "Unidentified");} 00071 result._return = 11; 00072 return SOAP_OK; 00073 } 00074 00075