Commit 55790a3a authored by redmitry@list.ru's avatar redmitry@list.ru

parse "metadata" for publications

parent 9e738d16
......@@ -58,12 +58,17 @@ import es.bsc.inb.elixir.openebench.model.Tool;
import es.bsc.inb.elixir.openebench.model.ToolLinkType;
import es.bsc.inb.elixir.openebench.model.ToolType;
import es.bsc.inb.elixir.openebench.model.Topic;
import java.time.ZonedDateTime;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.json.JsonArray;
import javax.json.JsonNumber;
import javax.json.JsonObject;
import javax.json.JsonValue;
import javax.json.JsonValue.ValueType;
/**
* @author Dmitry Repchevsky
......@@ -383,10 +388,55 @@ public class BiotoolsConverter {
publication.setVersion(jpublication.getString("version", null));
final String type = jpublication.getString("type", null);
try {
publication.setType(PublicationType.fromValue(type));
} catch(IllegalArgumentException ex) {
Logger.getLogger(BiotoolsConverter.class.getName()).log(Level.INFO, "unrecognized publication type: {0}", type);
if (type != null) {
try {
publication.setType(PublicationType.fromValue(type));
} catch(IllegalArgumentException ex) {
Logger.getLogger(BiotoolsConverter.class.getName()).log(Level.INFO, "unrecognized publication type: {0}", type);
}
}
final JsonValue jmetadata_value = jpublication.get("metadata");
if (jmetadata_value != null && jmetadata_value.getValueType() == ValueType.OBJECT) {
final JsonObject jmetadata = jmetadata_value.asJsonObject();
final String title = jmetadata.getString("title", null);
final String abridge = jmetadata.getString("abstract", null);
final String journal = jmetadata.getString("journal", null);
publication.setTitle(title);
publication.setAbstract(abridge);
publication.setJournal(journal);
final String date = jmetadata.getString("date", null);
if (date != null) {
try {
final ZonedDateTime date_time = ZonedDateTime.parse(date);
publication.setYear(date_time.toLocalDate().toString());
} catch (DateTimeParseException ex) {
Logger.getLogger(BiotoolsConverter.class.getName()).log(Level.INFO, "invalid date format: {0}", date);
}
}
final JsonNumber cit_count = jmetadata.getJsonNumber("citationCount");
if (cit_count != null) {
publication.setCitationsCount(cit_count.intValue());
}
final JsonArray jauthors = jmetadata.getJsonArray("authors");
if (jauthors != null && jauthors.size() > 0) {
final List<String> authors = new ArrayList(jauthors.size());
publication.setAuthors(authors);
for (int j = 0, m = jauthors.size(); j < m; j++) {
final JsonObject jauthor = jauthors.getJsonObject(j);
if (jauthor != null) {
final String author = jauthor.getString("name", null);
if (author != null) {
authors.add(author);
}
}
}
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment