diff --git a/data-access/engine/src/common/include/cutout.hpp b/data-access/engine/src/common/include/cutout.hpp index 65216f85d61c4b6f860e54b4dc94c73f357e9ede..72adb2fee18cb8937ef546384630f115dc26519e 100644 --- a/data-access/engine/src/common/include/cutout.hpp +++ b/data-access/engine/src/common/include/cutout.hpp @@ -84,6 +84,7 @@ struct coordinates std::vector<std::string> pol; // polarization states FIXME pol should be Set<enums> }; + coordinates parse_coordinates(const std::string region_string); coordinates to_coordinates(const position pos, const band bnd, const time_axis time, const std::vector<std::string> pol); diff --git a/data-access/engine/src/common/src/cutout.cpp b/data-access/engine/src/common/src/cutout.cpp index b1875b3a46484cdc3615b8737c4d2e51fc0aea2c..5fd4e5c485dc0d4d28020fa14c43d4e00988ee24 100644 --- a/data-access/engine/src/common/src/cutout.cpp +++ b/data-access/engine/src/common/src/cutout.cpp @@ -1,4 +1,5 @@ +#include "json_region.hpp" #include "cutout.hpp" #include "fitsfiles.hpp" #include "fits_header.hpp" @@ -200,6 +201,19 @@ string to_cfitsio_format_with_axis_type(vector<uint_bounds> bounds) } +coordinates parse_coordinates(const string region_string) +{ + LOG_trace(string(__func__) + " : " + region_string); + + json_region reg(region_string); + coordinates coord = to_coordinates(reg.get_pos(), reg.get_band(), reg.get_time(), reg.get_pol()); + + LOG_STREAM << "coord parsed: " << coord << endl; + + return coord; +} + + coordinates to_coordinates(const position pos, const band bnd, const time_axis time, const std::vector<std::string> pol) { coordinates coord; diff --git a/data-access/engine/src/common/src/json_region.hpp b/data-access/engine/src/common/src/json_region.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f45fe6efc5af860254e558c3bdd2572dc4d50688 --- /dev/null +++ b/data-access/engine/src/common/src/json_region.hpp @@ -0,0 +1,68 @@ + +#include "cutout.hpp" +#include "cutout_nljson.hpp" +#include "mcutout.hpp" +#include "mcutout_nljson.hpp" + +#include "json.hpp" +#include "io.hpp" +#include <string> +#include <vector> + +using json = nlohmann::json; + +/* All nlohmann-json exception are json::exception <- std::exception. + * So let them be caught by std::excpetion as 'Internal errors' in rpc-call's infinite loop, + * assuming all API syntactic errors were caught in servlet API parser + */ + + +class json_region +{ + public: + + json_region(std::string request_json) + { + LOG_trace(__func__); + + const bool ASSERTS = true; + m_jservice = json::parse(request_json, nullptr, ASSERTS); + + LOG_STREAM << m_jservice.dump() << std::endl; + } + + + position get_pos() + { + return (m_jservice.contains("pos") ? (position) m_jservice.at("pos") : pos_none ); + } + + + band get_band() + { + return (m_jservice.contains("band") ? (band) m_jservice.at("band") : band_none); + } + + + time_axis get_time() + { + return (m_jservice.contains("time") ? (time_axis) m_jservice.at("time") : time_none); + } + + + std::vector<std::string> get_pol() + { + std::vector<std::string> str; + if(m_jservice.contains("pol")) + { + json j = m_jservice.at("pol"); + str = j.get<std::vector<std::string>>(); + } + return str; + } + + + private: + json m_jservice; +}; + diff --git a/data-access/engine/src/vlkb/src/ast.cpp b/data-access/engine/src/vlkb/src/ast.cpp index 562afb25d2ebce068ebcec6db8e9cf1ab4c7d690..e01ff0163db47fa3758bccb1042c82712ba97003 100644 --- a/data-access/engine/src/vlkb/src/ast.cpp +++ b/data-access/engine/src/vlkb/src/ast.cpp @@ -6,7 +6,6 @@ #include "cutout_ostream.hpp" #include "service_string.hpp" #include "fitsfiles.hpp" // header-string needed -#include "json_request.hpp" // uses json for vlkb-overlap region-string #include "io.hpp" #include "my_assert.hpp" @@ -149,19 +148,6 @@ vector<string> split (const string &s, char delim) } -coordinates parse_coordinates(const string region_string) -{ - LOG_trace(string(__func__) + " : " + region_string); - - json_request req(region_string); - coordinates coord = to_coordinates(req.get_pos(), req.get_band(), req.get_time(), req.get_pol()); - - LOG_STREAM << "coord parsed: " << coord << endl; - - return coord; -} - - int vlkb_overlap(const string& pathname, const string& region, vector<uint_bounds>& bnds) { LOG_trace(__func__); diff --git a/data-access/engine/src/common/src/json_request.cpp b/data-access/engine/src/vlkbd/src/json_request.cpp similarity index 100% rename from data-access/engine/src/common/src/json_request.cpp rename to data-access/engine/src/vlkbd/src/json_request.cpp diff --git a/data-access/engine/src/common/include/json_request.hpp b/data-access/engine/src/vlkbd/src/json_request.hpp similarity index 100% rename from data-access/engine/src/common/include/json_request.hpp rename to data-access/engine/src/vlkbd/src/json_request.hpp