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

Go to the SVN repository for this file.

1 /* $Id: object_loading_task.cpp 46305 2021-03-10 15:32:24Z asztalos $
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: Roman Katargin
27  *
28  */
29 
30 #include <ncbi_pch.hpp>
31 
35 
41 #include <objmgr/scope.hpp>
42 
44 
45 
47 
51 
52 #include <wx/filename.h>
53 
56 
57 ///////////////////////////////////////////////////////////////////////////////
58 /// CObjectLoadingTask
59 
61 
63  : CAppJobTask(true, object_loader.GetDescription()),
64  m_Service(service), m_ObjectLoader(&object_loader), m_Options(options)
65 {
66  CIRef<IExecuteUnit> execute_unit(dynamic_cast<IExecuteUnit*>(&object_loader));
67  _ASSERT(execute_unit);
68  m_Job.Reset(new CAppJobExecuteUnit(*execute_unit, object_loader.GetDescription()));
69 }
70 
71 static void s_CallExtensionProjectItemCreated(vector<IProjectItemExtension*>& clients, CProjectItem& item, IServiceLocator* srvLocator)
72 {
73  ITERATE(vector<IProjectItemExtension*>, it, clients) {
74  string extName = "Unknown extension";
75  IExtension* ext = dynamic_cast<IExtension*>(*it);
76  if (ext) extName = ext->GetExtensionIdentifier();
77  try {
78  (*it)->ProjectItemCreated(item, srvLocator);
79  } NCBI_CATCH("Project item created \"" + extName + "\" error.");
80  }
81 }
82 
83 void CObjectLoadingTask::AddProjectItemExtra(const string& tag, const string& value)
84 {
86 }
87 
89 {
91 
92  if (m_State == eInitial) {
93  CIRef<IExecuteUnit> execute_unit(dynamic_cast<IExecuteUnit*>(m_ObjectLoader.GetPointer()));
94  if (!execute_unit || !execute_unit->PreExecute())
95  return eCanceled;
96  }
97  else if (state == eCompleted) {
98  CIRef<IExecuteUnit> execute_unit(dynamic_cast<IExecuteUnit*>(m_ObjectLoader.GetPointer()));
99  if (!execute_unit || !execute_unit->PostExecute())
100  return eCanceled;
101 
102  if (!AddObjects(m_Service->GetServiceLocator(),
103  m_ObjectLoader->GetObjects(), dynamic_cast<CLoaderDescriptor*>(m_ObjectLoader->GetLoader()),
105  return eCanceled;
106  }
107  return eCompleted;
108  }
109 
110  return state;
111 }
112 
114  IServiceLocator* serviceLocator,
116  CLoaderDescriptor* loader,
117  CSelectProjectOptions& options,
118  const map<string, string>& projectItemExtra)
119 {
120  vector<IProjectItemExtension*> clients;
122 
125  CSerialObject* so = dynamic_cast<CSerialObject*>(it->GetObjectPtr());
126  if (so) {
127  if (CSeq_entry* se = dynamic_cast<CSeq_entry*>(so)) {
129  }
130  else if (CBioseq* bioseq = dynamic_cast<CBioseq*>(so)) {
131  CRef<CSeq_entry> se(new CSeq_entry());
132  se->SetSeq(*bioseq);
134  }
135  else if (CBioseq_set* bioseqSet = dynamic_cast<CBioseq_set*>(so)) {
136  CRef<CSeq_entry> se(new CSeq_entry());
137  se->SetSet(*bioseqSet);
139  }
140  else if (CSeq_submit* sub = dynamic_cast<CSeq_submit*>(so)) {
141  if (sub && sub->IsSetData() && sub->IsEntrys()) {
142  NON_CONST_ITERATE(CSeq_submit::TData::TEntrys, ent, sub->SetData().SetEntrys()) {
144  }
145  }
146  }
147 
148  CRef<CProjectItem> item(new CProjectItem());
149  item->SetObject(*so);
150  item->SetLabel(it->GetDescription());
151 
152  list<string> comment;
153  NStr::Split(it->GetComment(), "\n\r", comment, NStr::fSplit_Tokenize);
154  ITERATE(list<string>, iter, comment) {
155  if (!iter->empty()) {
156  CRef<CAnnotdesc> annot(new CAnnotdesc());
157  annot->SetComment(*iter);
158  item->SetDescr().push_back(annot);
159  }
160  }
161 
162  for (auto t : projectItemExtra)
163  CProjectItemExtra::SetStr(*item, t.first, t.second);
164 
165  string filePath = it->GetFileName();
166  if (!filePath.empty()) {
167  if (m_SaveFilePath)
168  CProjectItemExtra::SetStr(*item, "OriginalPath", filePath);
169 
170  wxFileName fileName(wxString::FromUTF8(filePath.c_str()));
171  string fname(fileName.GetFullName().ToUTF8());
172  CProjectItemExtra::SetStr(*item, "OriginalFile", fname);
173  }
174 
175  s_CallExtensionProjectItemCreated(clients, *item, serviceLocator);
176 
177  items.push_back(item);
178  }
179  }
180 
182  data[CRef<CLoaderDescriptor>(loader)] = items;
183 
184  if (!options.AddItemsToWorkspace(serviceLocator->GetServiceByType<CProjectService>(), data))
185  return false;
186 
187  CPrefetchSeqDescr::PrefetchSeqDescr(serviceLocator, items);
188  return true;
189 }
190 
191 
User-defined methods of the data storage class.
CAnnotdesc –.
Definition: Annotdesc.hpp:66
CAppJobTask CAppJobTask is an adapter that allows for running IAppJobs as Tasks in App Task Service.
ETaskState m_State
CLoaderDescriptor –.
static bool m_SaveFilePath
CObjectLoadingTask.
static bool AddObjects(IServiceLocator *serviceLocator, IObjectLoader::TObjects &objects, objects::CLoaderDescriptor *loader, CSelectProjectOptions &options, const map< string, string > &projectItemExtra=map< string, string >())
void AddProjectItemExtra(const string &tag, const string &value)
map< string, string > m_ProjectItemExtra
CIRef< IObjectLoader > m_ObjectLoader
CIRef< CProjectService > m_Service
CSelectProjectOptions m_Options
CObjectLoadingTask(CProjectService *service, IObjectLoader &object_loader, CSelectProjectOptions &options)
virtual ETaskState Run()
execute the task, this function is called on the main UI thread if a task needs to execute in backgro...
static void PrefetchSeqDescr(IServiceLocator *serviceLocator, const vector< CRef< objects::CProjectItem > > &items)
static void SetStr(objects::CProjectItem &pi, const string &tag, const string &value)
void SetObject(CSerialObject &object)
wrapper for setting the object pointed to by this item
CProjectService - a service providing API for operations with Workspaces and Projects.
CProjectSelectOptions - describes how new Project Items shall be added to a workspace.
bool AddItemsToWorkspace(CProjectService *service, const TData &data)
Definition: Seq_entry.hpp:56
Base class for all serializable objects.
Definition: serialbase.hpp:150
IExtension IExtension interface represents an abstract pluggable component.
Definition: extension.hpp:57
vector< SObject > TObjects
virtual string GetDescription() const =0
IServiceLocator - an abstract mechanism for locating services.
Definition: service.hpp:71
#define true
Definition: bool.h:35
char data[12]
Definition: iconv.c:80
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
#define NCBI_CATCH(message)
Catch CExceptions as well This macro is deprecated - use *_X or *_XX variant instead of it.
Definition: ncbiexpt.hpp:580
CIRef< T > GetServiceByType()
retrieves a typed reference to a service, the name of C++ type is used as the name of the service.
Definition: service.hpp:91
CIRef< IAppJob > m_Job
ETaskState
List of task states defining the task management FSM.
Definition: app_task.hpp:87
virtual ETaskState Run()
execute the task, this function is called on the main UI thread if a task needs to execute in backgro...
@ eCanceled
canceled by Task Manager
Definition: app_task.hpp:94
@ eCompleted
successfully finished
Definition: app_task.hpp:92
@ eInitial
has not been executed yet
Definition: app_task.hpp:89
void GetExtensionAsInterface(const string &ext_point_id, vector< CIRef< I > > &interfaces)
GetExtensionAsInterface() is a helper function that extracts all extensions implementing the specifie...
virtual string GetExtensionIdentifier() const =0
returns the unique human-readable identifier for the extension the id should use lowercase letters se...
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
Definition: ncbistr.cpp:3461
@ fSplit_Tokenize
All delimiters are merged and trimmed, to get non-empty tokens only.
Definition: ncbistr.hpp:2508
TDescr & SetDescr(void)
Assign a value to Descr data member.
void SetLabel(const TLabel &value)
Assign a value to Label data member.
TSet & SetSet(void)
Select the variant.
Definition: Seq_entry_.cpp:130
TSeq & SetSeq(void)
Select the variant.
Definition: Seq_entry_.cpp:108
TComment & SetComment(void)
Select the variant.
Definition: Annotdesc_.hpp:548
list< CRef< CSeq_entry > > TEntrys
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
EIPRangeType t
Definition: ncbi_localip.c:101
const char * tag
USING_SCOPE(objects)
static void s_CallExtensionProjectItemCreated(vector< IProjectItemExtension * > &clients, CProjectItem &item, IServiceLocator *srvLocator)
The Object manager core.
#define EXT_POINT__PROJECT_ITEM_EXTENSION
void HandleCollidingIds(CSeq_entry &entry)
#define _ASSERT
Modified on Wed Apr 24 14:11:47 2024 by modify_doxy.py rev. 669887