forked from D-Net/dnet-hadoop
used vtd for parsing orcid xml record, set 4g heapspace
This commit is contained in:
parent
5d46ec7d5f
commit
7d759947ae
|
@ -1,27 +1,22 @@
|
||||||
package eu.dnetlib.doiboost.orcid;
|
package eu.dnetlib.doiboost.orcid;
|
||||||
|
|
||||||
|
import eu.dnetlib.dhp.application.ArgumentApplicationParser;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.fs.FileSystem;
|
import org.apache.hadoop.fs.FileSystem;
|
||||||
import org.apache.hadoop.fs.Path;
|
import org.apache.hadoop.fs.Path;
|
||||||
import org.slf4j.Logger;
|
import org.mortbay.log.Log;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import eu.dnetlib.dhp.application.ArgumentApplicationParser;
|
|
||||||
|
|
||||||
public class OrcidDSManager {
|
public class OrcidDSManager {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(OrcidDSManager.class);
|
|
||||||
|
|
||||||
private String hdfsServerUri;
|
private String hdfsServerUri;
|
||||||
private String hdfsOrcidDefaultPath;
|
private String hdfsOrcidDefaultPath;
|
||||||
private String summariesFileNameTarGz;
|
private String summariesFileNameTarGz;
|
||||||
private String outputAuthorsPath;
|
private String outputAuthorsPath;
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException, Exception {
|
public static void main(String[] args) throws IOException, Exception {
|
||||||
logger.info("OrcidDSManager started");
|
|
||||||
OrcidDSManager orcidDSManager = new OrcidDSManager();
|
OrcidDSManager orcidDSManager = new OrcidDSManager();
|
||||||
orcidDSManager.loadArgs(args);
|
orcidDSManager.loadArgs(args);
|
||||||
orcidDSManager.generateAuthors();
|
orcidDSManager.generateAuthors();
|
||||||
|
@ -31,8 +26,12 @@ public class OrcidDSManager {
|
||||||
Configuration conf = initConfigurationObject();
|
Configuration conf = initConfigurationObject();
|
||||||
FileSystem fs = initFileSystemObject(conf);
|
FileSystem fs = initFileSystemObject(conf);
|
||||||
String tarGzUri = hdfsServerUri.concat(hdfsOrcidDefaultPath).concat(summariesFileNameTarGz);
|
String tarGzUri = hdfsServerUri.concat(hdfsOrcidDefaultPath).concat(summariesFileNameTarGz);
|
||||||
logger.info("Started parsing "+tarGzUri);
|
Path outputPath =
|
||||||
Path outputPath = new Path(hdfsServerUri.concat(hdfsOrcidDefaultPath).concat(outputAuthorsPath).concat(Long.toString(System.currentTimeMillis())).concat("/authors.seq"));
|
new Path(
|
||||||
|
hdfsServerUri
|
||||||
|
.concat(hdfsOrcidDefaultPath)
|
||||||
|
.concat(outputAuthorsPath)
|
||||||
|
.concat("authors.seq"));
|
||||||
SummariesDecompressor.parseGzSummaries(conf, tarGzUri, outputPath);
|
SummariesDecompressor.parseGzSummaries(conf, tarGzUri, outputPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +47,7 @@ public class OrcidDSManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private FileSystem initFileSystemObject(Configuration conf) {
|
private FileSystem initFileSystemObject(Configuration conf) {
|
||||||
//Get the filesystem - HDFS
|
// Get the filesystem - HDFS
|
||||||
FileSystem fs = null;
|
FileSystem fs = null;
|
||||||
try {
|
try {
|
||||||
fs = FileSystem.get(URI.create(hdfsServerUri.concat(hdfsOrcidDefaultPath)), conf);
|
fs = FileSystem.get(URI.create(hdfsServerUri.concat(hdfsOrcidDefaultPath)), conf);
|
||||||
|
@ -60,16 +59,20 @@ public class OrcidDSManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadArgs(String[] args) throws IOException, Exception {
|
private void loadArgs(String[] args) throws IOException, Exception {
|
||||||
final ArgumentApplicationParser parser = new ArgumentApplicationParser(IOUtils.toString(OrcidDSManager.class.getResourceAsStream("/eu/dnetlib/dhp/doiboost/create_orcid_authors_data.json")));
|
final ArgumentApplicationParser parser =
|
||||||
|
new ArgumentApplicationParser(
|
||||||
|
IOUtils.toString(
|
||||||
|
OrcidDSManager.class.getResourceAsStream(
|
||||||
|
"/eu/dnetlib/dhp/doiboost/create_orcid_authors_data.json")));
|
||||||
parser.parseArgument(args);
|
parser.parseArgument(args);
|
||||||
|
|
||||||
final String hdfsServerUri = parser.get("hdfsServerUri");
|
hdfsServerUri = parser.get("hdfsServerUri");
|
||||||
logger.info("HDFS URI: "+hdfsServerUri);
|
Log.info("HDFS URI: " + hdfsServerUri);
|
||||||
Path hdfsOrcidDefaultPath = new Path(parser.get("hdfsOrcidDefaultPath"));
|
hdfsOrcidDefaultPath = parser.get("hdfsOrcidDefaultPath");
|
||||||
logger.info("Default Path: "+hdfsOrcidDefaultPath);
|
Log.info("Default Path: " + hdfsOrcidDefaultPath);
|
||||||
final String summariesFileNameTarGz = parser.get("summariesFileNameTarGz");
|
summariesFileNameTarGz = parser.get("summariesFileNameTarGz");
|
||||||
logger.info("Summaries File Name: "+summariesFileNameTarGz);
|
Log.info("Summaries File Name: " + summariesFileNameTarGz);
|
||||||
final String outputAuthorsPath = parser.get("summariesFileNameTarGz");
|
outputAuthorsPath = parser.get("outputAuthorsPath");
|
||||||
logger.info("Output Authors Data: "+outputAuthorsPath);
|
Log.info("Output Authors Data: " + outputAuthorsPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,11 @@ package eu.dnetlib.doiboost.orcid;
|
||||||
import eu.dnetlib.doiboost.orcid.json.JsonWriter;
|
import eu.dnetlib.doiboost.orcid.json.JsonWriter;
|
||||||
import eu.dnetlib.doiboost.orcid.model.AuthorData;
|
import eu.dnetlib.doiboost.orcid.model.AuthorData;
|
||||||
import eu.dnetlib.doiboost.orcid.xml.XMLRecordParser;
|
import eu.dnetlib.doiboost.orcid.xml.XMLRecordParser;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.URI;
|
||||||
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
|
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
|
||||||
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
|
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
|
@ -13,23 +18,14 @@ import org.apache.hadoop.io.SequenceFile;
|
||||||
import org.apache.hadoop.io.Text;
|
import org.apache.hadoop.io.Text;
|
||||||
import org.apache.hadoop.io.compress.CompressionCodec;
|
import org.apache.hadoop.io.compress.CompressionCodec;
|
||||||
import org.apache.hadoop.io.compress.CompressionCodecFactory;
|
import org.apache.hadoop.io.compress.CompressionCodecFactory;
|
||||||
import org.apache.log4j.Logger;
|
import org.mortbay.log.Log;
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.URI;
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
|
||||||
import javax.xml.xpath.XPathExpressionException;
|
|
||||||
|
|
||||||
public class SummariesDecompressor {
|
public class SummariesDecompressor {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(SummariesDecompressor.class);
|
private static final int MAX_XML_RECORDS_PARSED = -1;
|
||||||
|
|
||||||
public static void parseGzSummaries(Configuration conf, String inputUri, Path outputPath) throws Exception {
|
public static void parseGzSummaries(Configuration conf, String inputUri, Path outputPath)
|
||||||
|
throws Exception {
|
||||||
String uri = inputUri;
|
String uri = inputUri;
|
||||||
FileSystem fs = FileSystem.get(URI.create(uri), conf);
|
FileSystem fs = FileSystem.get(URI.create(uri), conf);
|
||||||
Path inputPath = new Path(uri);
|
Path inputPath = new Path(uri);
|
||||||
|
@ -46,12 +42,13 @@ public class SummariesDecompressor {
|
||||||
parseTarSummaries(fs, conf, gzipInputStream, outputPath);
|
parseTarSummaries(fs, conf, gzipInputStream, outputPath);
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
logger.debug("Closing gzip stream");
|
Log.debug("Closing gzip stream");
|
||||||
IOUtils.closeStream(gzipInputStream);
|
IOUtils.closeStream(gzipInputStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void parseTarSummaries(FileSystem fs, Configuration conf, InputStream gzipInputStream, Path outputPath) {
|
private static void parseTarSummaries(
|
||||||
|
FileSystem fs, Configuration conf, InputStream gzipInputStream, Path outputPath) {
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
int nameFound = 0;
|
int nameFound = 0;
|
||||||
int surnameFound = 0;
|
int surnameFound = 0;
|
||||||
|
@ -61,33 +58,43 @@ public class SummariesDecompressor {
|
||||||
try (TarArchiveInputStream tais = new TarArchiveInputStream(gzipInputStream)) {
|
try (TarArchiveInputStream tais = new TarArchiveInputStream(gzipInputStream)) {
|
||||||
TarArchiveEntry entry = null;
|
TarArchiveEntry entry = null;
|
||||||
|
|
||||||
try (SequenceFile.Writer writer = SequenceFile.createWriter(conf,
|
try (SequenceFile.Writer writer =
|
||||||
SequenceFile.Writer.file(outputPath), SequenceFile.Writer.keyClass(Text.class),
|
SequenceFile.createWriter(
|
||||||
|
conf,
|
||||||
|
SequenceFile.Writer.file(outputPath),
|
||||||
|
SequenceFile.Writer.keyClass(Text.class),
|
||||||
SequenceFile.Writer.valueClass(Text.class))) {
|
SequenceFile.Writer.valueClass(Text.class))) {
|
||||||
|
|
||||||
while ((entry = tais.getNextTarEntry()) != null) {
|
while ((entry = tais.getNextTarEntry()) != null) {
|
||||||
String filename = entry.getName();
|
String filename = entry.getName();
|
||||||
|
try {
|
||||||
if (entry.isDirectory()) {
|
if (entry.isDirectory()) {
|
||||||
logger.debug("Directory entry name: "+entry.getName());
|
Log.debug("Directory entry name: " + entry.getName());
|
||||||
} else {
|
} else {
|
||||||
logger.debug("XML record entry name: "+entry.getName());
|
Log.debug("XML record entry name: " + entry.getName());
|
||||||
counter++;
|
counter++;
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(tais)); // Read directly from tarInput
|
BufferedReader br =
|
||||||
|
new BufferedReader(
|
||||||
|
new InputStreamReader(
|
||||||
|
tais)); // Read directly from tarInput
|
||||||
String line;
|
String line;
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
while ((line = br.readLine()) != null) {
|
while ((line = br.readLine()) != null) {
|
||||||
buffer.append(line);
|
buffer.append(line);
|
||||||
}
|
}
|
||||||
try (ByteArrayInputStream bais = new ByteArrayInputStream(buffer.toString().getBytes())) {
|
AuthorData authorData =
|
||||||
AuthorData authorData = XMLRecordParser.parse(bais);
|
XMLRecordParser.VTDParse(buffer.toString().getBytes());
|
||||||
if (authorData!=null) {
|
if (authorData != null) {
|
||||||
if (authorData.getErrorCode()!=null) {
|
if (authorData.getErrorCode() != null) {
|
||||||
errorFromOrcidFound+=1;
|
errorFromOrcidFound += 1;
|
||||||
logger.debug("error from Orcid with code "+authorData.getErrorCode()+" for oid "+entry.getName());
|
Log.debug(
|
||||||
|
"error from Orcid with code "
|
||||||
|
+ authorData.getErrorCode()
|
||||||
|
+ " for oid "
|
||||||
|
+ entry.getName());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String jsonData = JsonWriter.create(authorData);
|
String jsonData = JsonWriter.create(authorData);
|
||||||
logger.debug("oid: "+authorData.getOid() + " data: "+jsonData);
|
Log.debug("oid: " + authorData.getOid() + " data: " + jsonData);
|
||||||
|
|
||||||
final Text key = new Text(authorData.getOid());
|
final Text key = new Text(authorData.getOid());
|
||||||
final Text value = new Text(jsonData);
|
final Text value = new Text(jsonData);
|
||||||
|
@ -95,48 +102,59 @@ public class SummariesDecompressor {
|
||||||
try {
|
try {
|
||||||
writer.append(key, value);
|
writer.append(key, value);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("Writing to sequence file: "+e.getMessage());
|
Log.debug("Writing to sequence file: " + e.getMessage());
|
||||||
e.printStackTrace();
|
Log.debug(e);
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (authorData.getName()!=null) {
|
if (authorData.getName() != null) {
|
||||||
nameFound+=1;
|
nameFound += 1;
|
||||||
}
|
}
|
||||||
if (authorData.getSurname()!=null) {
|
if (authorData.getSurname() != null) {
|
||||||
surnameFound+=1;
|
surnameFound += 1;
|
||||||
}
|
}
|
||||||
if (authorData.getCreditName()!=null) {
|
if (authorData.getCreditName() != null) {
|
||||||
creditNameFound+=1;
|
creditNameFound += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Log.warn(
|
||||||
|
"Data not retrievable ["
|
||||||
|
+ entry.getName()
|
||||||
|
+ "] "
|
||||||
|
+ buffer.toString());
|
||||||
|
xmlParserErrorFound += 1;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
logger.error("Data not retrievable ["+entry.getName()+"] "+buffer.toString());
|
|
||||||
xmlParserErrorFound+=1;
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (XPathExpressionException | ParserConfigurationException | SAXException e) {
|
|
||||||
logger.error("Parsing record from tar archive: "+e.getMessage());
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.warn(
|
||||||
|
"Parsing record from tar archive and xml record: "
|
||||||
|
+ filename
|
||||||
|
+ " "
|
||||||
|
+ e.getMessage());
|
||||||
|
Log.warn(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((counter % 100000) == 0) {
|
if ((counter % 100000) == 0) {
|
||||||
logger.info("Current xml records parsed: "+counter);
|
Log.info("Current xml records parsed: " + counter);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((MAX_XML_RECORDS_PARSED > -1) && (counter > MAX_XML_RECORDS_PARSED)) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("Parsing record from gzip archive: "+e.getMessage());
|
Log.warn("Parsing record from gzip archive: " + e.getMessage());
|
||||||
|
Log.warn(e);
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
logger.info("Summaries parse completed");
|
Log.info("Summaries parse completed");
|
||||||
logger.info("Total XML records parsed: "+counter);
|
Log.info("Total XML records parsed: " + counter);
|
||||||
logger.info("Name found: "+nameFound);
|
Log.info("Name found: " + nameFound);
|
||||||
logger.info("Surname found: "+surnameFound);
|
Log.info("Surname found: " + surnameFound);
|
||||||
logger.info("Credit name found: "+creditNameFound);
|
Log.info("Credit name found: " + creditNameFound);
|
||||||
logger.info("Error from Orcid found: "+errorFromOrcidFound);
|
Log.info("Error from Orcid found: " + errorFromOrcidFound);
|
||||||
logger.info("Error parsing xml record found: "+xmlParserErrorFound);
|
Log.info("Error parsing xml record found: " + xmlParserErrorFound);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,97 +1,80 @@
|
||||||
package eu.dnetlib.doiboost.orcid.xml;
|
package eu.dnetlib.doiboost.orcid.xml;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import com.ximpleware.AutoPilot;
|
||||||
import java.io.IOException;
|
import com.ximpleware.EOFException;
|
||||||
import java.util.Iterator;
|
import com.ximpleware.EncodingException;
|
||||||
|
import com.ximpleware.EntityException;
|
||||||
import javax.xml.namespace.NamespaceContext;
|
import com.ximpleware.ParseException;
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import com.ximpleware.VTDGen;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import com.ximpleware.VTDNav;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import eu.dnetlib.dhp.parser.utility.VtdException;
|
||||||
import javax.xml.xpath.XPath;
|
import eu.dnetlib.dhp.parser.utility.VtdUtilityParser;
|
||||||
import javax.xml.xpath.XPathConstants;
|
|
||||||
import javax.xml.xpath.XPathExpressionException;
|
|
||||||
import javax.xml.xpath.XPathFactory;
|
|
||||||
|
|
||||||
import eu.dnetlib.doiboost.orcid.model.AuthorData;
|
import eu.dnetlib.doiboost.orcid.model.AuthorData;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import java.util.Arrays;
|
||||||
import org.w3c.dom.Document;
|
import java.util.List;
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
|
|
||||||
|
|
||||||
public class XMLRecordParser {
|
public class XMLRecordParser {
|
||||||
|
|
||||||
public static AuthorData parse(ByteArrayInputStream bytesStream) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException {
|
private static final String NS_COMMON_URL = "http://www.orcid.org/ns/common";
|
||||||
bytesStream.reset();
|
private static final String NS_COMMON = "common";
|
||||||
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
|
private static final String NS_PERSON_URL = "http://www.orcid.org/ns/person";
|
||||||
builderFactory.setNamespaceAware(true);
|
private static final String NS_PERSON = "person";
|
||||||
DocumentBuilder builder = builderFactory.newDocumentBuilder();
|
private static final String NS_DETAILS_URL = "http://www.orcid.org/ns/personal-details";
|
||||||
|
private static final String NS_DETAILS = "personal-details";
|
||||||
|
private static final String NS_OTHER_URL = "http://www.orcid.org/ns/other-name";
|
||||||
|
private static final String NS_OTHER = "other-name";
|
||||||
|
private static final String NS_RECORD_URL = "http://www.orcid.org/ns/record";
|
||||||
|
private static final String NS_RECORD = "record";
|
||||||
|
private static final String NS_ERROR_URL = "http://www.orcid.org/ns/error";
|
||||||
|
private static final String NS_ERROR = "error";
|
||||||
|
|
||||||
Document xmlDocument = builder.parse(bytesStream);
|
public static AuthorData VTDParse(byte[] bytes)
|
||||||
XPath xPath = XPathFactory.newInstance().newXPath();
|
throws VtdException, EncodingException, EOFException, EntityException, ParseException {
|
||||||
xPath.setNamespaceContext(new NamespaceContext() {
|
final VTDGen vg = new VTDGen();
|
||||||
@Override
|
vg.setDoc(bytes);
|
||||||
public Iterator getPrefixes(String arg0) {
|
vg.parse(true);
|
||||||
return null;
|
final VTDNav vn = vg.getNav();
|
||||||
}
|
final AutoPilot ap = new AutoPilot(vn);
|
||||||
@Override
|
ap.declareXPathNameSpace(NS_COMMON, NS_COMMON_URL);
|
||||||
public String getPrefix(String arg0) {
|
ap.declareXPathNameSpace(NS_PERSON, NS_PERSON_URL);
|
||||||
return null;
|
ap.declareXPathNameSpace(NS_DETAILS, NS_DETAILS_URL);
|
||||||
}
|
ap.declareXPathNameSpace(NS_OTHER, NS_OTHER_URL);
|
||||||
@Override
|
ap.declareXPathNameSpace(NS_RECORD, NS_RECORD_URL);
|
||||||
public String getNamespaceURI(String arg0) {
|
ap.declareXPathNameSpace(NS_ERROR, NS_ERROR_URL);
|
||||||
if ("common".equals(arg0)) {
|
|
||||||
return "http://www.orcid.org/ns/common";
|
|
||||||
}
|
|
||||||
else if ("person".equals(arg0)) {
|
|
||||||
return "http://www.orcid.org/ns/person";
|
|
||||||
}
|
|
||||||
else if ("personal-details".equals(arg0)) {
|
|
||||||
return "http://www.orcid.org/ns/personal-details";
|
|
||||||
}
|
|
||||||
else if ("other-name".equals(arg0)) {
|
|
||||||
return "http://www.orcid.org/ns/other-name";
|
|
||||||
}
|
|
||||||
else if ("record".equals(arg0)) {
|
|
||||||
return "http://www.orcid.org/ns/record";
|
|
||||||
}
|
|
||||||
else if ("error".equals(arg0)) {
|
|
||||||
return "http://www.orcid.org/ns/error";
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
AuthorData authorData = new AuthorData();
|
AuthorData authorData = new AuthorData();
|
||||||
String errorPath = "//error:response-code";
|
final List<String> errors = VtdUtilityParser.getTextValue(ap, vn, "//error:response-code");
|
||||||
String error = (String)xPath.compile(errorPath).evaluate(xmlDocument, XPathConstants.STRING);
|
if (!errors.isEmpty()) {
|
||||||
if (!StringUtils.isBlank(error)) {
|
authorData.setErrorCode(errors.get(0));
|
||||||
authorData.setErrorCode(error);
|
|
||||||
return authorData;
|
return authorData;
|
||||||
}
|
}
|
||||||
String oidPath = "//record:record/@path";
|
|
||||||
String oid = (String)xPath.compile(oidPath).evaluate(xmlDocument, XPathConstants.STRING);
|
List<VtdUtilityParser.Node> recordNodes =
|
||||||
if (!StringUtils.isBlank(oid)) {
|
VtdUtilityParser.getTextValuesWithAttributes(
|
||||||
oid = oid.substring(1);
|
ap, vn, "//record:record", Arrays.asList("path"));
|
||||||
|
if (!recordNodes.isEmpty()) {
|
||||||
|
final String oid = (recordNodes.get(0).getAttributes().get("path")).substring(1);
|
||||||
authorData.setOid(oid);
|
authorData.setOid(oid);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String namePath = "//personal-details:given-names";
|
|
||||||
String name = (String)xPath.compile(namePath).evaluate(xmlDocument, XPathConstants.STRING);
|
final List<String> names =
|
||||||
if (!StringUtils.isBlank(name)) {
|
VtdUtilityParser.getTextValue(ap, vn, "//personal-details:given-names");
|
||||||
authorData.setName(name);
|
if (!names.isEmpty()) {
|
||||||
|
authorData.setName(names.get(0));
|
||||||
}
|
}
|
||||||
String surnamePath = "//personal-details:family-name";
|
|
||||||
String surname = (String)xPath.compile(surnamePath).evaluate(xmlDocument, XPathConstants.STRING);
|
final List<String> surnames =
|
||||||
if (!StringUtils.isBlank(surname)) {
|
VtdUtilityParser.getTextValue(ap, vn, "//personal-details:family-name");
|
||||||
authorData.setSurname(surname);
|
if (!surnames.isEmpty()) {
|
||||||
|
authorData.setSurname(surnames.get(0));
|
||||||
}
|
}
|
||||||
String creditnamePath = "//personal-details:credit-name";
|
|
||||||
String creditName = (String)xPath.compile(creditnamePath).evaluate(xmlDocument, XPathConstants.STRING);
|
final List<String> creditNames =
|
||||||
if (!StringUtils.isBlank(creditName)) {
|
VtdUtilityParser.getTextValue(ap, vn, "//personal-details:credit-name");
|
||||||
authorData.setCreditName(creditName);
|
if (!creditNames.isEmpty()) {
|
||||||
|
authorData.setCreditName(creditNames.get(0));
|
||||||
}
|
}
|
||||||
return authorData;
|
return authorData;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,4 +15,8 @@
|
||||||
<name>oozie.launcher.mapreduce.user.classpath.first</name>
|
<name>oozie.launcher.mapreduce.user.classpath.first</name>
|
||||||
<value>true</value>
|
<value>true</value>
|
||||||
</property>
|
</property>
|
||||||
|
<property>
|
||||||
|
<name>oozie.launcher.mapreduce.map.java.opts</name>
|
||||||
|
<value>-Xmx4g</value>
|
||||||
|
</property>
|
||||||
</configuration>
|
</configuration>
|
|
@ -1,4 +1,4 @@
|
||||||
<workflow-app name="import Crossref from index into HDFS" xmlns="uri:oozie:workflow:0.5">
|
<workflow-app name="import Orcid" xmlns="uri:oozie:workflow:0.5">
|
||||||
<parameters>
|
<parameters>
|
||||||
<property>
|
<property>
|
||||||
<name>workingPath</name>
|
<name>workingPath</name>
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package eu.dnetlib.doiboost.orcid.xml;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
|
import eu.dnetlib.doiboost.orcid.model.AuthorData;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
public class XMLRecordParserTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOrcidXMLRecordParser() throws Exception {
|
||||||
|
|
||||||
|
String xml =
|
||||||
|
IOUtils.toString(
|
||||||
|
this.getClass().getResourceAsStream("summary_0000-0001-6828-479X.xml"));
|
||||||
|
|
||||||
|
XMLRecordParser p = new XMLRecordParser();
|
||||||
|
|
||||||
|
AuthorData authorData = p.VTDParse(xml.getBytes());
|
||||||
|
assertNotNull(authorData);
|
||||||
|
assertNotNull(authorData.getName());
|
||||||
|
System.out.println("name: " + authorData.getName());
|
||||||
|
assertNotNull(authorData.getSurname());
|
||||||
|
System.out.println("surname: " + authorData.getSurname());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOrcidXMLErrorRecordParser() throws Exception {
|
||||||
|
|
||||||
|
String xml = IOUtils.toString(this.getClass().getResourceAsStream("summary_error.xml"));
|
||||||
|
|
||||||
|
XMLRecordParser p = new XMLRecordParser();
|
||||||
|
|
||||||
|
AuthorData authorData = p.VTDParse(xml.getBytes());
|
||||||
|
assertNotNull(authorData);
|
||||||
|
assertNotNull(authorData.getErrorCode());
|
||||||
|
System.out.println("error: " + authorData.getErrorCode());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,71 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<record:record xmlns:address="http://www.orcid.org/ns/address"
|
||||||
|
xmlns:email="http://www.orcid.org/ns/email
|
||||||
|
" xmlns:history="http://www.orcid.org/ns/history"
|
||||||
|
xmlns:employment="http://www.orcid.org/ns/employment"
|
||||||
|
xmlns:education="http://www.orcid.org/ns/education"
|
||||||
|
xmlns:other-name="http://www.orcid.org/ns/other-name"
|
||||||
|
xmlns:deprecated="http://www.orcid.org/ns/deprecated"
|
||||||
|
xmlns:funding="http://www.orcid.org/ns/funding"
|
||||||
|
xmlns:research-resource="http://www.orcid.org/ns/research-resource"
|
||||||
|
xmlns:service="http://www.orcid.org/ns/service"
|
||||||
|
xmlns:researcher-url="http://www.orcid.org/ns/researcher-url"
|
||||||
|
xmlns:distinction="http://www.orcid.org/ns/distinction"
|
||||||
|
xmlns:internal="http://www.orcid.org/ns/internal"
|
||||||
|
xmlns:membership="http://www.orcid.org/ns/membership"
|
||||||
|
xmlns:person="http://www.orcid.org/ns/person"
|
||||||
|
xmlns:personal-details="http://www.orcid.org/ns/personal-details"
|
||||||
|
xmlns:bulk="http://www.orcid.org/ns/bulk" xmlns:common="http://www.orcid.org/ns/common"
|
||||||
|
xmlns:record="http://www.orcid.org/ns/record" xmlns:keyword="http://www.orcid.org/ns/keyword"
|
||||||
|
xmlns:activities="http://www.orcid.org/ns/activities"
|
||||||
|
xmlns:qualification="http://www.orcid.org/ns/qualification"
|
||||||
|
xmlns:external-identifier="http://www.orcid.org/ns/external-identifier"
|
||||||
|
xmlns:error="http://www.orcid.org/ns/error"
|
||||||
|
xmlns:preferences="http://www.orcid.org/ns/preferences"
|
||||||
|
xmlns:invited-position="http://www.orcid.org/ns/invited-position"
|
||||||
|
xmlns:work="http://www.orcid.org/ns/work"
|
||||||
|
xmlns:peer-review="http://www.orcid.org/ns/peer-review" path="/0000-0001-6828-479X">
|
||||||
|
<common:orcid-identifier>
|
||||||
|
<common:uri>https://orcid.org/0000-0001-6828-479X</common:uri>
|
||||||
|
<common:path>0000-0001-6828-479X</common:path>
|
||||||
|
<common:host>orcid.org</common:host>
|
||||||
|
</common:orcid-identifier>
|
||||||
|
<preferences:preferences>
|
||||||
|
<preferences:locale>en</preferences:locale>
|
||||||
|
</preferences:preferences>
|
||||||
|
<history:history>
|
||||||
|
<history:creation-method>Member-referred</history:creation-method>
|
||||||
|
<history:submission-date>2017-02-17T06:16:06.428Z</history:submission-date>
|
||||||
|
<common:last-modified-date>2017-10-04T04:38:43.529Z</common:last-modified-date>
|
||||||
|
<history:claimed>true</history:claimed>
|
||||||
|
<history:verified-email>true</history:verified-email>
|
||||||
|
<history:verified-primary-email>true</history:verified-primary-email>
|
||||||
|
</history:history>
|
||||||
|
<person:person path="/0000-0001-6828-479X/person">
|
||||||
|
<person:name visibility="public" path="0000-0001-6828-479X">
|
||||||
|
<common:created-date>2017-02-17T06:16:06.428Z</common:created-date>
|
||||||
|
<common:last-modified-date>2017-02-17T06:16:06.652Z</common:last-modified-date>
|
||||||
|
<personal-details:given-names>Masahide</personal-details:given-names>
|
||||||
|
<personal-details:family-name>Terazima</personal-details:family-name>
|
||||||
|
</person:name>
|
||||||
|
<other-name:other-names path="/0000-0001-6828-479X/other-names"/>
|
||||||
|
<researcher-url:researcher-urls path="/0000-0001-6828-479X/researcher-urls"/>
|
||||||
|
<email:emails path="/0000-0001-6828-479X/email"/>
|
||||||
|
<address:addresses path="/0000-0001-6828-479X/address"/>
|
||||||
|
<keyword:keywords path="/0000-0001-6828-479X/keywords"/>
|
||||||
|
<external-identifier:external-identifiers path="/0000-0001-6828-479X/external-identifiers"/>
|
||||||
|
</person:person>
|
||||||
|
<activities:activities-summary path="/0000-0001-6828-479X/activities">
|
||||||
|
<activities:distinctions path="/0000-0001-6828-479X/distinctions"/>
|
||||||
|
<activities:educations path="/0000-0001-6828-479X/educations"/>
|
||||||
|
<activities:employments path="/0000-0001-6828-479X/employments"/>
|
||||||
|
<activities:fundings path="/0000-0001-6828-479X/fundings"/>
|
||||||
|
<activities:invited-positions path="/0000-0001-6828-479X/invited-positions"/>
|
||||||
|
<activities:memberships path="/0000-0001-6828-479X/memberships"/>
|
||||||
|
<activities:peer-reviews path="/0000-0001-6828-479X/peer-reviews"/>
|
||||||
|
<activities:qualifications path="/0000-0001-6828-479X/qualifications"/>
|
||||||
|
<activities:research-resources path="/0000-0001-6828-479X/research-resources"/>
|
||||||
|
<activities:services path="/0000-0001-6828-479X/services"/>
|
||||||
|
<activities:works path="/0000-0001-6828-479X/works"/>
|
||||||
|
</activities:activities-summary>
|
||||||
|
</record:record>
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<error:error xmlns:address="http://www.orcid.org/ns/address"
|
||||||
|
xmlns:email="http://www.orcid.org/ns/email" xmlns:history="http://www.orcid.org/ns/history"
|
||||||
|
xmlns:employment="http://www.orcid.org/ns/employment"
|
||||||
|
xmlns:education="http://www.orcid.org/ns/education"
|
||||||
|
xmlns:other-name="http://www.orcid.org/ns/other-name"
|
||||||
|
xmlns:deprecated="http://www.orcid.org/ns/deprecated"
|
||||||
|
xmlns:funding="http://www.orcid.org/ns/funding"
|
||||||
|
xmlns:research-resource="http://www.orcid.org/ns/research-resource"
|
||||||
|
xmlns:service="http://www.orcid.org/ns/service"
|
||||||
|
xmlns:researcher-url="http://www.orcid.org/ns/researcher-url"
|
||||||
|
xmlns:distinction="http://www.orcid.org/ns/distinction"
|
||||||
|
xmlns:internal="http://www.orcid.org/ns/internal"
|
||||||
|
xmlns:membership="http://www.orcid.org/ns/membership"
|
||||||
|
xmlns:person="http://www.orcid.org/ns/person"
|
||||||
|
xmlns:personal-details="http://www.orcid.org/ns/personal-details"
|
||||||
|
xmlns:bulk="http://www.orcid.org/ns/bulk" xmlns:common="http://www.orcid.org/ns/common"
|
||||||
|
xmlns:record="http://www.orcid.org/ns/record" xmlns:keyword="http://www.orcid.org/ns/keyword"
|
||||||
|
xmlns:activities="http://www.orcid.org/ns/activities"
|
||||||
|
xmlns:qualification="http://www.orcid.org/ns/qualification"
|
||||||
|
xmlns:external-identifier="http://www.orcid.org/ns/external-identifier"
|
||||||
|
xmlns:error="http://www.orcid.org/ns/error"
|
||||||
|
xmlns:preferences="http://www.orcid.org/ns/preferences"
|
||||||
|
xmlns:invited-position="http://www.orcid.org/ns/invited-position"
|
||||||
|
xmlns:work="http://www.orcid.org/ns/work"
|
||||||
|
xmlns:peer-review="http://www.orcid.org/ns/peer-review">
|
||||||
|
<error:response-code>409</error:response-code>
|
||||||
|
<error:developer-message>409 Conflict: The ORCID record is locked and cannot be edited. ORCID
|
||||||
|
https://orcid.org/0000-0002-9716-679X</error:developer-message>
|
||||||
|
<error:user-message>The ORCID record is locked.</error:user-message>
|
||||||
|
<error:error-code>9018</error:error-code>
|
||||||
|
<error:more-info>https://members.orcid.org/api/resources/troubleshooting</error:more-info>
|
||||||
|
</error:error>
|
Loading…
Reference in New Issue