annotate OrthancServer/StorageCommitmentReports.cpp @ 3754:ef625518c27c storage-commitment

closing branch storage-commitment
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 16 Mar 2020 12:15:52 +0100
parents e5713a9acebd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3736
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * you do not wish to do so, delete this exception statement from your
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "PrecompiledHeadersServer.h"
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "StorageCommitmentReports.h"
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include "../Core/OrthancException.h"
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 namespace Orthanc
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 void StorageCommitmentReports::Report::MarkAsComplete()
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 if (isComplete_)
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 {
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 throw OrthancException(ErrorCode_BadSequenceOfCalls);
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 }
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 else
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 isComplete_ = true;
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 }
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 }
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 void StorageCommitmentReports::Report::AddSuccess(const std::string& sopClassUid,
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 const std::string& sopInstanceUid)
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 if (isComplete_)
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 throw OrthancException(ErrorCode_BadSequenceOfCalls);
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 }
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 else
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 Success success;
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 success.sopClassUid_ = sopClassUid;
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 success.sopInstanceUid_ = sopInstanceUid;
3737
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
65 success_.push_back(success);
3736
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 }
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 }
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 void StorageCommitmentReports::Report::AddFailure(const std::string& sopClassUid,
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 const std::string& sopInstanceUid,
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 StorageCommitmentFailureReason reason)
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 {
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 if (isComplete_)
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 {
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 throw OrthancException(ErrorCode_BadSequenceOfCalls);
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 }
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 else
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 {
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 Failure failure;
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 failure.sopClassUid_ = sopClassUid;
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 failure.sopInstanceUid_ = sopInstanceUid;
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 failure.reason_ = reason;
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 failures_.push_back(failure);
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 }
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 }
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 StorageCommitmentReports::Report::Status StorageCommitmentReports::Report::GetStatus() const
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 {
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 if (!isComplete_)
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 {
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 return Status_Pending;
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 }
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 else if (failures_.empty())
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 {
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 return Status_Success;
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 }
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 else
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 {
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 return Status_Failure;
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 }
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 }
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
3737
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
105 void StorageCommitmentReports::Report::Format(Json::Value& json) const
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
106 {
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
107 static const char* const FIELD_STATUS = "Status";
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
108 static const char* const FIELD_SOP_CLASS_UID = "SOPClassUID";
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
109 static const char* const FIELD_SOP_INSTANCE_UID = "SOPInstanceUID";
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
110 static const char* const FIELD_FAILURE_REASON = "FailureReason";
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
111 static const char* const FIELD_DESCRIPTION = "Description";
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
112 static const char* const FIELD_REMOTE_AET = "RemoteAET";
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
113 static const char* const FIELD_SUCCESS = "Success";
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
114 static const char* const FIELD_FAILURES = "Failures";
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
115
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
116
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
117 json = Json::objectValue;
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
118 json[FIELD_REMOTE_AET] = remoteAet_;
3742
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
119
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
120 bool pending;
3737
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
121
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
122 switch (GetStatus())
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
123 {
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
124 case Status_Pending:
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
125 json[FIELD_STATUS] = "Pending";
3742
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
126 pending = true;
3737
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
127 break;
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
128
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
129 case Status_Success:
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
130 json[FIELD_STATUS] = "Success";
3742
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
131 pending = false;
3737
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
132 break;
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
133
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
134 case Status_Failure:
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
135 json[FIELD_STATUS] = "Failure";
3742
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
136 pending = false;
3737
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
137 break;
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
138
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
139 default:
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
140 throw OrthancException(ErrorCode_InternalError);
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
141 }
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
142
3742
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
143 if (!pending)
3737
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
144 {
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
145 {
3742
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
146 Json::Value success = Json::arrayValue;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
147 for (std::list<Success>::const_iterator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
148 it = success_.begin(); it != success_.end(); ++it)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
149 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
150 Json::Value item = Json::objectValue;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
151 item[FIELD_SOP_CLASS_UID] = it->sopClassUid_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
152 item[FIELD_SOP_INSTANCE_UID] = it->sopInstanceUid_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
153 success.append(item);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
154 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
155
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
156 json[FIELD_SUCCESS] = success;
3737
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
157 }
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
158
3742
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
159 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
160 Json::Value failures = Json::arrayValue;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
161 for (std::list<Failure>::const_iterator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
162 it = failures_.begin(); it != failures_.end(); ++it)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
163 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
164 Json::Value item = Json::objectValue;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
165 item[FIELD_SOP_CLASS_UID] = it->sopClassUid_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
166 item[FIELD_SOP_INSTANCE_UID] = it->sopInstanceUid_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
167 item[FIELD_FAILURE_REASON] = it->reason_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
168 item[FIELD_DESCRIPTION] = EnumerationToString(it->reason_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
169 failures.append(item);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
170 }
3737
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
171
3742
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3738
diff changeset
172 json[FIELD_FAILURES] = failures;
3737
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
173 }
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
174 }
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
175 }
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
176
f29843323daf accessing storage commitment reports from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3736
diff changeset
177
3738
bff4da769f6f new route: "/storage-commitment/{...}/remove"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3737
diff changeset
178 void StorageCommitmentReports::Report::GetSuccessSopInstanceUids(
bff4da769f6f new route: "/storage-commitment/{...}/remove"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3737
diff changeset
179 std::vector<std::string>& target) const
bff4da769f6f new route: "/storage-commitment/{...}/remove"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3737
diff changeset
180 {
bff4da769f6f new route: "/storage-commitment/{...}/remove"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3737
diff changeset
181 target.clear();
bff4da769f6f new route: "/storage-commitment/{...}/remove"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3737
diff changeset
182 target.reserve(success_.size());
bff4da769f6f new route: "/storage-commitment/{...}/remove"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3737
diff changeset
183
bff4da769f6f new route: "/storage-commitment/{...}/remove"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3737
diff changeset
184 for (std::list<Success>::const_iterator
bff4da769f6f new route: "/storage-commitment/{...}/remove"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3737
diff changeset
185 it = success_.begin(); it != success_.end(); ++it)
bff4da769f6f new route: "/storage-commitment/{...}/remove"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3737
diff changeset
186 {
bff4da769f6f new route: "/storage-commitment/{...}/remove"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3737
diff changeset
187 target.push_back(it->sopInstanceUid_);
bff4da769f6f new route: "/storage-commitment/{...}/remove"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3737
diff changeset
188 }
bff4da769f6f new route: "/storage-commitment/{...}/remove"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3737
diff changeset
189 }
bff4da769f6f new route: "/storage-commitment/{...}/remove"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3737
diff changeset
190
bff4da769f6f new route: "/storage-commitment/{...}/remove"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3737
diff changeset
191
3736
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 StorageCommitmentReports::~StorageCommitmentReports()
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 {
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 while (!content_.IsEmpty())
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 {
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 Report* report = NULL;
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 content_.RemoveOldest(report);
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 assert(report != NULL);
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 delete report;
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 }
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 }
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 void StorageCommitmentReports::Store(const std::string& transactionUid,
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 Report* report)
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 {
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 std::unique_ptr<Report> protection(report);
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 boost::mutex::scoped_lock lock(mutex_);
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 {
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 Report* previous = NULL;
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 if (content_.Contains(transactionUid, previous))
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 {
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 assert(previous != NULL);
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 delete previous;
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 content_.Invalidate(transactionUid);
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 }
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 }
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 assert(maxSize_ == 0 ||
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 content_.GetSize() <= maxSize_);
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 if (maxSize_ != 0 &&
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 content_.GetSize() == maxSize_)
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 {
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 assert(!content_.IsEmpty());
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 Report* oldest = NULL;
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 content_.RemoveOldest(oldest);
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 assert(oldest != NULL);
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 delete oldest;
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 }
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 assert(maxSize_ == 0 ||
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 content_.GetSize() < maxSize_);
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 content_.Add(transactionUid, protection.release());
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 }
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 StorageCommitmentReports::Accessor::Accessor(StorageCommitmentReports& that,
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 const std::string& transactionUid) :
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 lock_(that.mutex_),
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 transactionUid_(transactionUid)
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 {
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 if (that.content_.Contains(transactionUid, report_))
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 {
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 that.content_.MakeMostRecent(transactionUid);
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 }
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 else
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 {
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 report_ = NULL;
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 }
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 }
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 const StorageCommitmentReports::Report&
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 StorageCommitmentReports::Accessor::GetReport() const
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 {
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 if (report_ == NULL)
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 {
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 throw OrthancException(ErrorCode_BadSequenceOfCalls);
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 }
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 else
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 {
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 return *report_;
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 }
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 }
0540b54324f1 StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 }