From e25676ce365a90ae3f5c09abe4fea591fc7a33db Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 21 Apr 2016 00:59:47 +0100 Subject: Ingest package metadata basics --- .../service/maintenance/packageMetaProcessor.cpp | 52 ++++++++++++++++++++++ .../service/maintenance/packageMetaProcessor.h | 25 +++++++++++ gentoobrowse-api/service/maintenanceimpl.cpp | 2 + .../service/sql/maintenance/packageMetaUpdate.sql | 6 +++ 4 files changed, 85 insertions(+) create mode 100644 gentoobrowse-api/service/maintenance/packageMetaProcessor.cpp create mode 100644 gentoobrowse-api/service/maintenance/packageMetaProcessor.h create mode 100644 gentoobrowse-api/service/sql/maintenance/packageMetaUpdate.sql diff --git a/gentoobrowse-api/service/maintenance/packageMetaProcessor.cpp b/gentoobrowse-api/service/maintenance/packageMetaProcessor.cpp new file mode 100644 index 0000000..1f99ce2 --- /dev/null +++ b/gentoobrowse-api/service/maintenance/packageMetaProcessor.cpp @@ -0,0 +1,52 @@ +#include "packageMetaProcessor.h" +#include +#include "fileUtils.h" +#include "xmlUtils.h" +#include "dbUtils.h" +#include + +namespace U = Gentoo::Utils; +using namespace Gentoo::Utils::File; + +namespace Gentoo { + namespace Service { + const int PackageMetaProcessor::FILETYPEID = 4; + + void + PackageMetaProcessor::created(DB::Connection * dbc, const boost::filesystem::path & fn, const boost::filesystem::path & path) const + { + update(dbc, fn, path); + } + + void + PackageMetaProcessor::update(DB::Connection * dbc, const boost::filesystem::path & fn, const boost::filesystem::path & path) const + { + auto m = dbc->modify(sql::maintenance::packageMetaUpdate::sql); + U::XmlDoc md(path); + U::Database::bindOptionalsS(m, 0, { + md.getXPathValue("/pkgmetadata/longdescription[@lang='en']/text()"), + md.getXPathValue("/pkgmetadata/longdescription[1]/text()") + }); + m->bindParamS(1, (fn / 1).string()); + m->bindParamS(2, (fn / 2).string()); + m->execute(); + } + + void + PackageMetaProcessor::modified(DB::Connection * dbc, const boost::filesystem::path & fn, const boost::filesystem::path & path) const + { + update(dbc, fn, path); + } + + void + PackageMetaProcessor::deleted(DB::Connection * dbc, const boost::filesystem::path & fn) const + { + auto m = dbc->modify(sql::maintenance::packageMetaUpdate::sql); + m->bindNull(0); + m->bindParamS(1, (fn / 1).string()); + m->bindParamS(2, (fn / 2).string()); + m->execute(); + } + } +} + diff --git a/gentoobrowse-api/service/maintenance/packageMetaProcessor.h b/gentoobrowse-api/service/maintenance/packageMetaProcessor.h new file mode 100644 index 0000000..fb5ffa7 --- /dev/null +++ b/gentoobrowse-api/service/maintenance/packageMetaProcessor.h @@ -0,0 +1,25 @@ +#ifndef GENTOOBROWSE_API_SERVICE_MAINTENANCE_PACKAGEMETAPROC_H +#define GENTOOBROWSE_API_SERVICE_MAINTENANCE_PACKAGEMETAPROC_H + +#include "../maintenanceimpl.h" +#include +#include + +namespace Gentoo { + namespace Service { + class PackageMetaProcessor : public Maintenance::FileProcessor { + public: + static const int FILETYPEID; + + void created(DB::Connection * dbc, const boost::filesystem::path & fn, const boost::filesystem::path & path) const; + void modified(DB::Connection * dbc, const boost::filesystem::path & fn, const boost::filesystem::path & path) const; + void deleted(DB::Connection * dbc, const boost::filesystem::path & fn) const; + + private: + void update(DB::Connection * dbc, const boost::filesystem::path & fn, const boost::filesystem::path & path) const; + }; + } +} + +#endif + diff --git a/gentoobrowse-api/service/maintenanceimpl.cpp b/gentoobrowse-api/service/maintenanceimpl.cpp index d8b85ef..b81d959 100644 --- a/gentoobrowse-api/service/maintenanceimpl.cpp +++ b/gentoobrowse-api/service/maintenanceimpl.cpp @@ -8,6 +8,7 @@ #include #include "maintenance/categoryMetaProcessor.h" #include "maintenance/packageManifestProcessor.h" +#include "maintenance/packageMetaProcessor.h" /* 1 package metadata {"(1,metadata)","(2,md5-cache)"} @@ -49,6 +50,7 @@ namespace Gentoo { { fps[CategoryMetaProcessor::FILETYPEID] = new CategoryMetaProcessor(); fps[PackageManifestProcessor::FILETYPEID] = new PackageManifestProcessor(); + fps[PackageMetaProcessor::FILETYPEID] = new PackageMetaProcessor(); } Maintenance::~Maintenance() diff --git a/gentoobrowse-api/service/sql/maintenance/packageMetaUpdate.sql b/gentoobrowse-api/service/sql/maintenance/packageMetaUpdate.sql new file mode 100644 index 0000000..ec83634 --- /dev/null +++ b/gentoobrowse-api/service/sql/maintenance/packageMetaUpdate.sql @@ -0,0 +1,6 @@ +UPDATE gentoobrowse.packages p + SET summary = gentoobrowse.textclean(?) +FROM gentoobrowse.categories c +WHERE p.categoryid = c.categoryid +AND c.name = ? +AND p.name = ? -- cgit v1.2.3