this is a simple wrapper class; takes an xmlrpc method call, extracts the

UniqueId of the playlist, and calls the appropriate method of a StorageClient
This commit is contained in:
fgerlits 2004-10-04 09:00:25 +00:00
parent f0abe66287
commit b902abb8e6
4 changed files with 612 additions and 0 deletions

View File

@ -0,0 +1,140 @@
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/DeletePlaylistMethod.cxx,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <string>
#include "LiveSupport/Core/StorageClientInterface.h"
#include "LiveSupport/Storage/StorageClientFactory.h"
#include "ScheduleInterface.h"
#include "ScheduleFactory.h"
#include "DeletePlaylistMethod.h"
using namespace LiveSupport;
using namespace LiveSupport::Core;
using namespace LiveSupport::Storage;
using namespace LiveSupport::Scheduler;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* The name of this XML-RPC method.
*----------------------------------------------------------------------------*/
const std::string DeletePlaylistMethod::methodName = "deletePlaylist";
/*------------------------------------------------------------------------------
* The name of the playlistId member in the XML-RPC parameter
* structure.
*----------------------------------------------------------------------------*/
const std::string DeletePlaylistMethod::playlistIdName = "playlistId";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Construct the method and register it right away.
*----------------------------------------------------------------------------*/
DeletePlaylistMethod :: DeletePlaylistMethod (
Ptr<XmlRpc::XmlRpcServer>::Ref xmlRpcServer) throw()
: XmlRpc::XmlRpcServerMethod(methodName, xmlRpcServer.get())
{
}
/*------------------------------------------------------------------------------
* Extract the UniqueId from an XML-RPC function call parameter
*----------------------------------------------------------------------------*/
Ptr<UniqueId>::Ref
DeletePlaylistMethod :: extractPlaylistId(
XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument)
{
if (!xmlRpcValue.hasMember(playlistIdName)) {
throw std::invalid_argument("no playlist id in parameter structure");
}
Ptr<UniqueId>::Ref id(new UniqueId((int) xmlRpcValue[playlistIdName]));
return id;
}
/*------------------------------------------------------------------------------
* Execute the XML-RPC function call.
* (Overrides 'execute' in XmlRpcServerMethod.)
*----------------------------------------------------------------------------*/
void
DeletePlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters,
XmlRpc::XmlRpcValue & returnValue)
throw ()
{
try {
if (!parameters.valid()) {
// TODO: mark error
returnValue = XmlRpc::XmlRpcValue(false);
return;
}
Ptr<UniqueId>::Ref id = extractPlaylistId(parameters[0]);
Ptr<StorageClientFactory>::Ref scf;
Ptr<StorageClientInterface>::Ref storage;
scf = StorageClientFactory::getInstance();
storage = scf->getStorageClient();
if (!storage->existsPlaylist(id)) {
// TODO: mark error
returnValue = XmlRpc::XmlRpcValue(false);
return;
}
storage->deletePlaylist(id);
returnValue = XmlRpc::XmlRpcValue(true);
} catch (std::invalid_argument &e) {
// TODO: mark error
returnValue = XmlRpc::XmlRpcValue(false);
return;
}
}

View File

