diff --git a/livesupport/modules/storage/include/LiveSupport/Storage/StorageClientInterface.h b/livesupport/modules/storage/include/LiveSupport/Storage/StorageClientInterface.h index 60aaf586c..ca18ef216 100644 --- a/livesupport/modules/storage/include/LiveSupport/Storage/StorageClientInterface.h +++ b/livesupport/modules/storage/include/LiveSupport/Storage/StorageClientInterface.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.12 $ + Version : $Revision: 1.13 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/include/LiveSupport/Storage/StorageClientInterface.h,v $ ------------------------------------------------------------------------------*/ @@ -66,7 +66,7 @@ using namespace Core; * An interface for storage clients. * * @author $Author: fgerlits $ - * @version $Revision: 1.12 $ + * @version $Revision: 1.13 $ */ class StorageClientInterface { @@ -377,6 +377,23 @@ class StorageClientInterface throw (XmlRpcException) = 0; + /** + * Browse for metadata values. + * + * @param sessionId the session ID from the authentication client + * @param metadataType the type of metadata to browse for + * @param searchCriteria an object containing the search criteria + * @return a vector containing the metadata values found + * @exception XmlRpcException if there is a problem with the XML-RPC + * call. + */ + virtual Ptr >::Ref + browse(Ptr::Ref sessionId, + Ptr::Ref metadata, + Ptr::Ref searchCriteria) + throw (XmlRpcException) + = 0; + /** * Return the list of audio clip IDs found by the search method. * diff --git a/livesupport/modules/storage/src/TestStorageClient.h b/livesupport/modules/storage/src/TestStorageClient.h index 2d5c02e68..7d115cafa 100644 --- a/livesupport/modules/storage/src/TestStorageClient.h +++ b/livesupport/modules/storage/src/TestStorageClient.h @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: maroy $ - Version : $Revision: 1.31 $ + Author : $Author: fgerlits $ + Version : $Revision: 1.32 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/TestStorageClient.h,v $ ------------------------------------------------------------------------------*/ @@ -85,8 +85,8 @@ using namespace LiveSupport::Core; * <!ATTLIST testStorage tempFiles CDATA #REQUIRED > * * - * @author $Author: maroy $ - * @version $Revision: 1.31 $ + * @author $Author: fgerlits $ + * @version $Revision: 1.32 $ */ class TestStorageClient : virtual public Configurable, @@ -525,6 +525,26 @@ class TestStorageClient : Ptr::Ref searchCriteria) throw (XmlRpcException); + /** + * Browse for metadata values. Not implemented; always returns 0. + * + * @param sessionId the session ID from the authentication client + * @param metadataType the type of metadata to browse for + * @param searchCriteria an object containing the search criteria + * @return a vector containing the metadata values found + * @exception XmlRpcException if there is a problem with the XML-RPC + * call. + */ + virtual Ptr >::Ref + browse(Ptr::Ref sessionId, + Ptr::Ref metadataType, + Ptr::Ref searchCriteria) + throw (XmlRpcException) + { + Ptr >::Ref null; + return null; + } + /** * Return the list of audio clip IDs found by the search method. * diff --git a/livesupport/modules/storage/src/WebStorageClient.cxx b/livesupport/modules/storage/src/WebStorageClient.cxx index a402ac73d..9774b52ce 100644 --- a/livesupport/modules/storage/src/WebStorageClient.cxx +++ b/livesupport/modules/storage/src/WebStorageClient.cxx @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: maroy $ - Version : $Revision: 1.38 $ + Author : $Author: fgerlits $ + Version : $Revision: 1.39 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClient.cxx,v $ ------------------------------------------------------------------------------*/ @@ -245,6 +245,39 @@ static const std::string searchAudioClipCountParamName = "audioClipCnt"; *----------------------------------------------------------------------------*/ static const std::string searchPlaylistCountParamName = "playlistCnt"; +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ storage server constants: browse */ + +/*------------------------------------------------------------------------------ + * The name of the search method on the storage server + *----------------------------------------------------------------------------*/ +static const std::string browseMethodName + = "locstor.browseCategory"; + +/*------------------------------------------------------------------------------ + * The name of the session ID parameter in the input structure + *----------------------------------------------------------------------------*/ +static const std::string browseSessionIdParamName = "sessid"; + +/*------------------------------------------------------------------------------ + * The name of the metadata type parameter in the input structure + *----------------------------------------------------------------------------*/ +static const std::string browseMetadataParamName = "category"; + +/*------------------------------------------------------------------------------ + * The name of the search criteria parameter in the input structure + *----------------------------------------------------------------------------*/ +static const std::string browseCriteriaParamName = "criteria"; + +/*------------------------------------------------------------------------------ + * The name of the list of metadata values parameter returned by the method + *----------------------------------------------------------------------------*/ +static const std::string browseResultParamName = "results"; + +/*------------------------------------------------------------------------------ + * The name of the count parameter returned by the method + *----------------------------------------------------------------------------*/ +static const std::string browseResultCountParamName = "cnt"; + /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ playlist methods */ @@ -2093,6 +2126,80 @@ WebStorageClient :: search(Ptr::Ref sessionId, } +/*------------------------------------------------------------------------------ + * Browse for metadata values. + *----------------------------------------------------------------------------*/ +Ptr >::Ref +WebStorageClient :: browse(Ptr::Ref sessionId, + Ptr::Ref metadataType, + Ptr::Ref searchCriteria) + throw (XmlRpcException) +{ + XmlRpcValue parameters; + XmlRpcValue result; + + XmlRpcClient xmlRpcClient(storageServerName.c_str(), storageServerPort, + storageServerPath.c_str(), false); + + parameters.clear(); + parameters[browseSessionIdParamName] + = sessionId->getId(); + parameters[browseMetadataParamName] + = std::string(*metadataType); + parameters[browseCriteriaParamName] + = *searchCriteria; + + result.clear(); + if (!xmlRpcClient.execute(browseMethodName.c_str(), + parameters, result)) { + xmlRpcClient.close(); + std::string eMsg = "cannot execute XML-RPC method '"; + eMsg += browseMethodName; + eMsg += "'"; + throw XmlRpcCommunicationException(eMsg); + } + xmlRpcClient.close(); + + if (xmlRpcClient.isFault()) { + std::stringstream eMsg; + eMsg << "XML-RPC method '" + << browseMethodName + << "' returned error message:\n" + << result; + throw Core::XmlRpcMethodFaultException(eMsg.str()); + } + + if (! result.hasMember(browseResultParamName) + || result[browseResultParamName].getType() + != XmlRpcValue::TypeArray) { + std::stringstream eMsg; + eMsg << "XML-RPC method '" + << browseMethodName + << "' returned unexpected value:\n" + << result; + throw XmlRpcMethodResponseException(eMsg.str()); + } + + XmlRpcValue metadataValues = result[browseResultParamName]; + Ptr >::Ref + results(new std::vector); + + for (int i=0; i < metadataValues.size(); i++) { + if (metadataValues[i].getType() != XmlRpcValue::TypeString) { + std::stringstream eMsg; + eMsg << "Non-string metadata value returned by XML-RPC method '" + << browseMethodName + << "':\n" + << result; + throw XmlRpcMethodResponseException(eMsg.str()); + } + results->push_back(Glib::ustring(metadataValues[i])); + } + + return results; +} + + /*------------------------------------------------------------------------------ * Return a list of all playlists in the storage. *----------------------------------------------------------------------------*/ diff --git a/livesupport/modules/storage/src/WebStorageClient.h b/livesupport/modules/storage/src/WebStorageClient.h index 91ad18406..2cd60c56d 100644 --- a/livesupport/modules/storage/src/WebStorageClient.h +++ b/livesupport/modules/storage/src/WebStorageClient.h @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: maroy $ - Version : $Revision: 1.25 $ + Author : $Author: fgerlits $ + Version : $Revision: 1.26 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClient.h,v $ ------------------------------------------------------------------------------*/ @@ -95,8 +95,8 @@ using namespace LiveSupport::Core; * <!ATTLIST location path CDATA #REQUIRED > * * - * @author $Author: maroy $ - * @version $Revision: 1.25 $ + * @author $Author: fgerlits $ + * @version $Revision: 1.26 $ */ class WebStorageClient : virtual public Configurable, @@ -521,6 +521,22 @@ class WebStorageClient : Ptr::Ref searchCriteria) throw (XmlRpcException); + /** + * Browse for metadata values. + * + * @param sessionId the session ID from the authentication client + * @param metadataType the type of metadata to browse for + * @param searchCriteria an object containing the search criteria + * @return a vector containing the metadata values found + * @exception XmlRpcException if there is a problem with the XML-RPC + * call. + */ + virtual Ptr >::Ref + browse(Ptr::Ref sessionId, + Ptr::Ref metadataType, + Ptr::Ref searchCriteria) + throw (XmlRpcException); + /** * Return the list of playlist IDs found by the search method. * diff --git a/livesupport/modules/storage/src/WebStorageClientTest.cxx b/livesupport/modules/storage/src/WebStorageClientTest.cxx index 5a0cf4d79..d25f46d78 100644 --- a/livesupport/modules/storage/src/WebStorageClientTest.cxx +++ b/livesupport/modules/storage/src/WebStorageClientTest.cxx @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: maroy $ - Version : $Revision: 1.40 $ + Author : $Author: fgerlits $ + Version : $Revision: 1.41 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClientTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -709,6 +709,43 @@ WebStorageClientTest :: searchTest(void) } +/*------------------------------------------------------------------------------ + * Browse test. + *----------------------------------------------------------------------------*/ +void +WebStorageClientTest :: browseTest(void) + throw (CPPUNIT_NS::Exception) +{ + CPPUNIT_ASSERT_NO_THROW( + wsc->reset() + ); + + Ptr::Ref sessionId; + CPPUNIT_ASSERT_NO_THROW( + sessionId = authentication->login("root", "q") + ); + CPPUNIT_ASSERT(sessionId); + + Ptr::Ref metadata(new Glib::ustring("dc:title")); + Ptr::Ref criteria(new SearchCriteria()); + Ptr >::Ref values; + CPPUNIT_ASSERT_NO_THROW( + values = wsc->browse(sessionId, metadata, criteria) + ); + CPPUNIT_ASSERT(values); + CPPUNIT_ASSERT(values->size() >= 6); + + metadata.reset(new Glib::ustring("dcterms:extent")); + criteria.reset(new SearchCriteria("all", "dc:title", "=", "one")); + CPPUNIT_ASSERT_NO_THROW( + values = wsc->browse(sessionId, metadata, criteria) + ); + CPPUNIT_ASSERT(values); + CPPUNIT_ASSERT(values->size() >= 1); + CPPUNIT_ASSERT((*values)[0] == Glib::ustring("00:00:11.000000")); +} + + /*------------------------------------------------------------------------------ * Testing getAllPlaylists() and getAllAudioClips(). *----------------------------------------------------------------------------*/ diff --git a/livesupport/modules/storage/src/WebStorageClientTest.h b/livesupport/modules/storage/src/WebStorageClientTest.h index f476c0230..2d5567fab 100644 --- a/livesupport/modules/storage/src/WebStorageClientTest.h +++ b/livesupport/modules/storage/src/WebStorageClientTest.h @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: maroy $ - Version : $Revision: 1.10 $ + Author : $Author: fgerlits $ + Version : $Revision: 1.11 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClientTest.h,v $ ------------------------------------------------------------------------------*/ @@ -63,8 +63,8 @@ using namespace LiveSupport::Authentication; /** * Unit test for the UploadPlaylistMetohd class. * - * @author $Author: maroy $ - * @version $Revision: 1.10 $ + * @author $Author: fgerlits $ + * @version $Revision: 1.11 $ * @see WebStorageClient */ class WebStorageClientTest : public BaseTestMethod @@ -77,6 +77,7 @@ class WebStorageClientTest : public BaseTestMethod CPPUNIT_TEST(audioClipTest); CPPUNIT_TEST(searchTest); CPPUNIT_TEST(getAllTest); + CPPUNIT_TEST(browseTest); CPPUNIT_TEST_SUITE_END(); private: @@ -148,6 +149,14 @@ class WebStorageClientTest : public BaseTestMethod void getAllTest(void) throw (CPPUNIT_NS::Exception); + /** + * Testing browse(). + * + * @exception CPPUNIT_NS::Exception on test failures. + */ + void + browseTest(void) throw (CPPUNIT_NS::Exception); + public: