1 /**
2 * @file VConstraint.cpp
3 * @brief Base class for all SBML Validator Constraints
4 * @author Ben Bornstein
5 *
6 * <!--------------------------------------------------------------------------
7 * This file is part of libSBML. Please visit http://sbml.org for more
8 * information about SBML, and the latest version of libSBML.
9 *
10 * Copyright (C) 2020 jointly by the following organizations:
11 * 1. California Institute of Technology, Pasadena, CA, USA
12 * 2. University of Heidelberg, Heidelberg, Germany
13 * 3. University College London, London, UK
14 *
15 * Copyright (C) 2019 jointly by the following organizations:
16 * 1. California Institute of Technology, Pasadena, CA, USA
17 * 2. University of Heidelberg, Heidelberg, Germany
18 *
19 * Copyright (C) 2013-2018 jointly by the following organizations:
20 * 1. California Institute of Technology, Pasadena, CA, USA
21 * 2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
22 * 3. University of Heidelberg, Heidelberg, Germany
23 *
24 * Copyright (C) 2009-2013 jointly by the following organizations:
25 * 1. California Institute of Technology, Pasadena, CA, USA
26 * 2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
27 *
28 * Copyright (C) 2006-2008 by the California Institute of Technology,
29 * Pasadena, CA, USA
30 *
31 * Copyright (C) 2002-2005 jointly by the following organizations:
32 * 1. California Institute of Technology, Pasadena, CA, USA
33 * 2. Japan Science and Technology Agency, Japan
34 *
35 * This library is free software; you can redistribute it and/or modify it
36 * under the terms of the GNU Lesser General Public License as published by
37 * the Free Software Foundation. A copy of the license agreement is provided
38 * in the file named "LICENSE.txt" included with this software distribution and
39 * also available online as http://sbml.org/software/libsbml/license.html
40 * ---------------------------------------------------------------------- -->*/
41
42 #include <sbml/validator/VConstraint.h>
43 #include <sbml/extension/SBasePlugin.h>
44
45 /** @cond doxygenIgnored */
46 using namespace std;
47 /** @endcond */
48
49 LIBSBML_CPP_NAMESPACE_BEGIN
50 #ifdef __cplusplus
51
VConstraint(unsigned int id,Validator & v)52 VConstraint::VConstraint (unsigned int id, Validator& v) :
53 mId ( id )
54 , mSeverity ( 2 )
55 , mValidator( v )
56 , mLogMsg ( true )
57 {
58 }
59
60
~VConstraint()61 VConstraint::~VConstraint ()
62 {
63 }
64
65
66 /*
67 * @return the id of this Constraint.
68 */
69 unsigned int
getId() const70 VConstraint::getId () const
71 {
72 return mId;
73 }
74
75
76 /*
77 * @return the severity for violating this Constraint.
78 */
79 unsigned int
getSeverity() const80 VConstraint::getSeverity () const
81 {
82 return mSeverity;
83 }
84
85
86 /** @cond doxygenLibsbmlInternal */
87 /*
88 * Logs a constraint failure to the validator for the given SBML object.
89 */
90 void
logFailure(const SBase & object)91 VConstraint::logFailure (const SBase& object)
92 {
93 logFailure(object, msg);
94 }
95 /** @endcond */
96
97
98 /** @cond doxygenLibsbmlInternal */
99 /*
100 * Logs a constraint failure to the validator for the given SBML object.
101 * The parameter message is used instead of the constraint's member
102 * variable msg.
103 */
104 void
logFailure(const SBase & object,const std::string & message)105 VConstraint::logFailure (const SBase& object, const std::string& message)
106 {
107 std::string pkg = object.getPackageName();
108 unsigned int pkgVersion = object.getPackageVersion();
109 if (mId > 99999 && pkg == "core")
110 {
111 // we are dealing with a core object that is logging errors
112 // relating to a package
113 // need to work out which pkg
114
115 unsigned int offset = (unsigned int)(floor((double)mId/100000.0)) * 100000;
116
117 if (offset == 9900000)
118 {
119 // we are dealing with the strict units validator
120 mId = mId - offset;
121 }
122 else if (offset == 1400000 && object.getLevel() == 3 && object.getVersion() == 2)
123 {
124 // we are using the l3v2extended math package but in l3v2 which means we want to report core
125 mId = mId - offset;
126 }
127 else
128 {
129 // it is possible that the object does not have a direct plugin
130 // it may the child of an object that does
131 // so lets cut straight to the parent document
132 const SBMLDocument * doc = object.getSBMLDocument();
133 if (doc != NULL)
134 {
135 for (unsigned int i = 0; i < doc->getNumPlugins(); i++)
136 {
137 const SBMLExtension * ext = doc->getPlugin(i)->getSBMLExtension();
138
139 if (ext->getErrorIdOffset() == offset)
140 {
141 pkg = doc->getPlugin(i)->getPackageName();
142 pkgVersion = doc->getPlugin(i)->getPackageVersion();
143 break;
144 }
145 }
146 }
147 }
148 }
149
150 // if we are usinga consistency validator we want the level and version
151 // of the target sbml - which we have conveniently saved in the validator
152 // but for now only with 98000 numbers
153 unsigned int level = object.getLevel();
154 unsigned int version = object.getVersion();
155 if ((98000 < mId) && (mId < 98999))
156 {
157 if (mValidator.getConsistencyLevel() != 0)
158 {
159 level = mValidator.getConsistencyLevel();
160 version = mValidator.getConsistencyVersion();
161 }
162 }
163
164 SBMLError error = SBMLError( mId, level, version,
165 message, object.getLine(), object.getColumn(),
166 LIBSBML_SEV_UNKNOWN, LIBSBML_CAT_SBML, pkg, pkgVersion);
167
168 if (error.getSeverity() != LIBSBML_SEV_NOT_APPLICABLE)
169 mValidator.logFailure(error);
170
171 /* ( SBMLError( mId, object.getLevel(), object.getVersion(),
172 message, object.getLine(), object.getColumn(),
173 LIBSBML_SEV_ERROR, LIBSBML_CAT_SBML ));*/
174
175 }
176 /** @endcond */
177
178 #endif /* __cplusplus */
179
180
181 /** @cond doxygenIgnored */
182 /** @endcond */
183 LIBSBML_CPP_NAMESPACE_END
184
185