@ -0,0 +1,153 @@
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/DeletePlaylistMethod.h,v $
------------------------------------------------------------------------------*/
#ifndef DeletePlaylistMethod_h
#define DeletePlaylistMethod_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <stdexcept>
#include <string>
#include <XmlRpcServerMethod.h>
#include <XmlRpcValue.h>
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/Playlist.h"
namespace LiveSupport {
namespace Scheduler {
using namespace LiveSupport;
using namespace LiveSupport::Core;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* An XML-RPC method object to delete a playlist given by its playlist id.
*
* The name of the method when called through XML-RPC is "deletePlaylist".
* The expected parameter is an XML-RPC structure, with the following
* member:
* <ul>
* <li>playlistId - int - the unique id of the playlist
* to be deleted.</li>
* </ul>
*
* The XML-RPC function returns the XML-RPC value:
* <ul>
* <li>true if the operation completed successfully,</li>
* <li>false if playlist is not found or there was some other error.</li>
* </ul>
*
* @author $Author: fgerlits $
* @version $Revision: 1.1 $
*/
class DeletePlaylistMethod : public XmlRpc::XmlRpcServerMethod
{
private:
/**
* The name of this method, as it will be registered into the
* XML-RPC server.
*/
static const std::string methodName;
/**
* The name of the playlistId member in the XML-RPC parameter
* structure.
*/
static const std::string playlistIdName;
/**
* Extract the playlist id from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return a UniqueId that was found in the XML-RPC parameter.
* @exception std::invalid_argument if there was no UniqueId
* in xmlRpcValue
*/
Ptr<UniqueId>::Ref
extractPlaylistId(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
public:
/**
* A default constructor, for testing purposes.
*/
DeletePlaylistMethod(void) throw ()
: XmlRpc::XmlRpcServerMethod(methodName)
{
}
/**
* Constuctor that registers the method with the server right away.
*
* @param xmlRpcServer the XML-RPC server to register with.
*/
DeletePlaylistMethod(
Ptr<XmlRpc::XmlRpcServer>::Ref xmlRpcServer)
throw ();
/**
* Execute the display schedule command on the Scheduler daemon.
*
* @param parameters XML-RPC function call parameters
* @param returnValue the return value of the call (out parameter)
*/
void
execute( XmlRpc::XmlRpcValue & parameters,
XmlRpc::XmlRpcValue & returnValue) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Scheduler
} // namespace LiveSupport
#endif // DisplayPlaylistMethod_h

View File

@ -0,0 +1,174 @@
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/DeletePlaylistMethodTest.cxx,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#else
#error "Need unistd.h"
#endif
#include <string>
#include <iostream>
#include <XmlRpcValue.h>
#include "LiveSupport/Db/ConnectionManagerFactory.h"
#include "LiveSupport/Storage/StorageClientFactory.h"
#include "DeletePlaylistMethod.h"
#include "DeletePlaylistMethodTest.h"
using namespace LiveSupport::Db;
using namespace LiveSupport::Storage;
using namespace LiveSupport::Scheduler;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
CPPUNIT_TEST_SUITE_REGISTRATION(DeletePlaylistMethodTest);
/**
* The name of the configuration file for the storage client factory.
*/
const std::string DeletePlaylistMethodTest::storageClientConfig =
"etc/storageClient.xml";
/**
* The name of the configuration file for the connection manager factory.
*/
const std::string DeletePlaylistMethodTest::connectionManagerConfig =
"etc/connectionManagerFactory.xml";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Configure a Configurable with an XML file.
*----------------------------------------------------------------------------*/
void
DeletePlaylistMethodTest :: configure(
Ptr<Configurable>::Ref configurable,
const std::string fileName)
throw (std::invalid_argument,
xmlpp::exception)
{
Ptr<xmlpp::DomParser>::Ref parser(new xmlpp::DomParser(fileName, true));
const xmlpp::Document * document = parser->get_document();
const xmlpp::Element * root = document->get_root_node();
configurable->configure(*root);
}
/*------------------------------------------------------------------------------
* Set up the test environment
*----------------------------------------------------------------------------*/
void
DeletePlaylistMethodTest :: setUp(void) throw ()
{
try {
Ptr<StorageClientFactory>::Ref scf
= StorageClientFactory::getInstance();
configure(scf, storageClientConfig);
Ptr<ConnectionManagerFactory>::Ref cmf
= ConnectionManagerFactory::getInstance();
configure(cmf, connectionManagerConfig);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL("semantic error in configuration file");
} catch (xmlpp::exception &e) {
CPPUNIT_FAIL("error parsing configuration file");
} catch (std::exception &e) {
CPPUNIT_FAIL(e.what());
}
}
/*------------------------------------------------------------------------------
* Clean up the test environment
*----------------------------------------------------------------------------*/
void
DeletePlaylistMethodTest :: tearDown(void) throw ()
{
}
/*------------------------------------------------------------------------------
* Just a very simple smoke test
*----------------------------------------------------------------------------*/
void
DeletePlaylistMethodTest :: firstTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<DeletePlaylistMethod>::Ref method(new DeletePlaylistMethod());
XmlRpc::XmlRpcValue rootParameter;
XmlRpc::XmlRpcValue parameters;
XmlRpc::XmlRpcValue result;
// set up a structure for the parameters
parameters["playlistId"] = 1;
rootParameter[0] = parameters;
method->execute(rootParameter, result);
CPPUNIT_ASSERT(((bool) result) == true);
}
/*------------------------------------------------------------------------------
* A very simple negative test
*----------------------------------------------------------------------------*/
void
DeletePlaylistMethodTest :: negativeTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<DeletePlaylistMethod>::Ref method(new DeletePlaylistMethod());
XmlRpc::XmlRpcValue rootParameter;
XmlRpc::XmlRpcValue parameters;
XmlRpc::XmlRpcValue result;
// set up a structure for the parameters
parameters["playlistId"] = 9999;
rootParameter[0] = parameters;
method->execute(rootParameter, result);
CPPUNIT_ASSERT(((bool)result) == false);
}

View File

@ -0,0 +1,145 @@
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/DeletePlaylistMethodTest.h,v $
------------------------------------------------------------------------------*/
#ifndef DeletePlaylistMethodTest_h
#define DeletePlaylistMethodTest_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <cppunit/extensions/HelperMacros.h>
namespace LiveSupport {
namespace Scheduler {
using namespace LiveSupport;
using namespace LiveSupport::Core;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Unit test for the DeletePlaylistMethod class.
*
* @author $Author: maroy, fgerlits
$
* @version $Revision: 1.1 $
* @see DeletePlaylistMethod
*/
class DeletePlaylistMethodTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(DeletePlaylistMethodTest);
CPPUNIT_TEST(firstTest);
CPPUNIT_TEST(negativeTest);
CPPUNIT_TEST_SUITE_END();
/**
* The name of the configuration file for the storage client factory.
*/
static const std::string storageClientConfig;
/**
* The name of the configuration file for the connection manager
* factory.
*/
static const std::string connectionManagerConfig;
/**
* Configure a configurable with an XML file.
*
* @param configurable configure this
* @param fileName the name of the XML file to configure with.
* @exception std::invalid_argument on configuration errors.
* @exception xmlpp::exception on XML parsing errors.
*/
void
configure(Ptr<Configurable>::Ref configurable,
std::string fileName)
throw (std::invalid_argument,
xmlpp::exception);
protected:
/**
* A simple test.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
firstTest(void) throw (CPPUNIT_NS::Exception);
/**
* A simple negative test.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
negativeTest(void) throw (CPPUNIT_NS::Exception);
public:
/**
* Set up the environment for the test case.
*/
void
setUp(void) throw ();
/**
* Clean up the environment after the test case.
*/
void
tearDown(void) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Scheduler
} // namespace LiveSupport
#endif // DeletePlaylistMethodTest_h