75 for (
const auto& pPub :
arr) {
77 return pPub->GetPmid().Get();
100 int maxCount =
max(1, maxAttempts);
101 for (
int count = 0; count < maxCount; ++count) {
108 bool isConnectionError = s_IsConnectionFailure(errorVal);
109 if (isConnectionError && count < maxCount - 1) {
113 std::ostringstream oss;
114 oss <<
"Failed to retrieve publication for PMID "
117 if (isConnectionError) {
118 oss << count + 1 <<
" attempts made. ";
120 oss <<
"Pubmed error: " << errorVal;
121 string msg = oss.str();
122 if (pMessageListener) {
152 const STimeout timeout = { seconds, 0 };
183 std::ostringstream os;
196 reply =
result->SetReply().front();
197 if (reply->
IsError() && f_logger) {
198 const string& error_message =
203 f_logger(error_message);
226 vector<string> keys(
n);
227 vector<CRef<CT3Reply>*> cache_refs(
n);
229 for (
size_t i = 0;
i <
n; ++
i ) {
230 std::ostringstream os;
234 cache_refs[
i] = &reply;
239 to_ask[keys[
i]] = make_pair(
query[
i], &reply);
242 if ( !to_ask.
empty() ) {
245 for (
const auto& it : to_ask ) {
246 to_ask_vec.push_back(it.second);
248 size_t m = to_ask_vec.size();
251 for (
auto& it : to_ask_vec ) {
253 rq->SetOrg(*it.first);
254 requests.push_back(rq);
260 auto& replies = whole_reply->SetReply();
261 if ( replies.size() != m ) {
264 const string& error_message =
268 logger(error_message);
274 for (
auto& reply : replies ) {
275 auto& ask = to_ask_vec[
i++];
277 if (reply->IsError() && logger) {
278 auto& in_org = *ask.first;
279 const string& error_message =
282 reply->GetError().GetMessage();
284 logger(error_message);
285 }
else if (reply->IsData() && reply->SetData().IsSetOrg()) {
286 reply->SetData().SetOrg().ResetSyn();
294 for (
size_t i = 0;
i <
n; ++
i ) {
295 result->SetReply().push_back(*cache_refs[
i]);
299 for (
const auto& it :
query) {
316 if (! (pub && pub->IsMedline())) {
323 if (! pub->GetMedline().IsSetCit()) {
343 arr.push_back(new_pmid);
344 arr.push_back(new_pub);
368 copied->Assign(*res);
376 if (cfg.
HasEntry(
"RemotePubmedUpdate")) {
377 const string sect =
"RemotePubmedUpdate";
383 if (cfg.
HasEntry(sect,
"UseCache")) {
388 if (cfg.
HasEntry(
"RemoteTaxonomyUpdate")) {
389 const string sect =
"RemoteTaxonomyUpdate";
390 int delay = cfg.
GetInt(sect,
"RetryDelay", 20);
393 int count = cfg.
GetInt(sect,
"RetryCount", 5);
396 bool exponential = cfg.
GetBool(sect,
"RetryExponentially",
false);
398 SetTaxonTimeout(
static_cast<unsigned>(delay),
static_cast<unsigned>(count), exponential);
428 std::lock_guard<std::mutex> guard(
m_Mutex);
449 m_logger{ logger }, m_pm_normalize(norm)
455 m_pMessageListener(pMessageListener), m_pm_normalize(norm)
458 m_logger = [
this](
const string& error_message) {
471 std::lock_guard<std::mutex> guard(
m_Mutex);
499 for (
auto& it : submit->
SetData().SetEntrys()) {
529 std::lock_guard<std::mutex> guard(
m_Mutex);
531 for (
auto& pDesc : seq_descr.
Set()) {
532 if (! pDesc->IsPub() || ! pDesc->GetPub().IsSetPub()) {
536 auto&
arr = pDesc->SetPub().SetPub().Set();
557 for (
const auto& pPub :
arr) {
558 if (pPub->IsArticle()) {
577 void _UpdateOrgFromTaxon(
CSeq_entry& entry, TOrgMap& m)
581 _UpdateOrgFromTaxon(*it, m);
588 for (
auto& it : entry.
SetDescr().Set()) {
599 std::ostringstream os;
603 v.owner.insert(&owner);
609 void xUpdate(TOwnerSet& owners,
COrg_ref& org_ref)
611 for (
auto& owner_it : owners) {
612 if ((*owner_it)->IsOrg()) {
613 (*owner_it)->SetOrg(org_ref);
614 }
else if ((*owner_it)->IsSource()) {
615 (*owner_it)->SetSource().SetOrg(org_ref);
623 TOrgMap org_to_update;
625 _UpdateOrgFromTaxon(entry, org_to_update);
626 if (org_to_update.empty())
629 std::lock_guard<std::mutex> guard(
m_Mutex);
640 vector<CRef<COrg_ref>> reflist;
641 for (
auto& it : org_to_update) {
642 reflist.push_back(it.second.org_ref);
647 for (
auto& it : org_to_update) {
648 vector<CRef<COrg_ref>> reflist;
649 reflist.push_back(it.second.org_ref);
653 auto& reply_it = reply->SetReply().front();
654 if (reply_it->IsData() && reply_it->SetData().IsSetOrg()) {
655 xUpdate(it.second.owner, reply_it->SetData().SetOrg());
671 list<CRef<CAuthor>> authors_with_affil;
673 if (it->IsSetAffil()) {
674 authors_with_affil.push_back(it);
678 if (authors_with_affil.size() == 1) {
681 ERR_POST(
Error <<
"publication contains multiple affiliations");
683 auth_list.
SetAffil(authors_with_affil.front()->SetAffil());
684 authors_with_affil.front()->ResetAffil();
699 if (desc_it->IsPub()) {
712 if (it->IsSetAuthors()) {
720 for (
CBioseq_CI bioseq_it(obj); bioseq_it; ++bioseq_it) {
734 std::lock_guard<std::mutex> guard(
m_Mutex);
744 std::lock_guard<std::mutex> guard(
m_Mutex);
753 upd->ReportStats(os);
User-defined methods of the data storage class.
@Auth_list.hpp User-defined methods of the data storage class.
void ConvertMlToStd(bool normalize_suffix)
CRef< CTaxon3_reply > SendOrgRefList(const vector< CRef< COrg_ref >> &query, CRemoteUpdater::FLogger logger)
map< string, CRef< CT3Reply > > CCachedReplyMap
CRef< CT3Reply > GetOrgReply(const COrg_ref &in_org, CRemoteUpdater::FLogger f_logger)
unique_ptr< CTaxon3 > m_taxon
void InitWithTimeout(unsigned seconds, unsigned retries, bool exponential)
void ReportStats(std::ostream &str)
CRef< COrg_ref > GetOrg(const COrg_ref &org, CRemoteUpdater::FLogger f_logger)
unique_ptr< CCachedReplyMap > m_cache
virtual CRef< CPub > GetPubmedEntry(TEntrezId pmid, EPubmedError *=nullptr)
CAuth_list & SetAuthors(void)
bool IsSetAuthors(void) const
@Pubdesc.hpp User-defined methods of the data storage class.
static void PostProcessPubs(CSeq_entry_EditHandle &obj)
static CRemoteUpdater & GetInstance()
TPubInterceptor m_pm_interceptor
IObjtoolsListener * m_pMessageListener
CEUtilsUpdater::ENormalize m_pm_normalize
void UpdateOrgFromTaxon(CSeq_entry &entry)
void xUpdateOrgTaxname(COrg_ref &org)
unique_ptr< CCachedTaxon3_impl > m_taxClient
void xUpdatePubReferences(CSeq_entry &entry)
void ReportStats(std::ostream &str)
void SetTaxonTimeout(unsigned seconds, unsigned retries, bool exponential)
void SetMaxMlaAttempts(int max)
bool xUpdatePubPMID(list< CRef< CPub >> &pubs, TEntrezId id)
void SetPubmedClient(CEUtilsUpdater *)
CConstRef< CTaxon3_reply > SendOrgRefList(const vector< CRef< COrg_ref >> &list)
function< void(const string &)> FLogger
taxupdate_func_t m_taxon_update
static void ConvertToStandardAuthors(CAuth_list &auth_list)
CRemoteUpdater(IObjtoolsListener *pMessageListener, CEUtilsUpdater::ENormalize=CEUtilsUpdater::ENormalize::Off)
void UpdatePubReferences(CSerialObject &obj)
CPub::E_Choice m_pm_pub_type
unique_ptr< CEUtilsUpdater > m_pubmed
@Seq_descr.hpp User-defined methods of the data storage class.
void SetDescr(CSeq_descr &value)
bool IsSetDescr(void) const
Base class for all serializable objects.
static vector< string > arr
@ cannot_connect_searchbackend_pmdb
static const char * str(char *buf, int n)
SStrictId_Entrez::TId TEntrezId
TEntrezId type for entrez ids which require the same strictness as TGi.
const CNcbiRegistry & GetConfig(void) const
Get the application's cached configuration parameters (read-only).
static CNcbiApplicationAPI * Instance(void)
Singleton method.
SStrictId_Tax::TId TTaxId
Taxon id type.
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
@ eDiag_Warning
Warning message.
static void SetBaseURL(const string &url)
Set new base url for all e-utils requests.
void Error(CExceptionArgs_Base &args)
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
void Info(CExceptionArgs_Base &args)
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
virtual const CTypeInfo * GetThisTypeInfo(void) const =0
#define MSerial_AsnText
I/O stream manipulators –.
bool NotNull(void) const THROWS_NONE
Check if pointer is not null – same effect as NotEmpty().
void Reset(void)
Reset reference object.
bool NotEmpty(void) const THROWS_NONE
Check if CRef is not empty – pointing to an object and has a non-null value.
bool Empty(void) const THROWS_NONE
Check if CRef is empty – not pointing to any object, which means having a null value.
virtual bool GetBool(const string §ion, const string &name, bool default_value, TFlags flags=0, EErrAction err_action=eThrow) const
Get boolean value of specified parameter name.
virtual int GetInt(const string §ion, const string &name, int default_value, TFlags flags=0, EErrAction err_action=eThrow) const
Get integer value of specified parameter name.
virtual bool HasEntry(const string §ion, const string &name=kEmptyStr, TFlags flags=0) const
virtual string GetString(const string §ion, const string &name, const string &default_value, TFlags flags=0) const
Get the parameter string value.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define END_SCOPE(ns)
End the previously defined scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
#define BEGIN_SCOPE(ns)
Define a new scope.
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
double Elapsed(void) const
Return time elapsed since first Start() or last Restart() call (in seconds).
@ eStart
Start timer immediately after creating.
virtual bool IsType(TTypeInfo type) const
bool IsSetAffil(void) const
author affiliation Check if a value has been assigned to Affil data member.
void SetAffil(TAffil &value)
Assign a value to Affil data member.
bool IsSetNames(void) const
Check if a value has been assigned to Names data member.
void SetNames(TNames &value)
Assign a value to Names data member.
const TNames & GetNames(void) const
Get the Names member data.
bool IsStd(void) const
Check if variant Std is selected.
bool IsSetOrg(void) const
Check if a value has been assigned to Org data member.
void SetOrg(TOrg &value)
Assign a value to Org data member.
const TTaxname & GetTaxname(void) const
Get the Taxname member data.
bool IsSetTaxname(void) const
preferred formal name Check if a value has been assigned to Taxname data member.
TPmid & SetPmid(void)
Select the variant.
TMedline & SetMedline(void)
Select the variant.
TArticle & SetArticle(void)
Select the variant.
TSet & SetSet(void)
Select the variant.
bool IsSeq(void) const
Check if variant Seq is selected.
bool IsSet(void) const
Check if variant Set is selected.
TSeq & SetSeq(void)
Select the variant.
TSeq_set & SetSeq_set(void)
Assign a value to Seq_set data member.
void SetPub(TPub &value)
Assign a value to Pub data member.
TOrg & SetOrg(void)
Select the variant.
bool IsOrg(void) const
Check if variant Org is selected.
const TSource & GetSource(void) const
Get the variant data.
bool IsSource(void) const
Check if variant Source is selected.
TSource & SetSource(void)
Select the variant.
void SetDescr(TDescr &value)
Assign a value to Descr data member.
bool IsSetPub(void) const
the citation(s) Check if a value has been assigned to Pub data member.
Tdata & Set(void)
Assign a value to data member.
@ e_Pub
a reference to the publication
void SetData(TData &value)
Assign a value to Data data member.
bool IsData(void) const
Check if variant Data is selected.
bool IsSetOrg(void) const
Check if a value has been assigned to Org data member.
TRequest & SetRequest(void)
Assign a value to Request data member.
void SetOrg(TOrg &value)
Assign a value to Org data member.
bool IsError(void) const
Check if variant Error is selected.
const TError & GetError(void) const
Get the variant data.
const TMessage & GetMessage(void) const
Get the Message member data.
TData & SetData(void)
Select the variant.
static const bool kUseBulkTaxonQuery