PostgreSQL Trigger - make harvested/uploaded metadata records editable in Geoportal
By default, metadata records that are harvested into the Geoportal are not editable. This includes any records in the Geoportal that were not created explicitly with interface provided by the web application ("Use dedicated editor to create metadata manually"). The SQL below creates a database trigger that allows harvested records to be edited.
Be aware that there is the potential for a lossy data translation when you do this. The harvested record is completely rewritten using the schema definitions that your Geoportal implements. If the original harvested record has any data that is not included in your schema implementation, that data will be lost after the original is edited. Another way to put that is, if you edit a harvested record, the edited version will only contain information that you see in the editor interface. If the original started with anything else in it, that will be lost.
-- Function: geoportal."SetMethodToEditor"() -- DROP FUNCTION geoportal."SetMethodToEditor"(); CREATE OR REPLACE FUNCTION geoportal."SetMethodToEditor"() RETURNS trigger AS $BODY$BEGIN -- UPDATE gpt_resource SET pubmethod = 'editor' WHERE docuuid = NEW.docuuid; NEW.pubmethod := 'editor'; RETURN NEW; END;$BODY$ LANGUAGE plpgsql VOLATILE COST 100; ALTER FUNCTION geoportal."SetMethodToEditor"() OWNER TO postgres;
-- Trigger: SetImportsToEditor on geoportal.gpt_resource -- DROP TRIGGER "SetImportsToEditor" ON geoportal.gpt_resource; CREATE TRIGGER "SetImportsToEditor" BEFORE INSERT OR UPDATE ON geoportal.gpt_resource FOR EACH ROW EXECUTE PROCEDURE geoportal."SetMethodToEditor"();
Note: This is valid for a database where the geoportal tables are in a schema called "geoportal". Adjust as neccessary.