pid types

This commit is contained in:
Michele Artini 2021-04-29 09:50:05 +02:00
parent 7c5cd86927
commit f77ba34126
6 changed files with 34 additions and 131 deletions

View File

@ -11,9 +11,11 @@ import static eu.dnetlib.dhp.schema.oaf.utils.OafMapperUtils.structuredProperty;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
@ -33,6 +35,7 @@ import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.dhp.actionmanager.project.SparkAtomicActionJob;
import eu.dnetlib.dhp.actionmanager.ror.model.ExternalIdType;
import eu.dnetlib.dhp.actionmanager.ror.model.RorOrganization;
import eu.dnetlib.dhp.application.ArgumentApplicationParser;
import eu.dnetlib.dhp.common.HdfsSupport;
@ -59,11 +62,6 @@ public class GenerateRorActionSetJob {
private static final DataInfo ROR_DATA_INFO = dataInfo(false, "", false, false, ENTITYREGISTRY_PROVENANCE_ACTION, "0.92");
private static final Qualifier ROR_PID_TYPE = qualifier("ROR", "ROR", "dnet:pid_types", "dnet:pid_types");
private static final Qualifier GRID_PID_TYPE = qualifier("GRID", "GRID", "dnet:pid_types", "dnet:pid_types");
private static final Qualifier WIKIDATA_PID_TYPE = qualifier("Wikidata", "Wikidata", "dnet:pid_types", "dnet:pid_types");
private static final Qualifier ORGREF_PID_TYPE = qualifier("OrgRef", "OrgRef", "dnet:pid_types", "dnet:pid_types");
private static final Qualifier ISNI_PID_TYPE = qualifier("ISNI", "ISNI", "dnet:pid_types", "dnet:pid_types");
private static final Qualifier FUNDREF_PID_TYPE = qualifier("FundRef", "FundRef", "dnet:pid_types", "dnet:pid_types");
public static void main(final String[] args) throws Exception {
@ -157,21 +155,28 @@ public class GenerateRorActionSetJob {
private static List<StructuredProperty> pids(final RorOrganization r) {
final List<StructuredProperty> pids = new ArrayList<>();
pids.add(structuredProperty(r.getId(), ROR_PID_TYPE, ROR_DATA_INFO));
pids.add(structuredProperty(r.getExternalIds().getGrid().getAll(), GRID_PID_TYPE, ROR_DATA_INFO));
pids.addAll(pids(r.getExternalIds().getFundRef().getAll(), FUNDREF_PID_TYPE));
pids.addAll(pids(r.getExternalIds().getIsni().getAll(), ISNI_PID_TYPE));
pids.addAll(pids(r.getExternalIds().getOrgRef().getAll(), ORGREF_PID_TYPE));
pids.addAll(pids(r.getExternalIds().getWikidata().getAll(), WIKIDATA_PID_TYPE));
return pids;
for (final Map.Entry<String, ExternalIdType> e : r.getExternalIds().entrySet()) {
final String type = e.getKey();
final Object all = e.getValue().getAll();
if (all == null) {
// skip
} else if (all instanceof String) {
pids.add(structuredProperty(all.toString(), qualifier(type, type, "dnet:pid_types", "dnet:pid_types"), ROR_DATA_INFO));
} else if (all instanceof Collection) {
for (final Object pid : (Collection<?>) all) {
pids.add(structuredProperty(pid.toString(), qualifier(type, type, "dnet:pid_types", "dnet:pid_types"), ROR_DATA_INFO));
}
} else if (all instanceof String[]) {
for (final String pid : (String[]) all) {
pids.add(structuredProperty(pid, qualifier(type, type, "dnet:pid_types", "dnet:pid_types"), ROR_DATA_INFO));
}
} else {
log.warn("Invalid type for pid list: " + all.getClass());
}
}
private static List<StructuredProperty> pids(final List<String> list, final Qualifier pidType) {
if (list == null) { return new ArrayList<>(); }
return list.stream()
.filter(StringUtils::isNotBlank)
.distinct()
.map(s -> structuredProperty(s, pidType, ROR_DATA_INFO))
.collect(Collectors.toList());
return pids;
}
private static List<Field<String>> alternativeNames(final RorOrganization r) {

View File

@ -2,26 +2,24 @@
package eu.dnetlib.dhp.actionmanager.ror.model;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
public class ExternalIdType implements Serializable {
@JsonProperty("all")
private List<String> all = new ArrayList<>();
private Object all;
@JsonProperty("preferred")
private String preferred;
private final static long serialVersionUID = 2616688352998387611L;
public List<String> getAll() {
public Object getAll() {
return all;
}
public void setAll(final List<String> all) {
public void setAll(final Object all) {
this.all = all;
}

View File

@ -1,67 +0,0 @@
package eu.dnetlib.dhp.actionmanager.ror.model;
import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonProperty;
public class ExternalIds implements Serializable {
@JsonProperty("Wikidata")
private ExternalIdType wikidata;
@JsonProperty("OrgRef")
private ExternalIdType orgRef;
@JsonProperty("ISNI")
private ExternalIdType isni;
@JsonProperty("FundRef")
private ExternalIdType fundRef;
@JsonProperty("GRID")
private GridType grid;
private final static long serialVersionUID = 686536347353680869L;
public ExternalIdType getWikidata() {
return wikidata;
}
public void setWikidata(final ExternalIdType wikidata) {
this.wikidata = wikidata;
}
public ExternalIdType getOrgRef() {
return orgRef;
}
public void setOrgRef(final ExternalIdType orgRef) {
this.orgRef = orgRef;
}
public ExternalIdType getIsni() {
return isni;
}
public void setIsni(final ExternalIdType isni) {
this.isni = isni;
}
public ExternalIdType getFundRef() {
return fundRef;
}
public void setFundRef(final ExternalIdType fundRef) {
this.fundRef = fundRef;
}
public GridType getGrid() {
return grid;
}
public void setGrid(final GridType grid) {
this.grid = grid;
}
}

View File

@ -1,37 +0,0 @@
package eu.dnetlib.dhp.actionmanager.ror.model;
import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonProperty;
public class GridType implements Serializable {
/**
*
*/
private static final long serialVersionUID = -5605887658267581353L;
@JsonProperty("all")
private String all;
@JsonProperty("preferred")
private String preferred;
public String getAll() {
return all;
}
public void setAll(final String all) {
this.all = all;
}
public String getPreferred() {
return preferred;
}
public void setPreferred(final String preferred) {
this.preferred = preferred;
}
}

View File

@ -3,7 +3,9 @@ package eu.dnetlib.dhp.actionmanager.ror.model;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonProperty;
@ -46,7 +48,7 @@ public class RorOrganization implements Serializable {
private String emailAddress;
@JsonProperty("external_ids")
private ExternalIds externalIds;
private Map<String, ExternalIdType> externalIds = new LinkedHashMap<>();
@JsonProperty("id")
private String id;
@ -155,11 +157,11 @@ public class RorOrganization implements Serializable {
this.emailAddress = emailAddress;
}
public ExternalIds getExternalIds() {
public Map<String, ExternalIdType> getExternalIds() {
return externalIds;
}
public void setExternalIds(final ExternalIds externalIds) {
public void setExternalIds(final Map<String, ExternalIdType> externalIds) {
this.externalIds = externalIds;
}

View File

@ -4,6 +4,7 @@ import java.io.FileInputStream;
import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
@ -11,6 +12,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.dhp.actionmanager.ror.model.RorOrganization;
import eu.dnetlib.dhp.schema.oaf.Organization;
@Disabled
class GenerateRorActionSetJobTest {
private static final ObjectMapper mapper = new ObjectMapper();