<link field="item" reltype="has_a" key="id" map="" class="ccbi"/>
</links>
</class>
+
+ <class id="acs" controller="open-ils.cstore" oils_obj:fieldmapper="authority::control_set" oils_persist:tablename="authority.control_set" reporter:label="Authority Control Set">
+ <fields oils_persist:primary="id" oils_persist:sequence="authority.contol_set_id_seq">
+ <field reporter:label="Control Set ID" name="id" reporter:datatype="id" reporter:selector="name"/>
+ <field reporter:label="Name" name="name" reporter:datatype="text" oils_persist:i18n="true" oils_obj:required="true" />
+ <field reporter:label="Description" name="description" reporter:datatype="text" oils_persist:i18n="true" />
+ <field reporter:label="Controlling Authority Fields" name="authority_fields" reporter:datatype="link" oils_persist:virtual="true"/>
+ </fields>
+ <links>
+ <link field="authority_fields" reltype="has_many" key="control_set" map="" class="acsaf"/>
+ </links>
+ <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+ <actions>
+ <create permission="CREATE_AUTHORITY_CONTROLSET" global_required="true"/>
+ <retrieve/>
+ <update permission="UPDATE_AUTHORITY_CONTROLSET" global_required="true"/>
+ <delete permission="DELETE_AUTHORITY_CONTROLSET" global_required="true"/>
+ </actions>
+ </permacrud>
+ </class>
+
+ <class id="acsaf" controller="open-ils.cstore" oils_obj:fieldmapper="authority::control_set_authority_field" oils_persist:tablename="authority.control_set_authority_field" reporter:label="Authority Control Set Authority Field">
+ <fields oils_persist:primary="id" oils_persist:sequence="authority.contol_set_authority_field_id_seq">
+ <field reporter:label="Control Set Authority Field ID" name="id" reporter:datatype="id" reporter:selector="name"/>
+ <field reporter:label="Control Set" name="control_set" reporter:datatype="link"/>
+ <field reporter:label="Tag" name="tag" reporter:datatype="text" oils_obj:required="true" oils_obj:validate="^.{3}$"/>
+ <field reporter:label="Name" name="name" reporter:datatype="text" oils_persist:i18n="true" oils_obj:required="true" />
+ <field reporter:label="Description" name="description" reporter:datatype="text" oils_persist:i18n="true" />
+ <field reporter:label="Controlled Bib Fields" name="bib_fields" reporter:datatype="link" oils_persist:virtual="true"/>
+ <field reporter:label="Thesauri" name="thesauri" reporter:datatype="link" oils_persist:virtual="true"/>
+ </fields>
+ <links>
+ <link field="control_set" reltype="has_a" key="id" map="" class="acs"/>
+ <link field="bib_fields" reltype="has_many" key="authority_field" map="" class="acsbf"/>
+ <link field="thesauri" reltype="has_many" key="control_set" map="" class="at"/>
+ </links>
+ <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+ <actions>
+ <create permission="CREATE_AUTHORITY_CONTROLSET" global_required="true"/>
+ <retrieve/>
+ <update permission="UPDATE_AUTHORITY_CONTROLSET" global_required="true"/>
+ <delete permission="UPDATE_AUTHORITY_CONTROLSET" global_required="true"/>
+ </actions>
+ </permacrud>
+ </class>
+
+ <class id="acsbf" controller="open-ils.cstore" oils_obj:fieldmapper="authority::control_set_bib_field" oils_persist:tablename="authority.control_set_bib_field" reporter:label="Authority Control Set Bib Field">
+ <fields oils_persist:primary="id" oils_persist:sequence="authority.contol_set_bib_field_id_seq">
+ <field reporter:label="Controlled Bib Field ID" name="id" reporter:datatype="id" reporter:selector="name"/>
+ <field reporter:label="Controlling Authority Field" name="authority_field" reporter:datatype="link"/>
+ <field reporter:label="Tag" name="tag" reporter:datatype="text" oils_obj:required="true" oils_obj:validate="^.{3}$"/>
+ <field reporter:label="Name" name="name" reporter:datatype="text" oils_persist:i18n="true" oils_obj:required="true" />
+ <field reporter:label="Description" name="description" reporter:datatype="text" oils_persist:i18n="true" />
+ </fields>
+ <links>
+ <link field="authority_field" reltype="has_a" key="id" map="" class="acsaf"/>
+ </links>
+ <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+ <actions>
+ <create permission="CREATE_AUTHORITY_CONTROLSET" global_required="true"/>
+ <retrieve/>
+ <update permission="UPDATE_AUTHORITY_CONTROLSET" global_required="true"/>
+ <delete permission="UPDATE_AUTHORITY_CONTROLSET" global_required="true"/>
+ </actions>
+ </permacrud>
+ </class>
+
+ <class id="at" controller="open-ils.cstore" oils_obj:fieldmapper="authority::thesaurus" oils_persist:tablename="authority.thesaurus" reporter:label="Authority Thesaurus">
+ <fields oils_persist:primary="code">
+ <field reporter:label="Thesaurus Code" name="code" reporter:datatype="id" reporter:selector="name"/>
+ <field reporter:label="Control Set" name="control_set" reporter:datatype="link"/>
+ <field reporter:label="Name" name="name" reporter:datatype="text" oils_persist:i18n="true" oils_obj:required="true" />
+ <field reporter:label="Description" name="description" reporter:datatype="text" oils_persist:i18n="true" />
+ </fields>
+ <links>
+ <link field="control_set" reltype="has_a" key="id" map="" class="acs"/>
+ </links>
+ <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+ <actions>
+ <create permission="CREATE_AUTHORITY_CONTROLSET" global_required="true"/>
+ <retrieve/>
+ <update permission="UPDATE_AUTHORITY_CONTROLSET" global_required="true"/>
+ <delete permission="UPDATE_AUTHORITY_CONTROLSET" global_required="true"/>
+ </actions>
+ </permacrud>
+ </class>
+
<class id="are" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="authority::record_entry" oils_persist:tablename="authority.record_entry" reporter:label="Authority Record Entry">
<fields oils_persist:primary="id" oils_persist:sequence="authority.record_entry_id_seq">
<field name="active" reporter:datatype="bool"/>
<field name="last_xact_id" />
<field name="marc" />
<field name="source" />
+ <field reporter:label="Control Set" name="control_set" reporter:datatype="link"/>
<field reporter:label="Owner" name="owner" reporter:datatype="org_unit"/>
<field name="fixed_fields" oils_persist:virtual="true" reporter:datatype="link"/>
<field name="notes" oils_persist:virtual="true" reporter:datatype="link"/>
<field name="bib_links" oils_persist:virtual="true" reporter:datatype="link"/>
</fields>
<links>
+ <link field="control_set" reltype="has_a" key="id" map="" class="acs"/>
<link field="owner" reltype="has_a" key="id" map="" class="aou"/>
<link field="editor" reltype="has_a" key="id" map="" class="au"/>
<link field="creator" reltype="has_a" key="id" map="" class="au"/>
<field name="id" />
<field name="record" />
<field name="record_status" />
+ <field name="thesaurus" />
</fields>
<links>
<link field="record" reltype="has_a" key="id" map="" class="are"/>
+ <link field="thesaurus" reltype="might_have" key="code" map="" class="at"/>
</links>
</class>
<class id="abl" controller="open-ils.cstore" oils_obj:fieldmapper="authority::bib_linking" oils_persist:tablename="authority.bib_linking" reporter:label="Authority-Bibliographic Record Link">
SELECT authority.propagate_changes( authority, bib ) FROM authority.bib_linking WHERE authority = $1;
$func$ LANGUAGE SQL;
--- authority.rec_descriptor appears to be unused currently
+CREATE OR REPLACE FUNCTION authority.flatten_marc ( TEXT ) RETURNS SETOF authority.full_rec AS $func$
+
+use MARC::Record;
+use MARC::File::XML (BinaryEncoding => 'UTF-8');
+
+my $xml = shift;
+my $r = MARC::Record->new_from_xml( $xml );
+
+return_next( { tag => 'LDR', value => $r->leader } );
+
+for my $f ( $r->fields ) {
+ if ($f->is_control_field) {
+ return_next({ tag => $f->tag, value => $f->data });
+ } else {
+ for my $s ($f->subfields) {
+ return_next({
+ tag => $f->tag,
+ ind1 => $f->indicator(1),
+ ind2 => $f->indicator(2),
+ subfield => $s->[0],
+ value => $s->[1]
+ });
+
+ }
+ }
+}
+
+return undef;
+
+$func$ LANGUAGE PLPERLU;
+
+CREATE OR REPLACE FUNCTION authority.flatten_marc ( rid BIGINT ) RETURNS SETOF authority.full_rec AS $func$
+DECLARE
+ auth authority.record_entry%ROWTYPE;
+ output authority.full_rec%ROWTYPE;
+ field RECORD;
+BEGIN
+ SELECT INTO auth * FROM authority.record_entry WHERE id = rid;
+
+ FOR field IN SELECT * FROM authority.flatten_marc( auth.marc ) LOOP
+ output.record := rid;
+ output.ind1 := field.ind1;
+ output.ind2 := field.ind2;
+ output.tag := field.tag;
+ output.subfield := field.subfield;
+ IF field.subfield IS NOT NULL THEN
+ output.value := naco_normalize(field.value, field.subfield);
+ ELSE
+ output.value := field.value;
+ END IF;
+
+ CONTINUE WHEN output.value IS NULL;
+
+ RETURN NEXT output;
+ END LOOP;
+END;
+$func$ LANGUAGE PLPGSQL;
+
+-- authority.rec_descriptor appears to be unused currently XXX
CREATE OR REPLACE FUNCTION authority.reingest_authority_rec_descriptor( auth_id BIGINT ) RETURNS VOID AS $func$
BEGIN
DELETE FROM authority.rec_descriptor WHERE record = auth_id;
--- INSERT INTO authority.rec_descriptor (record, record_status, char_encoding)
+-- INSERT INTO authority.rec_descriptor (record, record_status, char_encoding, thesaurus)
-- SELECT auth_id, ;
RETURN;