NCBI C++ ToolKit
remote_updater.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: remote_updater.hpp 101487 2023-12-19 16:34:07Z stakhovv $
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: Sergiy Gotvyanskyy, NCBI
27  * Colleen Bolin, NCBI
28  *
29  * File Description:
30  * Front-end class for making remote request to MLA and taxon
31  *
32  * ===========================================================================
33  */
34 
35 #ifndef __REMOTE_UPDATER_HPP_INCLUDED__
36 #define __REMOTE_UPDATER_HPP_INCLUDED__
37 
38 #include <corelib/ncbimisc.hpp>
39 #include <functional>
40 #include <objects/pub/Pub.hpp>
44 #include <mutex>
45 
47 
48 class CSerialObject;
49 
51 
53 class CSeq_entry;
54 class CSeqdesc;
55 class CSeq_descr;
56 class COrg_ref;
57 class CAuth_list;
58 class IObjtoolsListener;
59 class CPubdesc;
60 class CTaxon3_reply;
61 
63 
64 enum class EPubmedSource
65 {
66  eEUtils,
67 };
68 
69 class CCachedTaxon3_impl;
70 
72 {
73 public:
76  {
77  }
78  virtual CRemoteUpdaterMessage *Clone(void) const {
79  return new CRemoteUpdaterMessage(GetText(), m_error);
80  }
81 
83 };
84 
86 {
87 public:
89 };
90 
92 {
93 public:
94 
95  using FLogger = function<void(const string&)>;
96 
97  // With this constructor, failure to retrieve
98  // a publication for a PMID is logged with the supplied message listener.
99  // If no message listener is supplied, an exception is thrown.
101  // NCBI_DEPRECATED
105  CRemoteUpdater(pMessageListener, norm)
106  {
107  }
110  CRemoteUpdater(logger, norm)
111  {
112  }
113  ~CRemoteUpdater();
114 
115  void UpdatePubReferences(CSerialObject& obj);
116  void UpdatePubReferences(CSeq_entry_EditHandle& obj);
117  void SetMaxMlaAttempts(int max);
118  // Specify flavor of updated CPub: CMedline_entry or CCit_art
120  {
121  if (t == CPub::e_Medline || t == CPub::e_Article) {
122  m_pm_pub_type = t;
123  } else {
124  throw std::invalid_argument("invalid CPub choice");
125  }
126  }
127 
128  CConstRef<CTaxon3_reply> SendOrgRefList(const vector<CRef<COrg_ref>>& list);
129 
130  void UpdateOrgFromTaxon(CSeq_entry& entry);
131  void UpdateOrgFromTaxon(CSeqdesc& desc);
132  void SetTaxonTimeout(unsigned seconds, unsigned retries, bool exponential);
133 
134  void ClearCache();
135  static void ConvertToStandardAuthors(CAuth_list& auth_list);
136  static void PostProcessPubs(CSeq_entry_EditHandle& obj);
137  static void PostProcessPubs(CSeq_entry& obj);
138  static void PostProcessPubs(CPubdesc& pubdesc);
139 
140  void SetPubmedClient(CEUtilsUpdater*);
141  // Use either shared singleton or individual instances
142  NCBI_DEPRECATED static CRemoteUpdater& GetInstance();
143  void ReportStats(std::ostream& str);
144  taxupdate_func_t GetUpdateFunc() const { return m_taxon_update; }
146  {
147  TPubInterceptor old = m_pm_interceptor;
148  m_pm_interceptor = f;
149  return old;
150  }
151 
152 private:
153  void xUpdatePubReferences(CSeq_entry& entry);
154  void xUpdatePubReferences(CSeq_descr& descr);
155  void xUpdateOrgTaxname(COrg_ref& org);
156  bool xUpdatePubPMID(list<CRef<CPub>>& pubs, TEntrezId id);
157  bool xSetFromConfig();
158  void xInitTaxCache();
159 
160  IObjtoolsListener* m_pMessageListener = nullptr;
161  FLogger m_logger = nullptr; // wrapper for compatibility between IObjtoolsListener and old FLogger
162 
163  string m_pm_url;
164  unique_ptr<CEUtilsUpdater> m_pubmed;
165  bool m_pm_use_cache = true;
167  TPubInterceptor m_pm_interceptor = nullptr;
169 
170  unique_ptr<CCachedTaxon3_impl> m_taxClient;
172 
173  std::mutex m_Mutex;
174  int m_MaxMlaAttempts = 3;
175 
176  bool m_TaxonTimeoutSet = false;
177  unsigned m_TaxonTimeout = 20; // in seconds
178  unsigned m_TaxonAttempts = 5;
179  bool m_TaxonExponential = false;
180 };
181 
185 
186 #endif
@Auth_list.hpp User-defined methods of the data storage class.
Definition: Auth_list.hpp:57
CConstRef –.
Definition: ncbiobj.hpp:1266
virtual string GetText(void) const
Definition: edit_error.hpp:93
@Pubdesc.hpp User-defined methods of the data storage class.
Definition: Pubdesc.hpp:54
virtual CRemoteUpdaterMessage * Clone(void) const
CRemoteUpdaterMessage(const string &msg, EPubmedError error)
std::mutex m_Mutex
void SetPubReturnType(CPub::E_Choice t)
TPubInterceptor SetPubmedInterceptor(TPubInterceptor f)
unique_ptr< CCachedTaxon3_impl > m_taxClient
CRemoteUpdater(FLogger logger, EPubmedSource, CEUtilsUpdater::ENormalize norm=CEUtilsUpdater::ENormalize::Off)
CRemoteUpdater(IObjtoolsListener *pMessageListener, EPubmedSource, CEUtilsUpdater::ENormalize norm=CEUtilsUpdater::ENormalize::Off)
function< void(const string &)> FLogger
taxupdate_func_t m_taxon_update
taxupdate_func_t GetUpdateFunc() const
unique_ptr< CEUtilsUpdater > m_pubmed
@Seq_descr.hpp User-defined methods of the data storage class.
Definition: Seq_descr.hpp:55
CSeq_entry_Handle –.
Definition: Seq_entry.hpp:56
Base class for all serializable objects.
Definition: serialbase.hpp:150
CTaxon3_reply –.
EPubmedError
std::function< void(CRef< CPub > &)> TPubInterceptor
static const char * str(char *buf, int n)
Definition: stats.c:84
SStrictId_Entrez::TId TEntrezId
TEntrezId type for entrez ids which require the same strictness as TGi.
Definition: ncbimisc.hpp:1041
@ eDiag_Warning
Warning message.
Definition: ncbidiag.hpp:652
CException(void)
Constructor with no arguments.
Definition: ncbiexpt.cpp:244
#define NCBI_DEPRECATED
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
#define NCBI_XOBJEDIT_EXPORT
Definition: ncbi_export.h:1291
E_Choice
Choice variants.
Definition: Pub_.hpp:100
@ e_Article
Definition: Pub_.hpp:106
@ e_Medline
Definition: Pub_.hpp:104
function< CRef< CTaxon3_reply >(const vector< CRef< COrg_ref > > &list)> taxupdate_func_t
Definition: itaxon3.hpp:60
Definition: fix_pub.hpp:45
EIPRangeType t
Definition: ncbi_localip.c:101
Miscellaneous common-use basic types and functionality.
T max(T x_, T y_)
double f(double x_, const double &y_)
Definition: njn_root.hpp:188
EPubmedSource
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
Modified on Wed Sep 04 15:03:09 2024 by modify_doxy.py rev. 669887