Skip to content

Commit

Permalink
Closes #2596 In legacy datasets, our brand new ORCID validation may c…
Browse files Browse the repository at this point in the history
…reate confusing errors when trying to save a draft after file edit (upload or changes in metadata or licenses)
  • Loading branch information
lbownik committed Dec 5, 2024
1 parent 40f4024 commit 7a09048
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
53 changes: 53 additions & 0 deletions scripts/database/delete_unfixable_orcids.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
-- !!!!!!! run fix_fixable_orcids.sql before this script,
-- !!!!!!! otherwse fixable ORCIDs will be lost
DO $$
DECLARE
ids numeric[];
BEGIN
-- find indetifiers of all dataset fields with supposed ORCID values
-- that don't match ORCIS format
SELECT ARRAY(select id
from datasetfield
where
datasetfieldtype_id in (select id
from datasetfieldtype
where
name = 'authorIdentifier')
and
datasetfieldparent_id in
(select datasetfieldparent_id
from datasetfield
where
id in (select datasetfield_id
from datasetfield_controlledvocabularyvalue
where
controlledvocabularyvalues_id in (select id
from controlledvocabularyvalue
where
strvalue = 'ORCID')))
and fieldvalue !~ '^(\d{4}-){3}\d{3}[\dX]$'
and fieldvalue is not null)
INTO ids;

-- clear all unfixable orcid values
update datasetfield
set
fieldvalue = null
where
id = any(ids);

-- clear indetified schema selections for deleted ORCIDs
delete
from datasetfield_controlledvocabularyvalue
where datasetfield_id in (select id from datasetfield
where
datasetfieldparent_id in (select datasetfieldparent_id
from datasetfield
where
id = any(ids))
and
datasetfieldtype_id in (select id
from datasetfieldtype
where
name = 'authorIdentifierScheme'));
END $$;
41 changes: 41 additions & 0 deletions scripts/database/fix_fixable_orcids.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
-- fixes ORCID values
update datasetfield set fieldvalue = LTRIM(fieldvalue, 'ORCID: ')
where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like 'ORCID: %';
update datasetfield set fieldvalue = LTRIM(fieldvalue, 'ORCID ')
where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like 'ORCID 0%';

update datasetfield set fieldvalue = LTRIM(fieldvalue, 'http://orcid.org/')
where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like 'http://orcid.org/%';
update datasetfield set fieldvalue = LTRIM(fieldvalue, 'https://orcid.org/')
where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like 'https://orcid.org/%';
update datasetfield set fieldvalue = LTRIM(fieldvalue, 'https://orcid.org/ ')
where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like 'https://orcid.org/ %';
update datasetfield set fieldvalue = LTRIM(fieldvalue, 'hhttps://orcid.org/')
where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like 'hhttps://orcid.org/%';
update datasetfield set fieldvalue = LTRIM(fieldvalue, 'Warsaw, Poland https://orcid.org/')
where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like 'Warsaw, Poland https://orcid.org/%';
update datasetfield set fieldvalue = LTRIM(fieldvalue, 'ORCID logo https://orcid.org/')
where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like 'ORCID logo https://orcid.org/%';
update datasetfield set fieldvalue = LTRIM(fieldvalue, 'orcid logo https://orcid.org/')
where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like 'orcid logo https://orcid.org/%';
update datasetfield set fieldvalue = LTRIM(fieldvalue, 'orcid.org/')
where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like 'orcid.org/%';

update datasetfield set fieldvalue = RTRIM(fieldvalue, 'Zbiór')
where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like '%Zbiór';

update datasetfield set fieldvalue = ('0' || fieldvalue)
where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like '000-%';

update datasetfield set fieldvalue = LTRIM(fieldvalue, '/')
where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like '/0000-%';

update datasetfield set fieldvalue = RTRIM(fieldvalue, '.')
where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like '%.';

update datasetfield set fieldvalue = RTRIM(fieldvalue, ',')
where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like '%,';


update datasetfield set fieldvalue = TRIM(fieldvalue)
where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier');

0 comments on commit 7a09048

Please sign in to comment.