Fesapi  2.0.0.0
This project provides C++ classes which allow an easy access in import and export to the Energistics standards.
AbstractObject.h
1 /*-----------------------------------------------------------------------
2 Licensed to the Apache Software Foundation (ASF) under one
3 or more contributor license agreements. See the NOTICE file
4 distributed with this work for additional information
5 regarding copyright ownership. The ASF licenses this file
6 to you under the Apache License, Version 2.0 (the
7 "License"; you may not use this file except in compliance
8 with the License. You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12 Unless required by applicable law or agreed to in writing,
13 software distributed under the License is distributed on an
14 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 KIND, either express or implied. See the License for the
16 specific language governing permissions and limitations
17 under the License.
18 -----------------------------------------------------------------------*/
19 #pragma once
20 
21 #include <unordered_map>
22 #include <vector>
23 #include <stdexcept>
24 
25 #include "DataObjectRepository.h"
26 
27 namespace COMMON_NS
28 {
31  {
32  private:
34  static char citationFormat[];
35 
43  void setUuid(const std::string & uuid);
44 
45  protected:
47  gsoap_resqml2_0_1::eml20__DataObjectReference* partialObject;
48 
50  gsoap_resqml2_0_1::eml20__AbstractCitedDataObject* gsoapProxy2_0_1;
51 
53  gsoap_eml2_1::eml21__AbstractObject* gsoapProxy2_1;
54 
56  gsoap_eml2_2::eml22__AbstractObject* gsoapProxy2_2;
57 
59  gsoap_eml2_3::eml23__AbstractObject* gsoapProxy2_3;
60 
62  COMMON_NS::DataObjectRepository* repository;
63 
67  AbstractObject() :
68  partialObject(nullptr), gsoapProxy2_0_1(nullptr),
69  gsoapProxy2_1(nullptr),
70  gsoapProxy2_2(nullptr),
71  gsoapProxy2_3(nullptr),
72  repository(nullptr) {}
73 
79  AbstractObject(gsoap_resqml2_0_1::eml20__DataObjectReference* partialObject_) :
80  partialObject(partialObject_), gsoapProxy2_0_1(nullptr),
81  gsoapProxy2_1(nullptr),
82  gsoapProxy2_2(nullptr),
83  gsoapProxy2_3(nullptr),
84  repository(nullptr) {}
86  partialObject(dor.toDor20()), gsoapProxy2_0_1(nullptr),
87  gsoapProxy2_1(nullptr),
88  gsoapProxy2_2(nullptr),
89  gsoapProxy2_3(nullptr),
90  repository(nullptr) {}
91 
97  AbstractObject(gsoap_resqml2_0_1::eml20__AbstractCitedDataObject* proxy) :
98  partialObject(nullptr), gsoapProxy2_0_1(proxy),
99  gsoapProxy2_1(nullptr),
100  gsoapProxy2_2(nullptr),
101  gsoapProxy2_3(nullptr),
102  repository(nullptr) {}
103 
109  AbstractObject(gsoap_eml2_1::eml21__AbstractObject* proxy) :
110  partialObject(nullptr), gsoapProxy2_0_1(nullptr),
111  gsoapProxy2_1(proxy),
112  gsoapProxy2_2(nullptr),
113  gsoapProxy2_3(nullptr),
114  repository(nullptr) {}
115 
121  AbstractObject(gsoap_eml2_2::eml22__AbstractObject* proxy) :
122  partialObject(nullptr), gsoapProxy2_0_1(nullptr),
123  gsoapProxy2_1(nullptr),
124  gsoapProxy2_2(proxy),
125  gsoapProxy2_3(nullptr),
126  repository(nullptr) {}
127 
133  AbstractObject(gsoap_eml2_3::eml23__AbstractObject* proxy) :
134  partialObject(nullptr), gsoapProxy2_0_1(nullptr),
135  gsoapProxy2_1(nullptr),
136  gsoapProxy2_2(nullptr),
137  gsoapProxy2_3(proxy),
138  repository(nullptr) {}
139 
148  friend COMMON_NS::AbstractObject* COMMON_NS::DataObjectRepository::addOrReplaceDataObject(AbstractObject* proxy, bool replaceOnlyContent);
149 
154  void initMandatoryMetadata();
155 
172  void setMetadata(const std::string & guid, const std::string & title, const std::string & editor, time_t creation, const std::string & originator,
173  const std::string & description, time_t lastUpdate, const std::string & descriptiveKeywords);
174 
176  void cannotBePartial() const;
177 
179  void changeToPartialObject();
180 
188  void readArrayNdOfDoubleValues(gsoap_resqml2_0_1::resqml20__AbstractDoubleArray * arrayInput, double * arrayOutput) const;
189 
197  void readArrayNdOfDoubleValues(gsoap_eml2_3::eml23__AbstractFloatingPointArray * arrayInput, double * arrayOutput) const;
198 
199  template <class T>
200  void readArrayNdOfNonHdf5IntegerValues(gsoap_resqml2_0_1::resqml20__AbstractIntegerArray const * arrayInput, T * arrayOutput) const {
201  switch (arrayInput->soap_type()) {
202  case SOAP_TYPE_gsoap_resqml2_0_1_resqml20__IntegerRangeArray:
203  {
204  gsoap_resqml2_0_1::resqml20__IntegerRangeArray const* rangeArray = static_cast<gsoap_resqml2_0_1::resqml20__IntegerRangeArray const *>(arrayInput);
205  if (rangeArray->Value + rangeArray->Count > (std::numeric_limits<T>::max)()) {
206  throw std::range_error("The range integer values are superior to unsigned int maximum value.");
207  }
208  for (unsigned int i = 0; i < static_cast<T>(rangeArray->Count); ++i) {
209  arrayOutput[i] = i + static_cast<T>(rangeArray->Value);
210  }
211  break;
212  }
213  case SOAP_TYPE_gsoap_resqml2_0_1_resqml20__IntegerConstantArray:
214  {
215  gsoap_resqml2_0_1::resqml20__IntegerConstantArray const* constantArray = static_cast<gsoap_resqml2_0_1::resqml20__IntegerConstantArray const*>(arrayInput);
216  if (constantArray->Value > (std::numeric_limits<T>::max)()) {
217  throw std::range_error("The constant integer value is superior to unsigned int maximum value.");
218  }
219  for (size_t i = 0; i < constantArray->Count; ++i) {
220  arrayOutput[i] = static_cast<T>(constantArray->Value);
221  }
222  break;
223  }
224  case SOAP_TYPE_gsoap_resqml2_0_1_resqml20__IntegerLatticeArray:
225  {
226  gsoap_resqml2_0_1::resqml20__IntegerLatticeArray const* latticeArray = static_cast<gsoap_resqml2_0_1::resqml20__IntegerLatticeArray const*>(arrayInput);
227  if (latticeArray->Offset.size() > 1) {
228  throw std::invalid_argument("The integer lattice array contains more than one offset.");
229  }
230  for (size_t i = 0; i <= latticeArray->Offset[0]->Count; ++i) {
231  arrayOutput[i] = latticeArray->StartValue + (i * latticeArray->Offset[0]->Value);
232  }
233  break;
234  }
235  default:
236  throw std::invalid_argument("The integer array type is not supported yet.");
237  }
238  }
239 
240  template <class T>
241  void readArrayNdOfNonHdf5IntegerValues(gsoap_eml2_3::eml23__AbstractIntegerArray const * arrayInput, T * arrayOutput) const {
242  switch (arrayInput->soap_type()) {
243  case SOAP_TYPE_gsoap_eml2_3_eml23__IntegerRangeArray:
244  {
245  gsoap_eml2_3::eml23__IntegerRangeArray const* rangeArray = static_cast<gsoap_eml2_3::eml23__IntegerRangeArray const*>(arrayInput);
246  if (rangeArray->Value + rangeArray->Count > (std::numeric_limits<T>::max)()) {
247  throw std::range_error("The range integer values are superior to unsigned int maximum value.");
248  }
249  for (unsigned int i = 0; i < static_cast<T>(rangeArray->Count); ++i) {
250  arrayOutput[i] = i + static_cast<T>(rangeArray->Value);
251  }
252  break;
253  }
254  case SOAP_TYPE_gsoap_eml2_3_eml23__IntegerConstantArray:
255  {
256  gsoap_eml2_3::eml23__IntegerConstantArray const* constantArray = static_cast<gsoap_eml2_3::eml23__IntegerConstantArray const*>(arrayInput);
257  if (constantArray->Value > (std::numeric_limits<T>::max)()) {
258  throw std::range_error("The constant integer value is superior to unsigned int maximum value.");
259  }
260  std::fill(arrayOutput, arrayOutput + constantArray->Count, static_cast<T>(constantArray->Value));
261  break;
262  }
263  case SOAP_TYPE_gsoap_eml2_3_eml23__IntegerLatticeArray:
264  {
265  gsoap_eml2_3::eml23__IntegerLatticeArray const* latticeArray = static_cast<gsoap_eml2_3::eml23__IntegerLatticeArray const*>(arrayInput);
266  if (latticeArray->Offset.size() > 1) {
267  throw std::invalid_argument("The integer lattice array contains more than one offset.");
268  }
269  for (size_t i = 0; i <= latticeArray->Offset[0]->Count; ++i) {
270  arrayOutput[i] = latticeArray->StartValue + (i * latticeArray->Offset[0]->Value);
271  }
272  break;
273  }
274  default: throw std::invalid_argument("The integer array type is not supported yet.");
275  }
276  }
277 
287  uint8_t readArrayNdOfUInt8Values(gsoap_resqml2_0_1::resqml20__AbstractIntegerArray const * arrayInput, uint8_t * arrayOutput) const;
288 
298  uint8_t readArrayNdOfUInt8Values(gsoap_eml2_3::eml23__AbstractIntegerArray const * arrayInput, uint8_t * arrayOutput) const;
299 
309  uint16_t readArrayNdOfUInt16Values(gsoap_resqml2_0_1::resqml20__AbstractIntegerArray const * arrayInput, uint16_t * arrayOutput) const;
310 
320  uint16_t readArrayNdOfUInt16Values(gsoap_eml2_3::eml23__AbstractIntegerArray const * arrayInput, uint16_t * arrayOutput) const;
321 
331  uint32_t readArrayNdOfUInt32Values(gsoap_resqml2_0_1::resqml20__AbstractIntegerArray const * arrayInput, uint32_t * arrayOutput) const;
332 
342  uint32_t readArrayNdOfUInt32Values(gsoap_eml2_3::eml23__AbstractIntegerArray const * arrayInput, uint32_t * arrayOutput) const;
343 
353  uint64_t readArrayNdOfUInt64Values(gsoap_resqml2_0_1::resqml20__AbstractIntegerArray const * arrayInput, uint64_t * arrayOutput) const;
354 
364  uint64_t readArrayNdOfUInt64Values(gsoap_eml2_3::eml23__AbstractIntegerArray const * arrayInput, uint64_t * arrayOutput) const;
365 
373  uint64_t getCountOfIntegerArray(gsoap_resqml2_0_1::resqml20__AbstractIntegerArray * arrayInput) const;
374 
382  uint64_t getCountOfIntegerArray(gsoap_eml2_3::eml23__AbstractIntegerArray * arrayInput) const;
383 
389  void convertDorIntoRel(const DataObjectReference& dor);
390 
400  template <class valueType>
401  void convertDorIntoRel(const DataObjectReference& dor)
402  {
403  valueType * targetObj = getRepository()->getDataObjectByUuid<valueType>(dor.getUuid());
404  if (targetObj == nullptr) { // partial transfer
405  getRepository()->createPartial(dor);
406  targetObj = getRepository()->getDataObjectByUuid<valueType>(dor.getUuid());
407  if (targetObj == nullptr) {
408  throw std::invalid_argument("The DOR looks invalid.");
409  }
410  }
411  getRepository()->addRelationship(this, targetObj);
412  }
413 
425  EML2_NS::AbstractHdfProxy* getHdfProxyFromDataset(gsoap_resqml2_0_1::eml20__Hdf5Dataset const * dataset, bool throwException = true) const;
426 
438  EML2_NS::AbstractHdfProxy* getHdfProxyFromDataset(gsoap_eml2_3::eml23__ExternalDatasetPart const * dataset, bool throwException = true) const;
439 
443  std::string getHdfGroup() const {
444  return "/" + getXmlNamespace() + "/" + getUuid();
445  }
446 
447  gsoap_resqml2_0_1::resqml20__IndexableElements mapIndexableElement(gsoap_eml2_3::resqml22__IndexableElement toMap) const;
448 
449  public:
450 
451  enum hdfDatatypeEnum { UNKNOWN = 0, DOUBLE = 1, FLOAT = 2, LONG_64 = 3, ULONG_64 = 4, INT = 5, UINT = 6, SHORT = 7, USHORT = 8, CHAR = 9, UCHAR = 10};
452 
453  DLL_IMPORT_OR_EXPORT virtual ~AbstractObject() = default;
454 
462  DLL_IMPORT_OR_EXPORT bool isPartial() const;
463 
464  DLL_IMPORT_OR_EXPORT virtual bool isTopLevelElement() const { return true; }
465 
475  DLL_IMPORT_OR_EXPORT std::string getUuid() const;
476 
486  DLL_IMPORT_OR_EXPORT std::string getTitle() const;
487 
497  DLL_IMPORT_OR_EXPORT std::string getEditor() const;
498 
510  DLL_IMPORT_OR_EXPORT time_t getCreation() const;
511 
522  DLL_IMPORT_OR_EXPORT tm getCreationAsTimeStructure() const;
523 
538  DLL_IMPORT_OR_EXPORT std::string getOriginator() const;
539 
549  DLL_IMPORT_OR_EXPORT std::string getDescription() const;
550 
560  DLL_IMPORT_OR_EXPORT time_t getLastUpdate() const;
561 
570  DLL_IMPORT_OR_EXPORT tm getLastUpdateAsTimeStructure() const;
571 
588  DLL_IMPORT_OR_EXPORT std::string getFormat() const;
589 
600  DLL_IMPORT_OR_EXPORT std::string getDescriptiveKeywords() const;
601 
608  DLL_IMPORT_OR_EXPORT std::string getVersion() const;
609 
620  DLL_IMPORT_OR_EXPORT void setTitle(const std::string & title);
621 
632  DLL_IMPORT_OR_EXPORT void setEditor(const std::string & editor);
633 
643  DLL_IMPORT_OR_EXPORT void setCreation(time_t creation);
644 
653  DLL_IMPORT_OR_EXPORT void setCreation(const tm & creation);
654 
669  DLL_IMPORT_OR_EXPORT void setOriginator(const std::string & originator);
670 
682  DLL_IMPORT_OR_EXPORT void setDescription(const std::string & description);
683 
693  DLL_IMPORT_OR_EXPORT void setLastUpdate(time_t lastUpdate);
694 
701  DLL_IMPORT_OR_EXPORT void setLastUpdate(const tm & lastUpdate);
702 
716  DLL_IMPORT_OR_EXPORT static void setFormat(const std::string & vendor, const std::string & applicationName, const std::string & applicationVersionNumber);
717 
730  DLL_IMPORT_OR_EXPORT void setDescriptiveKeywords(const std::string & descriptiveKeywords);
731 
740  DLL_IMPORT_OR_EXPORT void setVersion(const std::string & version);
741 
768  DLL_IMPORT_OR_EXPORT void setMetadata(const std::string & title, const std::string & editor, time_t creation, const std::string & originator,
769  const std::string & description, time_t lastUpdate, const std::string & descriptiveKeywords);
770 
779  DLL_IMPORT_OR_EXPORT void serializeIntoStream(std::ostream * stream);
780 
786  void setGsoapProxy(gsoap_resqml2_0_1::eml20__AbstractCitedDataObject* gsoapProxy) { gsoapProxy2_0_1 = gsoapProxy; }
787 
788  void setGsoapProxy(gsoap_eml2_1::eml21__AbstractObject* gsoapProxy) { gsoapProxy2_1 = gsoapProxy; }
789 
795  gsoap_resqml2_0_1::eml20__AbstractCitedDataObject* getEml20GsoapProxy() const { return gsoapProxy2_0_1; }
796 
802  gsoap_eml2_1::eml21__AbstractObject* getEml21GsoapProxy() const { return gsoapProxy2_1; }
803 
804  gsoap_eml2_2::eml22__AbstractObject* getEml22GsoapProxy() const { return gsoapProxy2_2; }
805  void setGsoapProxy(gsoap_eml2_2::eml22__AbstractObject* gsoapProxy) { gsoapProxy2_2 = gsoapProxy; }
806 
812  gsoap_eml2_3::eml23__AbstractObject* getEml23GsoapProxy() const { return gsoapProxy2_3; }
813  void setGsoapProxy(gsoap_eml2_3::eml23__AbstractObject* gsoapProxy) { gsoapProxy2_3 = gsoapProxy; }
814 
820  soap* getGsoapContext() const;
821 
829  int getGsoapType() const;
830 
836  gsoap_resqml2_0_1::eml20__DataObjectReference* newResqmlReference() const;
837 
843  DLL_IMPORT_OR_EXPORT gsoap_eml2_1::eml21__DataObjectReference* newEmlReference() const;
844 
850  gsoap_eml2_2::eml22__DataObjectReference* newEml22Reference() const;
851 
857  gsoap_eml2_3::eml23__DataObjectReference* newEml23Reference() const;
858 
864  gsoap_resqml2_0_1::resqml20__ContactElementReference* newContactElementReference2_0_1() const;
865 
871  gsoap_eml2_3::resqml22__ContactElement* newContactElementReference2_2() const;
872 
878  DLL_IMPORT_OR_EXPORT COMMON_NS::DataObjectRepository* getRepository() const {return repository;}
879 
885  DLL_IMPORT_OR_EXPORT virtual std::string getXmlNamespace() const = 0;
886 
892  DLL_IMPORT_OR_EXPORT virtual std::string getXmlTag() const = 0;
893 
900  DLL_IMPORT_OR_EXPORT virtual std::string getXmlNamespaceVersion() const;
901 
907  DLL_IMPORT_OR_EXPORT virtual std::string getContentType() const;
908 
914  DLL_IMPORT_OR_EXPORT virtual std::string getQualifiedType() const;
915 
921  DLL_IMPORT_OR_EXPORT virtual std::string getPartNameInEpcDocument() const;
922 
928  DLL_IMPORT_OR_EXPORT std::string serializeIntoString();
929 
939  DLL_IMPORT_OR_EXPORT void addAlias(const std::string & authority, const std::string & title);
940 
950  DLL_IMPORT_OR_EXPORT unsigned int getAliasCount() const;
951 
963  DLL_IMPORT_OR_EXPORT std::string getAliasAuthorityAtIndex(unsigned int index) const;
964 
976  DLL_IMPORT_OR_EXPORT std::string getAliasTitleAtIndex(unsigned int index) const;
977 
983  DLL_IMPORT_OR_EXPORT std::vector<EML2_NS::Activity*> getActivitySet() const;
984 
993  DLL_IMPORT_OR_EXPORT unsigned int getActivityCount() const;
994 
1006  DLL_IMPORT_OR_EXPORT EML2_NS::Activity* getActivity(unsigned int index) const;
1007 
1016  DLL_IMPORT_OR_EXPORT void pushBackExtraMetadata(const std::string & key, const std::string & value);
1017 
1025  DLL_IMPORT_OR_EXPORT std::unordered_map< std::string, std::string > getExtraMetadataSet() const;
1026 
1036  DLL_IMPORT_OR_EXPORT std::vector<std::string> getExtraMetadata(const std::string & key) const;
1037 
1045  DLL_IMPORT_OR_EXPORT unsigned int getExtraMetadataCount() const;
1046 
1057  DLL_IMPORT_OR_EXPORT std::string getExtraMetadataKeyAtIndex(unsigned int index) const;
1058 
1069  DLL_IMPORT_OR_EXPORT std::string getExtraMetadataStringValueAtIndex(unsigned int index) const;
1070 
1075  virtual void loadTargetRelationships() = 0;
1076  };
1077 }
An abstract data object.
Definition: AbstractObject.h:31
void setCreation(const tm &creation)
void setVersion(const std::string &version)
unsigned int getAliasCount() const
std::string getVersion() const
virtual std::string getContentType() const
void setTitle(const std::string &title)
std::unordered_map< std::string, std::string > getExtraMetadataSet() const
time_t getCreation() const
virtual void loadTargetRelationships()=0
std::string getExtraMetadataStringValueAtIndex(unsigned int index) const
std::string serializeIntoString()
gsoap_eml2_1::eml21__AbstractObject * getEml21GsoapProxy() const
Definition: AbstractObject.h:802
unsigned int getExtraMetadataCount() const
std::string getDescriptiveKeywords() const
virtual std::string getXmlNamespaceVersion() const
gsoap_resqml2_0_1::eml20__DataObjectReference * newResqmlReference() const
std::string getEditor() const
gsoap_resqml2_0_1::resqml20__ContactElementReference * newContactElementReference2_0_1() const
bool isPartial() const
common::DataObjectRepository * getRepository() const
Definition: AbstractObject.h:878
std::string getAliasTitleAtIndex(unsigned int index) const
virtual std::string getQualifiedType() const
void setEditor(const std::string &editor)
void setLastUpdate(time_t lastUpdate)
gsoap_resqml2_0_1::eml20__AbstractCitedDataObject * getEml20GsoapProxy() const
Definition: AbstractObject.h:795
soap * getGsoapContext() const
std::vector< eml2::Activity * > getActivitySet() const
std::string getUuid() const
gsoap_eml2_2::eml22__DataObjectReference * newEml22Reference() const
std::string getAliasAuthorityAtIndex(unsigned int index) const
void setDescription(const std::string &description)
int getGsoapType() const
gsoap_eml2_1::eml21__DataObjectReference * newEmlReference() const
void serializeIntoStream(std::ostream *stream)
void setDescriptiveKeywords(const std::string &descriptiveKeywords)
virtual std::string getXmlNamespace() const =0
void setCreation(time_t creation)
void pushBackExtraMetadata(const std::string &key, const std::string &value)
gsoap_eml2_3::eml23__AbstractObject * getEml23GsoapProxy() const
Definition: AbstractObject.h:812
void setLastUpdate(const tm &lastUpdate)
std::vector< std::string > getExtraMetadata(const std::string &key) const
eml2::Activity * getActivity(unsigned int index) const
std::string getOriginator() const
void setGsoapProxy(gsoap_resqml2_0_1::eml20__AbstractCitedDataObject *gsoapProxy)
Definition: AbstractObject.h:786
tm getCreationAsTimeStructure() const
tm getLastUpdateAsTimeStructure() const
void setMetadata(const std::string &title, const std::string &editor, time_t creation, const std::string &originator, const std::string &description, time_t lastUpdate, const std::string &descriptiveKeywords)
void setOriginator(const std::string &originator)
virtual std::string getPartNameInEpcDocument() const
std::string getDescription() const
gsoap_eml2_3::eml23__DataObjectReference * newEml23Reference() const
time_t getLastUpdate() const
static void setFormat(const std::string &vendor, const std::string &applicationName, const std::string &applicationVersionNumber)
virtual std::string getXmlTag() const =0
void addAlias(const std::string &authority, const std::string &title)
unsigned int getActivityCount() const
gsoap_eml2_3::resqml22__ContactElement * newContactElementReference2_2() const
std::string getTitle() const
std::string getFormat() const
std::string getExtraMetadataKeyAtIndex(unsigned int index) const
This class wraps an Energistics Data Object Reference whatever its version is.
Definition: DataObjectReference.h:43
gsoap_resqml2_0_1::eml20__DataObjectReference * toDor20() const
Definition: DataObjectReference.h:194