1 /*
2  * Copyright (C) 2017-2018 Red Hat, Inc.
3  *
4  * Licensed under the GNU Lesser General Public License Version 2.1
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef LIBDNF_TRANSACTION_TRANSFORMER_HPP
22 #define LIBDNF_TRANSACTION_TRANSFORMER_HPP
23 
24 #include <json.h>
25 #include <memory>
26 #include <vector>
27 
28 #include "../utils/sqlite3/Sqlite3.hpp"
29 
30 #include "CompsEnvironmentItem.hpp"
31 #include "CompsGroupItem.hpp"
32 #include "RPMItem.hpp"
33 #include "private/Transaction.hpp"
34 #include "private/TransformerTransaction.hpp"
35 #include "TransactionItem.hpp"
36 
37 namespace libdnf {
38 
39 /**
40  * Class providing an interface to the database transformation
41  */
42 class Transformer {
43 public:
44     class Exception : public std::runtime_error {
45     public:
Exception(const std::string & msg)46         Exception(const std::string &msg)
47           : runtime_error(msg)
48         {
49         }
Exception(const char * msg)50         Exception(const char *msg)
51           : runtime_error(msg)
52         {
53         }
54     };
55 
56     Transformer(const std::string &inputDir, const std::string &outputFile);
57     void transform();
58 
59     static void createDatabase(SQLite3Ptr conn);
60     static void migrateSchema(SQLite3Ptr conn);
61 
62     static TransactionItemReason getReason(const std::string &reason);
getVersion()63     static const char *getVersion() noexcept { return "1.2"; }
64 
65 protected:
66     void transformTrans(SQLite3Ptr swdb, SQLite3Ptr history);
67 
68     void transformGroups(SQLite3Ptr swdb);
69     void processGroupPersistor(SQLite3Ptr swdb, struct json_object *root);
70 
71 private:
72     void transformRPMItems(SQLite3Ptr swdb,
73                            SQLite3Ptr history,
74                            std::shared_ptr< TransformerTransaction > trans);
75     void transformOutput(SQLite3Ptr history, std::shared_ptr< TransformerTransaction > trans);
76     void transformTransWith(SQLite3Ptr swdb,
77                             SQLite3Ptr history,
78                             std::shared_ptr< TransformerTransaction > trans);
79     CompsGroupItemPtr processGroup(SQLite3Ptr swdb,
80                                    const char *groupId,
81                                    struct json_object *group);
82     std::shared_ptr<CompsEnvironmentItem> processEnvironment(SQLite3Ptr swdb,
83                                                              const char *envId,
84                                                              struct json_object *env);
85     std::string historyPath();
86     const std::string inputDir;
87     const std::string outputFile;
88     const std::string transformFile;
89 };
90 
91 } // namespace libdnf
92 
93 #endif
94