relationships from relatedIdentifier whose target id type is one of the pid type with an authority

This commit is contained in:
Alessia Bardi 2022-09-23 15:47:05 +02:00
parent ba33ff71fd
commit c5eb722170
3 changed files with 630 additions and 603 deletions

View File

@ -15,6 +15,7 @@ import java.net.URL;
import java.util.*;
import java.util.stream.Collectors;
import eu.dnetlib.dhp.schema.oaf.utils.PidType;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.validator.routines.UrlValidator;
import org.dom4j.*;
@ -68,6 +69,15 @@ public abstract class AbstractMdRecordToOafMapper {
nsContext.put("datacite", DATACITE_SCHEMA_KERNEL_3);
}
protected static final Set<String> pidTypeWithAuthority = new HashSet<>();
static {
pidTypeWithAuthority.addAll(IdentifierFactory.PID_AUTHORITY.keySet().stream()
.map(PidType::toString)
.map(String::toLowerCase)
.collect(Collectors.toCollection(HashSet::new)));
}
protected AbstractMdRecordToOafMapper(final VocabularyGroup vocs, final boolean invisible,
final boolean shouldHashId, final boolean forceOriginalId) {
this.vocs = vocs;

View File

@ -457,10 +457,12 @@ public class OdfToOafMapper extends AbstractMdRecordToOafMapper {
protected String guessRelatedIdentifier(final String idType, final String value) {
if (StringUtils.isBlank(idType) || StringUtils.isBlank(value))
return null;
if (idType.equalsIgnoreCase("OPENAIRE")) {
return createOpenaireId(50, value, false);
} else
if (idType.equalsIgnoreCase("OPENAIRE")) return createOpenaireId(50, value, false);
if(pidTypeWithAuthority.contains(idType.toLowerCase())){
return IdentifierFactory.idFromPid("50", idType, value, true);
}
return null;
}
@Override

View File

@ -933,7 +933,7 @@ class MappersTest {
System.out.println("***************");
System.out.println(new ObjectMapper().writeValueAsString(list));
System.out.println("***************");
assertEquals(3, list.size());
assertEquals(7, list.size());
final OtherResearchProduct p = (OtherResearchProduct) list.get(0);
assertValidId(p.getId());
assertValidId(p.getCollectedfrom().get(0).getKey());
@ -941,6 +941,21 @@ class MappersTest {
assertTrue(StringUtils.isNotBlank(p.getTitle().get(0).getValue()));
assertEquals("w3id", (p.getPid().get(0).getQualifier().getClassid()));
assertEquals("https://w3id.org/ro-id/0ab171a7-45c5-4194-82d4-850955504bca", (p.getPid().get(0).getValue()));
assertEquals(1, list.stream().filter(o -> o instanceof OtherResearchProduct).count());
assertEquals(6, list.stream().filter(o -> o instanceof Relation).count());
for(Oaf oaf : list){
if(oaf instanceof Relation){
String source = ((Relation) oaf).getSource();
String target = ((Relation) oaf).getTarget();
assertNotEquals(source, target);
assertTrue(source.equals(p.getId()) || target.equals(p.getId()));
assertNotNull(((Relation) oaf).getSubRelType());
assertNotNull( ((Relation) oaf).getRelClass());
assertNotNull(((Relation) oaf).getRelType());
}
}
}
@Test