From 48687b7565ef0f1ab002b74b9a6be500081c0e58 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 19 Dec 2015 21:05:22 +0000 Subject: Add support for getting a news item by Id --- gentoobrowse-api/api/portage.ice | 2 ++ gentoobrowse-api/domain/portage-models.ice | 16 +++++++++++++ gentoobrowse-api/service/portageimpl.cpp | 7 ++++++ gentoobrowse-api/service/portageimpl.h | 2 ++ .../service/sql/portage/getNewsItem.sql | 3 +++ gentoobrowse-api/unittests/testPortage.cpp | 28 ++++++++++++++++++++++ 6 files changed, 58 insertions(+) create mode 100644 gentoobrowse-api/service/sql/portage/getNewsItem.sql diff --git a/gentoobrowse-api/api/portage.ice b/gentoobrowse-api/api/portage.ice index c70c146..7e1eb43 100644 --- a/gentoobrowse-api/api/portage.ice +++ b/gentoobrowse-api/api/portage.ice @@ -19,6 +19,8 @@ module Gentoo { idempotent Bug getBug(int id); idempotent Bugs getPackageBugs(int packageId); idempotent SearchResultBugs getBugsSearch(string query); + + idempotent NewsItem getNewsItem(string newsid); }; }; diff --git a/gentoobrowse-api/domain/portage-models.ice b/gentoobrowse-api/domain/portage-models.ice index 4f98ce3..b5a75c9 100644 --- a/gentoobrowse-api/domain/portage-models.ice +++ b/gentoobrowse-api/domain/portage-models.ice @@ -63,6 +63,22 @@ module Gentoo { int repoid; }; + class NewsItem { + ["slicer:db:pkey"] + string newsid; + string title; + [ "slicer:conversion:boost.posix_time.ptime:boost.posix_time.to_iso_extended_string:boost.posix_time.time_from_string:nodeclare" ] + string posted; + [ "slicer:conversion:std.string:unpackPqTextArray:packPqTextArray" ] + StringList body; + optional(0) string authorname; + optional(1) string authoremail; + [ "slicer:conversion:std.string:unpackPqTextArray:packPqTextArray" ] + StringList atomspec; + [ "slicer:conversion:std.string:unpackPqTextArray:packPqTextArray" ] + StringList urls; + }; + sequence Categories; sequence Packages; sequence Ebuilds; diff --git a/gentoobrowse-api/service/portageimpl.cpp b/gentoobrowse-api/service/portageimpl.cpp index c1a7f36..b199934 100644 --- a/gentoobrowse-api/service/portageimpl.cpp +++ b/gentoobrowse-api/service/portageimpl.cpp @@ -13,6 +13,7 @@ #include #include #include +#include Portage::Portage(AdHoc::ResourcePool & d) : AbstractDatabaseClient(d) @@ -103,3 +104,9 @@ Portage::getBugsSearch(const std::string & query, const Ice::Current &) return fetch(query, query); } +Gentoo::NewsItemPtr +Portage::getNewsItem(const std::string & id, const Ice::Current &) +{ + return fetch(id); +} + diff --git a/gentoobrowse-api/service/portageimpl.h b/gentoobrowse-api/service/portageimpl.h index 6bdcc2e..9588095 100644 --- a/gentoobrowse-api/service/portageimpl.h +++ b/gentoobrowse-api/service/portageimpl.h @@ -25,6 +25,8 @@ class DLL_PUBLIC Portage : public Gentoo::Portage, AbstractDatabaseClient { Gentoo::BugPtr getBug(Ice::Int id, const Ice::Current &) override; Gentoo::Bugs getPackageBugs(Ice::Int packageId, const Ice::Current &) override; Gentoo::SearchResultBugs getBugsSearch(const std::string & query, const Ice::Current &) override; + + Gentoo::NewsItemPtr getNewsItem(const std::string &, const Ice::Current &) override; }; #endif diff --git a/gentoobrowse-api/service/sql/portage/getNewsItem.sql b/gentoobrowse-api/service/sql/portage/getNewsItem.sql new file mode 100644 index 0000000..d69aa6a --- /dev/null +++ b/gentoobrowse-api/service/sql/portage/getNewsItem.sql @@ -0,0 +1,3 @@ +SELECT n.newsid, n.title, n.posted, n.authorname, n.authoremail, n.body, n.atomspec, n.urls +FROM gentoobrowse.news n +WHERE n.newsid = ? diff --git a/gentoobrowse-api/unittests/testPortage.cpp b/gentoobrowse-api/unittests/testPortage.cpp index 063b6a4..8a8d5bb 100644 --- a/gentoobrowse-api/unittests/testPortage.cpp +++ b/gentoobrowse-api/unittests/testPortage.cpp @@ -240,6 +240,34 @@ BOOST_AUTO_TEST_CASE( getBugsSearch ) BOOST_REQUIRE_EQUAL(567682, bs[2]->bugid); } +BOOST_AUTO_TEST_CASE( getNewsItem ) +{ + MockPool mp; + auto p = Portage::PointerType(new Portage(mp)); + auto n = p->getNewsItem("2015-02-01-use-libav"); + BOOST_REQUIRE(n); + BOOST_REQUIRE_EQUAL("2015-02-01-use-libav", n->newsid); + BOOST_REQUIRE_EQUAL("ffmpeg/libav conflict management: USE=libav", n->title); + BOOST_REQUIRE_EQUAL("2015-02-01T00:00:00", n->posted); + BOOST_REQUIRE(n->authorname); + BOOST_REQUIRE_EQUAL("Michał Górny", *n->authorname); + BOOST_REQUIRE(n->authoremail); + BOOST_REQUIRE_EQUAL("mgorny@gentoo.org", *n->authoremail); + BOOST_REQUIRE_EQUAL(2, n->atomspec.size()); + BOOST_REQUIRE_EQUAL("media-video/ffmpeg", n->atomspec.front()); + BOOST_REQUIRE_EQUAL("media-video/libav", n->atomspec.back()); + BOOST_REQUIRE_EQUAL(5, n->body.size()); + BOOST_REQUIRE_EQUAL("The support for automatic choice between ffmpeg and libav is going to be deprecated in favor of explicit choice via USE flags. This change aims to solve multiple repeating issues, including Portage undesirably wanting to replace one package with the other, lack of proper reverse dependency on ffmpeg/libav upgrades and some of the hard-to-understand upgrade failures involving blockers. It also may be used to make ffmpeg and libav co-installable in the future.", n->body.front()); + BOOST_REQUIRE_EQUAL("Please do not alter the state of 'libav' flag on a per-package basis (e.g. via package.use). The flag needs to be set globally to have consistent value throughout all packages. Otherwise, blockers will prevent upgrades.", n->body.back()); + BOOST_REQUIRE_EQUAL(0, n->urls.size()); + + auto n2 = p->getNewsItem("2014-10-26-gcc_4_7_introduced_new_c++11_abi"); + BOOST_REQUIRE(n2); + BOOST_REQUIRE_EQUAL("2014-10-26-gcc_4_7_introduced_new_c++11_abi", n2->newsid); + BOOST_REQUIRE_EQUAL(1, n2->urls.size()); + BOOST_REQUIRE_EQUAL("http://ispras.linuxbase.org/index.php/ABI_compliance_checker", n2->urls.front()); +} + BOOST_AUTO_TEST_CASE( cache ) { MockPool mp; -- cgit v1.2.3