@@ -37,33 +37,6 @@ def __init__(self):
3737 self .data_store_port = data_store ['data_store_port' ]
3838 self .data_store_name = data_store ['data_store_name' ]
3939
40- def get_item (self , topic , name ):
41- """
42- For the command line tool, find the given item and return it. Intentionally not as flexible as
43- get_or_create_item.
44- :param topic:
45- :param name:
46- :return:
47- """
48- if topic == Actor :
49- item = self .get_or_create_item (model = topic , create = False , actor_name = name )
50- elif topic == ExtractStatus and name not in preload_extract_status_types :
51- item = self .get_or_create_item (model = topic , create = False , extract_status_name = name )
52- elif topic == ErrorType and name not in preload_error_types :
53- item = self .get_or_create_item (model = topic , create = False , error_type_name = name )
54- elif topic == ProcessType and name not in preload_process_types :
55- item = self .get_or_create_item (model = topic , create = False , process_type_name = name )
56- elif topic == ProcessStatus and name not in preload_process_status_types :
57- item = self .get_or_create_item (model = topic , create = False , process_status_name = name )
58- elif topic == Source :
59- item = self .get_or_create_item (model = topic , create = False , source_name = name )
60- elif topic == Tool :
61- item = self .get_or_create_item (model = topic , create = False , tool_name = name )
62- else :
63- ClickException ('The item is a protected record.' ).show ()
64-
65- return item
66-
6740 def get_or_create_item (self , model , create = True , ** kwargs ):
6841 """
6942 Testing if an entity instance exists or not. If does, return entity key. If not, create entity instance
@@ -218,37 +191,50 @@ def topic_deleter(self, topic, name):
218191 if item_delete :
219192 self .session .commit ()
220193
221- @staticmethod
222- def topic_updater (topic , item , name ):
194+ def topic_updater (self , topic , initial_name , name ):
223195 """
224196 For the command line tool, validate that the topic name is not a default value and if not, update it.
225- :param topic: The SQLAlchemy object type
226- :type topic: SQLAlchemy object
227- :param item : The SQLALchemy record to be updated.
228- :type item: SQLAlchemy record
229- :param name: The name of the item to be deleted .
230- :type name: str
197+ :param topic: name of the SQLAlchemy object
198+ :type topic: string
199+ :param initial_name : The name of the object to be updated.
200+ :type initial_name: string
201+ :param name: The updated name of the object to be updated .
202+ :type name: string
231203 :return:
232204 """
233- if topic == Actor :
234- item .actor_name = name
235- elif topic == ExtractStatus and item .extract_status_name not in preload_extract_status_types :
236- item .extract_status_name = name
237- elif topic == ErrorType and item .error_type_name not in preload_error_types :
238- item .error_type_name = name
239- elif topic == ProcessType and item .process_type_name not in preload_process_types :
240- item .process_type_name = name
241- elif topic == ProcessStatus and item .process_status_name not in preload_process_status_types :
242- item .process_status_name = name
243- elif topic == Source :
244- item .source_name = name
245- elif topic == Tool :
246- item .tool_name = name
247- else :
248- raise Exception ('The item could not be updated because it is a protected record.' )
205+ if self .topic_validator (topic = topic ):
206+ if topic == 'actor' :
207+ item = self .get_or_create_item (model = Actor , create = False , actor_name = initial_name )
208+ item .actor_name = name
209+
210+ elif topic == 'extract status' and initial_name not in preload_extract_status_types :
211+ item = self .get_or_create_item (model = ExtractStatus , create = False , extract_status_name = initial_name )
212+ item .extract_status_name = name
213+
214+ elif topic == 'error type' and initial_name not in preload_error_types :
215+ item = self .get_or_create_item (model = ErrorType , create = False , error_type_name = initial_name )
216+ item .error_type_name = name
217+
218+ elif topic == 'process type' and initial_name not in preload_process_types :
219+ item = self .get_or_create_item (model = ProcessType , create = False , process_type_name = initial_name )
220+ item .process_type_name = name
221+
222+ elif topic == 'process status' and initial_name not in preload_process_status_types :
223+ item = self .get_or_create_item (model = ProcessStatus , create = False , process_status_name = initial_name )
224+ item .process_status_name = name
225+ elif topic == 'source' :
226+ item = self .get_or_create_item (model = Source , create = False , source_name = initial_name )
227+ item .source_name = name
228+ elif topic == 'tool' :
229+ item = self .get_or_create_item (model = Tool , create = False , tool_name = initial_name )
230+ item .tool_name = name
231+ else :
232+ ClickException ('The item could not be updated because it is a protected record.' ).show ()
249233
250- item_session = Session .object_session (item )
251- item_session .commit ()
234+ self .session .commit ()
235+
236+ else :
237+ ClickException ('Invalid topic. Unable to update instance.' ).show ()
252238
253239 def topic_validator (self , topic ):
254240 """
0 commit comments