1 package OpenILS::Application::Acq::EDI;
2 use base qw/OpenILS::Application/;
4 use strict; use warnings;
6 use OpenSRF::AppSession;
7 use OpenSRF::EX qw/:try/;
8 use OpenILS::Application::Acq::EDI::Translator;
11 use OpenSRF::Utils::Logger qw(:logger);
12 # use OpenSRF::Utils::JSON;
13 # use OpenILS::Utils::Fieldmapper;
14 # use OpenILS::Utils::CStoreEditor q/:funcs/;
15 # use OpenILS::Const qw/:const/;
16 # use OpenILS::Application::AppUtils;
19 my($class, %args) = @_;
20 my $self = bless(\%args, $class);
28 return $translator ||= OpenILS::Application::Acq::EDI::Translator->new(@_);
31 __PACKAGE__->register_method(
33 api_name => 'open-ils.acq.edi.retrieve',
35 desc => 'Fetch incoming message(s) from EDI accounts. ' .
36 'Optional arguments to restrict to one vendor and/or a max number of messages. ' .
37 'Note that messages are not parsed or processed here, just fetched and translated.',
39 {desc => 'Authentication token', type => 'string'},
40 {desc => 'Vendor ID (undef for "all")', type => 'number'},
41 {desc => 'Max Messages Retrieved', type => 'number'}
44 desc => 'List of new message IDs (empty if none)',
51 my ($self, $conn, $auth, $vendor_id, $max) = @_;
54 my $e = new_editor(xact=>1, authtoken=>$auth);
55 unless ($e->checkauth) {
56 $logger->warn("checkauth failed for authtoken '$auth'");
61 $criteria->{vendor_id} = $vendor_id if $vendor_id;
62 my $set = $e->search_acq_edi_account(
68 ) or return $e->die_event;
70 my $tran = translator();
71 foreach my $account (@$set) {
72 $logger->warn("EDI check for " . $account->host);
74 # my $incoming = $e->create_acq_edi_message;
75 # $incoming->edi($content);
76 # $incoming->edi_account($account->id);
77 # my $json = $tran->edi2json;
79 # $logger->error("EDI Translator failed on $incoming->id");
82 # $incoming->json($json);
84 # delete remote copies of saved message (?)
85 # push @return, $incoming->id;
88 # return $e->die_event unless $e->allowed('RECEIVE_PURCHASE_ORDER', $li->purchase_order->ordering_agency);
95 my $account = shift or return;
100 my $account = shift or return;