diff --git a/CrestApi/CrestModel.h b/CrestApi/CrestModel.h index 7c5bb51ce3b7d21d5f0e7a7b46271b9895e712c9..5371db8093c15d2c8c65e2736764988aac29aba7 100644 --- a/CrestApi/CrestModel.h +++ b/CrestApi/CrestModel.h @@ -38,15 +38,17 @@ public: class CrestBaseResponse { -public: +private: int64_t size; +public: std::string datatype; std::string format; std::optional<RespPage> page; std::optional<GenericMap> filter; - + CrestBaseResponse():datatype("data"),format("StoreSetDto"){} + CrestBaseResponse(std::string _datatype,std::string _format):datatype(_datatype),format(_format){} json to_json() const; - + void setSize(int64_t _size){size=_size;} static CrestBaseResponse from_json(const json &j); }; @@ -104,10 +106,10 @@ public: std::string insertionTime; std::string modificationTime; // Ctor - TagDto(std::string name, std::string timeType, std::string description): name(name), timeType(timeType), + TagDto(std::string _name, std::string _timeType, std::string _description): name(_name), timeType(_timeType), objectType(""), synchronization(""), - description(description), + description(_description), lastValidatedTime(0), endOfValidity(0), insertionTime(""), modificationTime(""){ } @@ -232,6 +234,10 @@ public: std::string data; std::string streamerInfo; + StoreDto(long_t _since, std::string _data): + since(_since), hash(""), data(_data), streamerInfo("{}"){ + + } // Ctor StoreDto(long_t since, std::string hash, std::string data): since(since), hash(hash), data(data), streamerInfo("{}"){ @@ -250,7 +256,10 @@ class StoreSetDto : public CrestBaseResponse { public: std::vector<StoreDto> resources; - + StoreSetDto():CrestBaseResponse(){;} + void push_back(StoreDto dto); + size_t size(); + void clear(); json to_json() const; static StoreSetDto from_json(const json &j); diff --git a/src/CrestApiFs.cxx b/src/CrestApiFs.cxx index e1c0278cd5ecdd2a4d26b78cb4f1437e530dd597..e7c26bfc664e89d45b4b245e1fab8edc9701fa6f 100644 --- a/src/CrestApiFs.cxx +++ b/src/CrestApiFs.cxx @@ -203,7 +203,7 @@ namespace Crest GlobalTagDto dto = findGlobalTag(tag); tagSet.resources.push_back(dto); } - tagSet.size = tagNumber; + tagSet.setSize(tagNumber); tagSet.datatype = ""; tagSet.format = "TagSetDto"; } @@ -321,7 +321,7 @@ namespace Crest TagDto dto = findTag(tag); tagSet.resources.push_back(dto); } - tagSet.size = tagNumber; + tagSet.setSize(tagNumber); tagSet.datatype = ""; tagSet.format = "TagSetDto"; } diff --git a/src/CrestModel.cxx b/src/CrestModel.cxx index a92b8933881ef2f0ae8f7fb1e4a0d8ed41c1f1e7..6b8ed413d1777f124068a0295a88caa498984b5b 100644 --- a/src/CrestModel.cxx +++ b/src/CrestModel.cxx @@ -105,7 +105,7 @@ { globalTagSet.resources.push_back(GlobalTagDto::from_json(*it)); } - globalTagSet.size = j.value("size", 0); + globalTagSet.setSize(j.value("size", 0)); globalTagSet.datatype = j.value("datatype", ""); globalTagSet.format = j.value("format", "GlobalTagSetDto"); @@ -163,7 +163,18 @@ } json TagDto::to_json() const { - return { + json js={}; + js["name"]=name; + js["timeType"]=timeType; + js["payloadSpec"]=objectType; + js["synchronization"]=synchronization; + js["insertionTime"]=insertionTime; + js["description"]=description; + js["lastValidatedTime"]=lastValidatedTime; + js["endOfValidity"]=endOfValidity; + js["modificationTime"]=modificationTime; + return js; + /*{ {"name", name}, {"timeType", timeType}, {"payloadSpec", objectType}, @@ -172,7 +183,7 @@ {"lastValidatedTime", lastValidatedTime}, {"endOfValidity", endOfValidity}, {"insertionTime", insertionTime}, - {"modificationTime", modificationTime}}; + {"modificationTime", modificationTime}};*/ } TagDto TagDto::from_json(const json &j) { @@ -217,7 +228,7 @@ tagSet.resources.push_back(TagDto::from_json(*it)); } - tagSet.size = j.value("size", 0); + tagSet.setSize(j.value("size", 0)); tagSet.datatype = j.value("datatype", ""); tagSet.format = j.value("format", "TagSetDto"); @@ -268,7 +279,7 @@ tagMapSet.resources.push_back(GlobalTagMapDto::from_json(*it)); } - tagMapSet.size = j.value("size", 0); + tagMapSet.setSize(j.value("size", 0)); tagMapSet.datatype = j.value("datatype", ""); tagMapSet.format = j.value("format", "GlobalTagMapSetDto"); @@ -292,7 +303,7 @@ tagMapSet.resources.push_back(GlobalTagMapDto::from_json(*it)); } - tagMapSet.size = n; + tagMapSet.setSize(n); tagMapSet.datatype = "maps"; tagMapSet.format = "GlobalTagMapSetDto"; @@ -341,7 +352,7 @@ tagSet.resources.push_back(TagMetaDto::from_json(*it)); } - tagSet.size = j.value("size", 0); + tagSet.setSize(j.value("size", 0)); tagSet.datatype = j.value("datatype", ""); tagSet.format = j.value("format", ""); @@ -393,7 +404,7 @@ iovSet.resources.push_back(IovDto::from_json(*it)); } - iovSet.size = j.value("size", iovSet.resources.size()); + iovSet.setSize(j.value("size", iovSet.resources.size())); iovSet.datatype = j.value("datatype", ""); iovSet.format = j.value("format", ""); CrestBaseResponse cbr = CrestBaseResponse::from_json(j); @@ -416,7 +427,7 @@ iovSet.resources.push_back(IovDto::from_json(*it)); } - iovSet.size = n; + iovSet.setSize(n); iovSet.datatype = "iovs"; iovSet.format = "IovSetDto"; @@ -453,6 +464,17 @@ baseJson["resources"] = jsonResources; return baseJson; } + void StoreSetDto::push_back(StoreDto dto){ + resources.push_back(dto); + setSize(size()); + } + size_t StoreSetDto::size(){ + return resources.size(); + } + void StoreSetDto::clear(){ + resources.clear(); + setSize(size()); + } StoreSetDto StoreSetDto::from_json(const json &j) { @@ -460,10 +482,10 @@ json jsonResources = j.value("resources", json::array()); for (auto it = jsonResources.begin(); it != jsonResources.end(); ++it) { - storeSetDto.resources.push_back(StoreDto::from_json(*it)); + storeSetDto.push_back(StoreDto::from_json(*it)); } - storeSetDto.size = j.value("size", storeSetDto.resources.size()); + //storeSetDto.size = j.value("size", storeSetDto.resources.size()); storeSetDto.datatype = j.value("datatype", "data"); storeSetDto.format = j.value("format", "StoreSetDto"); // we are skipping the parse of RespPage for page, and GenericMap for filters @@ -528,7 +550,7 @@ } // Deserialize CrestBaseResponse part - payloadSetDto.size = j.value("size", payloadSetDto.resources.size()); + payloadSetDto.setSize(j.value("size", payloadSetDto.resources.size())); payloadSetDto.datatype = j.value("datatype", "data"); payloadSetDto.format = j.value("format", "PayloadSetDto"); // we are skipping the parse of RespPage for page, and GenericMap for filters