Custom Org Tree : DB and IDL
authorBill Erickson <berick@esilibrary.com>
Mon, 19 Mar 2012 20:30:52 +0000 (16:30 -0400)
committerMike Rylander <mrylander@gmail.com>
Mon, 2 Apr 2012 17:39:01 +0000 (13:39 -0400)
Support for building custom org unit hierarchies for display purposes.
Initially, this is meant to support custom OPAC trees, but the design
leaves from for other types of trees.

The only restrictions to custom org trees is that no org unit appear
more once and that they in fact be tree-shaped.  Otherwise, any node
can be the parent/child of any other node, regardless of ou_type, etc.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/examples/fm_IDL.xml
Open-ILS/src/sql/Pg/005.schema.actors.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.org_unit_opac_vis_and_sorting.sql

index c9357ba..10b5837 100644 (file)
@@ -4984,6 +4984,45 @@ SELECT  usr,
             </actions>
         </permacrud>
        </class>
+       <class id="aouct" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="actor::org_unit_custom_tree" oils_persist:tablename="actor.org_unit_custom_tree" reporter:label="Org Unit Custom Tree">
+               <fields oils_persist:primary="id" oils_persist:sequence="actor.org_unit_custom_tree_id_seq">
+                       <field reporter:label="ID" name="id" reporter:datatype="id"/>
+                       <field reporter:label="Active" name="active" reporter:datatype="bool"/>
+                       <field reporter:label="Purpose" name="purpose" reporter:datatype="text"/>
+               </fields>
+               <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+                       <actions>
+                               <create permission="ADMIN_ORG_UNIT_CUSTOM_TREE" global_required="true" />
+                               <retrieve/>
+                               <update permission="ADMIN_ORG_UNIT_CUSTOM_TREE" global_required="true" />
+                               <delete permission="ADMIN_ORG_UNIT_CUSTOM_TREE" global_required="true" />
+                       </actions>
+               </permacrud>
+       </class>
+       <class id="aouctn" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="actor::org_unit_custom_tree_node" oils_persist:tablename="actor.org_unit_custom_tree_node" reporter:label="Org Unit Custom Tree Node">
+               <fields oils_persist:primary="id" oils_persist:sequence="actor.org_unit_custom_tree_node_id_seq">
+                       <field reporter:label="ID" name="id" reporter:datatype="id"/>
+                       <field reporter:label="Tree" name="tree" reporter:datatype="link"/>
+                       <field reporter:label="Org Unit" name="org_unit" reporter:datatype="link"/>
+                       <field reporter:label="Parent" name="parent_node" reporter:datatype="link"/>
+                       <field reporter:label="Sibling Sort Order" name="sibling_order" reporter:datatype="int"/>
+                       <field reporter:label="Children" name="children" reporter:datatype="link" oils_persist:virtual="true" />
+               </fields>
+               <links>
+                       <link field="tree" reltype="has_a" key="id" map="" class="aouct"/>
+                       <link field="org_unit" reltype="has_a" key="id" map="" class="aou"/>
+                       <link field="parent_node" reltype="has_a" key="id" map="" class="aouctn"/>
+                       <link field="children" reltype="has_many" key="parent_node" map="" class="aouctn"/>
+               </links>
+               <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+                       <actions>
+                               <create permission="ADMIN_ORG_UNIT_CUSTOM_TREE" global_required="true" />
+                               <retrieve/>
+                               <update permission="ADMIN_ORG_UNIT_CUSTOM_TREE" global_required="true" />
+                               <delete permission="ADMIN_ORG_UNIT_CUSTOM_TREE" global_required="true" />
+                       </actions>
+               </permacrud>
+       </class>
        <class id="ccnb" controller="open-ils.cstore" oils_obj:fieldmapper="container::call_number_bucket" oils_persist:tablename="container.call_number_bucket" reporter:label="Call Number Bucket">
                <fields oils_persist:primary="id" oils_persist:sequence="container.call_number_bucket_id_seq">
                        <field name="items" oils_persist:virtual="true" reporter:datatype="link"/>
index 4f9f39b..21363b9 100644 (file)
@@ -665,4 +665,20 @@ CREATE UNIQUE INDEX label_once_per_ws ON actor.toolbar (ws, label) WHERE ws IS N
 CREATE UNIQUE INDEX label_once_per_org ON actor.toolbar (org, label) WHERE org IS NOT NULL;
 CREATE UNIQUE INDEX label_once_per_usr ON actor.toolbar (usr, label) WHERE usr IS NOT NULL;
 
+CREATE TYPE actor.org_unit_custom_tree_purpose AS ENUM ('opac');
+CREATE TABLE actor.org_unit_custom_tree (
+    id              SERIAL  PRIMARY KEY,
+    active          BOOLEAN DEFAULT FALSE,
+    purpose         actor.org_unit_custom_tree_purpose NOT NULL DEFAULT 'opac' UNIQUE
+);
+
+CREATE TABLE actor.org_unit_custom_tree_node (
+    id              SERIAL  PRIMARY KEY,
+    tree            INTEGER REFERENCES actor.org_unit_custom_tree (id) DEFERRABLE INITIALLY DEFERRED,
+       org_unit        INTEGER NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
+       parent_node     INTEGER REFERENCES actor.org_unit_custom_tree_node (id) DEFERRABLE INITIALLY DEFERRED,
+    sibling_order   INTEGER NOT NULL DEFAULT 0,
+    CONSTRAINT aouctn_once_per_org UNIQUE (tree, org_unit)
+);
+
 COMMIT;
index 115613a..fd1c002 100644 (file)
@@ -14,11 +14,32 @@ INSERT INTO config.global_flag (name, enabled, label)
         )
     );
 
+CREATE TYPE actor.org_unit_custom_tree_purpose AS ENUM ('opac');
+
+CREATE TABLE actor.org_unit_custom_tree (
+    id              SERIAL  PRIMARY KEY,
+    active          BOOLEAN DEFAULT FALSE,
+    purpose         actor.org_unit_custom_tree_purpose NOT NULL DEFAULT 'opac' UNIQUE
+);
+
+CREATE TABLE actor.org_unit_custom_tree_node (
+    id              SERIAL  PRIMARY KEY,
+    tree            INTEGER REFERENCES actor.org_unit_custom_tree (id) DEFERRABLE INITIALLY DEFERRED,
+       org_unit        INTEGER NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
+       parent_node     INTEGER REFERENCES actor.org_unit_custom_tree_node (id) DEFERRABLE INITIALLY DEFERRED,
+    sibling_order   INTEGER NOT NULL DEFAULT 0,
+    CONSTRAINT aouctn_once_per_org UNIQUE (tree, org_unit)
+);
+    
+
 COMMIT;
 
 /* UNDO
 BEGIN;
 DELETE FROM config.global_flag WHERE name = 'opac.org_unit.non_inheritied_visibility';
+DROP TABLE actor.org_unit_custom_tree_node;
+DROP TABLE actor.org_unit_custom_tree;
+DROP TYPE actor.org_unit_custom_tree_purpose;
 COMMIT;
 */