1 /*
2 # PostgreSQL Database Modeler (pgModeler)
3 #
4 # Copyright 2006-2020 - Raphael Araújo e Silva <raphael@pgmodeler.io>
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation version 3.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # The complete text of GPLv3 is at LICENSE file on source code root directory.
16 # Also, you can get the complete GNU General Public License at <http://www.gnu.org/licenses/>
17 */
18
19 #include "validationinfo.h"
20
ValidationInfo()21 ValidationInfo::ValidationInfo()
22 {
23 object=nullptr;
24 val_type=ValidationAborted;
25 }
26
ValidationInfo(unsigned val_type,BaseObject * object,vector<BaseObject * > references)27 ValidationInfo::ValidationInfo(unsigned val_type, BaseObject *object, vector<BaseObject *> references)
28 {
29 if(val_type >= SqlValidationError)
30 throw Exception(ErrorCode::AsgInvalidTypeObject,__PRETTY_FUNCTION__,__FILE__,__LINE__);
31 else if((val_type==NoUniqueName || val_type==BrokenReference) &&
32 (!object || references.empty()))
33 throw Exception(ErrorCode::AsgNotAllocattedObject,__PRETTY_FUNCTION__,__FILE__,__LINE__);
34
35 this->val_type=val_type;
36 this->object=object;
37 this->references=references;
38 }
39
ValidationInfo(Exception e)40 ValidationInfo::ValidationInfo(Exception e)
41 {
42 vector<Exception> err_list;
43
44 val_type=SqlValidationError;
45 e.getExceptionsList(err_list);
46
47 while(!err_list.empty())
48 {
49 errors.push_back(err_list.back().getErrorMessage());
50 err_list.pop_back();
51 }
52
53 errors.removeDuplicates();
54 }
55
ValidationInfo(const QString & msg)56 ValidationInfo::ValidationInfo(const QString &msg)
57 {
58 val_type=ValidationAborted;
59 errors.push_back(msg);
60 }
61
getValidationType()62 unsigned ValidationInfo::getValidationType()
63 {
64 return val_type;
65 }
66
getObject()67 BaseObject *ValidationInfo::getObject()
68 {
69 return object;
70 }
71
getReferences()72 vector<BaseObject *> ValidationInfo::getReferences()
73 {
74 return references;
75 }
76
getErrors()77 QStringList ValidationInfo::getErrors()
78 {
79 return errors;
80 }
81
isValid()82 bool ValidationInfo::isValid()
83 {
84 return (((val_type==NoUniqueName || val_type==BrokenReference) && object) ||
85 (val_type==SqlValidationError && !errors.empty()));
86 }
87