FF r361 and also minor bugfixes
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Wed, 5 Dec 2012 17:42:31 +0000 (12:42 -0500)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Wed, 5 Dec 2012 17:42:31 +0000 (12:42 -0500)
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/examples/fm_IDL.xml
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/asset.pm
Open-ILS/src/sql/Pg/090.schema.action.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.org_prox_adjust.sql

index efa3896..50db1da 100644 (file)
@@ -4836,7 +4836,7 @@ SELECT  usr,
                        <link field="hold_pickup_lib" reltype="has_a" key="id" map="" class="aou"/>
                        <link field="hold_request_lib" reltype="has_a" key="id" map="" class="aou"/>
                        <link field="circ_mod" reltype="has_a" key="code" map="" class="ccm"/>
-                       <link field="copy_location" reltype="has_a" key="id" map="" class="acqpl"/>
+                       <link field="copy_location" reltype="has_a" key="id" map="" class="acpl"/>
                </links>
         <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
             <actions>
index bd6116f..b4e3fbd 100644 (file)
@@ -402,18 +402,24 @@ sub copy_proximity {
        return unless ($cp && $org);
 
        if ($hold) {
-          return action::hold_request->db_Main->selectrow_hashref(
+               my $row = action::hold_request->db_Main->selectrow_hashref(
                        'SELECT proximity AS prox FROM action.hold_copy_map WHERE hold = ? and target_copy = ?',
                        {},
                        "$hold",
                        "$cp"
-               )->{prox} || action::hold_request->db_Main->selectrow_hashref(
+               );
+               return $row->{prox} if $row;
+
+               $log->debug("Calculating copy proximity with: action.hold_copy_calculated_proximity($hold,$cp,$org)", DEBUG);
+               $row = action::hold_request->db_Main->selectrow_hashref(
                        'SELECT action.hold_copy_calculated_proximity(?,?,?) AS prox',
                        {},
                        "$hold",
                        "$cp",
                        "$org"
-               )->{prox};
+               );
+
+               return $row->{prox} if $row;
        }
 
        $cp = asset::copy->retrieve($cp) unless (ref($cp));
index 55eccb4..902f99c 100644 (file)
@@ -452,6 +452,7 @@ CREATE TABLE action.hold_copy_map (
        id              BIGSERIAL       PRIMARY KEY,
        hold            INT     NOT NULL REFERENCES action.hold_request (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
        target_copy     BIGINT  NOT NULL, -- REFERENCES asset.copy (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, -- XXX could be an serial.issuance
+       proximity       NUMERIC,
        CONSTRAINT copy_once_per_hold UNIQUE (hold,target_copy)
 );
 -- CREATE INDEX acm_hold_idx ON action.hold_copy_map (hold);
@@ -995,16 +996,16 @@ BEGIN
     SELECT * INTO acl FROM asset.copy_location WHERE id = acp.location;
 
     -- First, gather the baseline proximity of "here" to pickup lib
-    SELECT prox INTO baseline_prox FROM actor.org_unit_proximity WHERE from_org = context_ou AND to_org = ahr.pickup_lib;
+    SELECT prox INTO baseline_prox FROM actor.org_unit_proximity WHERE from_org = acp.circ_lib AND to_org = ahr.pickup_lib;
 
     -- Find any absolute adjustments, and set the baseline prox to that
     SELECT  adj.* INTO aoupa
       FROM  actor.org_unit_proximity_adjustment adj
-            LEFT JOIN actor.org_unit_anscestors_distance(acp.circ_lib) acp_cl ON (acp_cl.id = adj.item_circ_lib)
-            LEFT JOIN actor.org_unit_anscestors_distance(acn.owning_lib) acn_ol ON (acn_ol.id = adj.item_owning_lib)
-            LEFT JOIN actor.org_unit_anscestors_distance(acl.owning_lib) acl_ol ON (acn_ol.id = adj.copy_location)
-            LEFT JOIN actor.org_unit_anscestors_distance(ahr.pickup_lib) ahr_pl ON (ahr_pl.id = adj.hold_pickup_lib)
-            LEFT JOIN actor.org_unit_anscestors_distance(ahr.request_lib) ahr_rl ON (ahr_rl.id = adj.hold_request_lib)
+            LEFT JOIN actor.org_unit_ancestors_distance(acp.circ_lib) acp_cl ON (acp_cl.id = adj.item_circ_lib)
+            LEFT JOIN actor.org_unit_ancestors_distance(acn.owning_lib) acn_ol ON (acn_ol.id = adj.item_owning_lib)
+            LEFT JOIN actor.org_unit_ancestors_distance(acl.owning_lib) acl_ol ON (acn_ol.id = adj.copy_location)
+            LEFT JOIN actor.org_unit_ancestors_distance(ahr.pickup_lib) ahr_pl ON (ahr_pl.id = adj.hold_pickup_lib)
+            LEFT JOIN actor.org_unit_ancestors_distance(ahr.request_lib) ahr_rl ON (ahr_rl.id = adj.hold_request_lib)
       WHERE (adj.circ_mod IS NULL OR adj.circ_mod = acp.circ_modifier) AND absolute_adjustment
       ORDER BY
             COALESCE(acp_cl.distance,999)
@@ -1023,11 +1024,11 @@ BEGIN
     FOR aoupa IN
         SELECT  adj.* 
           FROM  actor.org_unit_proximity_adjustment adj
-                LEFT JOIN actor.org_unit_anscestors_distance(acp.circ_lib) acp_cl ON (acp_cl.id = adj.item_circ_lib)
-                LEFT JOIN actor.org_unit_anscestors_distance(acn.owning_lib) acn_ol ON (acn_ol.id = adj.item_owning_lib)
-                LEFT JOIN actor.org_unit_anscestors_distance(acl.owning_lib) acl_ol ON (acn_ol.id = adj.copy_location)
-                LEFT JOIN actor.org_unit_anscestors_distance(ahr.pickup_lib) ahr_pl ON (ahr_pl.id = adj.hold_pickup_lib)
-                LEFT JOIN actor.org_unit_anscestors_distance(ahr.request_lib) ahr_rl ON (ahr_rl.id = adj.hold_request_lib)
+                LEFT JOIN actor.org_unit_ancestors_distance(acp.circ_lib) acp_cl ON (acp_cl.id = adj.item_circ_lib)
+                LEFT JOIN actor.org_unit_ancestors_distance(acn.owning_lib) acn_ol ON (acn_ol.id = adj.item_owning_lib)
+                LEFT JOIN actor.org_unit_ancestors_distance(acl.owning_lib) acl_ol ON (acn_ol.id = adj.copy_location)
+                LEFT JOIN actor.org_unit_ancestors_distance(ahr.pickup_lib) ahr_pl ON (ahr_pl.id = adj.hold_pickup_lib)
+                LEFT JOIN actor.org_unit_ancestors_distance(ahr.request_lib) ahr_rl ON (ahr_rl.id = adj.hold_request_lib)
           WHERE (adj.circ_mod IS NULL OR adj.circ_mod = acp.circ_modifier) AND NOT absolute_adjustment
     LOOP
         baseline_prox := baseline_prox + aoupa.prox_adjustment;
index da02094..b5bac94 100644 (file)
@@ -55,16 +55,16 @@ BEGIN
     SELECT * INTO acl FROM asset.copy_location WHERE id = acp.location;
 
     -- First, gather the baseline proximity of "here" to pickup lib
-    SELECT prox INTO baseline_prox FROM actor.org_unit_proximity WHERE from_org = context_ou AND to_org = ahr.pickup_lib;
+    SELECT prox INTO baseline_prox FROM actor.org_unit_proximity WHERE from_org = acp.circ_lib AND to_org = ahr.pickup_lib;
 
     -- Find any absolute adjustments, and set the baseline prox to that
     SELECT  adj.* INTO aoupa
       FROM  actor.org_unit_proximity_adjustment adj
-            LEFT JOIN actor.org_unit_anscestors_distance(acp.circ_lib) acp_cl ON (acp_cl.id = adj.item_circ_lib)
-            LEFT JOIN actor.org_unit_anscestors_distance(acn.owning_lib) acn_ol ON (acn_ol.id = adj.item_owning_lib)
-            LEFT JOIN actor.org_unit_anscestors_distance(acl.owning_lib) acl_ol ON (acn_ol.id = adj.copy_location)
-            LEFT JOIN actor.org_unit_anscestors_distance(ahr.pickup_lib) ahr_pl ON (ahr_pl.id = adj.hold_pickup_lib)
-            LEFT JOIN actor.org_unit_anscestors_distance(ahr.request_lib) ahr_rl ON (ahr_rl.id = adj.hold_request_lib)
+            LEFT JOIN actor.org_unit_ancestors_distance(acp.circ_lib) acp_cl ON (acp_cl.id = adj.item_circ_lib)
+            LEFT JOIN actor.org_unit_ancestors_distance(acn.owning_lib) acn_ol ON (acn_ol.id = adj.item_owning_lib)
+            LEFT JOIN actor.org_unit_ancestors_distance(acl.owning_lib) acl_ol ON (acn_ol.id = adj.copy_location)
+            LEFT JOIN actor.org_unit_ancestors_distance(ahr.pickup_lib) ahr_pl ON (ahr_pl.id = adj.hold_pickup_lib)
+            LEFT JOIN actor.org_unit_ancestors_distance(ahr.request_lib) ahr_rl ON (ahr_rl.id = adj.hold_request_lib)
       WHERE (adj.circ_mod IS NULL OR adj.circ_mod = acp.circ_modifier) AND absolute_adjustment
       ORDER BY
             COALESCE(acp_cl.distance,999)
@@ -83,11 +83,11 @@ BEGIN
     FOR aoupa IN
         SELECT  adj.* 
           FROM  actor.org_unit_proximity_adjustment adj
-                LEFT JOIN actor.org_unit_anscestors_distance(acp.circ_lib) acp_cl ON (acp_cl.id = adj.item_circ_lib)
-                LEFT JOIN actor.org_unit_anscestors_distance(acn.owning_lib) acn_ol ON (acn_ol.id = adj.item_owning_lib)
-                LEFT JOIN actor.org_unit_anscestors_distance(acl.owning_lib) acl_ol ON (acn_ol.id = adj.copy_location)
-                LEFT JOIN actor.org_unit_anscestors_distance(ahr.pickup_lib) ahr_pl ON (ahr_pl.id = adj.hold_pickup_lib)
-                LEFT JOIN actor.org_unit_anscestors_distance(ahr.request_lib) ahr_rl ON (ahr_rl.id = adj.hold_request_lib)
+                LEFT JOIN actor.org_unit_ancestors_distance(acp.circ_lib) acp_cl ON (acp_cl.id = adj.item_circ_lib)
+                LEFT JOIN actor.org_unit_ancestors_distance(acn.owning_lib) acn_ol ON (acn_ol.id = adj.item_owning_lib)
+                LEFT JOIN actor.org_unit_ancestors_distance(acl.owning_lib) acl_ol ON (acn_ol.id = adj.copy_location)
+                LEFT JOIN actor.org_unit_ancestors_distance(ahr.pickup_lib) ahr_pl ON (ahr_pl.id = adj.hold_pickup_lib)
+                LEFT JOIN actor.org_unit_ancestors_distance(ahr.request_lib) ahr_rl ON (ahr_rl.id = adj.hold_request_lib)
           WHERE (adj.circ_mod IS NULL OR adj.circ_mod = acp.circ_modifier) AND NOT absolute_adjustment
     LOOP
         baseline_prox := baseline_prox + aoupa.prox_adjustment;
@@ -102,4 +102,6 @@ ALTER TABLE actor.org_unit_proximity_adjustment
     FOREIGN KEY (circ_mod) REFERENCES config.circ_modifier (code)
     DEFERRABLE INITIALLY DEFERRED;
 
+ALTER TABLE action.hold_copy_map ADD COLUMN proximity NUMERIC;
+
 COMMIT;