Documentation for OpenFLUID 2.2.2
Loading...
Searching...
No Matches
WareIssues.hpp
Go to the documentation of this file.
1/*
2
3 This file is part of OpenFLUID software
4 Copyright(c) 2021-2026, INRAE
5
6
7 == GNU General Public License Usage ==
8
9 OpenFLUID is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 OpenFLUID is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21
22
23 == Other Usage ==
24
25 Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26 license, and requires a written agreement between You and INRA.
27 Licensees for Other Usage of OpenFLUID may use this file in accordance
28 with the terms contained in the written agreement between You and INRA.
29
30*/
31
32
33/**
34 @file WareIssues.hpp
35
36 @author Jean-Christophe FABRE <jean-christophe.fabre@inrae.fr>
37 @author Armel THÖNI <armel.thoni@inrae.fr>
38 */
39
40#ifndef __OPENFLUID_WARE_WAREISSUES_HPP__
41#define __OPENFLUID_WARE_WAREISSUES_HPP__
42
43
44#include <string>
45#include <map>
46
51
52
53namespace openfluid { namespace ware {
54
55
56enum class IssueUrgency { LOW, MEDIUM, HIGH };
57
58
60{
61 public:
62
63 unsigned int ID;
64
65 std::string Title;
66
67 std::string Description;
68
69 std::vector<std::string> Tags;
70
71 std::string Creator;
72
74
76
77 bool IsOpen = true;
78
79
80 openfluid::thirdparty::json toJSON(unsigned int NewID=0) const
81 {
82 if (NewID == 0)
83 {
84 NewID = ID;
85 }
86 auto IObj = openfluid::thirdparty::json::object();
87 IObj["id"] = NewID;
88 IObj["title"] = Title;
89 IObj["description"] = Description;
90 IObj["tags"] = Tags;
91 IObj["creator"] = Creator;
92 IObj["created_at"] = CreatedAt.getAsISOString();
93 IObj["updated_at"] = UpdatedAt.getAsISOString();
94 IObj["state"] = IsOpen ? "open" : "closed";
95 return IObj;
96 }
97
99 {
100 WareIssue NewI;
101 if (!IssueJson.contains("id"))
102 {
103 throw openfluid::base::FrameworkException("Info not containing id");
104 }
105 if (IssueJson["id"].is_number_integer())
106 {
107 NewI.ID = IssueJson["id"].get<unsigned int>();
108 }
109 else
110 {
111 throw openfluid::base::FrameworkException("Bad id format for ware issue");
112 }
113 NewI.Title = IssueJson.value("title","");
114 NewI.Description = IssueJson.value("description","");
115 if (IssueJson.contains("tags"))
116 {
117 NewI.Tags = IssueJson.value("tags",std::vector<std::string>());
118 }
119
120 NewI.Creator = IssueJson.value("creator","");
121 NewI.CreatedAt = openfluid::core::DateTime::fromISOString(IssueJson.value("created_at",""));
122 NewI.UpdatedAt = openfluid::core::DateTime::fromISOString(IssueJson.value("updated_at",""));
123 NewI.IsOpen = (IssueJson.value("state","") != "closed");
124 return NewI;
125 }
126 //NOTE: issue comparison is implemented in waresdev/tests, move here as class method when needed
127};
128
129
130// =====================================================================
131// =====================================================================
132
133
135{
136 private:
137
138 std::map<unsigned int,WareIssue> m_Issues;
139
140
141 public:
142
143 /**
144 Adds an issue and automatically assigns an ID
145 @param[in] Issue The issue to add
146 */
147 void add(const WareIssue& Issue);
148
149 /**
150 Inserts an issue with the given ID
151 @param[in] Issue The issue to insert
152 @param[in] ID The ID of the issue to insert
153 */
154 void insert(const WareIssue& Issue, unsigned int ID);
155
156 /**
157 Removes the issue with the given ID (does nothing if the ID does not exist)
158 @param[in] ID The ID of the issue to remove
159 */
160 void remove(unsigned int ID);
161
162 /**
163 Returns the issue with the given ID
164 @param[in] ID The ID of the issue
165 */
166 const WareIssue& get(unsigned int ID) const;
167
168 /**
169 Returns all the issues as a map indexed by issues ID
170 @return All issues
171 */
172 const std::map<unsigned int,WareIssue>& getAll() const;
173
174 /**
175 Returns all the issues as a map indexed by issues ID
176 @return All issues
177 */
178 const std::map<unsigned int,WareIssue>& operator()() const;
179
180 void clear()
181 {
182 m_Issues.clear();
183 }
184};
185
186
187} } // namespaces
188
189
190#endif /* __OPENFLUID_WARE_WAREISSUES_HPP__ */
Definition FrameworkException.hpp:51
Class for management of date and time information.
Definition DateTime.hpp:88
std::string getAsISOString() const
static DateTime fromISOString(const std::string &DateTimeStr)
Definition WareIssues.hpp:60
std::string Title
Definition WareIssues.hpp:65
std::string Description
Definition WareIssues.hpp:67
openfluid::thirdparty::json toJSON(unsigned int NewID=0) const
Definition WareIssues.hpp:80
unsigned int ID
Definition WareIssues.hpp:63
openfluid::core::DateTime CreatedAt
Definition WareIssues.hpp:73
std::string Creator
Definition WareIssues.hpp:71
openfluid::core::DateTime UpdatedAt
Definition WareIssues.hpp:75
static WareIssue fromJSON(const openfluid::thirdparty::json &IssueJson)
Definition WareIssues.hpp:98
bool IsOpen
Definition WareIssues.hpp:77
std::vector< std::string > Tags
Definition WareIssues.hpp:69
Definition WareIssues.hpp:135
void clear()
Definition WareIssues.hpp:180
const WareIssue & get(unsigned int ID) const
void insert(const WareIssue &Issue, unsigned int ID)
const std::map< unsigned int, WareIssue > & getAll() const
void remove(unsigned int ID)
const std::map< unsigned int, WareIssue > & operator()() const
void add(const WareIssue &Issue)
#define OPENFLUID_API
Definition dllexport.hpp:86
nlohmann::ordered_json json
Definition JSON.hpp:52
IssueUrgency
Definition WareIssues.hpp:56
Definition ApplicationException.hpp:47