|
8 | 8 | from py42.exceptions import Py42NotFoundError |
9 | 9 | from py42.exceptions import Py42UpdateClosedCaseError |
10 | 10 |
|
| 11 | +from code42cli.bulk import generate_template_cmd_factory |
| 12 | +from code42cli.bulk import run_bulk_process |
11 | 13 | from code42cli.click_ext.groups import OrderedGroup |
12 | 14 | from code42cli.errors import Code42CLIError |
| 15 | +from code42cli.file_readers import read_csv_arg |
13 | 16 | from code42cli.options import format_option |
14 | 17 | from code42cli.options import sdk_options |
15 | 18 | from code42cli.options import set_begin_default_dict |
@@ -261,3 +264,60 @@ def remove(state, case_number, event_id): |
261 | 264 | state.sdk.cases.file_events.delete(case_number, event_id) |
262 | 265 | except Py42NotFoundError: |
263 | 266 | raise Code42CLIError("Invalid case-number or event-id.") |
| 267 | + |
| 268 | + |
| 269 | +@file_events.group(cls=OrderedGroup) |
| 270 | +@sdk_options(hidden=True) |
| 271 | +def bulk(state): |
| 272 | + """Tools for executing bulk case file-event actions.""" |
| 273 | + pass |
| 274 | + |
| 275 | + |
| 276 | +FILE_EVENTS_HEADERS = [ |
| 277 | + "number", |
| 278 | + "eventId", |
| 279 | +] |
| 280 | + |
| 281 | +case_file_events_generate_template = generate_template_cmd_factory( |
| 282 | + group_name="file_events", |
| 283 | + commands_dict={"add": FILE_EVENTS_HEADERS, "remove": FILE_EVENTS_HEADERS}, |
| 284 | +) |
| 285 | +bulk.add_command(case_file_events_generate_template) |
| 286 | + |
| 287 | + |
| 288 | +@bulk.command( |
| 289 | + name="add", |
| 290 | + help="Bulk associate file events to cases using a CSV file with " |
| 291 | + "format: {}.".format(",".join(FILE_EVENTS_HEADERS)), |
| 292 | +) |
| 293 | +@read_csv_arg(headers=FILE_EVENTS_HEADERS) |
| 294 | +@sdk_options() |
| 295 | +def bulk_add(state, csv_rows): |
| 296 | + sdk = state.sdk |
| 297 | + |
| 298 | + def handle_row(case_number, event_id): |
| 299 | + sdk.cases.file_events.add(case_number, event_id) |
| 300 | + |
| 301 | + run_bulk_process( |
| 302 | + handle_row, csv_rows, progress_label="Associating file events to cases:", |
| 303 | + ) |
| 304 | + |
| 305 | + |
| 306 | +@bulk.command( |
| 307 | + name="remove", |
| 308 | + help="Bulk remove the file event association from cases using a CSV file with " |
| 309 | + "format: {}.".format(",".join(FILE_EVENTS_HEADERS)), |
| 310 | +) |
| 311 | +@read_csv_arg(headers=FILE_EVENTS_HEADERS) |
| 312 | +@sdk_options() |
| 313 | +def bulk_remove(state, csv_rows): |
| 314 | + sdk = state.sdk |
| 315 | + |
| 316 | + def handle_row(case_number, event_id): |
| 317 | + sdk.cases.file_events.delete(case_number, event_id) |
| 318 | + |
| 319 | + run_bulk_process( |
| 320 | + handle_row, |
| 321 | + csv_rows, |
| 322 | + progress_label="Removing the file event association from cases:", |
| 323 | + ) |
0 commit comments