///////////////////////////////////////////////////////////////////////////
| 83 | |
| 84 | //////////////////////////////////////////////////////////////////////////////// |
| 85 | int CmdImportV2::import(const std::vector<std::map<std::string, std::string>>& task_data) { |
| 86 | auto count = 0; |
| 87 | const std::string uuid_key = "uuid"; |
| 88 | const std::string id_key = "id"; |
| 89 | const std::string descr_key = "description"; |
| 90 | auto& replica = Context::getContext().tdb2.replica(); |
| 91 | rust::Vec<tc::Operation> ops; |
| 92 | tc::add_undo_point(ops); |
| 93 | |
| 94 | for (auto& task : task_data) { |
| 95 | auto uuid_iter = task.find(uuid_key); |
| 96 | if (uuid_iter == task.end()) { |
| 97 | std::cout << " err - Task with no UUID\n"; |
| 98 | continue; |
| 99 | } |
| 100 | auto uuid_str = uuid_iter->second; |
| 101 | auto uuid = tc::uuid_from_string(uuid_str); |
| 102 | |
| 103 | bool added_task = false; |
| 104 | auto maybe_task_data = replica->get_task_data(uuid); |
| 105 | auto task_data = maybe_task_data.is_some() ? maybe_task_data.take() : [&]() { |
| 106 | added_task = true; |
| 107 | return tc::create_task(uuid, ops); |
| 108 | }(); |
| 109 | |
| 110 | for (auto& attr : task) { |
| 111 | if (attr.first == uuid_key || attr.first == id_key) { |
| 112 | continue; |
| 113 | } |
| 114 | task_data->update(attr.first, attr.second, ops); |
| 115 | } |
| 116 | count++; |
| 117 | |
| 118 | if (added_task) { |
| 119 | std::cout << " add "; |
| 120 | } else { |
| 121 | std::cout << " mod "; |
| 122 | } |
| 123 | std::cout << uuid_str << ' '; |
| 124 | if (auto descr_iter = task.find(descr_key); descr_iter != task.end()) { |
| 125 | std::cout << descr_iter->second; |
| 126 | } else { |
| 127 | std::cout << "(no description)"; |
| 128 | } |
| 129 | std::cout << "\n"; |
| 130 | } |
| 131 | |
| 132 | replica->commit_operations(std::move(ops)); |
| 133 | return count; |
| 134 | } |
| 135 | |
| 136 | //////////////////////////////////////////////////////////////////////////////// |
nothing calls this directly
no test coverage detected