ImagingTools Core SDK
TCreateUpdateCollectionWrap.h
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ImtCore-Commercial
2#pragma once
3
4
5// Qt includes
6#include <QtCore/QByteArray>
7
8
9// forward declareation
10namespace istd
11{
12class IChangeable;
13}
14
15namespace imtgql
16{
17class CGqlRequest;
18}
19
20
21namespace imtservergql
22{
23
63template<class _CreateRepresentation, class _UpdateRequest, class _Base, const char* _OID>
64class TCreateUpdateCollectionWrap: public _Base
65{
66public:
67 typedef _Base BaseClass;
68
69protected:
70 // abstract methods
71 [[nodiscard]]virtual _CreateRepresentation GetRepresentationFromRequest(const _UpdateRequest& request)const = 0;
72 [[nodiscard]]virtual bool SetObjectDataFromRepresentation(istd::IChangeable& object, const _CreateRepresentation& representation, QString& errorMessage) const = 0;
73
74 // reimplemented (_Base)
75 istd::IChangeableUniquePtr CreateObjectFromRepresentation(
76 const _CreateRepresentation& representation,
77 QByteArray& newObjectId,
78 QString& errorMessage) const override;
79
80 bool UpdateObjectFromRepresentationRequest(
81 const ::imtgql::CGqlRequest& rawGqlRequest,
82 const _UpdateRequest& updateRequest,
83 istd::IChangeable& object,
84 QString& errorMessage) const override;
85};
86
87
88// protected methods
89
90// reimplemented (_Base)
91template<class _CreateRepresentation, class _UpdateRequest, class _Base, const char* _OID>
92istd::IChangeableUniquePtr TCreateUpdateCollectionWrap<_CreateRepresentation, _UpdateRequest, _Base, _OID>::CreateObjectFromRepresentation(
93 const _CreateRepresentation& representation,
94 QByteArray& /*newObjectId*/,
95 QString& errorMessage) const
96{
97 std::unique_ptr<istd::IChangeable> objetPtr(_Base::CreateObject(QByteArray(_OID)));
98 if (objetPtr){
99 const bool isUpdated = SetObjectDataFromRepresentation(*objetPtr, representation, errorMessage);
100 if (isUpdated){
101 return objetPtr.release();
102 }
103 }
104
105 return nullptr;
106}
107
108
109template<class _CreateRepresentation, class _UpdateRequest, class _Base, const char* _OID>
110bool TCreateUpdateCollectionWrap<_CreateRepresentation, _UpdateRequest, _Base, _OID>::UpdateObjectFromRepresentationRequest(
111 const imtgql::CGqlRequest& /*gqlRequest*/,
112 const _UpdateRequest& updateRequest,
113 istd::IChangeable& object,
114 QString& errorMessage) const
115{
116 _CreateRepresentation repreesentation = GetRepresentationFromRequest(updateRequest);
117
118 return SetObjectDataFromRepresentation(object, repreesentation, errorMessage);
119}
120
121
122} // namespac imtservergql