|
17 | 17 | import com.mindee.pdf.PdfOperation; |
18 | 18 | import com.mindee.pdf.SplitQuery; |
19 | 19 | import com.mindee.product.custom.CustomV1; |
| 20 | +import com.mindee.product.generated.GeneratedV1; |
20 | 21 | import java.io.IOException; |
21 | 22 | import java.net.URL; |
22 | 23 |
|
@@ -312,7 +313,7 @@ private <T extends Inference> AsyncPredictResponse<T> enqueueAndParse( |
312 | 313 | Thread.sleep(initialDelaySec); |
313 | 314 |
|
314 | 315 | while (retryCount < pollingOptions.getMaxRetries()) { |
315 | | - parseResponse = parseQueued(type, jobId); |
| 316 | + parseResponse = this.mindeeApi.documentQueueGet(type, endpoint, jobId); |
316 | 317 | if (parseResponse.getDocument().isPresent()) { |
317 | 318 | return parseResponse; |
318 | 319 | } |
@@ -490,6 +491,280 @@ private PredictResponse<CustomV1> parse( |
490 | 491 | .build()); |
491 | 492 | } |
492 | 493 |
|
| 494 | + /** |
| 495 | + * Send a local file to a Generated prediction async API queue. |
| 496 | + */ |
| 497 | + public <T extends GeneratedV1> AsyncPredictResponse<T> enqueue( |
| 498 | + Class<T> type, |
| 499 | + Endpoint endpoint, |
| 500 | + LocalInputSource localInputSource |
| 501 | + ) throws IOException { |
| 502 | + return this.enqueue( |
| 503 | + type, |
| 504 | + endpoint, |
| 505 | + localInputSource.getFile(), |
| 506 | + localInputSource.getFilename(), |
| 507 | + null, |
| 508 | + null |
| 509 | + ); |
| 510 | + } |
| 511 | + |
| 512 | + /** |
| 513 | + * Send a local file to a Generated prediction async API queue. |
| 514 | + */ |
| 515 | + public <T extends GeneratedV1> AsyncPredictResponse<T> enqueue( |
| 516 | + Class<T> type, |
| 517 | + Endpoint endpoint, |
| 518 | + LocalInputSource localInputSource, |
| 519 | + PredictOptions predictOptions, |
| 520 | + PageOptions pageOptions |
| 521 | + ) throws IOException { |
| 522 | + return this.enqueue( |
| 523 | + type, |
| 524 | + endpoint, |
| 525 | + getSplitFile(localInputSource, pageOptions), |
| 526 | + localInputSource.getFilename(), |
| 527 | + predictOptions, |
| 528 | + null |
| 529 | + ); |
| 530 | + } |
| 531 | + |
| 532 | + /** |
| 533 | + * Send a remote file to a Generated prediction async API queue. |
| 534 | + */ |
| 535 | + public <T extends GeneratedV1> AsyncPredictResponse<T> enqueue( |
| 536 | + Class<T> type, |
| 537 | + Endpoint endpoint, |
| 538 | + URL sourceUrl |
| 539 | + ) throws IOException { |
| 540 | + InputSourceUtils.validateUrl(sourceUrl); |
| 541 | + return this.enqueue( |
| 542 | + type, |
| 543 | + endpoint, |
| 544 | + null, |
| 545 | + null, |
| 546 | + null, |
| 547 | + sourceUrl |
| 548 | + ); |
| 549 | + } |
| 550 | + |
| 551 | + /** |
| 552 | + * Send a remote file to a Generated prediction async API queue. |
| 553 | + */ |
| 554 | + public <T extends GeneratedV1> AsyncPredictResponse<T> enqueue( |
| 555 | + Class<T> type, |
| 556 | + Endpoint endpoint, |
| 557 | + URL sourceUrl, |
| 558 | + PredictOptions predictOptions |
| 559 | + ) throws IOException { |
| 560 | + InputSourceUtils.validateUrl(sourceUrl); |
| 561 | + return this.enqueue( |
| 562 | + type, |
| 563 | + endpoint, |
| 564 | + null, |
| 565 | + null, |
| 566 | + predictOptions, |
| 567 | + sourceUrl |
| 568 | + ); |
| 569 | + } |
| 570 | + |
| 571 | + |
| 572 | + /** |
| 573 | + * Send a local file to a Generated prediction API async queue, poll, and parse when complete. |
| 574 | + */ |
| 575 | + public <T extends GeneratedV1> AsyncPredictResponse<T> enqueueAndParse( |
| 576 | + Class<T> type, |
| 577 | + Endpoint endpoint, |
| 578 | + LocalInputSource localInputSource |
| 579 | + ) throws IOException, InterruptedException { |
| 580 | + return this.enqueueAndParse( |
| 581 | + type, |
| 582 | + endpoint, |
| 583 | + null, |
| 584 | + localInputSource.getFile(), |
| 585 | + localInputSource.getFilename(), |
| 586 | + null, |
| 587 | + null); |
| 588 | + } |
| 589 | + |
| 590 | + /** |
| 591 | + * Send a local file to a Generated prediction API async queue, poll, and parse when complete. |
| 592 | + */ |
| 593 | + public <T extends GeneratedV1> AsyncPredictResponse<T> enqueueAndParse( |
| 594 | + Class<T> type, |
| 595 | + Endpoint endpoint, |
| 596 | + LocalInputSource localInputSource, |
| 597 | + AsyncPollingOptions pollingOptions |
| 598 | + ) throws IOException, InterruptedException { |
| 599 | + return this.enqueueAndParse( |
| 600 | + type, |
| 601 | + endpoint, |
| 602 | + pollingOptions, |
| 603 | + localInputSource.getFile(), |
| 604 | + localInputSource.getFilename(), |
| 605 | + null, |
| 606 | + null |
| 607 | + ); |
| 608 | + } |
| 609 | + |
| 610 | + /** |
| 611 | + * Send a local file to a Generated prediction API async queue, poll, and parse when complete. |
| 612 | + */ |
| 613 | + public <T extends GeneratedV1> AsyncPredictResponse<T> enqueueAndParse( |
| 614 | + Class<T> type, |
| 615 | + Endpoint endpoint, |
| 616 | + LocalInputSource localInputSource, |
| 617 | + PredictOptions predictOptions, |
| 618 | + PageOptions pageOptions, |
| 619 | + AsyncPollingOptions pollingOptions |
| 620 | + ) throws IOException, InterruptedException { |
| 621 | + return this.enqueueAndParse( |
| 622 | + type, |
| 623 | + endpoint, |
| 624 | + pollingOptions, |
| 625 | + getSplitFile(localInputSource, pageOptions), |
| 626 | + localInputSource.getFilename(), |
| 627 | + predictOptions, |
| 628 | + null |
| 629 | + ); |
| 630 | + } |
| 631 | + |
| 632 | + /** |
| 633 | + * Send a remote file to a Generated prediction API async queue, poll, and parse when complete. |
| 634 | + */ |
| 635 | + public <T extends GeneratedV1> AsyncPredictResponse<T> enqueueAndParse( |
| 636 | + Class<T> type, |
| 637 | + Endpoint endpoint, |
| 638 | + URL sourceUrl |
| 639 | + ) throws IOException, InterruptedException { |
| 640 | + InputSourceUtils.validateUrl(sourceUrl); |
| 641 | + return this.enqueueAndParse( |
| 642 | + type, |
| 643 | + endpoint, |
| 644 | + null, |
| 645 | + null, |
| 646 | + null, |
| 647 | + null, |
| 648 | + sourceUrl |
| 649 | + ); |
| 650 | + } |
| 651 | + |
| 652 | + /** |
| 653 | + * Send a local file to a Generated prediction API and parse the results. |
| 654 | + */ |
| 655 | + public <T extends GeneratedV1> PredictResponse<T> parse( |
| 656 | + Class<T> type, |
| 657 | + Endpoint endpoint, |
| 658 | + LocalInputSource localInputSource |
| 659 | + ) throws IOException { |
| 660 | + return this.parse( |
| 661 | + type, |
| 662 | + endpoint, |
| 663 | + localInputSource.getFile(), |
| 664 | + localInputSource.getFilename(), |
| 665 | + null, |
| 666 | + null |
| 667 | + ); |
| 668 | + } |
| 669 | + |
| 670 | + /** |
| 671 | + * Send a local file to a Generated prediction API and parse the results. |
| 672 | + */ |
| 673 | + public <T extends GeneratedV1> PredictResponse<T> parse( |
| 674 | + Class<T> type, |
| 675 | + Endpoint endpoint, |
| 676 | + LocalInputSource localInputSource, |
| 677 | + PredictOptions predictOptions |
| 678 | + ) throws IOException { |
| 679 | + return this.parse( |
| 680 | + type, |
| 681 | + endpoint, |
| 682 | + localInputSource.getFile(), |
| 683 | + localInputSource.getFilename(), |
| 684 | + predictOptions, |
| 685 | + null |
| 686 | + ); |
| 687 | + } |
| 688 | + |
| 689 | + /** |
| 690 | + * Send a local file to a Generated prediction API and parse the results. |
| 691 | + */ |
| 692 | + public <T extends GeneratedV1> PredictResponse<T> parse( |
| 693 | + Class<T> type, |
| 694 | + Endpoint endpoint, |
| 695 | + LocalInputSource localInputSource, |
| 696 | + PageOptions pageOptions |
| 697 | + ) throws IOException { |
| 698 | + return this.parse( |
| 699 | + type, |
| 700 | + endpoint, |
| 701 | + getSplitFile(localInputSource, pageOptions), |
| 702 | + localInputSource.getFilename(), |
| 703 | + null, |
| 704 | + null |
| 705 | + ); |
| 706 | + } |
| 707 | + |
| 708 | + /** |
| 709 | + * Send a local file to a Standard prediction API and parse the results. |
| 710 | + */ |
| 711 | + public <T extends GeneratedV1> PredictResponse<T> parse( |
| 712 | + Class<T> type, |
| 713 | + Endpoint endpoint, |
| 714 | + LocalInputSource localInputSource, |
| 715 | + PredictOptions predictOptions, |
| 716 | + PageOptions pageOptions |
| 717 | + ) throws IOException { |
| 718 | + return this.parse( |
| 719 | + type, |
| 720 | + endpoint, |
| 721 | + getSplitFile(localInputSource, pageOptions), |
| 722 | + localInputSource.getFilename(), |
| 723 | + predictOptions, |
| 724 | + null |
| 725 | + ); |
| 726 | + } |
| 727 | + |
| 728 | + /** |
| 729 | + * Send a remote file to a Generated prediction API and parse the results. |
| 730 | + */ |
| 731 | + public <T extends GeneratedV1> PredictResponse<T> parse( |
| 732 | + Class<T> type, |
| 733 | + Endpoint endpoint, |
| 734 | + URL documentUrl |
| 735 | + ) throws IOException { |
| 736 | + InputSourceUtils.validateUrl(documentUrl); |
| 737 | + return this.parse(type, endpoint, null, null, null, documentUrl); |
| 738 | + } |
| 739 | + |
| 740 | + /** |
| 741 | + * Send a remote file to a Generated prediction API and parse the results. |
| 742 | + */ |
| 743 | + public <T extends GeneratedV1> PredictResponse<T> parse( |
| 744 | + Class<T> type, |
| 745 | + Endpoint endpoint, |
| 746 | + URL documentUrl, |
| 747 | + PredictOptions predictOptions |
| 748 | + ) throws IOException { |
| 749 | + InputSourceUtils.validateUrl(documentUrl); |
| 750 | + return this.parse(type, endpoint, null, null, predictOptions, documentUrl); |
| 751 | + } |
| 752 | + |
| 753 | + /** |
| 754 | + * Parse a document from a Generated prediction API async queue. |
| 755 | + */ |
| 756 | + public <T extends GeneratedV1> AsyncPredictResponse<T> parseQueued( |
| 757 | + Class<T> type, |
| 758 | + Endpoint endpoint, |
| 759 | + String jobId |
| 760 | + ) { |
| 761 | + return this.mindeeApi.documentQueueGet( |
| 762 | + type, |
| 763 | + endpoint, |
| 764 | + jobId |
| 765 | + ); |
| 766 | + } |
| 767 | + |
493 | 768 | /** |
494 | 769 | * Load a local prediction. |
495 | 770 | * Typically used when wanting to load from a webhook callback. |
|
0 commit comments