From a410f131f2f277aea8bdff759de836b2ae0fdd09 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 24 Sep 2015 17:18:19 -0400 Subject: [PATCH] JBAS-886 classroom cards generation / BSD CSV Accounts are loaded via CVS the same as student accounts. CSV for the BSD acccounst included. They are slightly different from student accounts: * expire date now() + 10 years. * different alert message * different profile, ident_type, ident_value Signed-off-by: Bill Erickson --- .../classroom_cards/405.classroom-cards.csv | 51 ++++++++++++++++++++ .../import_students/generate-patrons-from-csv.pl | 54 +++++++++++++++------- 2 files changed, 89 insertions(+), 16 deletions(-) create mode 100644 KCLS/utility-scripts/import_students/classroom_cards/405.classroom-cards.csv diff --git a/KCLS/utility-scripts/import_students/classroom_cards/405.classroom-cards.csv b/KCLS/utility-scripts/import_students/classroom_cards/405.classroom-cards.csv new file mode 100644 index 0000000000..52c26c7c0e --- /dev/null +++ b/KCLS/utility-scripts/import_students/classroom_cards/405.classroom-cards.csv @@ -0,0 +1,51 @@ +action,student_id,active,first_given_name,family_name,day_phone,address_type,street1,street2,city,county,state,post_code +C,0000,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0001,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0002,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0003,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0004,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0005,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0006,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0007,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0008,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0009,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0010,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0011,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0012,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0013,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0014,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0015,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0016,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0017,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0018,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0019,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0020,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0021,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0022,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0023,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0024,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0025,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0026,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0027,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0028,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0029,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0030,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0031,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0032,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0033,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0034,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0035,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0036,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0037,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0038,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0039,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0040,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0041,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0042,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0043,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0044,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0045,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0046,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0047,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0048,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 +C,0049,true,Bellevue,High,,,10416 Wolverine Way,,Bellevue,,WA,98004 diff --git a/KCLS/utility-scripts/import_students/generate-patrons-from-csv.pl b/KCLS/utility-scripts/import_students/generate-patrons-from-csv.pl index 8330b7e5f2..e252972e37 100755 --- a/KCLS/utility-scripts/import_students/generate-patrons-from-csv.pl +++ b/KCLS/utility-scripts/import_students/generate-patrons-from-csv.pl @@ -13,10 +13,14 @@ use Sys::Syslog qw(syslog openlog); my $syslog_facility = 'LOCAL6'; # matches Evergreen gateway my $syslog_ops = 'pid'; my $profile = 901; # "Student Ecard" +my $c_profile = 902; # "Classroom Databases" my $net_access = 101; # No Access my $ident_type = 101; # "Sch-district file" ident type +my $c_ident_type = 3; # ident type "Other" +my $c_ident_value = "KCLS generated"; my $syslog_ident = 'ECARD'; my $alert_msg = 'Student Ecard: No physical checkouts. No computer/printing. No laptops.'; +my $c_alert_msg = 'Classroom use only: No physical checkouts. No computer/printing. No laptops.'; my $alert_type = 20; # "Alerting note, no Blocks" standing penalty my $root_org = 1; # KCLS org unit for penalty application my $db_handle; @@ -50,6 +54,7 @@ my $district_code; # 3-char school district code my $default_pass; my $commit_mode = 'rollback'; # single xact, then rollback (for testing) my $assume_new = 0; +my $is_classroom = 0; my $purge_all = 0; my $out_dir = '.'; my $log_stdout = 0; # copy logs to stdout @@ -68,6 +73,7 @@ GetOptions( 'assume-new' => \$assume_new, 'purge-all' => \$purge_all, 'default-pass=s' => \$default_pass, + 'classroom' => \$is_classroom, 'log-stdout' => \$log_stdout, 'out-dir=s' => \$out_dir, 'db-user=s' => \$db_user, @@ -275,9 +281,17 @@ SQL # expire date is set to July 1 after the patron's 18th birthday. sub set_expire_date { my $phash = shift; + my $now_date = DateTime->now; + my $now_year = $now_date->year; + + if ($is_classroom) { + # classroom cards expire after 10 years. + $now_date->set_year($now_year + 10); + $phash->{expire_date} = $now_date; + return; + } my ($year, $mon, $day) = ($phash->{dob} =~ /(\d{4})-(\d{2})-(\d{2})/); - my $now_year = DateTime->now->year; my $expire_year = $now_year + (18 - ($now_year - $year)); # Invalid DoB's can lead to expire_date's far in the future. @@ -296,7 +310,7 @@ sub set_expire_date { } # Fills in gaps and massages data in the CSV hash. -# Returns 1 on successful translation, undef on error. +# Returns 1 on successful translation, undef on error.qw/student_id first_given_name family_name dob/) { sub translate_patron_data { my $phash = shift; my $barcode = $phash->{barcode}; @@ -326,22 +340,28 @@ sub translate_patron_fields { $phash->{$_} =~ s/(^\s*|\s*$)//g if $phash->{$_}; } + my @required = qw/student_id first_given_name family_name/; + push (@required, 'dob') unless $is_classroom; + # check required fields - for my $field (qw/student_id first_given_name family_name dob/) { + for my $field (@required) { push(@errors, "No data present for required field $field") unless $phash->{$field}; } - if ($phash->{dob} =~ m|\d{1,2}/\d{1,2}/\d{4}|) { - # dob is encoded in American-style month/day/year - # Translate it to ISO8601 - my ($mon, $day, $year) = - $phash->{dob} =~ m|(\d{1,2})/(\d{1,2})/(\d{4})|; - $phash->{dob} = sprintf("%s-%02d-%02d", $year, $mon, $day); - } + if (!$is_classroom) { # classroom cards have no DoB - push(@errors, "Invalid dob") - unless $phash->{dob} =~ m/^\d{4}-\d{2}-\d{2}$/; + if ($phash->{dob} =~ m|\d{1,2}/\d{1,2}/\d{4}|) { + # dob is encoded in American-style month/day/year + # Translate it to ISO8601 + my ($mon, $day, $year) = + $phash->{dob} =~ m|(\d{1,2})/(\d{1,2})/(\d{4})|; + $phash->{dob} = sprintf("%s-%02d-%02d", $year, $mon, $day); + } + + push(@errors, "Invalid dob") + unless $phash->{dob} =~ m/^\d{4}-\d{2}-\d{2}$/; + } if (my $dp = $phash->{day_phone}) { @@ -571,10 +591,12 @@ sub create_patron { my $barcode = $phash->{barcode}; my @user_bind = ( - 't', $profile, $ident_type, $barcode, - $home_ou, $net_access, + 't', + $is_classroom ? $c_profile : $profile, + $is_classroom ? $c_ident_type : $ident_type, + $barcode, $home_ou, $net_access, $phash->{passwd}, - $phash->{student_id}, + $is_classroom ? $c_ident_value : $phash->{student_id}, $phash->{first_given_name}, $phash->{second_given_name}, $phash->{family_name}, @@ -599,7 +621,7 @@ sub create_patron { my @alrt_bind = ( $root_org, $alert_type, - $alert_msg + $is_classroom ? $c_alert_msg : $alert_msg ); return unless handle_insert($phash, $create_user_sth, \@user_bind); -- 2.11.0