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
7{
8 std::optional<armarx::motion::mdb::arondto::MDBReference>
9 createFromFile(const std::filesystem::path& pathToInfoJson)
10 {
11 if (std::filesystem::exists(pathToInfoJson) &&
12 std::filesystem::is_regular_file(pathToInfoJson))
13 {
14 std::ifstream ifs(pathToInfoJson);
15 std::string file_content((std::istreambuf_iterator<char>(ifs)),
16 (std::istreambuf_iterator<char>()));
17
18 armarx::motion::mdb::arondto::MDBReference motionReference;
19 auto json = nlohmann::json::parse(file_content);
20
21 motionReference.id = json["id"];
22 motionReference.associatedInstitution = json["associatedInstitution"];
23 motionReference.associatedProject = json["associatedProject"];
24 motionReference.comment = json["comment"];
25 motionReference.createdDate = DateTime(Duration::Seconds(json["createdDate"]));
26 motionReference.createdUser = json["createdUser"];
27 motionReference.modifiedDate = DateTime(Duration::Seconds(json["modifiedDate"]));
28 motionReference.modifiedUser = json["modifiedUser"];
29 motionReference.date = json["date"];
30 for (auto it = json["attachedFiles"].begin(); it != json["attachedFiles"].end(); ++it)
31 {
32 const auto& key = it.key();
33 const auto& value = it.value();
34
35 for (const auto& attachedFile : value)
36 {
37 armarx::motion::mdb::arondto::FileReference fileRef;
38 fileRef.attachedToId = attachedFile["attachedToId"];
39 fileRef.createdDate =
40 DateTime(Duration::MicroSeconds(attachedFile["createdDate"]));
41 fileRef.createdUser = attachedFile["createdUser"];
42 fileRef.description = attachedFile["description"];
43 fileRef.fileName = attachedFile["fileName"];
44
45 motionReference.attachedFiles[key].emplace_back(fileRef);
46 }
47 }
48 return motionReference;
49 }
50 else
51 {
52 return std::nullopt;
53 }
54 }
55} // namespace armarx::armem::server::motions::mdb::conversion
Represents a point in time.
Definition DateTime.h:25
static Duration MicroSeconds(std::int64_t microSeconds)
Constructs a duration in microseconds.
Definition Duration.cpp:24
static Duration Seconds(std::int64_t seconds)
Constructs a duration in seconds.
Definition Duration.cpp:72
std::optional< armarx::motion::mdb::arondto::MDBReference > createFromFile(const std::filesystem::path &pathToInfoJson)