add a default datainfo if missing

This commit is contained in:
Michele Artini 2020-04-20 09:43:27 +02:00
parent d2058fdc47
commit 25307965d2
1 changed files with 426 additions and 431 deletions

View File

@ -1,443 +1,438 @@
package eu.dnetlib.dhp.oa.graph.raw; package eu.dnetlib.dhp.oa.graph.raw;
import static eu.dnetlib.dhp.oa.graph.raw.common.OafMapperUtils.*; import static eu.dnetlib.dhp.oa.graph.raw.common.OafMapperUtils.createOpenaireId;
import static eu.dnetlib.dhp.oa.graph.raw.common.OafMapperUtils.dataInfo;
import static eu.dnetlib.dhp.oa.graph.raw.common.OafMapperUtils.field;
import static eu.dnetlib.dhp.oa.graph.raw.common.OafMapperUtils.journal;
import static eu.dnetlib.dhp.oa.graph.raw.common.OafMapperUtils.keyValue;
import static eu.dnetlib.dhp.oa.graph.raw.common.OafMapperUtils.listFields;
import static eu.dnetlib.dhp.oa.graph.raw.common.OafMapperUtils.oaiIProvenance;
import static eu.dnetlib.dhp.oa.graph.raw.common.OafMapperUtils.qualifier;
import static eu.dnetlib.dhp.oa.graph.raw.common.OafMapperUtils.structuredProperty;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import eu.dnetlib.dhp.schema.oaf.*;
import java.util.*;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.dom4j.Document; import org.dom4j.Document;
import org.dom4j.DocumentFactory; import org.dom4j.DocumentFactory;
import org.dom4j.DocumentHelper; import org.dom4j.DocumentHelper;
import org.dom4j.Node; import org.dom4j.Node;
import eu.dnetlib.dhp.schema.oaf.Author;
import eu.dnetlib.dhp.schema.oaf.DataInfo;
import eu.dnetlib.dhp.schema.oaf.Dataset;
import eu.dnetlib.dhp.schema.oaf.Field;
import eu.dnetlib.dhp.schema.oaf.GeoLocation;
import eu.dnetlib.dhp.schema.oaf.Instance;
import eu.dnetlib.dhp.schema.oaf.Journal;
import eu.dnetlib.dhp.schema.oaf.KeyValue;
import eu.dnetlib.dhp.schema.oaf.OAIProvenance;
import eu.dnetlib.dhp.schema.oaf.Oaf;
import eu.dnetlib.dhp.schema.oaf.OtherResearchProduct;
import eu.dnetlib.dhp.schema.oaf.Publication;
import eu.dnetlib.dhp.schema.oaf.Qualifier;
import eu.dnetlib.dhp.schema.oaf.Relation;
import eu.dnetlib.dhp.schema.oaf.Result;
import eu.dnetlib.dhp.schema.oaf.Software;
import eu.dnetlib.dhp.schema.oaf.StructuredProperty;
public abstract class AbstractMdRecordToOafMapper { public abstract class AbstractMdRecordToOafMapper {
protected final Map<String, String> code2name; protected final Map<String, String> code2name;
protected static final Qualifier MAIN_TITLE_QUALIFIER = protected static final Qualifier MAIN_TITLE_QUALIFIER =
qualifier("main title", "main title", "dnet:dataCite_title", "dnet:dataCite_title"); qualifier("main title", "main title", "dnet:dataCite_title", "dnet:dataCite_title");
protected static final Qualifier PUBLICATION_RESULTTYPE_QUALIFIER = protected static final Qualifier PUBLICATION_RESULTTYPE_QUALIFIER =
qualifier( qualifier("publication", "publication", "dnet:result_typologies", "dnet:result_typologies");
"publication", protected static final Qualifier DATASET_RESULTTYPE_QUALIFIER =
"publication", qualifier("dataset", "dataset", "dnet:result_typologies", "dnet:result_typologies");
"dnet:result_typologies", protected static final Qualifier SOFTWARE_RESULTTYPE_QUALIFIER =
"dnet:result_typologies"); qualifier("software", "software", "dnet:result_typologies", "dnet:result_typologies");
protected static final Qualifier DATASET_RESULTTYPE_QUALIFIER = protected static final Qualifier OTHER_RESULTTYPE_QUALIFIER =
qualifier("dataset", "dataset", "dnet:result_typologies", "dnet:result_typologies"); qualifier("other", "other", "dnet:result_typologies", "dnet:result_typologies");
protected static final Qualifier SOFTWARE_RESULTTYPE_QUALIFIER = protected static final Qualifier REPOSITORY_QUALIFIER =
qualifier("software", "software", "dnet:result_typologies", "dnet:result_typologies"); qualifier("sysimport:crosswalk:repository", "sysimport:crosswalk:repository", "dnet:provenanceActions", "dnet:provenanceActions");
protected static final Qualifier OTHER_RESULTTYPE_QUALIFIER =
qualifier("other", "other", "dnet:result_typologies", "dnet:result_typologies"); protected AbstractMdRecordToOafMapper(final Map<String, String> code2name) {
this.code2name = code2name;
protected AbstractMdRecordToOafMapper(final Map<String, String> code2name) { }
this.code2name = code2name;
} public List<Oaf> processMdRecord(final String xml) {
try {
public List<Oaf> processMdRecord(final String xml) { final Map<String, String> nsContext = new HashMap<>();
try { nsContext.put("dr", "http://www.driver-repository.eu/namespace/dr");
final Map<String, String> nsContext = new HashMap<>(); nsContext.put("dri", "http://www.driver-repository.eu/namespace/dri");
nsContext.put("dr", "http://www.driver-repository.eu/namespace/dr"); nsContext.put("oaf", "http://namespace.openaire.eu/oaf");
nsContext.put("dri", "http://www.driver-repository.eu/namespace/dri"); nsContext.put("oai", "http://www.openarchives.org/OAI/2.0/");
nsContext.put("oaf", "http://namespace.openaire.eu/oaf"); nsContext.put("prov", "http://www.openarchives.org/OAI/2.0/provenance");
nsContext.put("oai", "http://www.openarchives.org/OAI/2.0/"); nsContext.put("dc", "http://purl.org/dc/elements/1.1/");
nsContext.put("prov", "http://www.openarchives.org/OAI/2.0/provenance"); nsContext.put("datacite", "http://datacite.org/schema/kernel-3");
nsContext.put("dc", "http://purl.org/dc/elements/1.1/"); DocumentFactory.getInstance().setXPathNamespaceURIs(nsContext);
nsContext.put("datacite", "http://datacite.org/schema/kernel-3");
DocumentFactory.getInstance().setXPathNamespaceURIs(nsContext); final Document doc =
DocumentHelper.parseText(xml.replaceAll("http://datacite.org/schema/kernel-4", "http://datacite.org/schema/kernel-3"));
final Document doc =
DocumentHelper.parseText( final String type = doc.valueOf("//dr:CobjCategory/@type");
xml.replaceAll( final KeyValue collectedFrom =
"http://datacite.org/schema/kernel-4", keyValue(doc.valueOf("//oaf:collectedFrom/@id"), doc.valueOf("//oaf:collectedFrom/@name"));
"http://datacite.org/schema/kernel-3")); final KeyValue hostedBy =
StringUtils.isBlank(doc.valueOf("//oaf:hostedBy/@id"))
final String type = doc.valueOf("//dr:CobjCategory/@type"); ? collectedFrom
final KeyValue collectedFrom = : keyValue(doc.valueOf("//oaf:hostedBy/@id"), doc.valueOf("//oaf:hostedBy/@name"));
keyValue(
doc.valueOf("//oaf:collectedFrom/@id"), final DataInfo info = prepareDataInfo(doc);
doc.valueOf("//oaf:collectedFrom/@name")); final long lastUpdateTimestamp = new Date().getTime();
final KeyValue hostedBy =
StringUtils.isBlank(doc.valueOf("//oaf:hostedBy/@id")) return createOafs(doc, type, collectedFrom, hostedBy, info, lastUpdateTimestamp);
? collectedFrom } catch (final Exception e) {
: keyValue( throw new RuntimeException(e);
doc.valueOf("//oaf:hostedBy/@id"), }
doc.valueOf("//oaf:hostedBy/@name")); }
final DataInfo info = prepareDataInfo(doc); protected List<Oaf> createOafs(
final long lastUpdateTimestamp = new Date().getTime(); final Document doc,
final String type,
return createOafs(doc, type, collectedFrom, hostedBy, info, lastUpdateTimestamp); final KeyValue collectedFrom,
} catch (final Exception e) { final KeyValue hostedBy,
throw new RuntimeException(e); final DataInfo info,
} final long lastUpdateTimestamp) {
}
final List<Oaf> oafs = new ArrayList<>();
protected List<Oaf> createOafs(
final Document doc, switch (type.toLowerCase()) {
final String type, case "":
final KeyValue collectedFrom, case "publication":
final KeyValue hostedBy, final Publication p = new Publication();
final DataInfo info, populateResultFields(p, doc, collectedFrom, hostedBy, info, lastUpdateTimestamp);
final long lastUpdateTimestamp) { p.setResulttype(PUBLICATION_RESULTTYPE_QUALIFIER);
p.setJournal(prepareJournal(doc, info));
final List<Oaf> oafs = new ArrayList<>(); oafs.add(p);
break;
switch (type.toLowerCase()) { case "dataset":
case "": final Dataset d = new Dataset();
case "publication": populateResultFields(d, doc, collectedFrom, hostedBy, info, lastUpdateTimestamp);
final Publication p = new Publication(); d.setResulttype(DATASET_RESULTTYPE_QUALIFIER);
populateResultFields(p, doc, collectedFrom, hostedBy, info, lastUpdateTimestamp); d.setStoragedate(prepareDatasetStorageDate(doc, info));
p.setResulttype(PUBLICATION_RESULTTYPE_QUALIFIER); d.setDevice(prepareDatasetDevice(doc, info));
p.setJournal(prepareJournal(doc, info)); d.setSize(prepareDatasetSize(doc, info));
oafs.add(p); d.setVersion(prepareDatasetVersion(doc, info));
break; d.setLastmetadataupdate(prepareDatasetLastMetadataUpdate(doc, info));
case "dataset": d.setMetadataversionnumber(prepareDatasetMetadataVersionNumber(doc, info));
final Dataset d = new Dataset(); d.setGeolocation(prepareDatasetGeoLocations(doc, info));
populateResultFields(d, doc, collectedFrom, hostedBy, info, lastUpdateTimestamp); oafs.add(d);
d.setResulttype(DATASET_RESULTTYPE_QUALIFIER); break;
d.setStoragedate(prepareDatasetStorageDate(doc, info)); case "software":
d.setDevice(prepareDatasetDevice(doc, info)); final Software s = new Software();
d.setSize(prepareDatasetSize(doc, info)); populateResultFields(s, doc, collectedFrom, hostedBy, info, lastUpdateTimestamp);
d.setVersion(prepareDatasetVersion(doc, info)); s.setResulttype(SOFTWARE_RESULTTYPE_QUALIFIER);
d.setLastmetadataupdate(prepareDatasetLastMetadataUpdate(doc, info)); s.setDocumentationUrl(prepareSoftwareDocumentationUrls(doc, info));
d.setMetadataversionnumber(prepareDatasetMetadataVersionNumber(doc, info)); s.setLicense(prepareSoftwareLicenses(doc, info));
d.setGeolocation(prepareDatasetGeoLocations(doc, info)); s.setCodeRepositoryUrl(prepareSoftwareCodeRepositoryUrl(doc, info));
oafs.add(d); s.setProgrammingLanguage(prepareSoftwareProgrammingLanguage(doc, info));
break; oafs.add(s);
case "software": break;
final Software s = new Software(); case "otherresearchproducts":
populateResultFields(s, doc, collectedFrom, hostedBy, info, lastUpdateTimestamp); default:
s.setResulttype(SOFTWARE_RESULTTYPE_QUALIFIER); final OtherResearchProduct o = new OtherResearchProduct();
s.setDocumentationUrl(prepareSoftwareDocumentationUrls(doc, info)); populateResultFields(o, doc, collectedFrom, hostedBy, info, lastUpdateTimestamp);
s.setLicense(prepareSoftwareLicenses(doc, info)); o.setResulttype(OTHER_RESULTTYPE_QUALIFIER);
s.setCodeRepositoryUrl(prepareSoftwareCodeRepositoryUrl(doc, info)); o.setContactperson(prepareOtherResearchProductContactPersons(doc, info));
s.setProgrammingLanguage(prepareSoftwareProgrammingLanguage(doc, info)); o.setContactgroup(prepareOtherResearchProductContactGroups(doc, info));
oafs.add(s); o.setTool(prepareOtherResearchProductTools(doc, info));
break; oafs.add(o);
case "otherresearchproducts": break;
default: }
final OtherResearchProduct o = new OtherResearchProduct();
populateResultFields(o, doc, collectedFrom, hostedBy, info, lastUpdateTimestamp); if (!oafs.isEmpty()) {
o.setResulttype(OTHER_RESULTTYPE_QUALIFIER); oafs.addAll(addProjectRels(doc, collectedFrom, info, lastUpdateTimestamp));
o.setContactperson(prepareOtherResearchProductContactPersons(doc, info)); oafs.addAll(addOtherResultRels(doc, collectedFrom, info, lastUpdateTimestamp));
o.setContactgroup(prepareOtherResearchProductContactGroups(doc, info)); }
o.setTool(prepareOtherResearchProductTools(doc, info));
oafs.add(o); return oafs;
break; }
}
private List<Oaf> addProjectRels(
if (!oafs.isEmpty()) { final Document doc,
oafs.addAll(addProjectRels(doc, collectedFrom, info, lastUpdateTimestamp)); final KeyValue collectedFrom,
oafs.addAll(addOtherResultRels(doc, collectedFrom, info, lastUpdateTimestamp)); final DataInfo info,
} final long lastUpdateTimestamp) {
return oafs; final List<Oaf> res = new ArrayList<>();
}
final String docId = createOpenaireId(50, doc.valueOf("//dri:objIdentifier"), false);
private List<Oaf> addProjectRels(
final Document doc, for (final Object o : doc.selectNodes("//oaf:projectid")) {
final KeyValue collectedFrom, final String projectId = createOpenaireId(40, ((Node) o).getText(), true);
final DataInfo info,
final long lastUpdateTimestamp) { final Relation r1 = new Relation();
r1.setRelType("resultProject");
final List<Oaf> res = new ArrayList<>(); r1.setSubRelType("outcome");
r1.setRelClass("isProducedBy");
final String docId = createOpenaireId(50, doc.valueOf("//dri:objIdentifier"), false); r1.setSource(docId);
r1.setTarget(projectId);
for (final Object o : doc.selectNodes("//oaf:projectid")) { r1.setCollectedFrom(Arrays.asList(collectedFrom));
final String projectId = createOpenaireId(40, ((Node) o).getText(), true); r1.setDataInfo(info);
r1.setLastupdatetimestamp(lastUpdateTimestamp);
final Relation r1 = new Relation(); res.add(r1);
r1.setRelType("resultProject");
r1.setSubRelType("outcome"); final Relation r2 = new Relation();
r1.setRelClass("isProducedBy"); r2.setRelType("resultProject");
r1.setSource(docId); r2.setSubRelType("outcome");
r1.setTarget(projectId); r2.setRelClass("produces");
r1.setCollectedFrom(Arrays.asList(collectedFrom)); r2.setSource(projectId);
r1.setDataInfo(info); r2.setTarget(docId);
r1.setLastupdatetimestamp(lastUpdateTimestamp); r2.setCollectedFrom(Arrays.asList(collectedFrom));
res.add(r1); r2.setDataInfo(info);
r2.setLastupdatetimestamp(lastUpdateTimestamp);
final Relation r2 = new Relation(); res.add(r2);
r2.setRelType("resultProject"); }
r2.setSubRelType("outcome");
r2.setRelClass("produces"); return res;
r2.setSource(projectId); }
r2.setTarget(docId);
r2.setCollectedFrom(Arrays.asList(collectedFrom)); protected abstract List<Oaf> addOtherResultRels(
r2.setDataInfo(info); final Document doc,
r2.setLastupdatetimestamp(lastUpdateTimestamp); final KeyValue collectedFrom,
res.add(r2); final DataInfo info,
} final long lastUpdateTimestamp);
return res; private void populateResultFields(
} final Result r,
final Document doc,
protected abstract List<Oaf> addOtherResultRels( final KeyValue collectedFrom,
final Document doc, final KeyValue hostedBy,
final KeyValue collectedFrom, final DataInfo info,
final DataInfo info, final long lastUpdateTimestamp) {
final long lastUpdateTimestamp); r.setDataInfo(info);
r.setLastupdatetimestamp(lastUpdateTimestamp);
private void populateResultFields( r.setId(createOpenaireId(50, doc.valueOf("//dri:objIdentifier"), false));
final Result r, r.setOriginalId(Arrays.asList(doc.valueOf("//dri:objIdentifier")));
final Document doc, r.setCollectedfrom(Arrays.asList(collectedFrom));
final KeyValue collectedFrom, r.setPid(prepareListStructProps(doc, "//oaf:identifier", "@identifierType", "dnet:pid_types", "dnet:pid_types", info));
final KeyValue hostedBy, r.setDateofcollection(doc.valueOf("//dr:dateOfCollection"));
final DataInfo info, r.setDateoftransformation(doc.valueOf("//dr:dateOfTransformation"));
final long lastUpdateTimestamp) { r.setExtraInfo(new ArrayList<>()); // NOT PRESENT IN MDSTORES
r.setDataInfo(info); r.setOaiprovenance(prepareOAIprovenance(doc));
r.setLastupdatetimestamp(lastUpdateTimestamp); r.setAuthor(prepareAuthors(doc, info));
r.setId(createOpenaireId(50, doc.valueOf("//dri:objIdentifier"), false)); r.setLanguage(prepareLanguages(doc));
r.setOriginalId(Arrays.asList(doc.valueOf("//dri:objIdentifier"))); r.setCountry(new ArrayList<>()); // NOT PRESENT IN MDSTORES
r.setCollectedfrom(Arrays.asList(collectedFrom)); r.setSubject(prepareSubjects(doc, info));
r.setPid( r.setTitle(prepareTitles(doc, info));
prepareListStructProps( r.setRelevantdate(prepareRelevantDates(doc, info));
doc, r.setDescription(prepareDescriptions(doc, info));
"//oaf:identifier", r.setDateofacceptance(prepareField(doc, "//oaf:dateAccepted", info));
"@identifierType", r.setPublisher(preparePublisher(doc, info));
"dnet:pid_types", r.setEmbargoenddate(prepareField(doc, "//oaf:embargoenddate", info));
"dnet:pid_types", r.setSource(prepareSources(doc, info));
info)); r.setFulltext(new ArrayList<>()); // NOT PRESENT IN MDSTORES
r.setDateofcollection(doc.valueOf("//dr:dateOfCollection")); r.setFormat(prepareFormats(doc, info));
r.setDateoftransformation(doc.valueOf("//dr:dateOfTransformation")); r.setContributor(prepareContributors(doc, info));
r.setExtraInfo(new ArrayList<>()); // NOT PRESENT IN MDSTORES r.setResourcetype(prepareResourceType(doc, info));
r.setOaiprovenance(prepareOAIprovenance(doc)); r.setCoverage(prepareCoverages(doc, info));
r.setAuthor(prepareAuthors(doc, info)); r.setContext(new ArrayList<>()); // NOT PRESENT IN MDSTORES
r.setLanguage(prepareLanguages(doc)); r.setExternalReference(new ArrayList<>()); // NOT PRESENT IN MDSTORES
r.setCountry(new ArrayList<>()); // NOT PRESENT IN MDSTORES r.setInstance(prepareInstances(doc, info, collectedFrom, hostedBy));
r.setSubject(prepareSubjects(doc, info)); }
r.setTitle(prepareTitles(doc, info));
r.setRelevantdate(prepareRelevantDates(doc, info)); protected abstract Qualifier prepareResourceType(Document doc, DataInfo info);
r.setDescription(prepareDescriptions(doc, info));
r.setDateofacceptance(prepareField(doc, "//oaf:dateAccepted", info)); protected abstract List<Instance> prepareInstances(
r.setPublisher(preparePublisher(doc, info)); Document doc,
r.setEmbargoenddate(prepareField(doc, "//oaf:embargoenddate", info)); DataInfo info,
r.setSource(prepareSources(doc, info)); KeyValue collectedfrom,
r.setFulltext(new ArrayList<>()); // NOT PRESENT IN MDSTORES KeyValue hostedby);
r.setFormat(prepareFormats(doc, info));
r.setContributor(prepareContributors(doc, info)); protected abstract List<Field<String>> prepareSources(Document doc, DataInfo info);
r.setResourcetype(prepareResourceType(doc, info));
r.setCoverage(prepareCoverages(doc, info)); protected abstract List<StructuredProperty> prepareRelevantDates(Document doc, DataInfo info);
r.setContext(new ArrayList<>()); // NOT PRESENT IN MDSTORES
r.setExternalReference(new ArrayList<>()); // NOT PRESENT IN MDSTORES protected abstract List<Field<String>> prepareCoverages(Document doc, DataInfo info);
r.setInstance(prepareInstances(doc, info, collectedFrom, hostedBy));
} protected abstract List<Field<String>> prepareContributors(Document doc, DataInfo info);
protected abstract Qualifier prepareResourceType(Document doc, DataInfo info); protected abstract List<Field<String>> prepareFormats(Document doc, DataInfo info);
protected abstract List<Instance> prepareInstances( protected abstract Field<String> preparePublisher(Document doc, DataInfo info);
Document doc, DataInfo info, KeyValue collectedfrom, KeyValue hostedby);
protected abstract List<Field<String>> prepareDescriptions(Document doc, DataInfo info);
protected abstract List<Field<String>> prepareSources(Document doc, DataInfo info);
protected abstract List<StructuredProperty> prepareTitles(Document doc, DataInfo info);
protected abstract List<StructuredProperty> prepareRelevantDates(Document doc, DataInfo info);
protected abstract List<StructuredProperty> prepareSubjects(Document doc, DataInfo info);
protected abstract List<Field<String>> prepareCoverages(Document doc, DataInfo info);
protected abstract Qualifier prepareLanguages(Document doc);
protected abstract List<Field<String>> prepareContributors(Document doc, DataInfo info);
protected abstract List<Author> prepareAuthors(Document doc, DataInfo info);
protected abstract List<Field<String>> prepareFormats(Document doc, DataInfo info);
protected abstract List<Field<String>> prepareOtherResearchProductTools(
protected abstract Field<String> preparePublisher(Document doc, DataInfo info); Document doc,
DataInfo info);
protected abstract List<Field<String>> prepareDescriptions(Document doc, DataInfo info);
protected abstract List<Field<String>> prepareOtherResearchProductContactGroups(
protected abstract List<StructuredProperty> prepareTitles(Document doc, DataInfo info); Document doc,
DataInfo info);
protected abstract List<StructuredProperty> prepareSubjects(Document doc, DataInfo info);
protected abstract List<Field<String>> prepareOtherResearchProductContactPersons(
protected abstract Qualifier prepareLanguages(Document doc); Document doc,
DataInfo info);
protected abstract List<Author> prepareAuthors(Document doc, DataInfo info);
protected abstract Qualifier prepareSoftwareProgrammingLanguage(Document doc, DataInfo info);
protected abstract List<Field<String>> prepareOtherResearchProductTools(
Document doc, DataInfo info); protected abstract Field<String> prepareSoftwareCodeRepositoryUrl(Document doc, DataInfo info);
protected abstract List<Field<String>> prepareOtherResearchProductContactGroups( protected abstract List<StructuredProperty> prepareSoftwareLicenses(
Document doc, DataInfo info); Document doc,
DataInfo info);
protected abstract List<Field<String>> prepareOtherResearchProductContactPersons(
Document doc, DataInfo info); protected abstract List<Field<String>> prepareSoftwareDocumentationUrls(
Document doc,
protected abstract Qualifier prepareSoftwareProgrammingLanguage(Document doc, DataInfo info); DataInfo info);
protected abstract Field<String> prepareSoftwareCodeRepositoryUrl(Document doc, DataInfo info); protected abstract List<GeoLocation> prepareDatasetGeoLocations(Document doc, DataInfo info);
protected abstract List<StructuredProperty> prepareSoftwareLicenses( protected abstract Field<String> prepareDatasetMetadataVersionNumber(
Document doc, DataInfo info); Document doc,
DataInfo info);
protected abstract List<Field<String>> prepareSoftwareDocumentationUrls(
Document doc, DataInfo info); protected abstract Field<String> prepareDatasetLastMetadataUpdate(Document doc, DataInfo info);
protected abstract List<GeoLocation> prepareDatasetGeoLocations(Document doc, DataInfo info); protected abstract Field<String> prepareDatasetVersion(Document doc, DataInfo info);
protected abstract Field<String> prepareDatasetMetadataVersionNumber( protected abstract Field<String> prepareDatasetSize(Document doc, DataInfo info);
Document doc, DataInfo info);
protected abstract Field<String> prepareDatasetDevice(Document doc, DataInfo info);
protected abstract Field<String> prepareDatasetLastMetadataUpdate(Document doc, DataInfo info);
protected abstract Field<String> prepareDatasetStorageDate(Document doc, DataInfo info);
protected abstract Field<String> prepareDatasetVersion(Document doc, DataInfo info);
private Journal prepareJournal(final Document doc, final DataInfo info) {
protected abstract Field<String> prepareDatasetSize(Document doc, DataInfo info); final Node n = doc.selectSingleNode("//oaf:journal");
if (n != null) {
protected abstract Field<String> prepareDatasetDevice(Document doc, DataInfo info); final String name = n.getText();
final String issnPrinted = n.valueOf("@issn");
protected abstract Field<String> prepareDatasetStorageDate(Document doc, DataInfo info); final String issnOnline = n.valueOf("@eissn");
final String issnLinking = n.valueOf("@lissn");
private Journal prepareJournal(final Document doc, final DataInfo info) { final String ep = n.valueOf("@ep");
final Node n = doc.selectSingleNode("//oaf:journal"); final String iss = n.valueOf("@iss");
if (n != null) { final String sp = n.valueOf("@sp");
final String name = n.getText(); final String vol = n.valueOf("@vol");
final String issnPrinted = n.valueOf("@issn"); final String edition = n.valueOf("@edition");
final String issnOnline = n.valueOf("@eissn"); if (StringUtils.isNotBlank(name)) { return journal(name, issnPrinted, issnOnline, issnLinking, ep, iss, sp, vol, edition, null, null, info); }
final String issnLinking = n.valueOf("@lissn"); }
final String ep = n.valueOf("@ep"); return null;
final String iss = n.valueOf("@iss"); }
final String sp = n.valueOf("@sp");
final String vol = n.valueOf("@vol"); protected Qualifier prepareQualifier(
final String edition = n.valueOf("@edition"); final Node node,
if (StringUtils.isNotBlank(name)) { final String xpath,
return journal( final String schemeId,
name, final String schemeName) {
issnPrinted, final String classId = node.valueOf(xpath);
issnOnline, final String className = code2name.get(classId);
issnLinking, return qualifier(classId, className, schemeId, schemeName);
ep, }
iss,
sp, protected List<StructuredProperty> prepareListStructProps(
vol, final Node node,
edition, final String xpath,
null, final String xpathClassId,
null, final String schemeId,
info); final String schemeName,
} final DataInfo info) {
} final List<StructuredProperty> res = new ArrayList<>();
return null; for (final Object o : node.selectNodes(xpath)) {
} final Node n = (Node) o;
final String classId = n.valueOf(xpathClassId);
protected Qualifier prepareQualifier( final String className = code2name.get(classId);
final Node node, final String xpath, final String schemeId, final String schemeName) { res.add(structuredProperty(n.getText(), classId, className, schemeId, schemeName, info));
final String classId = node.valueOf(xpath); }
final String className = code2name.get(classId); return res;
return qualifier(classId, className, schemeId, schemeName); }
}
protected List<StructuredProperty> prepareListStructProps(
protected List<StructuredProperty> prepareListStructProps( final Node node,
final Node node, final String xpath,
final String xpath, final Qualifier qualifier,
final String xpathClassId, final DataInfo info) {
final String schemeId, final List<StructuredProperty> res = new ArrayList<>();
final String schemeName, for (final Object o : node.selectNodes(xpath)) {
final DataInfo info) { final Node n = (Node) o;
final List<StructuredProperty> res = new ArrayList<>(); res.add(structuredProperty(n.getText(), qualifier, info));
for (final Object o : node.selectNodes(xpath)) { }
final Node n = (Node) o; return res;
final String classId = n.valueOf(xpathClassId); }
final String className = code2name.get(classId);
res.add( protected List<StructuredProperty> prepareListStructProps(
structuredProperty( final Node node,
n.getText(), classId, className, schemeId, schemeName, info)); final String xpath,
} final DataInfo info) {
return res; final List<StructuredProperty> res = new ArrayList<>();
} for (final Object o : node.selectNodes(xpath)) {
final Node n = (Node) o;
protected List<StructuredProperty> prepareListStructProps( res.add(structuredProperty(n.getText(), n.valueOf("@classid"), n.valueOf("@classname"), n.valueOf("@schemeid"), n.valueOf("@schemename"), info));
final Node node, final String xpath, final Qualifier qualifier, final DataInfo info) { }
final List<StructuredProperty> res = new ArrayList<>(); return res;
for (final Object o : node.selectNodes(xpath)) { }
final Node n = (Node) o;
res.add(structuredProperty(n.getText(), qualifier, info)); protected OAIProvenance prepareOAIprovenance(final Document doc) {
} final Node n =
return res; doc.selectSingleNode("//*[local-name()='provenance']/*[local-name()='originDescription']");
}
if (n == null) { return null; }
protected List<StructuredProperty> prepareListStructProps(
final Node node, final String xpath, final DataInfo info) { final String identifier = n.valueOf("./*[local-name()='identifier']");
final List<StructuredProperty> res = new ArrayList<>(); final String baseURL = n.valueOf("./*[local-name()='baseURL']");;
for (final Object o : node.selectNodes(xpath)) { final String metadataNamespace = n.valueOf("./*[local-name()='metadataNamespace']");;
final Node n = (Node) o; final boolean altered = n.valueOf("@altered").equalsIgnoreCase("true");
res.add( final String datestamp = n.valueOf("./*[local-name()='datestamp']");;
structuredProperty( final String harvestDate = n.valueOf("@harvestDate");;
n.getText(),
n.valueOf("@classid"), return oaiIProvenance(identifier, baseURL, metadataNamespace, altered, datestamp, harvestDate);
n.valueOf("@classname"), }
n.valueOf("@schemeid"),
n.valueOf("@schemename"), protected DataInfo prepareDataInfo(final Document doc) {
info)); final Node n = doc.selectSingleNode("//oaf:datainfo");
}
return res; if (n == null) { return dataInfo(false, null, false, false, REPOSITORY_QUALIFIER, "0.9"); }
}
final String paClassId = n.valueOf("./oaf:provenanceaction/@classid");
protected OAIProvenance prepareOAIprovenance(final Document doc) { final String paClassName = n.valueOf("./oaf:provenanceaction/@classname");
final Node n = final String paSchemeId = n.valueOf("./oaf:provenanceaction/@schemeid");
doc.selectSingleNode( final String paSchemeName = n.valueOf("./oaf:provenanceaction/@schemename");
"//*[local-name()='provenance']/*[local-name()='originDescription']");
final boolean deletedbyinference =
if (n == null) { Boolean.parseBoolean(n.valueOf("./oaf:deletedbyinference"));
return null; final String inferenceprovenance = n.valueOf("./oaf:inferenceprovenance");
} final Boolean inferred = Boolean.parseBoolean(n.valueOf("./oaf:inferred"));
final String trust = n.valueOf("./oaf:trust");
final String identifier = n.valueOf("./*[local-name()='identifier']");
final String baseURL = n.valueOf("./*[local-name()='baseURL']"); return dataInfo(deletedbyinference, inferenceprovenance, inferred, false, qualifier(paClassId, paClassName, paSchemeId, paSchemeName), trust);
; }
final String metadataNamespace = n.valueOf("./*[local-name()='metadataNamespace']");
; protected Field<String> prepareField(final Node node, final String xpath, final DataInfo info) {
final boolean altered = n.valueOf("@altered").equalsIgnoreCase("true"); return field(node.valueOf(xpath), info);
final String datestamp = n.valueOf("./*[local-name()='datestamp']"); }
;
final String harvestDate = n.valueOf("@harvestDate"); protected List<Field<String>> prepareListFields(
; final Node node,
final String xpath,
return oaiIProvenance( final DataInfo info) {
identifier, baseURL, metadataNamespace, altered, datestamp, harvestDate); return listFields(info, prepareListString(node, xpath));
} }
protected DataInfo prepareDataInfo(final Document doc) { protected List<String> prepareListString(final Node node, final String xpath) {
final Node n = doc.selectSingleNode("//oaf:datainfo"); final List<String> res = new ArrayList<>();
for (final Object o : node.selectNodes(xpath)) {
if (n == null) { final String s = ((Node) o).getText().trim();
return null; if (StringUtils.isNotBlank(s)) {
} res.add(s);
}
final String paClassId = n.valueOf("./oaf:provenanceaction/@classid"); }
final String paClassName = n.valueOf("./oaf:provenanceaction/@classname"); return res;
final String paSchemeId = n.valueOf("./oaf:provenanceaction/@schemeid"); }
final String paSchemeName = n.valueOf("./oaf:provenanceaction/@schemename");
final boolean deletedbyinference =
Boolean.parseBoolean(n.valueOf("./oaf:deletedbyinference"));
final String inferenceprovenance = n.valueOf("./oaf:inferenceprovenance");
final Boolean inferred = Boolean.parseBoolean(n.valueOf("./oaf:inferred"));
final String trust = n.valueOf("./oaf:trust");
return dataInfo(
deletedbyinference,
inferenceprovenance,
inferred,
false,
qualifier(paClassId, paClassName, paSchemeId, paSchemeName),
trust);
}
protected Field<String> prepareField(final Node node, final String xpath, final DataInfo info) {
return field(node.valueOf(xpath), info);
}
protected List<Field<String>> prepareListFields(
final Node node, final String xpath, final DataInfo info) {
return listFields(info, prepareListString(node, xpath));
}
protected List<String> prepareListString(final Node node, final String xpath) {
final List<String> res = new ArrayList<>();
for (final Object o : node.selectNodes(xpath)) {
final String s = ((Node) o).getText().trim();
if (StringUtils.isNotBlank(s)) {
res.add(s);
}
}
return res;
}
} }