]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/support-scripts/test-scripts/notes.pl
a518662c8ae927c7b3c7135eb75a79799db8288d
[Evergreen.git] / Open-ILS / src / support-scripts / test-scripts / notes.pl
1 #!/usr/bin/perl
2 require '../oils_header.pl';
3 use vars qw/ $user $authtoken /;
4 use strict; use warnings;
5 use Time::HiRes qw/time/;
6 use Data::Dumper;
7 use JSON;
8
9 #-----------------------------------------------------------------------------
10 # Does a checkout, renew, and checkin 
11 #-----------------------------------------------------------------------------
12
13 err("usage: $0 <config> <username> <password> <patronid> <title> <text>") unless $ARGV[5];
14
15 my $config              = shift; # - bootstrap config
16 my $username    = shift; # - oils login username
17 my $password    = shift; # - oils login password
18 my $patronid    = shift;
19 my $title               = shift;
20 my $text                        = shift;
21
22
23 sub go {
24         osrf_connect($config);
25         oils_login($username, $password);
26         create_note();
27         retrieve_notes();
28         delete_notes();
29         oils_logout();
30 }
31 go();
32
33
34
35 #-----------------------------------------------------------------------------
36
37 #-----------------------------------------------------------------------------
38 my @created_ids;
39 sub create_note {
40
41         for(0..9) {
42                 my $note = Fieldmapper::actor::usr_note->new;
43         
44                 $note->usr($patronid);
45                 $note->title($title);
46                 $note->value($text);
47                 $note->pub(0);
48         
49                 my $id = simplereq(
50                         'open-ils.actor', 
51                         'open-ils.actor.note.create', $authtoken, $note );
52         
53                 oils_event_die($id);
54                 printl("created new note $id");
55                 push(@created_ids, $id);
56         }
57
58         return 1;
59 }
60
61 sub retrieve_notes {
62
63         my $notes = simplereq(
64                 'open-ils.actor',
65                 'open-ils.actor.note.retrieve.all', $authtoken, 
66                 { patronid => $patronid} );
67
68         oils_event_die($notes);
69
70         for my $n (@$notes) {
71                 printl("received note:");
72                 printl("\t". $n->creator);
73                 printl("\t". $n->usr);
74                 printl("\t". $n->title);
75                 printl("\t". $n->value);
76         }
77 }
78
79 sub delete_notes {
80         for(@created_ids) {
81                 my $stat = simplereq(
82                         'open-ils.actor', 
83                         'open-ils.actor.note.delete', $authtoken, $_);
84                 oils_event_die($stat);
85                 printl("deleted note $_");
86         }
87 }
88