1 #ifndef PSGS_ASYNCRESOLVEBASE__HPP 2 #define PSGS_ASYNCRESOLVEBASE__HPP 3 4 /* $Id: async_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 * asynchronously 33 * 34 */ 35 36 #include <corelib/request_status.hpp> 37 #include <corelib/ncbidiag.hpp> 38 39 #include "cass_fetch.hpp" 40 #include "psgs_request.hpp" 41 #include "psgs_reply.hpp" 42 #include "cass_processor_base.hpp" 43 #include "pubseq_gateway_utils.hpp" 44 45 #include <objects/seqloc/Seq_id.hpp> 46 USING_NCBI_SCOPE; 47 USING_SCOPE(objects); 48 USING_IDBLOB_SCOPE; 49 50 #include <functional> 51 52 using TSeqIdResolutionFinishedCB = 53 function<void(SBioseqResolution && async_bioseq_resolution)>; 54 using TSeqIdResolutionErrorCB = 55 function<void(CRequestStatus::ECode status, 56 int code, 57 EDiagSev severity, 58 const string & message)>; 59 using TSeqIdResolutionStartProcessingCB = 60 function<void(void)>; 61 62 63 64 class CPSGS_AsyncResolveBase : virtual public CPSGS_CassProcessorBase 65 { 66 public: 67 CPSGS_AsyncResolveBase(); 68 CPSGS_AsyncResolveBase(shared_ptr<CPSGS_Request> request, 69 shared_ptr<CPSGS_Reply> reply, 70 TSeqIdResolutionFinishedCB finished_cb, 71 TSeqIdResolutionErrorCB error_cb, 72 TSeqIdResolutionStartProcessingCB start_processing_cb); 73 virtual ~CPSGS_AsyncResolveBase(); 74 75 public: 76 void Process(int16_t effective_version, 77 int16_t effective_seq_id_type, 78 list<string> && secondary_id_list, 79 string && primary_seq_id, 80 bool composed_ok, 81 SBioseqResolution && bioseq_resolution); 82 83 private: 84 enum EPSGS_ResolveStage { 85 eInit, // Initial stage; nothing has been done yet 86 ePrimaryBioseq, // BIOSEQ_INFO (primary) request issued 87 88 eSecondarySi2csi, // loop over all secondary seq_id in SI2CSI 89 90 eSecondaryAsIs, 91 eSecondaryAsIsModified, // strip or add '|' 92 93 eFinished, 94 95 ePostSi2Csi // Special case for seq_id like gi|156232 96 }; 97 98 protected: 99 int16_t GetEffectiveVersion(const CTextseq_id * text_seq_id); 100 string GetRequestSeqId(void); 101 int16_t GetRequestSeqIdType(void); 102 SPSGS_ResolveRequest::TPSGS_BioseqIncludeData GetBioseqInfoFields(void); 103 bool NonKeyBioseqInfoFieldsRequested(void); 104 bool CanSkipBioseqInfoRetrieval(const CBioseqInfoRecord & bioseq_info_record); 105 SPSGS_RequestBase::EPSGS_AccSubstitutioOption 106 GetAccessionSubstitutionOption(void); 107 EPSGS_AccessionAdjustmentResult 108 AdjustBioseqAccession(SBioseqResolution & bioseq_resolution); 109 protected: GetAsyncResolutionStartTimestamp(void) const110 TPSGS_HighResolutionTimePoint GetAsyncResolutionStartTimestamp(void) const 111 { 112 return m_AsyncCassResolutionStart; 113 } 114 SetAsyncResolutionStartTimestamp(const TPSGS_HighResolutionTimePoint & ts)115 void SetAsyncResolutionStartTimestamp(const TPSGS_HighResolutionTimePoint & ts) 116 { 117 m_AsyncCassResolutionStart = ts; 118 } 119 120 private: 121 void x_Process(void); 122 123 private: 124 void x_PreparePrimaryBioseqInfoQuery(const CBioseqInfoRecord::TAccession & seq_id, 125 CBioseqInfoRecord::TVersion version, 126 CBioseqInfoRecord::TSeqIdType seq_id_type, 127 CBioseqInfoRecord::TGI gi, 128 bool with_seq_id_type); 129 void x_PrepareSecondarySi2csiQuery(void); 130 void x_PrepareSecondaryAsIsSi2csiQuery(void); 131 void x_PrepareSecondaryAsIsModifiedSi2csiQuery(void); 132 void x_PrepareSi2csiQuery(const string & secondary_id, 133 int16_t effective_seq_id_type); 134 135 public: 136 void x_OnBioseqInfo(vector<CBioseqInfoRecord>&& records); 137 void x_OnBioseqInfoWithoutSeqIdType(vector<CBioseqInfoRecord>&& records); 138 void x_OnBioseqInfoError(CRequestStatus::ECode status, int code, 139 EDiagSev severity, const string & message); 140 void x_OnSi2csiRecord(vector<CSI2CSIRecord> && records); 141 void x_OnSi2csiError(CRequestStatus::ECode status, int code, 142 EDiagSev severity, const string & message); 143 144 private: 145 void x_OnSeqIdAsyncResolutionFinished( 146 SBioseqResolution && async_bioseq_resolution); 147 void x_SignalStartProcessing(void); 148 149 protected: 150 TSeqIdResolutionFinishedCB m_FinishedCB; 151 TSeqIdResolutionErrorCB m_ErrorCB; 152 TSeqIdResolutionStartProcessingCB m_StartProcessingCB; 153 154 EPSGS_ResolveStage m_ResolveStage; 155 bool m_ComposedOk; 156 string m_PrimarySeqId; 157 int16_t m_EffectiveVersion; 158 int16_t m_EffectiveSeqIdType; 159 size_t m_SecondaryIndex; 160 list<string> m_SecondaryIdList; 161 SBioseqResolution m_BioseqResolution; 162 163 CCassFetch * m_CurrentFetch; 164 CCassFetch * m_NoSeqIdTypeFetch; 165 166 CBioseqInfoRecord::TAccession m_BioseqInfoRequestedAccession; 167 CBioseqInfoRecord::TVersion m_BioseqInfoRequestedVersion; 168 CBioseqInfoRecord::TSeqIdType m_BioseqInfoRequestedSeqIdType; 169 CBioseqInfoRecord::TGI m_BioseqInfoRequestedGI; 170 171 TPSGS_HighResolutionTimePoint m_BioseqInfoStart; 172 TPSGS_HighResolutionTimePoint m_Si2csiStart; 173 TPSGS_HighResolutionTimePoint m_AsyncCassResolutionStart; 174 175 bool m_StartProcessingCalled; 176 }; 177 178 #endif // PSGS_ASYNCRESOLVEBASE__HPP 179 180