Skip to content

Commit c8a7657

Browse files
committed
Fix issue with duplicate file_type
1 parent 40dbde4 commit c8a7657

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

include/fdp/registry/api.hxx

+2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ public:
104104

105105
Json::Value post_storage_root(Json::Value &post_data, const std::string &token);
106106

107+
Json::Value post_file_type(Json::Value &post_data, const std::string &token);
108+
107109
Json::Value get_by_json_query(const std::string &addr_path,
108110
Json::Value &query_data,
109111
long expected_response = 200,

src/objects/config.cxx

+3-3
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ void FairDataPipeline::Config::initialise(RESTAPI api_location) {
267267
Json::Value config_file_type_value;
268268
config_file_type_value["name"] = "yaml";
269269
config_file_type_value["extension"] = "yaml";
270-
Json::Value config_file_type_url_ = api_->post("file_type", config_file_type_value, token_)["url"];
270+
Json::Value config_file_type_url_ = api_->post_file_type(config_file_type_value, token_)["url"];
271271

272272
config_value_["file_type"] = config_file_type_url_;
273273

@@ -304,7 +304,7 @@ void FairDataPipeline::Config::initialise(RESTAPI api_location) {
304304
Json::Value script_file_type_value_;
305305
script_file_type_value_["name"] = "C++ Submission Script" + script_file_path_.extension().string();
306306
script_file_type_value_["extension"] = script_file_path_.extension().string();
307-
Json::Value script_file_type_url_ = api_->post("file_type", script_file_type_value_, token_)["url"];
307+
Json::Value script_file_type_url_ = api_->post_file_type(script_file_type_value_, token_)["url"];
308308

309309
Json::Value script_value_;
310310
script_value_["description"] = "Working script location in datastore";
@@ -667,7 +667,7 @@ void FairDataPipeline::Config::finalise(){
667667
Json::Value filetypeData;
668668
filetypeData["name"] = extension;
669669
filetypeData["extension"] = extension;
670-
ApiObject::sptr filetypeObj = ApiObject::from_json(api_->post("file_type", filetypeData, token_));
670+
ApiObject::sptr filetypeObj = ApiObject::from_json(api_->post_file_type(filetypeData, token_));
671671

672672
Json::Value namespaceData;
673673
namespaceData["name"] = currentWrite.get_use_namespace();

src/registry/api.cxx

+15
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,21 @@ Json::Value API::post_storage_root(Json::Value &post_data, const std::string &to
217217
return API::post_patch_request("storage_root", post_data, token, 201, false);
218218
}
219219

220+
Json::Value API::post_file_type(Json::Value &post_data, const std::string &token){
221+
if (!post_data["name"]){
222+
logger::get_logger()->error() << "Error: Post Data does not contain a file extension";
223+
throw rest_apiquery_error("Failed to post file_type");
224+
}
225+
post_data["name"] = boost::regex_replace(post_data["name"].asString(), boost::regex("."), "");
226+
Json::Value _file_type_query;
227+
_file_type_query["name"] = post_data["name"];
228+
Json::Value _file_type_exists = get_by_json_query("file_type", _file_type_query);
229+
if (_file_type_exists) {
230+
return _file_type_exists[0];
231+
}
232+
return post("file_type", post_data, token);
233+
}
234+
220235
Json::Value API::patch(std::string addr_path, Json::Value &post_data,
221236
const std::string &token, long expected_response) {
222237
return API::post_patch_request(addr_path, post_data, token, expected_response, true);

0 commit comments

Comments
 (0)