Fesapi 2.7.0.0
This project provides C++ classes which allow an easy access in import and export to the Energistics standards.
Loading...
Searching...
No Matches
AbstractObject.h
1/*-----------------------------------------------------------------------
2Licensed to the Apache Software Foundation (ASF) under one
3or more contributor license agreements. See the NOTICE file
4distributed with this work for additional information
5regarding copyright ownership. The ASF licenses this file
6to you under the Apache License, Version 2.0 (the
7"License"; you may not use this file except in compliance
8with the License. You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12Unless required by applicable law or agreed to in writing,
13software distributed under the License is distributed on an
14"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15KIND, either express or implied. See the License for the
16specific language governing permissions and limitations
17under the License.
18-----------------------------------------------------------------------*/
19#pragma once
20
21#include <unordered_map>
22#include <vector>
23#include <sstream>
24#include <stdexcept>
25
26#include "DataObjectRepository.h"
27
28namespace COMMON_NS
29{
32 {
33 public:
34
35 enum class numericalDatatypeEnum { UNKNOWN = 0, DOUBLE = 1, FLOAT = 2, INT64 = 3, UINT64 = 4, INT32 = 5, UINT32 = 6, INT16 = 7, UINT16 = 8, INT8 = 9, UINT8 = 10};
36
37 DLL_IMPORT_OR_EXPORT virtual ~AbstractObject() = default;
38
46 DLL_IMPORT_OR_EXPORT bool isPartial() const;
47
48 DLL_IMPORT_OR_EXPORT virtual bool isTopLevelElement() const { return true; }
49
59 DLL_IMPORT_OR_EXPORT std::string getUuid() const;
60
70 DLL_IMPORT_OR_EXPORT std::string getTitle() const;
71
81 DLL_IMPORT_OR_EXPORT std::string getEditor() const;
82
94 DLL_IMPORT_OR_EXPORT time_t getCreation() const;
95
106 DLL_IMPORT_OR_EXPORT tm getCreationAsTimeStructure() const;
107
122 DLL_IMPORT_OR_EXPORT std::string getOriginator() const;
123
133 DLL_IMPORT_OR_EXPORT std::string getDescription() const;
134
144 DLL_IMPORT_OR_EXPORT time_t getLastUpdate() const;
145
154 DLL_IMPORT_OR_EXPORT tm getLastUpdateAsTimeStructure() const;
155
172 DLL_IMPORT_OR_EXPORT std::string getFormat() const;
173
184 DLL_IMPORT_OR_EXPORT std::string getDescriptiveKeywords() const;
185
192 DLL_IMPORT_OR_EXPORT std::string getVersion() const;
193
204 DLL_IMPORT_OR_EXPORT void setTitle(const std::string & title);
205
216 DLL_IMPORT_OR_EXPORT void setEditor(const std::string & editor);
217
227 DLL_IMPORT_OR_EXPORT void setCreation(time_t creation);
228
237 DLL_IMPORT_OR_EXPORT void setCreation(const tm & creation);
238
253 DLL_IMPORT_OR_EXPORT void setOriginator(const std::string & originator);
254
266 DLL_IMPORT_OR_EXPORT void setDescription(const std::string & description);
267
277 DLL_IMPORT_OR_EXPORT void setLastUpdate(time_t lastUpdate);
278
285 DLL_IMPORT_OR_EXPORT void setLastUpdate(const tm & lastUpdate);
286
300 DLL_IMPORT_OR_EXPORT static void setFormat(const std::string & vendor, const std::string & applicationName, const std::string & applicationVersionNumber);
301
314 DLL_IMPORT_OR_EXPORT void setDescriptiveKeywords(const std::string & descriptiveKeywords);
315
324 DLL_IMPORT_OR_EXPORT void setVersion(const std::string & version);
325
352 DLL_IMPORT_OR_EXPORT void setMetadata(const std::string & title, const std::string & editor, time_t creation, const std::string & originator,
353 const std::string & description, time_t lastUpdate, const std::string & descriptiveKeywords);
354
363 DLL_IMPORT_OR_EXPORT void serializeIntoStream(std::ostream * stream);
364
370 gsoap_resqml2_0_1::eml20__AbstractCitedDataObject* getEml20GsoapProxy() const { return gsoapProxy2_0_1; }
376 void setGsoapProxy(gsoap_resqml2_0_1::eml20__AbstractCitedDataObject* gsoapProxy) { gsoapProxy2_0_1 = gsoapProxy; }
377
383 gsoap_eml2_3::eml23__AbstractObject* getEml23GsoapProxy() const { return gsoapProxy2_3; }
389 void setGsoapProxy(gsoap_eml2_3::eml23__AbstractObject* gsoapProxy) { gsoapProxy2_3 = gsoapProxy; }
390
396 soap* getGsoapContext() const;
397
405 int getGsoapType() const;
406
412 gsoap_resqml2_0_1::eml20__DataObjectReference* newResqmlReference() const;
413
419 gsoap_eml2_3::eml23__DataObjectReference* newEml23Reference() const;
420
426 gsoap_resqml2_0_1::resqml20__ContactElementReference* newContactElementReference2_0_1() const;
427
433 gsoap_eml2_3::resqml22__ContactElement* newContactElementReference2_2() const;
434
440 DLL_IMPORT_OR_EXPORT COMMON_NS::DataObjectRepository* getRepository() const {return repository;}
441
447 DLL_IMPORT_OR_EXPORT virtual std::string getXmlNamespace() const = 0;
448
454 DLL_IMPORT_OR_EXPORT virtual std::string getXmlTag() const = 0;
455
462 DLL_IMPORT_OR_EXPORT virtual std::string getXmlNamespaceVersion() const;
463
469 DLL_IMPORT_OR_EXPORT virtual std::string getContentType() const;
470
476 DLL_IMPORT_OR_EXPORT virtual std::string getQualifiedType() const;
477
483 DLL_IMPORT_OR_EXPORT virtual std::string getPartNameInEpcDocument() const;
484
490 DLL_IMPORT_OR_EXPORT std::string serializeIntoString();
491
501 DLL_IMPORT_OR_EXPORT void addAlias(const std::string & authority, const std::string & title);
502
512 DLL_IMPORT_OR_EXPORT unsigned int getAliasCount() const;
513
525 DLL_IMPORT_OR_EXPORT std::string getAliasAuthorityAtIndex(unsigned int index) const;
526
538 DLL_IMPORT_OR_EXPORT std::string getAliasTitleAtIndex(unsigned int index) const;
539
545 DLL_IMPORT_OR_EXPORT std::vector<EML2_NS::Activity*> getActivitySet() const;
546
555 DLL_IMPORT_OR_EXPORT unsigned int getActivityCount() const;
556
568 DLL_IMPORT_OR_EXPORT EML2_NS::Activity* getActivity(unsigned int index) const;
569
578 DLL_IMPORT_OR_EXPORT void pushBackExtraMetadata(const std::string & key, const std::string & value);
579
587 DLL_IMPORT_OR_EXPORT std::unordered_map< std::string, std::string > getExtraMetadataSet() const;
588
598 DLL_IMPORT_OR_EXPORT std::vector<std::string> getExtraMetadata(const std::string & key) const;
599
607 DLL_IMPORT_OR_EXPORT unsigned int getExtraMetadataCount() const;
608
619 DLL_IMPORT_OR_EXPORT std::string getExtraMetadataKeyAtIndex(unsigned int index) const;
620
631 DLL_IMPORT_OR_EXPORT std::string getExtraMetadataStringValueAtIndex(unsigned int index) const;
632
638 DLL_IMPORT_OR_EXPORT std::string buildEtp12Uri() const {
639 std::string tmp = uriSource_.empty() ? "eml:///" : uriSource_;
640 return (tmp.back() == '/' ? tmp : tmp + '/') + getQualifiedType() + '(' + getUuid() + ')';
641 }
642
646 DLL_IMPORT_OR_EXPORT void setUriSource(const std::string & uriSource) { uriSource_ = uriSource; }
647
651 DLL_IMPORT_OR_EXPORT const std::string& getUriSource() const { return uriSource_; }
652
657 std::string getEpcSourceFolder() const {
658 if (uriSource_.find(".epc") != uriSource_.size() - 4 &&
659 uriSource_.find(".EPC") != uriSource_.size() - 4) {
660 return "";
661 }
662
663 const size_t slashPos = uriSource_.find_last_of("/\\");
664 return slashPos != std::string::npos ? uriSource_.substr(0, slashPos + 1) : "";
665 }
666
671
676 virtual void loadTargetRelationships() = 0;
677
678 protected:
680 gsoap_resqml2_0_1::eml20__DataObjectReference* partialObject;
681
683 gsoap_resqml2_0_1::eml20__AbstractCitedDataObject* gsoapProxy2_0_1;
684
686 gsoap_eml2_3::eml23__AbstractObject* gsoapProxy2_3;
687
689 COMMON_NS::DataObjectRepository* repository;
690
695 partialObject(nullptr),
696 gsoapProxy2_0_1(nullptr),
697 gsoapProxy2_3(nullptr),
698 repository(nullptr) {}
699
705 AbstractObject(gsoap_resqml2_0_1::eml20__DataObjectReference* partialObject_) :
706 partialObject(partialObject_),
707 gsoapProxy2_0_1(nullptr),
708 gsoapProxy2_3(nullptr),
709 repository(nullptr) {}
710 AbstractObject(const DataObjectReference& dor) :
711 partialObject(dor.toDor20()),
712 gsoapProxy2_0_1(nullptr),
713 gsoapProxy2_3(nullptr),
714 repository(nullptr) {}
715
721 AbstractObject(gsoap_resqml2_0_1::eml20__AbstractCitedDataObject* proxy) :
722 partialObject(nullptr),
723 gsoapProxy2_0_1(proxy),
724 gsoapProxy2_3(nullptr),
725 repository(nullptr) {}
726
732 AbstractObject(gsoap_eml2_3::eml23__AbstractObject* proxy) :
733 partialObject(nullptr),
734 gsoapProxy2_0_1(nullptr),
735 gsoapProxy2_3(proxy),
736 repository(nullptr) {}
737
738
739 friend bool COMMON_NS::DataObjectRepository::addDataObject(COMMON_NS::AbstractObject* proxy);
740 friend COMMON_NS::AbstractObject* COMMON_NS::DataObjectRepository::addOrReplaceDataObject(AbstractObject* proxy, bool replaceOnlyContent);
741
746 void initMandatoryMetadata();
747
764 void setMetadata(const std::string & guid, const std::string & title, const std::string & editor, time_t creation, const std::string & originator,
765 const std::string & description, time_t lastUpdate, const std::string & descriptiveKeywords);
766
768 void cannotBePartial() const;
769
777 void readArrayNdOfFloatValues(gsoap_resqml2_0_1::resqml20__AbstractDoubleArray const* arrayInput, float* arrayOutput) const;
778
786 void readArrayNdOfFloatValues(gsoap_eml2_3::eml23__AbstractFloatingPointArray const* arrayInput, float* arrayOutput) const;
787
795 void readArrayNdOfDoubleValues(gsoap_resqml2_0_1::resqml20__AbstractDoubleArray const* arrayInput, double * arrayOutput) const;
796
804 void readArrayNdOfDoubleValues(gsoap_eml2_3::eml23__AbstractFloatingPointArray const* arrayInput, double * arrayOutput) const;
805
806 template <class T>
807 void readArrayNdOfNonHdf5IntegerValues(gsoap_resqml2_0_1::resqml20__AbstractIntegerArray const * arrayInput, T * arrayOutput) const {
808 switch (arrayInput->soap_type()) {
809 case SOAP_TYPE_gsoap_resqml2_0_1_resqml20__IntegerRangeArray:
810 {
811 gsoap_resqml2_0_1::resqml20__IntegerRangeArray const* rangeArray = static_cast<gsoap_resqml2_0_1::resqml20__IntegerRangeArray const *>(arrayInput);
812 if (rangeArray->Value + rangeArray->Count > (std::numeric_limits<T>::max)()) {
813 throw std::range_error("The range integer values are superior to unsigned int maximum value.");
814 }
815 for (unsigned int i = 0; i < static_cast<T>(rangeArray->Count); ++i) {
816 arrayOutput[i] = i + static_cast<T>(rangeArray->Value);
817 }
818 break;
819 }
820 case SOAP_TYPE_gsoap_resqml2_0_1_resqml20__IntegerConstantArray:
821 {
822 gsoap_resqml2_0_1::resqml20__IntegerConstantArray const* constantArray = static_cast<gsoap_resqml2_0_1::resqml20__IntegerConstantArray const*>(arrayInput);
823 if (constantArray->Value > (std::numeric_limits<T>::max)()) {
824 throw std::range_error("The constant integer value is superior to unsigned int maximum value.");
825 }
826 for (size_t i = 0; i < constantArray->Count; ++i) {
827 arrayOutput[i] = static_cast<T>(constantArray->Value);
828 }
829 break;
830 }
831 case SOAP_TYPE_gsoap_resqml2_0_1_resqml20__IntegerLatticeArray:
832 {
833 gsoap_resqml2_0_1::resqml20__IntegerLatticeArray const* latticeArray = static_cast<gsoap_resqml2_0_1::resqml20__IntegerLatticeArray const*>(arrayInput);
834 if (latticeArray->Offset.size() > 1) {
835 throw std::invalid_argument("The integer lattice array contains more than one offset.");
836 }
837 for (size_t i = 0; i <= latticeArray->Offset[0]->Count; ++i) {
838 arrayOutput[i] = latticeArray->StartValue + (i * latticeArray->Offset[0]->Value);
839 }
840 break;
841 }
842 default:
843 throw std::invalid_argument("The integer array type is not supported yet.");
844 }
845 }
846
847 template <class T>
848 T readArrayNdOfNonHdf5IntegerValues(gsoap_eml2_3::eml23__AbstractIntegerArray const * arrayInput, T * arrayOutput) const {
849 switch (arrayInput->soap_type()) {
850 case SOAP_TYPE_gsoap_eml2_3_eml23__IntegerConstantArray:
851 {
852 gsoap_eml2_3::eml23__IntegerConstantArray const* constantArray = static_cast<gsoap_eml2_3::eml23__IntegerConstantArray const*>(arrayInput);
853 if (constantArray->Value > (std::numeric_limits<T>::max)()) {
854 throw std::range_error("The constant integer value is superior to maximum value of read datatype.");
855 }
856 std::fill(arrayOutput, arrayOutput + constantArray->Count, static_cast<T>(constantArray->Value));
857 return (std::numeric_limits<T>::max)();
858 }
859 case SOAP_TYPE_gsoap_eml2_3_eml23__IntegerLatticeArray:
860 {
861 gsoap_eml2_3::eml23__IntegerLatticeArray const* latticeArray = static_cast<gsoap_eml2_3::eml23__IntegerLatticeArray const*>(arrayInput);
862 if (latticeArray->Offset.empty() || latticeArray->Offset.size() > 1) {
863 throw std::invalid_argument("The integer lattice array of UUID " + getUuid() + " contains zero or more than one offset.");
864 }
865 if (latticeArray->Offset[0]->Count < 0) {
866 throw std::invalid_argument("The count of the integer lattice array of UUID " + getUuid() + " is negative which is not valid.");
867 }
868
869 for (size_t i = 0; i <= static_cast<size_t>(latticeArray->Offset[0]->Count); ++i) {
870 arrayOutput[i] = latticeArray->StartValue + (i * latticeArray->Offset[0]->Value);
871 }
872 return (std::numeric_limits<T>::max)();
873 }
874 case SOAP_TYPE_gsoap_eml2_3_eml23__IntegerXmlArray:
875 {
876 gsoap_eml2_3::eml23__IntegerXmlArray const * xmlArray = static_cast<gsoap_eml2_3::eml23__IntegerXmlArray const*>(arrayInput);
877 std::istringstream iss(xmlArray->Values);
878 auto str = std::string{};
879 size_t index = 0;
880 while (iss >> str) {
881 arrayOutput[index++] = std::stoll(str);
882 }
883 return (std::numeric_limits<T>::max)();
884 }
885 default: throw std::invalid_argument("The integer array type is not supported yet.");
886 }
887 }
888
898 uint8_t readArrayNdOfUInt8Values(gsoap_resqml2_0_1::resqml20__AbstractIntegerArray const* arrayInput, uint8_t * arrayOutput) const;
899
909 uint8_t readArrayNdOfUInt8Values(gsoap_eml2_3::eml23__AbstractIntegerArray const* arrayInput, uint8_t * arrayOutput) const;
910
920 uint16_t readArrayNdOfUInt16Values(gsoap_resqml2_0_1::resqml20__AbstractIntegerArray const* arrayInput, uint16_t * arrayOutput) const;
921
931 uint16_t readArrayNdOfUInt16Values(gsoap_eml2_3::eml23__AbstractIntegerArray const* arrayInput, uint16_t * arrayOutput) const;
932
942 uint32_t readArrayNdOfUInt32Values(gsoap_resqml2_0_1::resqml20__AbstractIntegerArray const* arrayInput, uint32_t * arrayOutput) const;
943
953 uint32_t readArrayNdOfUInt32Values(gsoap_eml2_3::eml23__AbstractIntegerArray const* arrayInput, uint32_t * arrayOutput) const;
954
964 uint64_t readArrayNdOfUInt64Values(gsoap_resqml2_0_1::resqml20__AbstractIntegerArray const* arrayInput, uint64_t * arrayOutput) const;
965
975 uint64_t readArrayNdOfUInt64Values(gsoap_eml2_3::eml23__AbstractIntegerArray const* arrayInput, uint64_t * arrayOutput) const;
976
986 int8_t readArrayNdOfInt8Values(gsoap_resqml2_0_1::resqml20__AbstractIntegerArray const* arrayInput, int8_t * arrayOutput) const;
987
997 int8_t readArrayNdOfInt8Values(gsoap_eml2_3::eml23__AbstractIntegerArray const* arrayInput, int8_t * arrayOutput) const;
998
1008 int16_t readArrayNdOfInt16Values(gsoap_resqml2_0_1::resqml20__AbstractIntegerArray const* arrayInput, int16_t * arrayOutput) const;
1009
1019 int16_t readArrayNdOfInt16Values(gsoap_eml2_3::eml23__AbstractIntegerArray const* arrayInput, int16_t * arrayOutput) const;
1020
1030 int32_t readArrayNdOfInt32Values(gsoap_resqml2_0_1::resqml20__AbstractIntegerArray const* arrayInput, int32_t * arrayOutput) const;
1031
1041 int32_t readArrayNdOfInt32Values(gsoap_eml2_3::eml23__AbstractIntegerArray const* arrayInput, int32_t * arrayOutput) const;
1042
1052 int64_t readArrayNdOfInt64Values(gsoap_resqml2_0_1::resqml20__AbstractIntegerArray const* arrayInput, int64_t * arrayOutput) const;
1053
1063 int64_t readArrayNdOfInt64Values(gsoap_eml2_3::eml23__AbstractIntegerArray const* arrayInput, int64_t * arrayOutput) const;
1064
1072 uint64_t getCountOfIntegerArray(gsoap_resqml2_0_1::resqml20__AbstractIntegerArray const* arrayInput) const;
1073
1081 uint64_t getCountOfArray(gsoap_eml2_3::eml23__AbstractValueArray const * arrayInput) const;
1082
1088 void convertDorIntoRel(const DataObjectReference& dor);
1089
1099 template <class valueType>
1100 void convertDorIntoRel(const DataObjectReference& dor)
1101 {
1102 valueType * targetObj = getRepository()->getDataObjectByUuid<valueType>(dor.getUuid());
1103 if (targetObj == nullptr) { // partial transfer
1104 getRepository()->createPartial(dor);
1105 targetObj = getRepository()->getDataObjectByUuid<valueType>(dor.getUuid());
1106 if (targetObj == nullptr) {
1107 throw std::invalid_argument("The DOR looks invalid.");
1108 }
1109 targetObj->setUriSource(getUriSource());
1110 }
1111 getRepository()->addRelationship(this, targetObj);
1112 }
1113
1125 EML2_NS::AbstractHdfProxy* getHdfProxyFromDataset(gsoap_resqml2_0_1::eml20__Hdf5Dataset const * dataset, bool throwException = true) const;
1126
1137 EML2_NS::AbstractHdfProxy* getOrCreateHdfProxyFromDataArrayPart(gsoap_eml2_3::eml23__ExternalDataArrayPart const * dataArrayPart) const;
1138
1142 std::string getHdfGroup() const {
1143 return "/" + getXmlNamespace() + "/" + getUuid();
1144 }
1145
1149 gsoap_eml2_3::eml23__ExternalDataArrayPart* createExternalDataArrayPart(const std::string& datasetName, LONG64 count, EML2_NS::AbstractHdfProxy* proxy = nullptr) const;
1150
1151 gsoap_resqml2_0_1::resqml20__IndexableElements mapIndexableElement(gsoap_eml2_3::eml23__IndexableElement toMap) const;
1152
1153 private:
1155 static char citationFormat[];
1156
1160 std::string uriSource_;
1161
1169 void setUuid(const std::string & uuid);
1170 };
1171}
An abstract data object.
Definition AbstractObject.h:32
soap * getGsoapContext() const
std::vector< eml2 ::Activity * > getActivitySet() const
void setCreation(const tm &creation)
void setGsoapProxy(gsoap_eml2_3::eml23__AbstractObject *gsoapProxy)
Definition AbstractObject.h:389
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
gsoap_eml2_3::resqml22__ContactElement * newContactElementReference2_2() const
std::string serializeIntoString()
std::string buildEtp12Uri() const
Definition AbstractObject.h:638
unsigned int getExtraMetadataCount() const
std::string getDescriptiveKeywords() const
gsoap_resqml2_0_1::eml20__DataObjectReference * newResqmlReference() const
virtual std::string getXmlNamespaceVersion() const
common::DataObjectRepository * getRepository() const
Definition AbstractObject.h:440
void setUriSource(const std::string &uriSource)
Definition AbstractObject.h:646
std::string getEditor() const
bool isPartial() const
gsoap_eml2_3::eml23__DataObjectReference * newEml23Reference() const
std::string getAliasTitleAtIndex(unsigned int index) const
virtual std::string getQualifiedType() const
void setEditor(const std::string &editor)
void setLastUpdate(time_t lastUpdate)
std::string getUuid() const
std::string getAliasAuthorityAtIndex(unsigned int index) const
void setDescription(const std::string &description)
int getGsoapType() const
void serializeIntoStream(std::ostream *stream)
void setDescriptiveKeywords(const std::string &descriptiveKeywords)
virtual std::string getXmlNamespace() const =0
void setCreation(time_t creation)
gsoap_resqml2_0_1::resqml20__ContactElementReference * newContactElementReference2_0_1() const
void pushBackExtraMetadata(const std::string &key, const std::string &value)
const std::string & getUriSource() const
Definition AbstractObject.h:651
void setLastUpdate(const tm &lastUpdate)
eml2::Activity * getActivity(unsigned int index) const
gsoap_resqml2_0_1::eml20__AbstractCitedDataObject * getEml20GsoapProxy() const
Definition AbstractObject.h:370
gsoap_eml2_3::eml23__AbstractObject * getEml23GsoapProxy() const
Definition AbstractObject.h:383
std::vector< std::string > getExtraMetadata(const std::string &key) const
std::string getOriginator() const
void setGsoapProxy(gsoap_resqml2_0_1::eml20__AbstractCitedDataObject *gsoapProxy)
Definition AbstractObject.h:376
tm getCreationAsTimeStructure() const
std::string getEpcSourceFolder() const
Definition AbstractObject.h:657
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
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
std::string getTitle() const
std::string getFormat() const
std::string getExtraMetadataKeyAtIndex(unsigned int index) const