Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add OL identifier case sensitive and RRID regex validator #6965

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package org.orcid.core.utils.v3.identifiers.normalizers;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;

import com.google.common.collect.Lists;

@Component
public class CurieNormalizer implements Normalizer {
public class CurieNormalizer implements NormalizerWithURLTransform {

private static final List<String> canHandle = Lists.newArrayList("rrid");
private static final Pattern pattern = Pattern.compile("(?:(?i)RRID:)?(AB_\\d{6}|CVCL_[0-9A-Z]{4}|SCR_\\d{6}|IMSR_JAX\\:\\d{6}|Addgene_\\d{5}|SAMN\\d{8}|MMRRC_\\d{6}-UCD)");

@Override
public List<String> canHandle() {
Expand All @@ -19,16 +22,29 @@ public List<String> canHandle() {

@Override
public String normalise(String apiTypeName, String value) {
if (!canHandle.contains(apiTypeName))
return value;
if (!value.startsWith(apiTypeName.toUpperCase() + ":"))
return apiTypeName.toUpperCase() + ":" + value;
return value;
return curieIdentifier(apiTypeName, value);
}

@Override
public int getOrder() {
return Ordered.LOWEST_PRECEDENCE;
}

@Override
public String normaliseURL(String apiTypeName, String value) {
return curieIdentifier(apiTypeName, value);
}

private String curieIdentifier(String apiTypeName, String value) {
if (!canHandle.contains(apiTypeName))
return value;
Matcher m = pattern.matcher(value);
if (m.find()){
String n = m.group(1);
if (n != null){
return "RRID:"+n;
}
}
return "";
}
}
1 change: 1 addition & 0 deletions orcid-persistence/src/main/resources/db-master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -380,4 +380,5 @@
<include file="/db/updates/dw_alter_event.xml" />
<include file="/db/updates/dw_alter_event_2.xml" />
<include file="/db/updates/grant_select_to_dw_user_on_dw_event.xml" />
<include file="/db/updates/identifier-types/update-ol-to-be-case-sensitive.xml" />
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">

<changeSet id="UPDATE-ETHOS-TO-BE-CASE-SENSITIVE" author="Daniel Palafox">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="1">select count(*) from identifier_type WHERE id_name = 'OL';</sqlCheck>
</preConditions>
<sql>UPDATE identifier_type SET "case_sensitive" = true WHERE id_name = 'OL';</sql>
</changeSet>

</databaseChangeLog>