|
30 | 30 | ProcessContact, |
31 | 31 | ProcessDatasetType, |
32 | 32 | ProcessDependency, |
| 33 | + ProcessFilter, |
33 | 34 | ProcessTracking, |
34 | 35 | ProcessStatus, |
35 | 36 | ProcessSource, |
|
43 | 44 | from process_tracker.models.schedule import ScheduleFrequency |
44 | 45 | from process_tracker.models.source import ( |
45 | 46 | DatasetType, |
| 47 | + FilterType, |
46 | 48 | Source, |
47 | 49 | SourceContact, |
48 | 50 | SourceDatasetType, |
@@ -498,6 +500,124 @@ def find_process_by_schedule_frequency(self, frequency="daily"): |
498 | 500 |
|
499 | 501 | return process_list |
500 | 502 |
|
| 503 | + def find_process_filters(self, process): |
| 504 | + """ |
| 505 | + For the given process, find the filters required for querying the source system. |
| 506 | + :param process: The process' process id. |
| 507 | + :type process: integer |
| 508 | + """ |
| 509 | + |
| 510 | + filter_list = list() |
| 511 | + |
| 512 | + filters = ( |
| 513 | + self.session.query( |
| 514 | + Source.source_name, |
| 515 | + SourceObject.source_object_name, |
| 516 | + SourceObjectAttribute.source_object_attribute_name, |
| 517 | + FilterType.filter_type_code, |
| 518 | + ProcessFilter.filter_value_numeric, |
| 519 | + ProcessFilter.filter_value_string, |
| 520 | + ) |
| 521 | + .join(SourceObjectAttribute, ProcessFilter.attributes) |
| 522 | + .join(SourceObject, SourceObjectAttribute.source_objects) |
| 523 | + .join(Source) |
| 524 | + .join(FilterType) |
| 525 | + .filter(ProcessFilter.process_id == process) |
| 526 | + .orderby( |
| 527 | + Source.source_name, |
| 528 | + SourceObject.source_object_name, |
| 529 | + SourceObjectAttribute.source_object_attribute_name, |
| 530 | + ) |
| 531 | + ) |
| 532 | + |
| 533 | + for filter in filters: |
| 534 | + filter_list.append( |
| 535 | + { |
| 536 | + "source_name": filter.source_name, |
| 537 | + "source_object_name": filter.source_object_name, |
| 538 | + "source_object_attribute_name": filter.source_object_attribute_name, |
| 539 | + "filter_type_code": filter.filter_type_code, |
| 540 | + "filter_value_numeric": filter.filter_value_numeric, |
| 541 | + "filter_value_string": filter.filter_value_string, |
| 542 | + } |
| 543 | + ) |
| 544 | + |
| 545 | + return filter_list |
| 546 | + |
| 547 | + def find_process_source_attributes(self, process): |
| 548 | + """ |
| 549 | + For the given process, find the attributes used for process sources. |
| 550 | + :param process: |
| 551 | + :return: |
| 552 | + """ |
| 553 | + |
| 554 | + source_attribute_list = list() |
| 555 | + |
| 556 | + source_attributes = ( |
| 557 | + self.session.query( |
| 558 | + Source.source_name, |
| 559 | + SourceObject.source_object_name, |
| 560 | + SourceObjectAttribute.source_object_attribute_name, |
| 561 | + ) |
| 562 | + .join(SourceObject, SourceObjectAttribute.source_objects) |
| 563 | + .join(Source, SourceObject.sources) |
| 564 | + .join(ProcessSourceObjectAttribute) |
| 565 | + .filter(ProcessSourceObjectAttribute.process_id == process) |
| 566 | + .order_by( |
| 567 | + Source.source_name, |
| 568 | + SourceObject.source_object_name, |
| 569 | + SourceObjectAttribute.source_object_attribute_name, |
| 570 | + ) |
| 571 | + ) |
| 572 | + |
| 573 | + for attribute in source_attributes: |
| 574 | + source_attribute_list.append( |
| 575 | + { |
| 576 | + "source_name": attribute.source_name, |
| 577 | + "source_object_name": attribute.source_object_name, |
| 578 | + "source_object_attribute_name": attribute.source_object_attribute_name, |
| 579 | + } |
| 580 | + ) |
| 581 | + |
| 582 | + return source_attribute_list |
| 583 | + |
| 584 | + def find_process_target_attributes(self, process): |
| 585 | + """ |
| 586 | + For the given process, find the attributes used for process targets. |
| 587 | + :param process: |
| 588 | + :return: |
| 589 | + """ |
| 590 | + |
| 591 | + target_attribute_list = list() |
| 592 | + |
| 593 | + source_attributes = ( |
| 594 | + self.session.query( |
| 595 | + Source.source_name, |
| 596 | + SourceObject.source_object_name, |
| 597 | + SourceObjectAttribute.source_object_attribute_name, |
| 598 | + ) |
| 599 | + .join(SourceObject, SourceObjectAttribute.source_objects) |
| 600 | + .join(Source, SourceObject.sources) |
| 601 | + .join(ProcessTargetObjectAttribute) |
| 602 | + .filter(ProcessTargetObjectAttribute.process_id == process) |
| 603 | + .order_by( |
| 604 | + Source.source_name, |
| 605 | + SourceObject.source_object_name, |
| 606 | + SourceObjectAttribute.source_object_attribute_name, |
| 607 | + ) |
| 608 | + ) |
| 609 | + |
| 610 | + for attribute in source_attributes: |
| 611 | + target_attribute_list.append( |
| 612 | + { |
| 613 | + "target_name": attribute.source_name, |
| 614 | + "target_object_name": attribute.source_object_name, |
| 615 | + "target_object_attribute_name": attribute.source_object_attribute_name, |
| 616 | + } |
| 617 | + ) |
| 618 | + |
| 619 | + return target_attribute_list |
| 620 | + |
501 | 621 | def get_latest_tracking_record(self, process): |
502 | 622 | """ |
503 | 623 | For the given process, find the latest tracking record. |
|
0 commit comments