Skip to content

Commit b83208d

Browse files
authored
Merge pull request #59 from eodms-sgdot/development
Added Record Id Check at Prompt
2 parents b61ceec + f272e75 commit b83208d

File tree

2 files changed

+40
-23
lines changed

2 files changed

+40
-23
lines changed

eodms_cli.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1736,7 +1736,28 @@ def prompt(self):
17361736
sar_tb.ingest_request()
17371737
else:
17381738
inputs = self.ask_st_images(input_val)
1739-
self.params['input_val'] = inputs
1739+
1740+
coll_id, ids = inputs.split(':')
1741+
# If Order Keys are entered, check if they exist
1742+
if inputs.find("_") > -1:
1743+
ord_keys = ids.split('|')
1744+
rec_ids = self.eod.get_record_ids(coll_id, ord_keys)
1745+
1746+
if len(rec_ids) == 0:
1747+
err_msg = f"No images could be found with Order Keys: "\
1748+
f"{', '.join(ord_keys)}."
1749+
self.eod.logger.error(err_msg)
1750+
# self.print_support(err_msg)
1751+
self.eod.print_msg(err_msg, heading='error')
1752+
self.eod.exit_cli(1)
1753+
else:
1754+
rec_ids = ids.split('|')
1755+
1756+
print(f"\nSubmitting images with Record Ids: " \
1757+
f"{', '.join(rec_ids)}")
1758+
1759+
self.params['input_val'] = {"collection_id": coll_id,
1760+
"record_ids": rec_ids}
17401761

17411762
# sar_tb = self.ask_st(self.params['input_val'])
17421763
sar_tb = self.ask_st()

scripts/utils.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,22 @@ def get_input_fields(self, in_csv):
12371237

12381238
# return displayed_fields
12391239

1240+
def get_record_ids(self, coll_id, order_keys):
1241+
1242+
if not isinstance(order_keys, list):
1243+
order_keys = [order_keys]
1244+
1245+
record_ids = []
1246+
for ok in order_keys:
1247+
filters = {'Order Key': ('=', ok)}
1248+
self.eodms_rapi.search(coll_id, filters)
1249+
1250+
res = self.eodms_rapi.get_results()
1251+
if len(res) > 0:
1252+
record_ids = [r.get('recordId') for r in res]
1253+
1254+
return record_ids
1255+
12401256
def get_image_from_order(self, order):
12411257
"""
12421258
Gets an image from the RAPI based on an order into an image.Image object.
@@ -2604,28 +2620,8 @@ def order_st(self, sar_toolbox, params): # sar_toolbox, priority):
26042620
in_vals = params.get('input_val')
26052621
priority = params.get('priority')
26062622

2607-
coll_id, ids = in_vals.split(':')
2608-
2609-
if ids.find("_") > -1:
2610-
ord_keys = ids.split('|')
2611-
for ok in ord_keys:
2612-
filters = {'Order Key': ('=', ok)}
2613-
self.eodms_rapi.search(coll_id, filters)
2614-
2615-
res = self.eodms_rapi.get_results()
2616-
if len(res) > 0:
2617-
record_ids = [r.get('recordId') for r in res]
2618-
2619-
# print(f"res: {res}")
2620-
# answer = input("Press enter...")
2621-
else:
2622-
record_ids = ids.split('|')
2623-
2624-
# print(f"record_ids: {record_ids}")
2625-
# answer = input("Press enter...")
2626-
2627-
sar_toolbox.set_coll_id(coll_id)
2628-
sar_toolbox.set_record_ids(record_ids)
2623+
sar_toolbox.set_coll_id(in_vals.get('collection_id'))
2624+
sar_toolbox.set_record_ids(in_vals.get('record_ids'))
26292625

26302626
start_str = self._set_result_fn()
26312627
self.logger.info(f"Process start time: {start_str}")

0 commit comments

Comments
 (0)