From: <sar...@us...> - 2019-06-10 12:05:00
|
Revision: 26063 http://sourceforge.net/p/sbml/code/26063 Author: sarahkeating Date: 2019-06-10 12:04:56 +0000 (Mon, 10 Jun 2019) Log Message: ----------- Fix for https://www.pivotaltracker.com/story/show/166576120 when using addCVTerm and appendAnnotation depending on the order you use the functions in you lose information. Modified Paths: -------------- trunk/libsbml/src/sbml/SBase.cpp trunk/libsbml/src/sbml/annotation/test/TestSyncAnnotation.cpp Modified: trunk/libsbml/src/sbml/SBase.cpp =================================================================== --- trunk/libsbml/src/sbml/SBase.cpp 2019-06-07 19:48:56 UTC (rev 26062) +++ trunk/libsbml/src/sbml/SBase.cpp 2019-06-10 12:04:56 UTC (rev 26063) @@ -1496,7 +1496,16 @@ // syncAnnotation() doesn't need to be invoked in this function because // existing mCVTerm objects are properly merged in the following code. // + // except when they have not been updated (ie CVTerm has been added but not synced + // see bug reported via libsbml-team + // https://www.pivotaltracker.com/story/show/166576120 + if (getNumCVTerms() > 0 && mAnnotation == NULL) + { + syncAnnotation(); + } + + if(annotation == NULL) return LIBSBML_OPERATION_SUCCESS; @@ -1596,7 +1605,15 @@ // syncAnnotation() doesn't need to be invoked in this function because // existing mCVTerm objects are properly merged in the following code. // + // except when they have not been updated (ie CVTerm has been added but not synced + // see bug reported via libsbml-team + // https://www.pivotaltracker.com/story/show/166576120 + if (getNumCVTerms() > 0 && mAnnotation == NULL) + { + syncAnnotation(); + } + int success = LIBSBML_OPERATION_FAILED; XMLNode* annt_xmln; if (getSBMLDocument() != NULL) Modified: trunk/libsbml/src/sbml/annotation/test/TestSyncAnnotation.cpp =================================================================== --- trunk/libsbml/src/sbml/annotation/test/TestSyncAnnotation.cpp 2019-06-07 19:48:56 UTC (rev 26062) +++ trunk/libsbml/src/sbml/annotation/test/TestSyncAnnotation.cpp 2019-06-10 12:04:56 UTC (rev 26063) @@ -1579,7 +1579,102 @@ END_TEST +START_TEST(test_SyncAnnotation_ordering_bug_1) +{ + // report via libsbml team + // if addCVTerm and then appendAnnotation is used teh CVTerm gets lost + // but it works the other way round + Compartment* c = new Compartment(2, 3); + c->setMetaId("_000003"); + c->setId("A"); + + CVTerm * cv = new CVTerm(BIOLOGICAL_QUALIFIER); + cv->setBiologicalQualifierType(BQB_IS); + cv->addResource("http://www.geneontology.org/#GO:0007274"); + + + const char * addedAnn = + "<prA:other xmlns:prA=\"http://some\">This is additional</prA:other>"; + + // this way works even with the bug + c->appendAnnotation(addedAnn); + c->addCVTerm(cv); + + const char * expected = + "<compartment metaid=\"_000003\" id=\"A\">\n" + " <annotation>\n" + " <prA:other xmlns:prA=\"http://some\">This is additional</prA:other>\n" + " <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:vCard=\"http://www.w3.org/2001/vcard-rdf/3.0#\" xmlns:bqbiol=\"http://biomodels.net/biology-qualifiers/\" xmlns:bqmodel=\"http://biomodels.net/model-qualifiers/\">\n" + " <rdf:Description rdf:about=\"#_000003\">\n" + " <bqbiol:is>\n" + " <rdf:Bag>\n" + " <rdf:li rdf:resource=\"http://www.geneontology.org/#GO:0007274\"/>\n" + " </rdf:Bag>\n" + " </bqbiol:is>\n" + " </rdf:Description>\n" + " </rdf:RDF>\n" + " </annotation>\n" + "</compartment>"; + + char * sbml = c->toSBML(); + + fail_unless(equals(expected, sbml)); + + free(sbml); + delete c; +} +END_TEST + + +START_TEST(test_SyncAnnotation_ordering_bug_2) +{ + // report via libsbml team + // if addCVTerm and then appendAnnotation is used teh CVTerm gets lost + // but it works the other way round + + Compartment* c = new Compartment(2, 3); + c->setMetaId("_000003"); + c->setId("A"); + + CVTerm * cv = new CVTerm(BIOLOGICAL_QUALIFIER); + cv->setBiologicalQualifierType(BQB_IS); + cv->addResource("http://www.geneontology.org/#GO:0007274"); + + + const char * addedAnn = + "<prA:other xmlns:prA=\"http://some\">This is additional</prA:other>"; + + // this way did hit the bug and CVTerm was lost + c->addCVTerm(cv); + c->appendAnnotation(addedAnn); + + const char * expected = + "<compartment metaid=\"_000003\" id=\"A\">\n" + " <annotation>\n" + " <prA:other xmlns:prA=\"http://some\">This is additional</prA:other>\n" + " <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:vCard=\"http://www.w3.org/2001/vcard-rdf/3.0#\" xmlns:bqbiol=\"http://biomodels.net/biology-qualifiers/\" xmlns:bqmodel=\"http://biomodels.net/model-qualifiers/\">\n" + " <rdf:Description rdf:about=\"#_000003\">\n" + " <bqbiol:is>\n" + " <rdf:Bag>\n" + " <rdf:li rdf:resource=\"http://www.geneontology.org/#GO:0007274\"/>\n" + " </rdf:Bag>\n" + " </bqbiol:is>\n" + " </rdf:Description>\n" + " </rdf:RDF>\n" + " </annotation>\n" + "</compartment>"; + + char * sbml = c->toSBML(); + + fail_unless(equals(expected, sbml)); + + free(sbml); + delete c; +} +END_TEST + + Suite * create_suite_SyncAnnotation (void) { @@ -1617,6 +1712,9 @@ tcase_add_test(tcase, test_SyncAnnotation_nestedCV_invalid ); + tcase_add_test(tcase, test_SyncAnnotation_ordering_bug_1); + tcase_add_test(tcase, test_SyncAnnotation_ordering_bug_2); + suite_add_tcase(suite, tcase); return suite; |