NCBI C++ ToolKit
table_data_validate.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: table_data_validate.cpp 37305 2016-12-22 14:24:03Z filippov $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Dmitry Rudnev
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
35 
38 
39 // maximal amount of Validate we should realistically see in a Validate table
40 const size_t CTableDataValidate::c_MaxRows(100000);
41 
42 // widths (in chars) of eMessageAndObjectDesc columns
43 // if wider, it will be wrapped
45 
47  : m_Scope(scope), m_Errs(errs), m_MinSeverityToShow(eDiagSevMin)
48 {
50 }
51 
53 {
54 }
55 
57 {
58  m_MinSeverityToShow = sev;
60 }
61 
62 
63 void CTableDataValidate::SetErrCode(string errcode)
64 {
65  m_ErrCode = errcode;
66  if (NStr::EqualNocase(m_ErrCode, "ALL")) {
67  m_ErrCode = "";
68  }
69 
71 }
72 
73 
75 {
76  size_t count = 0;
77 
78  for (size_t row = 0; row < m_Errs->GetData().size(); row++) {
79  CConstRef<CValidErrItem> pValidErrItem(m_Errs->GetData()[row]);
80  if (pValidErrItem->GetSeverity() == sev) {
81  count++;
82  }
83  }
84  return count;
85 }
86 
87 
88 vector<string> CTableDataValidate::GetErrorList() const
89 {
90  vector<string> list;
91 
92  for (size_t row = 0; row < m_Errs->GetData().size(); row++) {
93  CConstRef<CValidErrItem> pValidErrItem(m_Errs->GetData()[row]);
94  list.push_back(pValidErrItem->GetErrCode());
95  }
96  sort(list.begin(), list.end());
97  vector<string>::iterator final = unique(list.begin(), list.end());
98  list.resize( std::distance(list.begin(), final) );
99 
100  return list;
101 }
102 
103 
104 bool CTableDataValidate::x_MatchFilter(const objects::CValidErrItem& valitem) const
105 {
106  if (valitem.GetSeverity() >= m_MinSeverityToShow &&
107  (NStr::IsBlank(m_ErrCode) || NStr::EqualNocase(m_ErrCode, valitem.GetErrCode()))) {
108  return true;
109  } else {
110  return false;
111  }
112 }
113 
114 
116 {
117  size_t max = 0;
118  for (size_t row = 0; row < m_Errs->GetData().size(); row++) {
119  CConstRef<CValidErrItem> pValidErrItem(m_Errs->GetData()[row]);
120  if (pValidErrItem && x_MatchFilter(*pValidErrItem)) {
121  max++;
122  }
123  }
124  return max;
125 }
126 
127 
128 // number of entries and order must correspond with CTableDataValidate::EColContents
129 static const string s_ColNames[] = {
130  "Severity",
131  "Sequence",
132  "Error title",
133  "Message & Object Description"
134 };
135 
137 {
139 }
140 
141 
142 bool CTableDataValidate::IsHtmlColumn(size_t col) const
143 {
144  return false;
145 }
146 
147 string CTableDataValidate::GetColumnLabel(size_t col) const
148 {
149  if (col < CTableDataValidate::eMaxColNum) {
150  return s_ColNames[col];
151  }
152 
153  return kEmptyStr;
154 }
155 
156 
158 {
159  return m_CurrentRowCount;
160 }
161 
162 
164 {
165  return (size_t)CTableDataValidate::eMaxColNum;
166 }
167 
168 
169 void CTableDataValidate::GetStringValue(size_t row, size_t col, string& value) const
170 {
171  value.clear();
172 
173  if (row < GetRowsCount()) {
174  CConstRef<CValidErrItem> pValidErrItem(x_GetRowData(row));
175 
176  switch(col){
177  case eSeverity:
178  value = CValidErrItem::ConvertSeverity(pValidErrItem->GetSeverity());
179  if (pValidErrItem->GetSeverity() == eDiag_Critical)
180  value = "Reject"; // per GB-6508
181  break;
182 
184  value = pValidErrItem->CanGetMsg() ? pValidErrItem->GetMsg() + "; " : "";
185  value.append(pValidErrItem->CanGetObjDesc() ? pValidErrItem->GetObjDesc() : "");
186  break;
187 
188  case eErrorTitle:
189  value = (pValidErrItem->CanGetErrorGroup() ? pValidErrItem->GetErrorGroup() + " " : "") +
190  (pValidErrItem->CanGetErrorName() ? pValidErrItem->GetErrorName() : "");
191  break;
192 
193  case eAccessionVersion:
194  value = pValidErrItem->CanGetAccnver() ? pValidErrItem->GetAccnver() : "";
195  break;
196 
197  default:
198  break;
199  }
200  }
201 
202 }
203 
204 
205 string CTableDataValidate::GetHtmlValue(size_t row, size_t col) const
206 {
207  list<string> values;
208  string sDelimiter("<br>");
209  if (row < GetRowsCount()) {
210  CConstRef<CValidErrItem> pValidErrItem(x_GetRowData(row));
211 
212  switch(col){
213  // for now, this column is not an html column
215  {
216  string val = pValidErrItem->CanGetMsg() ? pValidErrItem->GetMsg() + "; " : "";
217  val.append(pValidErrItem->CanGetObjDesc() ? pValidErrItem->GetObjDesc() : "");
219  break;
220  }
221 
222  default:
223  break;
224  }
225  }
226  return NStr::Join(values, sDelimiter);
227 }
228 
229 
230 long CTableDataValidate::GetIntValue(size_t row, size_t col) const
231 {
232  return 0L;
233 }
234 
235 
237 {
238  return GetRowObject(row);
239 }
240 
241 
243 {
245  if (row < GetRowsCount()) {
247  if (err_item) {
248  //!! this is not quite correct since there may be several objects
249  //!! differently scoped
250  value.scope = m_Scope;
251  value.object = CConstRef<CSerialObject>(&err_item->GetObject());
252  }
253  }
254  return value;
255 }
256 
257 
259 {
260  if (!m_Errs) {
261  return CConstRef<CValidErrItem>();
262  }
263  size_t pos = 0;
264  size_t offset = 0;
265  CConstRef<CValidErrItem> pValidErrItem(NULL);
266  while (pos < row + 1 && offset < m_Errs->GetData().size()) {
267  pValidErrItem.Reset(m_Errs->GetData()[offset]);
268  if (pValidErrItem && x_MatchFilter(*pValidErrItem)) {
269  pos++;
270  }
271  offset++;
272  }
273  if (pos != row + 1) {
274  pValidErrItem.Reset(NULL);
275  }
276  return pValidErrItem;
277 }
278 
279 
281 
static CRef< CScope > m_Scope
CConstRef –.
Definition: ncbiobj.hpp:1266
void SetErrCode(string errcode)
virtual string GetColumnLabel(size_t col) const
vector< string > GetErrorList() const
virtual string GetHtmlValue(size_t, size_t) const
CRef< CObjectFor< objects::CValidError::TErrs > > m_Errs
size_t CountBySeverity(EDiagSev sev) const
static const size_t c_MsgObjectDescrWidth
void SetSeverity(EDiagSev sev)
virtual size_t GetRowsCount() const
static const size_t c_MaxRows
virtual void GetStringValue(size_t row, size_t col, string &value) const
virtual ColumnType GetColumnType(size_t col) const
CRef< objects::CScope > m_Scope
CTableDataValidate(CObjectFor< objects::CValidError::TErrs > *errs, objects::CScope *scope)
bool x_MatchFilter(const objects::CValidErrItem &valitem) const
CConstRef< objects::CValidErrItem > x_GetRowData(size_t row) const
virtual bool IsHtmlColumn(size_t col) const
virtual SConstScopedObject GetRowObject(size_t row) const
virtual SConstScopedObject GetObjectValue(size_t row, size_t col) const
virtual long GetIntValue(size_t row, size_t col) const
virtual size_t GetColsCount() const
static const string & ConvertSeverity(EDiagSev sev)
int offset
Definition: replacements.h:160
#define NULL
Definition: ncbistd.hpp:225
EDiagSev
Severity level for the posted diagnostics.
Definition: ncbidiag.hpp:650
@ eDiagSevMin
Verbosity level for min. severity.
Definition: ncbidiag.hpp:660
@ eDiag_Critical
Critical error message.
Definition: ncbidiag.hpp:654
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:1439
T & GetData(void)
Get data as a reference.
Definition: ncbiobj.hpp:2346
TObjectType & GetObject(void) const
Get object.
Definition: ncbiobj.hpp:1697
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define kEmptyStr
Definition: ncbistr.hpp:123
static bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
static string Join(const TContainer &arr, const CTempString &delim)
Join strings using the specified delimiter.
Definition: ncbistr.hpp:2697
static bool EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
Definition: ncbistr.hpp:5353
static void Wrap(const string &str, SIZE_TYPE width, IWrapDest &dest, TWrapFlags flags, const string *prefix, const string *prefix1)
Definition: ncbistr.cpp:5347
constexpr auto sort(_Init &&init)
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
T max(T x_, T y_)
#define row(bind, expected)
Definition: string_bind.c:73
static const string s_ColNames[]
USING_SCOPE(objects)
Modified on Wed Apr 17 13:08:08 2024 by modify_doxy.py rev. 669887