diff --git a/catalogue/CatalogueTest.cpp b/catalogue/CatalogueTest.cpp index 19f659c11679d79cabd883ecfbbb144fe99bdeb3..0e31d03ee7785a4a1f720994d2f45499e312e4ad 100644 --- a/catalogue/CatalogueTest.cpp +++ b/catalogue/CatalogueTest.cpp @@ -3160,6 +3160,42 @@ TEST_P(cta_catalogue_CatalogueTest, createTape_many_tapes) { } } + { + catalogue::TapeSearchCriteria searchCriteria; + searchCriteria.vid = ""; + ASSERT_THROW(m_catalogue->getTapes(searchCriteria), exception::UserError); + } + + { + catalogue::TapeSearchCriteria searchCriteria; + searchCriteria.mediaType = ""; + ASSERT_THROW(m_catalogue->getTapes(searchCriteria), exception::UserError); + } + + { + catalogue::TapeSearchCriteria searchCriteria; + searchCriteria.vendor = ""; + ASSERT_THROW(m_catalogue->getTapes(searchCriteria), exception::UserError); + } + + { + catalogue::TapeSearchCriteria searchCriteria; + searchCriteria.logicalLibrary = ""; + ASSERT_THROW(m_catalogue->getTapes(searchCriteria), exception::UserError); + } + + { + catalogue::TapeSearchCriteria searchCriteria; + searchCriteria.tapePool = ""; + ASSERT_THROW(m_catalogue->getTapes(searchCriteria), exception::UserError); + } + + { + catalogue::TapeSearchCriteria searchCriteria; + searchCriteria.vo = ""; + ASSERT_THROW(m_catalogue->getTapes(searchCriteria), exception::UserError); + } + { catalogue::TapeSearchCriteria searchCriteria; searchCriteria.vid = "vid1"; diff --git a/catalogue/RdbmsCatalogue.cpp b/catalogue/RdbmsCatalogue.cpp index 64bbdfba00f8464a3fe25101baf1dbffb61092c2..d01017d90973550214901a8441069b970599ff2f 100644 --- a/catalogue/RdbmsCatalogue.cpp +++ b/catalogue/RdbmsCatalogue.cpp @@ -1946,6 +1946,13 @@ std::list<common::dataStructures::Tape> RdbmsCatalogue::getTapes(const TapeSearc //------------------------------------------------------------------------------ std::list<common::dataStructures::Tape> RdbmsCatalogue::getTapes(rdbms::Conn &conn, const TapeSearchCriteria &searchCriteria) const { + if(isSetAndEmpty(searchCriteria.vid)) throw exception::UserError("VID cannot be an empty string"); + if(isSetAndEmpty(searchCriteria.mediaType)) throw exception::UserError("Media type cannot be an empty string"); + if(isSetAndEmpty(searchCriteria.vendor)) throw exception::UserError("Vendor cannot be an empty string"); + if(isSetAndEmpty(searchCriteria.logicalLibrary)) throw exception::UserError("Logical library cannot be an empty string"); + if(isSetAndEmpty(searchCriteria.tapePool)) throw exception::UserError("Tape pool cannot be an empty string"); + if(isSetAndEmpty(searchCriteria.vo)) throw exception::UserError("Virtual organisation cannot be an empty string"); + try { std::list<common::dataStructures::Tape> tapes; std::string sql = @@ -5865,5 +5872,12 @@ uint64_t RdbmsCatalogue::getNbTapesInPool(rdbms::Conn &conn, const std::string & } } +//------------------------------------------------------------------------------ +// isSetAndEmpty +//------------------------------------------------------------------------------ +bool RdbmsCatalogue::isSetAndEmpty(const optional<std::string> &optionalStr) const { + return optionalStr && optionalStr->empty(); +} + } // namespace catalogue } // namespace cta diff --git a/catalogue/RdbmsCatalogue.hpp b/catalogue/RdbmsCatalogue.hpp index 56e6415781659dc9a1a529aa2d43df8a60d692d2..d6cdbfe7f960a7f22c9730040468bc01b71d0c1e 100644 --- a/catalogue/RdbmsCatalogue.hpp +++ b/catalogue/RdbmsCatalogue.hpp @@ -1280,6 +1280,14 @@ protected: */ uint64_t getNbTapesInPool(rdbms::Conn &conn, const std::string &name) const; + /** + * Returns true if the specified optional string is both set and empty. + * + * @param optionalStr The optional string. + * @return True if the specified optional string is both set and empty. + */ + bool isSetAndEmpty(const optional<std::string> &optionalStr) const; + /** * Cached versions of tape copy to tape tape pool mappings for specific * storage classes.