CARMA C++
PDB_XML_Convert.h
1 /*
2  * Convert PDB XML to JSON (Conversion Portion)
3  *
4  * This code handles XML produced by two different processes:
5  * 1) Original PDB DBXML Backend (one project/obsblock/subObsblock/trial per file)
6  * 2) Proposal System XML Output (an entire semester's information in one file)
7  */
8 
9 #ifndef PDB_XML_CONVERT_H
10 #define PDB_XML_CONVERT_H
11 
12 #include <vector>
13 #include <string>
14 
15 namespace carma {
16 namespace observertools {
17 
18 /*
19  * Structure to hold the results of the conversion of one or more XML files
20  * into JSON. The results are JSON strings (one per object) in a format
21  * suitable for direct loading into MongoDB.
22  */
23 struct PDB_JSON_Results {
24  std::vector<std::string> projects;
25  std::vector<std::string> obsblocks;
26  std::vector<std::string> subobsblocks;
27  std::vector<std::string> trials;
28  std::vector<std::string> scripts;
29 };
30 
31 /*
32  * Convert one or more files from PDB XML into JSON for MongoDB, and
33  * return the results in memory. The @results structure IS NOT cleared,
34  * new results are appended.
35  *
36  * Various exceptions are thrown by the underlying code, and you should
37  * catch them yourself if you want to detect failures.
38  *
39  * Pretty-printing is available.
40  */
41 void convertXmlToJson(const std::string &xmlContents, const bool pretty, PDB_JSON_Results &results);
42 
43 /*
44  * Pretty-print some JSON
45  *
46  * The JSON must be well-formed, otherwise the code may throw an exception
47  * or crash the program completely.
48  */
49 std::string jsonPrettyPrint(const std::string &json);
50 
51 } // namespace carma::observertools
52 } // namespace carma
53 
54 #endif /* PDB_XML_CONVERT_H */
55 
56 /* vim: set ts=8 sts=8 sw=8 noet tw=92: */