comparison Framework/TransferQuery.cpp @ 0:95226b754d9e

initial release
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 17 Sep 2018 11:34:55 +0200
parents
children 7e207ade2f1a
comparison
equal deleted inserted replaced
-1:000000000000 0:95226b754d9e
1 /**
2 * Transfers accelerator plugin for Orthanc
3 * Copyright (C) 2018 Osimis, Belgium
4 *
5 * This program is free software: you can redistribute it and/or
6 * modify it under the terms of the GNU Affero General Public License
7 * as published by the Free Software Foundation, either version 3 of
8 * the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 **/
18
19
20 #include "TransferQuery.h"
21
22 #include <Core/OrthancException.h>
23
24
25 namespace OrthancPlugins
26 {
27 TransferQuery::TransferQuery(const Json::Value& body)
28 {
29 if (body.type() != Json::objectValue ||
30 !body.isMember(KEY_RESOURCES) ||
31 !body.isMember(KEY_PEER) ||
32 !body.isMember(KEY_COMPRESSION) ||
33 body[KEY_RESOURCES].type() != Json::arrayValue ||
34 body[KEY_PEER].type() != Json::stringValue ||
35 body[KEY_COMPRESSION].type() != Json::stringValue)
36 {
37 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
38 }
39
40 peer_ = body[KEY_PEER].asString();
41 resources_ = body[KEY_RESOURCES];
42 compression_ = StringToBucketCompression(body[KEY_COMPRESSION].asString());
43
44 if (body.isMember(KEY_ORIGINATOR_UUID))
45 {
46 if (body[KEY_ORIGINATOR_UUID].type() != Json::stringValue)
47 {
48 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
49 }
50 else
51 {
52 hasOriginator_ = true;
53 originator_ = body[KEY_ORIGINATOR_UUID].asString();
54 }
55 }
56 else
57 {
58 hasOriginator_ = false;
59 }
60
61 if (body.isMember(KEY_PRIORITY))
62 {
63 if (body[KEY_PRIORITY].type() != Json::intValue &&
64 body[KEY_PRIORITY].type() != Json::uintValue)
65 {
66 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
67 }
68 else
69 {
70 priority_ = body[KEY_PRIORITY].asInt();
71 }
72 }
73 else
74 {
75 priority_ = 0;
76 }
77 }
78
79
80 const std::string& TransferQuery::GetOriginator() const
81 {
82 if (hasOriginator_)
83 {
84 return originator_;
85 }
86 else
87 {
88 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
89 }
90 }
91
92
93 void TransferQuery::Serialize(Json::Value& target) const
94 {
95 target = Json::objectValue;
96 target[KEY_PEER] = peer_;
97 target[KEY_RESOURCES] = resources_;
98 target[KEY_COMPRESSION] = EnumerationToString(compression_);
99
100 if (hasOriginator_)
101 {
102 target[KEY_ORIGINATOR_UUID] = originator_;
103 }
104 }
105 }