1 #ifndef PSGS_RESOLVEBASE__HPP
2 #define PSGS_RESOLVEBASE__HPP
3 
4 /*  $Id: resolve_base.hpp 629837 2021-04-22 12:47:49Z ivanov $
5  * ===========================================================================
6  *
7  *                            PUBLIC DOMAIN NOTICE
8  *               National Center for Biotechnology Information
9  *
10  *  This software/database is a "United States Government Work" under the
11  *  terms of the United States Copyright Act.  It was written as part of
12  *  the author's official duties as a United States Government employee and
13  *  thus cannot be copyrighted.  This software/database is freely available
14  *  to the public for use. The National Library of Medicine and the U.S.
15  *  Government have not placed any restriction on its use or reproduction.
16  *
17  *  Although all reasonable efforts have been taken to ensure the accuracy
18  *  and reliability of the software and data, the NLM and the U.S.
19  *  Government do not and cannot warrant the performance or results that
20  *  may be obtained by using this software or data. The NLM and the U.S.
21  *  Government disclaim all warranties, express or implied, including
22  *  warranties of performance, merchantability or fitness for any particular
23  *  purpose.
24  *
25  *  Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Sergey Satskiy
30  *
31  * File Description: base class for processors which need to resolve seq_id
32  *
33  */
34 
35 #include <corelib/request_status.hpp>
36 #include <corelib/ncbidiag.hpp>
37 
38 #include "cass_fetch.hpp"
39 #include "psgs_request.hpp"
40 #include "psgs_reply.hpp"
41 #include "cass_processor_base.hpp"
42 #include "async_resolve_base.hpp"
43 #include "async_bioseq_info_base.hpp"
44 
45 #include <objects/seqloc/Seq_id.hpp>
46 USING_NCBI_SCOPE;
47 USING_SCOPE(objects);
48 USING_IDBLOB_SCOPE;
49 
50 struct SResolveInputSeqIdError;
51 
52 
53 // Deriving from CPSGS_CassProcessorBase is not required because
54 // CPSGS_AsyncResolveBase and CPSGS_AsyncBioseqInfoBase derive from it
55 // (virtually) as well
56 class CPSGS_ResolveBase : public CPSGS_AsyncResolveBase,
57                           public CPSGS_AsyncBioseqInfoBase
58 {
59 public:
60     CPSGS_ResolveBase();
61     CPSGS_ResolveBase(shared_ptr<CPSGS_Request> request,
62                       shared_ptr<CPSGS_Reply> reply,
63                       TSeqIdResolutionFinishedCB finished_cb,
64                       TSeqIdResolutionErrorCB error_cb,
65                       TSeqIdResolutionStartProcessingCB resolution_start_processing_cb);
66     virtual ~CPSGS_ResolveBase();
67 
68 private:
69     SPSGS_RequestBase::EPSGS_CacheAndDbUse x_GetRequestUseCache(void);
70     bool x_GetEffectiveSeqIdType(const CSeq_id &  parsed_seq_id,
71                                  int16_t &  eff_seq_id_type,
72                                  bool  need_trace);
73     EPSGS_SeqIdParsingResult x_ParseInputSeqId(CSeq_id &  seq_id,
74                                                string &  err_msg);
75     bool x_ComposeOSLT(CSeq_id &  parsed_seq_id,
76                        int16_t &  effective_seq_id_type,
77                        list<string> &  secondary_id_list,
78                        string &  primary_id);
79 
80 private:
81     EPSGS_CacheLookupResult x_ResolvePrimaryOSLTInCache(
82                                 const string &  primary_id,
83                                 int16_t  effective_version,
84                                 int16_t  effective_seq_id_type,
85                                 SBioseqResolution &  bioseq_resolution);
86     EPSGS_CacheLookupResult x_ResolveSecondaryOSLTInCache(
87                                 const string &  secondary_id,
88                                 int16_t  effective_seq_id_type,
89                                 SBioseqResolution &  bioseq_resolution);
90     EPSGS_CacheLookupResult x_ResolveAsIsInCache(
91                                 SBioseqResolution &  bioseq_resolution,
92                                 bool  need_as_is=true);
93     void x_ResolveViaComposeOSLTInCache(
94                                 CSeq_id &  parsed_seq_id,
95                                 int16_t  effective_seq_id_type,
96                                 const list<string> &  secondary_id_list,
97                                 const string &  primary_id,
98                                 SBioseqResolution &  bioseq_resolution);
99 
100 private:
101     void x_OnResolutionGoodData(void);
102     void x_OnSeqIdResolveError(
103                         CRequestStatus::ECode  status,
104                         int  code,
105                         EDiagSev  severity,
106                         const string &  message);
107     void x_OnSeqIdResolveFinished(
108                         SBioseqResolution &&  bioseq_resolution);
109     void x_RegisterSuccessTiming(const SBioseqResolution &  bioseq_resolution);
110 
111 protected:
112     void ResolveInputSeqId(void);
113 
114 public:
115     SBioseqResolution  ResolveTestInputSeqId(void);
116 
117 private:
118     TSeqIdResolutionFinishedCB          m_FinalFinishedCB;
119     TSeqIdResolutionErrorCB             m_FinalErrorCB;
120     TSeqIdResolutionStartProcessingCB   m_FinalStartProcessingCB;
121 
122     bool                                m_AsyncStarted;
123 };
124 
125 #endif  // PSGS_RESOLVEBASE__HPP
126 
127