]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Acq/EDI.pm
Patch from Joe Atzberger that does several things:
[working/Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Acq / EDI.pm
1 package OpenILS::Application::Acq::EDI;
2 use base qw/OpenILS::Application/;
3
4 use strict; use warnings;
5
6 use OpenSRF::AppSession;
7 use OpenSRF::EX qw/:try/;
8 use OpenILS::Application::Acq::EDI::Translator;
9
10 # use OpenILS::Event;
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;
17
18 sub new {
19     my($class, %args) = @_;
20     my $self = bless(\%args, $class);
21     # $self->{args} = {};
22     return $self;
23 }
24
25 our $translator;
26
27 sub translator {
28     return $translator ||= OpenILS::Application::Acq::EDI::Translator->new(@_);
29 }
30
31 __PACKAGE__->register_method(
32         method    => 'retrieve',
33         api_name  => 'open-ils.acq.edi.retrieve',
34         signature => {
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.',
38         param => [
39             {desc => 'Authentication token',        type => 'string'},
40             {desc => 'Vendor ID (undef for "all")', type => 'number'},
41             {desc => 'Max Messages Retrieved',      type => 'number'}
42         ],
43         return => {
44             desc => 'List of new message IDs (empty if none)',
45             type => 'array'
46         }
47     }
48 );
49
50 sub retrieve {
51     my ($self, $conn, $auth, $vendor_id, $max) = @_;
52
53     my @return = ();
54     my $e = new_editor(xact=>1, authtoken=>$auth);
55     unless ($e->checkauth) {
56         $logger->warn("checkauth failed for authtoken '$auth'");
57         return @return;
58     }
59
60     my $criteria = {};
61     $criteria->{vendor_id} = $vendor_id if $vendor_id;
62     my $set = $e->search_acq_edi_account(
63         $criteria, {
64             flesh => 1,
65             flesh_fields => {
66             }
67         }
68     ) or return $e->die_event;
69
70     my $tran = translator();
71     foreach my $account (@$set) {
72         $logger->warn("EDI check for " . $account->host);
73 # foreach message {
74 #       my $incoming = $e->create_acq_edi_message;
75 #       $incoming->edi($content);
76 #       $incoming->edi_account($account->id);
77 #       my $json = $tran->edi2json;
78 #       unless ($json) {
79 #           $logger->error("EDI Translator failed on $incoming->id");
80 #           next;
81 #       }
82 #       $incoming->json($json);
83 #       $e->commit;
84 #       delete remote copies of saved message (?)
85 #       push @return, $incoming->id;
86 # }
87     }
88     # return $e->die_event unless $e->allowed('RECEIVE_PURCHASE_ORDER', $li->purchase_order->ordering_agency);
89     # $e->commit;
90     return @return;
91 }
92
93 sub record_activity {
94     my $self = shift;
95     my $account = shift or return;
96 }
97
98 sub retrieve_one {
99     my $self = shift;
100     my $account = shift or return;
101
102 }
103
104 1;
105