4SOIL::Function::Function(std::shared_ptr<Element> parent, std::string uuid, std::string name, std::string description, std::string ontology) :
Element(parent, uuid, name, description, ontology)
6 if (
uuid.substr(0, 3) !=
"FUN")
8 throw std::logic_error(
"UUIDs for functions must start with FUN!");
11 allowed_methods = { HTTP::Methods::GET, HTTP::Methods::POST, HTTP::Methods::OPTIONS, HTTP::Methods::HEAD };
18std::shared_ptr<SOIL::Function>
SOIL::Function::create(std::shared_ptr<Element> parent, std::string uuid, std::string name, std::string description, std::string ontology)
20 Function* function =
new Function(parent, uuid, name, description, ontology);
21 return function->
ptr();
27 json_root[U(
"arguments")] = HTTP::Json::array();
29 for (
auto& a : arguments)
31 json_root[U(
"arguments")][i] = a.second->wjson();
35 json_root[U(
"returns")] = HTTP::Json::array();
37 for (
auto& r : returns)
39 json_root[U(
"returns")][i] = r.second->wjson();
42 json_root[U(
"errors")] = HTTP::Json::array();
49 response.set_body(this->wjson());
50 response.set_status_code(HTTP::Status::OK);
56 auto task = request.extract_json();
59 std::map<std::string, HTTP::Json> arguments;
62 auto json_arguments = body[U(
"arguments")].as_array();
64 for (
auto i = json_arguments.begin(); i != json_arguments.end(); i++)
66 auto json_argument = i->as_object();
67 std::string uuid = SOIL::to_value<std::string>(json_argument[U(
"uuid")]);
70 arguments[uuid] = value;
73 std::map<std::string, HTTP::Json> returns = this->invoke(arguments);
75 std::vector<web::json::value> json_returns;
77 for (
auto i = returns.begin(); i != returns.end(); i++)
79 web::json::value local;
80 local[U(
"uuid")] = SOIL::to_json<std::string>(i->first);
81 local[U(
"value")] = i ->second;
82 json_returns.push_back(local);
86 json[U(
"returns")] =HTTP::Json::array(json_returns);
89 response.set_body(
json);
90 response.set_status_code(HTTP::Status::OK);
97 throw std::logic_error(
"The method has not been implemented!");
std::vector< web::http::method > allowed_methods
Allowed methods.
std::string uuid
Local UUID.
virtual HTTP::Json wjson(void)
HTTP JSON.
DLL std::shared_ptr< Function > ptr(void)
Get Pointer.
static std::shared_ptr< Function > create(std::shared_ptr< Element > parent, std::string uuid, std::string name, std::string description, std::string ontology="")
Create new Function.
virtual DLL HTTP::Response handle_post(HTTP::Request request, std::smatch match=std::smatch())
Handle HTTP POST request.
virtual DLL HTTP::Response handle_get(HTTP::Request request, std::smatch match=std::smatch())
Handle HTTP GET request.
DLL ~Function()
Destructor.
virtual DLL std::map< std::string, HTTP::Json > invoke(std::map< std::string, HTTP::Json > arguments)
Core Invocation.
DLL Function(std::shared_ptr< Element > parent, std::string uuid, std::string name, std::string description, std::string ontology="")
Constructor.
DLL HTTP::Json wjson(void)
HTTP JSON.
web::json::value Json
HTTP JSON.
web::http::http_request Request
HTTP Request.
web::http::http_response Response
HTTP Response.