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
#2605)

Closes #2596 In legacy datasets, our brand new ORCID validation may create confusing errors when trying to save a draft after file edit (upload or changes in metadata or licenses)

---------

Co-authored-by: lbownik <[email protected]>
  • Loading branch information
lbownik and lbownik authored Dec 10, 2024
1 parent 3268227 commit 363170c
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
52 changes: 52 additions & 0 deletions scripts/database/delete_unfixable_orcids.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-- !!!!!!! 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 controlledvocabularyvalue.id
from controlledvocabularyvalue join datasetfieldtype ON controlledvocabularyvalue.datasetfieldtype_id = datasetfieldtype.id
where controlledvocabularyvalue.strvalue = 'ORCID' and datasetfieldtype.name = 'authorIdentifierScheme')))
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 363170c

Please sign in to comment.