From: Mike Rylander Date: Tue, 16 May 2017 16:49:42 +0000 (-0400) Subject: webstaff: Repair new API for gathering predictions without saving them X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=430225c15ec76348dab20893f3653cc7ee0e65ed;p=working%2FEvergreen.git webstaff: Repair new API for gathering predictions without saving them Signed-off-by: Mike Rylander Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm index d83e191962..179306695e 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm @@ -891,6 +891,21 @@ __PACKAGE__->register_method( } ); +sub make_predictions { + my ($self, $conn, $authtoken, $args) = @_; + + my $ssub_id = $args->{ssub_id}; + + my $editor = OpenILS::Utils::CStoreEditor->new(); + my $ssub = $editor->retrieve_serial_subscription([$ssub_id]); + 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) + ); +} + __PACKAGE__->register_method( method => 'make_prediction_values', api_name => 'open-ils.serial.make_prediction_values', @@ -907,23 +922,9 @@ __PACKAGE__->register_method( } ); -sub make_predictions { - my ($self, $conn, $authtoken, $args) = @_; - - my $ssub_id = $args->{ssub_id}; - - my $editor = OpenILS::Utils::CStoreEditor->new(); - my $ssub = $editor->retrieve_serial_subscription([$ssub_id]); - 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) = @_; + $logger->debug('make_prediction_values with args: ' . OpenSRF::Utils::JSON->perl2JSON($args)); my $ssub_id = $args->{ssub_id}; @@ -981,7 +982,7 @@ sub make_prediction_values { }; my $predict_from_siss; if ($args->{base_issuance}) { # predict from a given issuance - $predict_from_siss = $args->{base_issuance}->holding_code; + $predict_from_siss = $args->{base_issuance}; } else { # default to predicting from last published my $last_published = $editor->search_serial_issuance([ {'caption_and_pattern' => $scap->id, @@ -1006,22 +1007,25 @@ sub make_prediction_values { ); } } + $logger->debug('make_prediction_values reviving holdings: ' . OpenSRF::Utils::JSON->perl2JSON($predict_from_siss)); $options->{predict_from} = _revive_holding($predict_from_siss->holding_code, $caption_field, 1); # fresh MFHD Record, so we simply default to 1 for seqno if ($fake_chron_needed) { $options->{faked_chron_date} = DateTime::Format::ISO8601->new->parse_datetime(cleanse_ISO8601($predict_from_siss->date_published)); } + $logger->debug('make_prediction_values predicting with options: ' . OpenSRF::Utils::JSON->perl2JSON($options)); push( @predictions, _generate_issuance_values($mfhd, $options) ); $link_id++; } - return @predictions; + $logger->debug('make_prediction_values predictions: ' . OpenSRF::Utils::JSON->perl2JSON(\@predictions)); + return \@predictions; } sub store_predictions { - my ($self, $conn, $authtoken, $args, $ssub, $sdists, @predictions) = @_; + my ($self, $conn, $authtoken, $args, $ssub, $sdists, $predictions) = @_; my @issuances; - foreach my $prediction (@predictions) { + foreach my $prediction (@$predictions) { my $issuance = new Fieldmapper::serial::issuance; $issuance->isnew(1); $issuance->label($prediction->{label}); @@ -1038,7 +1042,7 @@ sub store_predictions { my @items; for (my $i = 0; $i < @issuances; $i++) { - my $date_expected = $predictions[$i]->{date_published}->add(seconds => interval_to_seconds($ssub->expected_date_offset))->strftime('%F'); + my $date_expected = $$predictions[$i]->{date_published}->add(seconds => interval_to_seconds($ssub->expected_date_offset))->strftime('%F'); my $issuance = $issuances[$i]; #$issuance->label(interval_to_seconds($ssub->expected_date_offset)); foreach my $sdist (@$sdists) { @@ -1083,6 +1087,7 @@ sub _generate_issuance_values { my $predict_from = $options->{predict_from}; # MFHD::Holding to predict from my $faked_chron_date = $options->{faked_chron_date}; # serial does not have a (complete) chronology caption, so add one (temporarily) based on this date + $logger->debug('_generate_issuance_values predict_from: ' . OpenSRF::Utils::JSON->perl2JSON($predict_from)); # Only needed for 'real' MFHD records, not our temp records # my $link_id = $caption->link_id; @@ -1122,6 +1127,7 @@ sub _generate_issuance_values { # to recreate rather than try to update $faked_caption = new MFHD::Caption($faked_caption); $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); + $logger->debug('_generate_issuance_values fake predict_from: ' . OpenSRF::Utils::JSON->perl2JSON($predict_from)); } my @predictions = $mfhd->generate_predictions({ @@ -1130,6 +1136,7 @@ sub _generate_issuance_values { 'num_to_predict' => $num_to_predict, 'end_date' => $end_date }); + $logger->debug('_generate_issuance_values predictions: ' . OpenSRF::Utils::JSON->perl2JSON(\@predictions)); 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 ba46c31d52..16a6725da9 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD.pm @@ -308,7 +308,7 @@ sub generate_predictions { my @predictions; push(@predictions, $curr_holding) if ($include_base_issuance); - + if ($num_to_predict) { for (my $i = 0; $i < $num_to_predict; $i++) { push(@predictions, $curr_holding->increment->clone);