1 #include "JsonToArticleConverter.h"
2 #include "WalkerException.h"
6 //! \todo really ugly workaround, passing in the ArticleCollection instance... :/
7 Article
* JsonToArticleConverter::convertToArticle(std::string json
, ArticleCollection
& articleCache
)
11 bool success
= reader
.parse(json
, document
, false);
14 throw WalkerException("Error parsing JSON");
17 auto allPages
= document
.get("query", Json::Value::nullSingleton())
18 .get("pages", Json::Value::nullSingleton());
20 // only get first page
21 auto wantedPage
= allPages
.get(allPages
.getMemberNames()[0],
22 Json::Value::nullSingleton());
24 if(wantedPage
.isMember("missing")) {
25 throw WalkerException("Article doesn't exist");
26 } else if(wantedPage
.isMember("invalid")) {
27 throw WalkerException("Invalid article");
30 //! get normalized title not necessary, "title" is already
31 std::string wantedArticleTitle
= wantedPage
.get("title", Json::Value::nullSingleton()).asString();
32 Article
* wantedArticle
= articleCache
.get(wantedArticleTitle
);
34 if(wantedArticle
== nullptr) {
35 wantedArticle
= new Article(wantedArticleTitle
);
38 articleCache
.add(wantedArticle
);
41 for(const auto &linked
: wantedPage
.get("links", Json::Value::nullSingleton())) {
42 auto linkedPageTitle
= linked
.get("title", Json::Value::nullSingleton()).asString();
43 auto par
= articleCache
.get(linkedPageTitle
);
46 par
= new Article(linkedPageTitle
);
47 articleCache
.add(par
);
50 wantedArticle
->addLink(par
);
53 wantedArticle
->setAnalyzed(true);
55 if(!document
.isMember("batchcomplete")) {
58 document
.get("continue", Json::Value::nullSingleton())
59 .get("plcontinue", Json::Value::nullSingleton())