From b3a99a69fa12bd926c158b49dc24ecde629bd949 Mon Sep 17 00:00:00 2001 From: Sarah Date: Sat, 6 Aug 2022 13:57:37 +0100 Subject: [PATCH 1/5] make dates optional --- src/sbml/annotation/ModelHistory.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/sbml/annotation/ModelHistory.cpp b/src/sbml/annotation/ModelHistory.cpp index 8055fdef90..87967de60e 100644 --- a/src/sbml/annotation/ModelHistory.cpp +++ b/src/sbml/annotation/ModelHistory.cpp @@ -374,11 +374,14 @@ ModelHistory::hasRequiredAttributes() { bool valid = true; - if ( getNumCreators() < 1 || - !isSetCreatedDate() || - !isSetModifiedDate() ) + if ( getNumCreators() < 1) + // relax requirement for dates + //|| + //!isSetCreatedDate() || + //!isSetModifiedDate() ) { valid = false; + return valid; } unsigned int i = 0; @@ -394,15 +397,19 @@ ModelHistory::hasRequiredAttributes() return valid; } - valid = getCreatedDate()->representsValidDate(); - - if (!valid) + if (isSetCreatedDate()) { - return valid; + valid = getCreatedDate()->representsValidDate(); + if (!valid) + { + return valid; + } } - for (i = 0; i < getNumModifiedDates(); ++i) + i = 0; + while (valid && i < getNumModifiedDates()) { valid = getModifiedDate(i)->representsValidDate(); + i++; } return valid; From 9e3551359bf2019de3ace4e67a9be147fa357907 Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 8 Aug 2022 09:53:38 +0100 Subject: [PATCH 2/5] add copy of parent sbase --- src/sbml/annotation/ModelHistory.cpp | 61 ++++++++++++++++++--- src/sbml/annotation/ModelHistory.h | 12 ++++ src/sbml/annotation/RDFAnnotationParser.cpp | 1 + src/sbml/annotation/test/TestValidation.cpp | 12 ++-- 4 files changed, 72 insertions(+), 14 deletions(-) diff --git a/src/sbml/annotation/ModelHistory.cpp b/src/sbml/annotation/ModelHistory.cpp index 87967de60e..2af83f7d9a 100644 --- a/src/sbml/annotation/ModelHistory.cpp +++ b/src/sbml/annotation/ModelHistory.cpp @@ -55,7 +55,8 @@ LIBSBML_CPP_NAMESPACE_BEGIN * Creates a new ModelHistory. */ ModelHistory::ModelHistory (): - mHasBeenModified (false) + mHasBeenModified (false), + mParentSBMLObject (NULL) { mCreatedDate = NULL; // mModifiedDate = NULL; @@ -112,6 +113,7 @@ ModelHistory::ModelHistory(const ModelHistory& orig) mCreatedDate = NULL; } mHasBeenModified = orig.mHasBeenModified; + mParentSBMLObject = orig.mParentSBMLObject; } @@ -164,6 +166,7 @@ ModelHistory::operator=(const ModelHistory& rhs) mCreatedDate = NULL; mHasBeenModified = rhs.mHasBeenModified; + mParentSBMLObject = rhs.mParentSBMLObject; } return *this; @@ -373,15 +376,25 @@ bool ModelHistory::hasRequiredAttributes() { bool valid = true; + + const SBase * parent = getParentSBMLObject(); - if ( getNumCreators() < 1) - // relax requirement for dates - //|| - //!isSetCreatedDate() || - //!isSetModifiedDate() ) + if (parent == NULL || parent->getLevel() < 3) { - valid = false; - return valid; + if (getNumCreators() < 1 || + !isSetCreatedDate() || + !isSetModifiedDate()) + { + return false; + } + } + else + { + // remove restriction that dates be present in L3 + if (getNumCreators() < 1) + { + return false; + } } unsigned int i = 0; @@ -473,6 +486,38 @@ ModelHistory::resetModifiedFlags() } /** @endcond */ +/** @cond doxygenLibsbmlInternal */ + +const SBase * +ModelHistory::getParentSBMLObject() const +{ + return mParentSBMLObject; +} + + +bool +ModelHistory::isSetParentSBMLObject() const +{ + return (mParentSBMLObject != NULL); +} + + +void +ModelHistory::setParentSBMLObject(const SBase * sb) +{ + mParentSBMLObject = sb; +} + + +int +ModelHistory::unsetParentSBMLObject() +{ + mParentSBMLObject = NULL; + return LIBSBML_OPERATION_SUCCESS; +} + +/** @endcond */ + #endif /* __cplusplus */ diff --git a/src/sbml/annotation/ModelHistory.h b/src/sbml/annotation/ModelHistory.h index 5991f80c62..9ff4af4333 100644 --- a/src/sbml/annotation/ModelHistory.h +++ b/src/sbml/annotation/ModelHistory.h @@ -385,6 +385,16 @@ class LIBSBML_EXTERN ModelHistory protected: /** @cond doxygenLibsbmlInternal */ + + // record the SBML Object on which this ModelHistory is set + + const SBase * getParentSBMLObject() const; + bool isSetParentSBMLObject() const; + void setParentSBMLObject(const SBase * sb); + int unsetParentSBMLObject(); + + friend class RDFAnnotationParser; + /* Can have more than one creator. */ List * mCreators; @@ -400,6 +410,8 @@ class LIBSBML_EXTERN ModelHistory List * mModifiedDates; bool mHasBeenModified; + const SBase *mParentSBMLObject; + /** @endcond */ diff --git a/src/sbml/annotation/RDFAnnotationParser.cpp b/src/sbml/annotation/RDFAnnotationParser.cpp index 23aad7e42e..c9ef3f21cb 100644 --- a/src/sbml/annotation/RDFAnnotationParser.cpp +++ b/src/sbml/annotation/RDFAnnotationParser.cpp @@ -710,6 +710,7 @@ RDFAnnotationParser::parseModelHistory(const SBase *object) { return NULL; } + history->setParentSBMLObject(object); XMLNode *description = createRDFDescriptionWithHistory(object); diff --git a/src/sbml/annotation/test/TestValidation.cpp b/src/sbml/annotation/test/TestValidation.cpp index 82738b2381..ff7d8e538c 100644 --- a/src/sbml/annotation/test/TestValidation.cpp +++ b/src/sbml/annotation/test/TestValidation.cpp @@ -138,14 +138,15 @@ START_TEST (test_Validation_ModelHistory1) fail_unless (!(mh->hasRequiredAttributes())); - Date * date = new Date(2007, 12, 30, 12, 15, 45, 1, 2, 0); - mh->setCreatedDate(date); + // relaxed requirement + //Date * date = new Date(2007, 12, 30, 12, 15, 45, 1, 2, 0); + //mh->setCreatedDate(date); - fail_unless (!(mh->hasRequiredAttributes())); + //fail_unless (!(mh->hasRequiredAttributes())); - mh->setModifiedDate(date); + //mh->setModifiedDate(date); - fail_unless (!(mh->hasRequiredAttributes())); + //fail_unless (!(mh->hasRequiredAttributes())); ModelCreator * mc = new ModelCreator(); mc->setFamilyName("Keating"); @@ -157,7 +158,6 @@ START_TEST (test_Validation_ModelHistory1) delete mh; delete mc; - delete date; } END_TEST From e5195cdf792d58567708635ef10dfc1b288cfeab Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 8 Aug 2022 10:01:53 +0100 Subject: [PATCH 3/5] no change - bad commit --- src/sbml/annotation/test/TestValidation.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/sbml/annotation/test/TestValidation.cpp b/src/sbml/annotation/test/TestValidation.cpp index ff7d8e538c..7802cb753b 100644 --- a/src/sbml/annotation/test/TestValidation.cpp +++ b/src/sbml/annotation/test/TestValidation.cpp @@ -133,20 +133,20 @@ END_TEST START_TEST (test_Validation_ModelHistory1) { + ModelHistory * mh = new ModelHistory(); fail_unless(mh != NULL); fail_unless (!(mh->hasRequiredAttributes())); - // relaxed requirement - //Date * date = new Date(2007, 12, 30, 12, 15, 45, 1, 2, 0); - //mh->setCreatedDate(date); + Date * date = new Date(2007, 12, 30, 12, 15, 45, 1, 2, 0); + mh->setCreatedDate(date); - //fail_unless (!(mh->hasRequiredAttributes())); + fail_unless (!(mh->hasRequiredAttributes())); - //mh->setModifiedDate(date); + mh->setModifiedDate(date); - //fail_unless (!(mh->hasRequiredAttributes())); + fail_unless (!(mh->hasRequiredAttributes())); ModelCreator * mc = new ModelCreator(); mc->setFamilyName("Keating"); @@ -222,7 +222,6 @@ START_TEST (test_Validation_ModelHistory3) } END_TEST - START_TEST (test_Validation_CVTerm1) { CVTerm * cv = new CVTerm(); From 73fa34d7c879968193df745e543b7588a0f492b3 Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 8 Aug 2022 11:00:45 +0100 Subject: [PATCH 4/5] add parent sbase everywhere and create test --- src/sbml/Model.cpp | 2 +- src/sbml/SBase.cpp | 2 +- src/sbml/SpeciesReference.cpp | 2 +- src/sbml/annotation/RDFAnnotationParser.cpp | 9 ++++-- src/sbml/annotation/RDFAnnotationParser.h | 2 +- .../annotation/test/TestRDFAnnotation2.cpp | 2 ++ .../test/TestRDFAnnotationNestedCVTerms.cpp | 28 +++++++++---------- .../test/test-data/annotationNested-l3v1.xml | 3 -- 8 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/sbml/Model.cpp b/src/sbml/Model.cpp index 18b982feae..9a8d716d04 100644 --- a/src/sbml/Model.cpp +++ b/src/sbml/Model.cpp @@ -4578,7 +4578,7 @@ Model::readOtherXML (XMLInputStream& stream) if (RDFAnnotationParser::hasHistoryRDFAnnotation(mAnnotation)) { mHistory = RDFAnnotationParser::parseRDFAnnotation(mAnnotation, - getMetaId().c_str(), &(stream)); + getMetaId().c_str(), &(stream), this); if (mHistory != NULL && mHistory->hasRequiredAttributes() == false) { diff --git a/src/sbml/SBase.cpp b/src/sbml/SBase.cpp index 855a49a70a..71f1b1eec8 100644 --- a/src/sbml/SBase.cpp +++ b/src/sbml/SBase.cpp @@ -4712,7 +4712,7 @@ SBase::readAnnotation (XMLInputStream& stream) if (RDFAnnotationParser::hasHistoryRDFAnnotation(mAnnotation)) { mHistory = RDFAnnotationParser::parseRDFAnnotation(mAnnotation, - getMetaId().c_str(), &(stream)); + getMetaId().c_str(), &(stream), this); if (mHistory != NULL && mHistory->hasRequiredAttributes() == false) { logError(RDFNotCompleteModelHistory, getLevel(), getVersion(), diff --git a/src/sbml/SpeciesReference.cpp b/src/sbml/SpeciesReference.cpp index 837014a29b..24acd77864 100644 --- a/src/sbml/SpeciesReference.cpp +++ b/src/sbml/SpeciesReference.cpp @@ -1213,7 +1213,7 @@ SpeciesReference::readOtherXML (XMLInputStream& stream) if (RDFAnnotationParser::hasHistoryRDFAnnotation(mAnnotation)) { mHistory = RDFAnnotationParser::parseRDFAnnotation(mAnnotation, - getMetaId().c_str(), &(stream)); + getMetaId().c_str(), &(stream), this); if (mHistory != NULL && mHistory->hasRequiredAttributes() == false) { diff --git a/src/sbml/annotation/RDFAnnotationParser.cpp b/src/sbml/annotation/RDFAnnotationParser.cpp index c9ef3f21cb..3285221e55 100644 --- a/src/sbml/annotation/RDFAnnotationParser.cpp +++ b/src/sbml/annotation/RDFAnnotationParser.cpp @@ -248,7 +248,8 @@ ModelHistory* RDFAnnotationParser::parseRDFAnnotation( const XMLNode * annotation, const char* metaId, - XMLInputStream* stream /*= NULL*/) + XMLInputStream* stream /*= NULL*/, + const SBase* parent) { ModelHistory * history = NULL; @@ -310,7 +311,11 @@ RDFAnnotationParser::parseRDFAnnotation( { history = deriveHistoryFromAnnotation(annotation); } - + // add a parent SBase object with level and version + if (parent != NULL) + { + history->setParentSBMLObject(parent); + } return history; } diff --git a/src/sbml/annotation/RDFAnnotationParser.h b/src/sbml/annotation/RDFAnnotationParser.h index 55a55150a8..759f6659f8 100644 --- a/src/sbml/annotation/RDFAnnotationParser.h +++ b/src/sbml/annotation/RDFAnnotationParser.h @@ -139,7 +139,7 @@ class LIBSBML_EXTERN RDFAnnotationParser * @return a pointer to the ModelHistory created. */ static ModelHistory* parseRDFAnnotation(const XMLNode *annotation, - const char* metaId = NULL, XMLInputStream* stream = NULL); + const char* metaId = NULL, XMLInputStream* stream = NULL, const SBase* parent = NULL); /** diff --git a/src/sbml/annotation/test/TestRDFAnnotation2.cpp b/src/sbml/annotation/test/TestRDFAnnotation2.cpp index eaa17d4732..fb04f0bfab 100644 --- a/src/sbml/annotation/test/TestRDFAnnotation2.cpp +++ b/src/sbml/annotation/test/TestRDFAnnotation2.cpp @@ -155,6 +155,8 @@ START_TEST (test_RDFAnnotation2_getModelHistory) fail_unless(Date_getHoursOffset(date) == 0); fail_unless(Date_getMinutesOffset(date) == 0); fail_unless(!strcmp(Date_getDateAsString(date), "2007-01-16T15:31:52Z")); + + fail_unless(ModelHistory_hasRequiredAttributes(history) == 1); } END_TEST diff --git a/src/sbml/annotation/test/TestRDFAnnotationNestedCVTerms.cpp b/src/sbml/annotation/test/TestRDFAnnotationNestedCVTerms.cpp index cad62ba0f6..0bf8855d24 100644 --- a/src/sbml/annotation/test/TestRDFAnnotationNestedCVTerms.cpp +++ b/src/sbml/annotation/test/TestRDFAnnotationNestedCVTerms.cpp @@ -584,6 +584,9 @@ END_TEST START_TEST (test_RDFAnnotationNestedCVTerm_dcterms_31) { + ModelHistory * mh = m31->getModelHistory(); + fail_unless(mh->hasRequiredAttributes() == true); + XMLNode* node = RDFAnnotationParser::parseModelHistory(m31); fail_unless(node->getNumChildren() == 1); @@ -600,7 +603,7 @@ START_TEST (test_RDFAnnotationNestedCVTerm_dcterms_31) fail_unless(!strcmp(XMLNode_getName(desc), "Description")); fail_unless(!strcmp(XMLNode_getPrefix(desc), "rdf")); fail_unless(!strcmp(XMLNode_getURI(desc), "http://www.w3.org/1999/02/22-rdf-syntax-ns#")); - fail_unless(XMLNode_getNumChildren(desc) == 3); + fail_unless(XMLNode_getNumChildren(desc) == 2); const XMLNode_t * creator = XMLNode_getChild(desc, 0); fail_unless(!strcmp(XMLNode_getName(creator), "creator")); @@ -671,17 +674,17 @@ START_TEST (test_RDFAnnotationNestedCVTerm_dcterms_31) fail_unless(!strcmp(XMLNode_getURI(cr_date), "http://purl.org/dc/terms/")); fail_unless(XMLNode_getNumChildren(cr_date) == 1); - const XMLNode_t * modified = XMLNode_getChild(desc, 2); - fail_unless(!strcmp(XMLNode_getName(modified), "modified")); - fail_unless(!strcmp(XMLNode_getPrefix(modified), "dcterms")); - fail_unless(!strcmp(XMLNode_getURI(modified), "http://purl.org/dc/terms/")); - fail_unless(XMLNode_getNumChildren(modified) == 1); + //const XMLNode_t * modified = XMLNode_getChild(desc, 2); + //fail_unless(!strcmp(XMLNode_getName(modified), "modified")); + //fail_unless(!strcmp(XMLNode_getPrefix(modified), "dcterms")); + //fail_unless(!strcmp(XMLNode_getURI(modified), "http://purl.org/dc/terms/")); + //fail_unless(XMLNode_getNumChildren(modified) == 1); - const XMLNode_t * mo_date = XMLNode_getChild(created, 0); - fail_unless(!strcmp(XMLNode_getName(mo_date), "W3CDTF")); - fail_unless(!strcmp(XMLNode_getPrefix(mo_date), "dcterms")); - fail_unless(!strcmp(XMLNode_getURI(mo_date), "http://purl.org/dc/terms/")); - fail_unless(XMLNode_getNumChildren(mo_date) == 1); + //const XMLNode_t * mo_date = XMLNode_getChild(created, 0); + //fail_unless(!strcmp(XMLNode_getName(mo_date), "W3CDTF")); + //fail_unless(!strcmp(XMLNode_getPrefix(mo_date), "dcterms")); + //fail_unless(!strcmp(XMLNode_getURI(mo_date), "http://purl.org/dc/terms/")); + //fail_unless(XMLNode_getNumChildren(mo_date) == 1); delete node; @@ -714,9 +717,6 @@ START_TEST(test_RDFAnnotationNestedCVTerm_writeDC_creator_31) " \n" " 2005-02-02T14:56:11\n" " \n" - " \n" - " 2006-05-30T10:46:02\n" - " \n" " \n" " \n" " \n" diff --git a/src/sbml/annotation/test/test-data/annotationNested-l3v1.xml b/src/sbml/annotation/test/test-data/annotationNested-l3v1.xml index ef3e59e8b7..cc94c59f63 100644 --- a/src/sbml/annotation/test/test-data/annotationNested-l3v1.xml +++ b/src/sbml/annotation/test/test-data/annotationNested-l3v1.xml @@ -21,9 +21,6 @@ 2005-02-02T14:56:11 - - 2006-05-30T10:46:02 - From bc15bea07be48a1eeedc7a53055ae1fdb780dc1d Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 8 Aug 2022 12:02:08 +0100 Subject: [PATCH 5/5] caught segfault --- src/sbml/annotation/RDFAnnotationParser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sbml/annotation/RDFAnnotationParser.cpp b/src/sbml/annotation/RDFAnnotationParser.cpp index 3285221e55..5fd9824edb 100644 --- a/src/sbml/annotation/RDFAnnotationParser.cpp +++ b/src/sbml/annotation/RDFAnnotationParser.cpp @@ -312,7 +312,7 @@ RDFAnnotationParser::parseRDFAnnotation( history = deriveHistoryFromAnnotation(annotation); } // add a parent SBase object with level and version - if (parent != NULL) + if (history != NULL && parent != NULL) { history->setParentSBMLObject(parent); }