mdb_conversions.cpp
Go to the documentation of this file.
1 // Header
2 #include "mdb_conversions.h"
3 
4 #include <SimoxUtility/json/json.hpp>
5 
6 
8 {
9  std::optional<armarx::motion::mdb::arondto::MDBReference> createFromFile(const std::filesystem::path& pathToInfoJson)
10  {
11  if (std::filesystem::exists(pathToInfoJson) && std::filesystem::is_regular_file(pathToInfoJson))
12  {
13  std::ifstream ifs(pathToInfoJson);
14  std::string file_content((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>()));
15 
16  armarx::motion::mdb::arondto::MDBReference motionReference;
17  auto json = nlohmann::json::parse(file_content);
18 
19  motionReference.id = json["id"];
20  motionReference.associatedInstitution = json["associatedInstitution"];
21  motionReference.associatedProject = json["associatedProject"];
22  motionReference.comment = json["comment"];
23  motionReference.createdDate = DateTime(Duration::Seconds(json["createdDate"]));
24  motionReference.createdUser = json["createdUser"];
25  motionReference.modifiedDate = DateTime(Duration::Seconds(json["modifiedDate"]));
26  motionReference.modifiedUser = json["modifiedUser"];
27  motionReference.date = json["date"];
28  for (auto it = json["attachedFiles"].begin(); it != json["attachedFiles"].end(); ++it)
29  {
30  const auto& key = it.key();
31  const auto& value = it.value();
32 
33  for (const auto& attachedFile : value)
34  {
35  armarx::motion::mdb::arondto::FileReference fileRef;
36  fileRef.attachedToId = attachedFile["attachedToId"];
37  fileRef.createdDate = DateTime(Duration::MicroSeconds(attachedFile["createdDate"]));
38  fileRef.createdUser = attachedFile["createdUser"];
39  fileRef.description = attachedFile["description"];
40  fileRef.fileName = attachedFile["fileName"];
41 
42  motionReference.attachedFiles[key].emplace_back(fileRef);
43  }
44  }
45  return motionReference;
46  }
47  else
48  {
49  return std::nullopt;
50  }
51  }
52 }
armarx::armem::server::motions::mdb::conversion::createFromFile
std::optional< armarx::motion::mdb::arondto::MDBReference > createFromFile(const std::filesystem::path &pathToInfoJson)
Definition: mdb_conversions.cpp:9
armarx::armem::server::motions::mdb::conversion
Definition: mdb_conversions.cpp:7
mdb_conversions.h
armarx::core::time::Duration::Seconds
static Duration Seconds(std::int64_t seconds)
Constructs a duration in seconds.
Definition: Duration.cpp:83
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
armarx::core::time::Duration::MicroSeconds
static Duration MicroSeconds(std::int64_t microSeconds)
Constructs a duration in microseconds.
Definition: Duration.cpp:27