From a061b167aff149927c8c44d5a0c2e9481d1d8335 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Mon, 15 May 2017 16:27:47 -0400 Subject: [PATCH] webstaff: Teach serials perl to predict for "current" issue, not just future Signed-off-by: Mike Rylander Signed-off-by: Galen Charlton --- .../src/perlmods/lib/OpenILS/Application/Serial.pm | 53 ++++++++++++++++++++-- Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD.pm | 3 ++ 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm index 75f915ab0c..d83e191962 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm @@ -891,17 +891,49 @@ __PACKAGE__->register_method( } ); +__PACKAGE__->register_method( + method => 'make_prediction_values', + api_name => 'open-ils.serial.make_prediction_values', + api_level => 1, + argc => 1, + signature => { + desc => 'Receives an ssub id and returns objects that can be used to populate the issuance and item tables', + 'params' => [ { + name => 'ssub_id', + desc => 'Serial Subscription ID', + type => 'int' + } + ] + } +); + sub make_predictions { my ($self, $conn, $authtoken, $args) = @_; - my $editor = OpenILS::Utils::CStoreEditor->new(); my $ssub_id = $args->{ssub_id}; - my $mfhd = MFHD->new(MARC::Record->new()); + my $editor = OpenILS::Utils::CStoreEditor->new(); my $ssub = $editor->retrieve_serial_subscription([$ssub_id]); - my $scaps = $editor->search_serial_caption_and_pattern({ subscription => $ssub_id, active => 't'}); my $sdists = $editor->search_serial_distribution( [{ subscription => $ssub->id }, { flesh => 1, flesh_fields => {sdist => [ qw/ streams / ]} }] ); #TODO: 'deleted' support? + return store_predictions( + $self, $conn, $authtoken, $args, $ssub, $sdists, + make_prediction_values($self, $conn, $authtoken, $args, $ssub, $sdists, $editor) + ); +} + +sub make_prediction_values { + my ($self, $conn, $authtoken, $args, $ssub, $sdists, $editor) = @_; + + my $ssub_id = $args->{ssub_id}; + + $editor ||= OpenILS::Utils::CStoreEditor->new(); + $ssub ||= $editor->retrieve_serial_subscription([$ssub_id]); + $sdists ||= $editor->search_serial_distribution( [{ subscription => $ssub->id }, { flesh => 1, flesh_fields => {sdist => [ qw/ streams / ]} }] ); #TODO: 'deleted' support? + + my $scaps = $editor->search_serial_caption_and_pattern({ subscription => $ssub_id, active => 't'}); + my $mfhd = MFHD->new(MARC::Record->new()); + my $total_streams = 0; foreach (@$sdists) { $total_streams += scalar(@{$_->streams}); @@ -942,6 +974,7 @@ sub make_predictions { my $options = { 'caption' => $caption_field, 'scap_id' => $scap->id, + 'include_base_issuance' => $args->{include_base_issuance}, 'num_to_predict' => $args->{num_to_predict}, 'end_date' => defined $args->{end_date} ? $_strp_date->parse_datetime($args->{end_date}) : undef @@ -981,6 +1014,12 @@ sub make_predictions { $link_id++; } + return @predictions; +} + +sub store_predictions { + my ($self, $conn, $authtoken, $args, $ssub, $sdists, @predictions) = @_; + my @issuances; foreach my $prediction (@predictions) { my $issuance = new Fieldmapper::serial::issuance; @@ -1038,6 +1077,7 @@ sub _generate_issuance_values { my ($mfhd, $options) = @_; my $caption = $options->{caption}; my $scap_id = $options->{scap_id}; + my $include_base_issuance = $options->{include_base_issuance}; my $num_to_predict = $options->{num_to_predict}; my $end_date = $options->{end_date}; my $predict_from = $options->{predict_from}; # MFHD::Holding to predict from @@ -1084,7 +1124,12 @@ sub _generate_issuance_values { $predict_from = new MFHD::Holding($predict_from->seqno, new MARC::Field($predict_from->tag, $predict_from->indicator(1), $predict_from->indicator(2), $predict_from->subfields_list), $faked_caption); } - my @predictions = $mfhd->generate_predictions({'base_holding' => $predict_from, 'num_to_predict' => $num_to_predict, 'end_date' => $end_date}); + my @predictions = $mfhd->generate_predictions({ + 'include_base_issuance' => $include_base_issuance, + 'base_holding' => $predict_from, + 'num_to_predict' => $num_to_predict, + 'end_date' => $end_date + }); my $pub_date; my @issuance_values; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD.pm b/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD.pm index 03975cf176..ba46c31d52 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD.pm @@ -273,6 +273,7 @@ sub _holding_date { # generate_predictions() # Accepts a hash ref of options initially defined as: # base_holding : reference to the holding field to predict from +# include_base_issuance : whether to "predict" the startting holding, so as to generate a label for it # num_to_predict : the number of issues you wish to predict # OR # end_holding : holding field ref, keep predicting until you meet or exceed it @@ -293,6 +294,7 @@ sub generate_predictions { my $end_holding = $options->{end_holding}; my $end_date = $options->{end_date}; my $max_to_predict = $options->{max_to_predict} || 10000; # fail-safe + my $include_base_issuance = $options->{include_base_issuance}; if (!defined($base_holding)) { carp("Base holding not defined in generate_predictions, returning empty set"); @@ -305,6 +307,7 @@ sub generate_predictions { my $curr_holding = $base_holding->clone; # prevent side-effects my @predictions; + push(@predictions, $curr_holding) if ($include_base_issuance); if ($num_to_predict) { for (my $i = 0; $i < $num_to_predict; $i++) { -- 2.11.0