From fdac4da9f95d76221cecd6d3967ce44e143a82cd Mon Sep 17 00:00:00 2001 From: Lam Voong Date: Wed, 9 Sep 2026 10:33:46 -0700 Subject: [PATCH 1/2] CSC-2445: Add/update DDL for UCBG findvoucherlabels, voucherlabeltype --- ...blic-findvoucherlabels-nuxeo_botgarden.sql | 19 ++- ...ublic-voucherlabeltype-nuxeo_botgarden.sql | 129 ++++++++++++++++++ 2 files changed, 142 insertions(+), 6 deletions(-) create mode 100644 services/common/src/main/resources/db/postgresql/tenants/ucbg/type-public-voucherlabeltype-nuxeo_botgarden.sql diff --git a/services/common/src/main/resources/db/postgresql/tenants/ucbg/fnc-public-findvoucherlabels-nuxeo_botgarden.sql b/services/common/src/main/resources/db/postgresql/tenants/ucbg/fnc-public-findvoucherlabels-nuxeo_botgarden.sql index 3a5235da44..2ca24a7352 100644 --- a/services/common/src/main/resources/db/postgresql/tenants/ucbg/fnc-public-findvoucherlabels-nuxeo_botgarden.sql +++ b/services/common/src/main/resources/db/postgresql/tenants/ucbg/fnc-public-findvoucherlabels-nuxeo_botgarden.sql @@ -1,8 +1,11 @@ -CREATE OR REPLACE FUNCTION public.findvoucherlabels() - RETURNS SETOF voucherlabeltype - LANGUAGE plpgsql - IMMUTABLE STRICT -AS $function$ +-- +-- Name: findvoucherlabels(); Type: FUNCTION; Schema: public; Owner: nuxeo_botgarden +-- Dependency: voucherlabeltype; Type: TYPE; Schema: public; Owner: nuxeo_botgarden +-- + +CREATE OR REPLACE FUNCTION public.findvoucherlabels() RETURNS SETOF public.voucherlabeltype + LANGUAGE plpgsql IMMUTABLE STRICT + AS $_$ DECLARE sheetcount integer; r voucherlabeltype%rowtype; @@ -98,4 +101,8 @@ AS $function$ RETURN; END; - $function$ + $_$; + + +ALTER FUNCTION public.findvoucherlabels() OWNER TO nuxeo_botgarden; + diff --git a/services/common/src/main/resources/db/postgresql/tenants/ucbg/type-public-voucherlabeltype-nuxeo_botgarden.sql b/services/common/src/main/resources/db/postgresql/tenants/ucbg/type-public-voucherlabeltype-nuxeo_botgarden.sql new file mode 100644 index 0000000000..b6d9c0d34e --- /dev/null +++ b/services/common/src/main/resources/db/postgresql/tenants/ucbg/type-public-voucherlabeltype-nuxeo_botgarden.sql @@ -0,0 +1,129 @@ +-- +-- Name: voucherlabeltype; Type: TYPE; Schema: public; Owner: nuxeo_botgarden +-- + +CREATE TYPE public.voucherlabeltype AS ( + objectnumber character varying, + determinationformatted character varying, + family character varying, + collectioninfo character varying, + vouchernumber character varying, + numbersheets integer, + labelrequested character varying, + gardeninfo character varying, + vouchertype character varying, + fieldcollectionnote character varying, + annotation character varying, + vouchercollectioninfo character varying +); + + +ALTER TYPE public.voucherlabeltype OWNER TO nuxeo_botgarden; + +-- +-- Name: findvoucherlabels(); Type: FUNCTION; Schema: public; Owner: nuxeo_botgarden +-- + +CREATE FUNCTION public.findvoucherlabels() RETURNS SETOF public.voucherlabeltype + LANGUAGE plpgsql IMMUTABLE STRICT + AS $_$ + DECLARE + sheetcount integer; + r voucherlabeltype%rowtype; + n integer; + + BEGIN + + FOR r IN + select co1.objectnumber, + findhybridaffinhtml(tig.id) determinationformatted, + case when (tn.family is not null and tn.family <> '') + then regexp_replace(tn.family, '^.*\)''(.*)''$', '\1') + end as family, + case when fc.item is not null and co1.fieldcollectionnumber is not null and sdg.datedisplaydate is not null + then regexp_replace(fc.item, '^.*\)''(.*)''$', '\1')||' '||co1.fieldcollectionnumber||', '||sdg.datedisplaydate + when fc.item is not null and co1.fieldcollectionnumber is not null and sdg.datedisplaydate is null + then regexp_replace(fc.item, '^.*\)''(.*)''$', '\1')||' '||co1.fieldcollectionnumber||', s.d.' + when fc.item is not null and co1.fieldcollectionnumber is null and sdg.datedisplaydate is not null + then regexp_replace(fc.item, '^.*\)''(.*)''$', '\1')||' s.n., '||sdg.datedisplaydate + when fc.item is not null and co1.fieldcollectionnumber is null and sdg.datedisplaydate is null + then regexp_replace(fc.item, '^.*\)''(.*)''$', '\1')||' s.n., s.d.' + when fc.item is null and co1.fieldcollectionnumber is not null and sdg.datedisplaydate is not null + then co1.fieldcollectionnumber||', '||sdg.datedisplaydate + when fc.item is null and co1.fieldcollectionnumber is not null and sdg.datedisplaydate is null + then co1.fieldcollectionnumber||', s.d.' + when fc.item is null and co1.fieldcollectionnumber is null and sdg.datedisplaydate is not null + then 's.n., '||sdg.datedisplaydate + end as collectioninfo, + lc.loanoutnumber vouchernumber, + lnh.numlent numbersheets, + lb.labelrequested, + case when (lb.gardenlocation is not null and lb.gardenlocation <> '') + then 'Garden No. '||co1.objectnumber||', Bed '||regexp_replace(lb.gardenlocation, '^.*\)''(.*)''$', '\1') + else 'Garden No. '||co1.objectnumber||', Bed unknown' + end as gardeninfo, + case when lb.hortwild='Horticultural' then 'Horticultural voucher:' + when lb.hortwild='Wild' then 'Wild voucher:' + end as vouchertype, + lb.fieldcollectionnote, + lb.annotation, + case when (lbc.item is not null and lbc.item <> '' and lc.loanoutdate is not null) + then regexp_replace(lbc.item, '^.*\)''(.*)''$', '\1')||', '||to_char(date(lc.loanoutdate + interval '8 hours'), 'MM/dd/yyyy') + when (lbc.item is not null and lbc.item <> '' and lc.loanoutdate is null) + then regexp_replace(lbc.item, '^.*\)''(.*)''$', '\1') + when (lbc.item is null and lc.loanoutdate is not null) + then to_char(date(lc.loanoutdate + interval '8 hours'), 'MM/dd/yyyy') + end as vouchercollectioninfo + from loansout_common lc + join loansout_naturalhistory lnh on (lc.id=lnh.id) + join loansout_botgarden lb on (lc.id=lb.id) + left outer join loansout_botgarden_collectorlist lbc on (lbc.id = lc.id and lbc.pos=0) + + join hierarchy h1 on lc.id=h1.id + join relations_common r1 on (h1.name=r1.subjectcsid and objectdocumenttype='CollectionObject') + join hierarchy h2 on (r1.objectcsid=h2.name) + join collectionobjects_common co1 on (co1.id=h2.id) + + left outer join hierarchy htig + on (co1.id = htig.parentid and htig.pos = 0 and htig.name = 'collectionobjects_naturalhistory:taxonomicIdentGroupList') + left outer join taxonomicIdentGroup tig on (tig.id = htig.id) + + join collectionspace_core core on (core.id=co1.id) + join misc misc2 on (misc2.id = co1.id and misc2.lifecyclestate <> 'deleted') + join misc misc1 on (misc1.id = lc.id and misc1.lifecyclestate <> 'deleted') + left outer join taxon_common tc on (tig.taxon=tc.refname) + left outer join taxon_naturalhistory tn on (tc.id=tn.id) + + left outer join hierarchy htt + on (tc.id=htt.parentid and htt.name='taxon_common:taxonTermGroupList' and htt.pos=0) + left outer join taxontermgroup tt on (tt.id=htt.id) + + left outer join collectionobjects_common_fieldCollectors fc on (co1.id = fc.id and fc.pos = 0) + + left outer join hierarchy hfcdg on (co1.id = hfcdg.parentid and hfcdg.name='collectionobjects_common:fieldCollectionDateGroup') + left outer join structureddategroup sdg on (sdg.id = hfcdg.id) + + where lb.labelrequested = 'Yes' + order by objectnumber + + LOOP + + -- return next r; + + sheetcount := r.numbersheets; + + for n in 1..sheetcount loop + + return next r; + + END LOOP; + + END LOOP; + + RETURN; + END; + $_$; + + +ALTER FUNCTION public.findvoucherlabels() OWNER TO nuxeo_botgarden; + From 54b58d10e9862499f8a8191de6218fa737b8cdf0 Mon Sep 17 00:00:00 2001 From: Lam Voong Date: Wed, 9 Sep 2026 10:37:13 -0700 Subject: [PATCH 2/2] CSC-2445: Remove extraneous code from voucherlabeltype DDL --- ...ublic-voucherlabeltype-nuxeo_botgarden.sql | 107 ------------------ 1 file changed, 107 deletions(-) diff --git a/services/common/src/main/resources/db/postgresql/tenants/ucbg/type-public-voucherlabeltype-nuxeo_botgarden.sql b/services/common/src/main/resources/db/postgresql/tenants/ucbg/type-public-voucherlabeltype-nuxeo_botgarden.sql index b6d9c0d34e..1ab3bdb02c 100644 --- a/services/common/src/main/resources/db/postgresql/tenants/ucbg/type-public-voucherlabeltype-nuxeo_botgarden.sql +++ b/services/common/src/main/resources/db/postgresql/tenants/ucbg/type-public-voucherlabeltype-nuxeo_botgarden.sql @@ -20,110 +20,3 @@ CREATE TYPE public.voucherlabeltype AS ( ALTER TYPE public.voucherlabeltype OWNER TO nuxeo_botgarden; --- --- Name: findvoucherlabels(); Type: FUNCTION; Schema: public; Owner: nuxeo_botgarden --- - -CREATE FUNCTION public.findvoucherlabels() RETURNS SETOF public.voucherlabeltype - LANGUAGE plpgsql IMMUTABLE STRICT - AS $_$ - DECLARE - sheetcount integer; - r voucherlabeltype%rowtype; - n integer; - - BEGIN - - FOR r IN - select co1.objectnumber, - findhybridaffinhtml(tig.id) determinationformatted, - case when (tn.family is not null and tn.family <> '') - then regexp_replace(tn.family, '^.*\)''(.*)''$', '\1') - end as family, - case when fc.item is not null and co1.fieldcollectionnumber is not null and sdg.datedisplaydate is not null - then regexp_replace(fc.item, '^.*\)''(.*)''$', '\1')||' '||co1.fieldcollectionnumber||', '||sdg.datedisplaydate - when fc.item is not null and co1.fieldcollectionnumber is not null and sdg.datedisplaydate is null - then regexp_replace(fc.item, '^.*\)''(.*)''$', '\1')||' '||co1.fieldcollectionnumber||', s.d.' - when fc.item is not null and co1.fieldcollectionnumber is null and sdg.datedisplaydate is not null - then regexp_replace(fc.item, '^.*\)''(.*)''$', '\1')||' s.n., '||sdg.datedisplaydate - when fc.item is not null and co1.fieldcollectionnumber is null and sdg.datedisplaydate is null - then regexp_replace(fc.item, '^.*\)''(.*)''$', '\1')||' s.n., s.d.' - when fc.item is null and co1.fieldcollectionnumber is not null and sdg.datedisplaydate is not null - then co1.fieldcollectionnumber||', '||sdg.datedisplaydate - when fc.item is null and co1.fieldcollectionnumber is not null and sdg.datedisplaydate is null - then co1.fieldcollectionnumber||', s.d.' - when fc.item is null and co1.fieldcollectionnumber is null and sdg.datedisplaydate is not null - then 's.n., '||sdg.datedisplaydate - end as collectioninfo, - lc.loanoutnumber vouchernumber, - lnh.numlent numbersheets, - lb.labelrequested, - case when (lb.gardenlocation is not null and lb.gardenlocation <> '') - then 'Garden No. '||co1.objectnumber||', Bed '||regexp_replace(lb.gardenlocation, '^.*\)''(.*)''$', '\1') - else 'Garden No. '||co1.objectnumber||', Bed unknown' - end as gardeninfo, - case when lb.hortwild='Horticultural' then 'Horticultural voucher:' - when lb.hortwild='Wild' then 'Wild voucher:' - end as vouchertype, - lb.fieldcollectionnote, - lb.annotation, - case when (lbc.item is not null and lbc.item <> '' and lc.loanoutdate is not null) - then regexp_replace(lbc.item, '^.*\)''(.*)''$', '\1')||', '||to_char(date(lc.loanoutdate + interval '8 hours'), 'MM/dd/yyyy') - when (lbc.item is not null and lbc.item <> '' and lc.loanoutdate is null) - then regexp_replace(lbc.item, '^.*\)''(.*)''$', '\1') - when (lbc.item is null and lc.loanoutdate is not null) - then to_char(date(lc.loanoutdate + interval '8 hours'), 'MM/dd/yyyy') - end as vouchercollectioninfo - from loansout_common lc - join loansout_naturalhistory lnh on (lc.id=lnh.id) - join loansout_botgarden lb on (lc.id=lb.id) - left outer join loansout_botgarden_collectorlist lbc on (lbc.id = lc.id and lbc.pos=0) - - join hierarchy h1 on lc.id=h1.id - join relations_common r1 on (h1.name=r1.subjectcsid and objectdocumenttype='CollectionObject') - join hierarchy h2 on (r1.objectcsid=h2.name) - join collectionobjects_common co1 on (co1.id=h2.id) - - left outer join hierarchy htig - on (co1.id = htig.parentid and htig.pos = 0 and htig.name = 'collectionobjects_naturalhistory:taxonomicIdentGroupList') - left outer join taxonomicIdentGroup tig on (tig.id = htig.id) - - join collectionspace_core core on (core.id=co1.id) - join misc misc2 on (misc2.id = co1.id and misc2.lifecyclestate <> 'deleted') - join misc misc1 on (misc1.id = lc.id and misc1.lifecyclestate <> 'deleted') - left outer join taxon_common tc on (tig.taxon=tc.refname) - left outer join taxon_naturalhistory tn on (tc.id=tn.id) - - left outer join hierarchy htt - on (tc.id=htt.parentid and htt.name='taxon_common:taxonTermGroupList' and htt.pos=0) - left outer join taxontermgroup tt on (tt.id=htt.id) - - left outer join collectionobjects_common_fieldCollectors fc on (co1.id = fc.id and fc.pos = 0) - - left outer join hierarchy hfcdg on (co1.id = hfcdg.parentid and hfcdg.name='collectionobjects_common:fieldCollectionDateGroup') - left outer join structureddategroup sdg on (sdg.id = hfcdg.id) - - where lb.labelrequested = 'Yes' - order by objectnumber - - LOOP - - -- return next r; - - sheetcount := r.numbersheets; - - for n in 1..sheetcount loop - - return next r; - - END LOOP; - - END LOOP; - - RETURN; - END; - $_$; - - -ALTER FUNCTION public.findvoucherlabels() OWNER TO nuxeo_botgarden; -