Added exporter for BibLaTeX format
This commit is contained in:
parent
436c117b8b
commit
9b8730f077
|
@ -29,3 +29,5 @@ replay_pid*
|
|||
/.project
|
||||
/exported-gcat-deposit.json
|
||||
/exported-zenodo-deposit.json
|
||||
/gcat.bib
|
||||
/gcat.json
|
||||
|
|
|
@ -1,167 +0,0 @@
|
|||
{
|
||||
"name" : "gcat",
|
||||
"short_description" : "gCube Catalogue (gCat) Service allows any client to publish on the gCube Catalogue.",
|
||||
"publish" : "NONE",
|
||||
"export" : "ALL",
|
||||
"default_files" : [ {
|
||||
"url" : "https://code-repo.d4science.org/gCubeSystem/{{name}}/archive/v{{version}}.zip",
|
||||
"desired_name" : "{{name}}-v{{version}}.zip"
|
||||
}, {
|
||||
"url" : "https://code-repo.d4science.org/gCubeSystem/{{name}}/archive/v{{version}}.tar.gz",
|
||||
"desired_name" : "{{name}}-v{{version}}.tar.gz"
|
||||
}, {
|
||||
"url" : "https://nexus.d4science.org/nexus/service/local/repo_groups/gcube-releases-all/content/org/gcube/data-publishing/{{name}}/{{version}}/{{name}}-{{version}}.war",
|
||||
"desired_name" : "{{name}}-v{{version}}.war"
|
||||
} ],
|
||||
"default_code_location" : "https://code-repo.d4science.org/gCubeSystem/{{name}}/releases/tag/v{{version}}",
|
||||
"code_location_text" : "\n\n<p>The official source code location of this software version is available at:</p>\n\n<p><a href=\"{{code_location}}\">{{code_location}}</a></p>",
|
||||
"versions" : [ {
|
||||
"version" : "1.0.0",
|
||||
"date" : "2019-01-10",
|
||||
"files" : [ {
|
||||
"url" : "https://nexus.d4science.org/nexus/service/local/repositories/gcube-snapshots/content/org/gcube/data-publishing/gcat/1.0.0-SNAPSHOT/gcat-1.0.0-20190109.172827-2.war",
|
||||
"desired_name" : "{{name}}-v{{version}}.war"
|
||||
} ],
|
||||
"gcube_release_version" : null,
|
||||
"gcube_release_ticket" : null,
|
||||
"code_location" : false,
|
||||
"concept_doi_url" : "https://doi.org/10.5072/zenodo.1139445",
|
||||
"doi_url" : "https://doi.org/10.5072/zenodo.1139446"
|
||||
}, {
|
||||
"version" : "1.1.0",
|
||||
"date" : "2019-02-26",
|
||||
"files" : [ {
|
||||
"url" : "https://nexus.d4science.org/nexus/service/local/repo_groups/gcube-releases-all/content/org/gcube/data-publishing/gcat/1.1.0-4.13.1-177071/gcat-1.1.0-4.13.1-177071-src.zip",
|
||||
"desired_name" : "{{name}}-v{{version}}.zip"
|
||||
}, {
|
||||
"url" : "https://nexus.d4science.org/nexus/service/local/repo_groups/gcube-releases-all/content/org/gcube/data-publishing/gcat/1.1.0-4.13.1-177071/gcat-1.1.0-4.13.1-177071.war",
|
||||
"desired_name" : "{{name}}-v{{version}}.war"
|
||||
} ],
|
||||
"gcube_release_version" : "4.13.1",
|
||||
"gcube_release_ticket" : "https://support.d4science.org/issues/12988",
|
||||
"code_location" : false,
|
||||
"concept_doi_url" : "https://doi.org/10.5072/zenodo.1139445",
|
||||
"doi_url" : "https://doi.org/10.5072/zenodo.1140461"
|
||||
}, {
|
||||
"version" : "1.2.0",
|
||||
"date" : "2019-05-20",
|
||||
"files" : [ {
|
||||
"url" : "https://nexus.d4science.org/nexus/service/local/repositories/gcube-snapshots/content/org/gcube/data-publishing/gcat/1.2.0-SNAPSHOT/gcat-1.2.0-20190520.132914-10.war",
|
||||
"desired_name" : "{{name}}-v{{version}}.war"
|
||||
} ],
|
||||
"gcube_release_version" : null,
|
||||
"gcube_release_ticket" : null,
|
||||
"code_location" : false,
|
||||
"concept_doi_url" : "https://doi.org/10.5072/zenodo.1139445",
|
||||
"doi_url" : "https://doi.org/10.5072/zenodo.1140750"
|
||||
}, {
|
||||
"version" : "1.3.0",
|
||||
"date" : "2019-06-27",
|
||||
"files" : [ {
|
||||
"url" : "https://nexus.d4science.org/nexus/service/local/repo_groups/gcube-releases-all/content/org/gcube/data-publishing/gcat/1.3.0-4.14.0-179505/gcat-1.3.0-4.14.0-179505-src.zip",
|
||||
"desired_name" : "{{name}}-v{{version}}.zip"
|
||||
}, {
|
||||
"url" : "https://nexus.d4science.org/nexus/service/local/repo_groups/gcube-releases-all/content/org/gcube/data-publishing/gcat/1.3.0-4.14.0-179505/gcat-1.3.0-4.14.0-179505.war",
|
||||
"desired_name" : "{{name}}-v{{version}}.war"
|
||||
} ],
|
||||
"gcube_release_version" : "4.14.0",
|
||||
"gcube_release_ticket" : "https://support.d4science.org/issues/16743",
|
||||
"code_location" : false,
|
||||
"concept_doi_url" : "https://doi.org/10.5072/zenodo.1139445",
|
||||
"doi_url" : "https://doi.org/10.5072/zenodo.1143572"
|
||||
}, {
|
||||
"version" : "1.4.0",
|
||||
"date" : "2019-11-20",
|
||||
"gcube_release_version" : "4.15.0",
|
||||
"gcube_release_ticket" : "https://support.d4science.org/issues/17294",
|
||||
"concept_doi_url" : "https://doi.org/10.5072/zenodo.1139445",
|
||||
"doi_url" : "https://doi.org/10.5072/zenodo.1143583"
|
||||
}, {
|
||||
"version" : "1.4.1",
|
||||
"date" : "2019-12-20",
|
||||
"gcube_release_version" : "4.18.0",
|
||||
"gcube_release_ticket" : "https://support.d4science.org/issues/18335",
|
||||
"concept_doi_url" : "https://doi.org/10.5072/zenodo.1139445",
|
||||
"doi_url" : "https://doi.org/10.5072/zenodo.1143585"
|
||||
}, {
|
||||
"version" : "1.4.2",
|
||||
"date" : "2020-02-14",
|
||||
"gcube_release_version" : "4.20.0",
|
||||
"gcube_release_ticket" : "https://support.d4science.org/issues/18507",
|
||||
"concept_doi_url" : "https://doi.org/10.5072/zenodo.1139445",
|
||||
"doi_url" : "https://doi.org/10.5072/zenodo.1143586"
|
||||
}, {
|
||||
"version" : "1.4.3",
|
||||
"date" : "2020-06-16",
|
||||
"gcube_release_version" : "4.23.0",
|
||||
"gcube_release_ticket" : "https://support.d4science.org/issues/19322",
|
||||
"concept_doi_url" : "https://doi.org/10.5072/zenodo.1139445",
|
||||
"doi_url" : "https://doi.org/10.5072/zenodo.1143587"
|
||||
}, {
|
||||
"version" : "1.4.4",
|
||||
"date" : "2021-02-24",
|
||||
"gcube_release_version" : "5.0.0",
|
||||
"gcube_release_ticket" : "https://support.d4science.org/issues/20648",
|
||||
"concept_doi_url" : "https://doi.org/10.5072/zenodo.1139445",
|
||||
"doi_url" : "https://doi.org/10.5072/zenodo.1143589"
|
||||
}, {
|
||||
"version" : "1.4.5",
|
||||
"date" : "2021-05-31",
|
||||
"gcube_release_version" : "5.1.0",
|
||||
"gcube_release_ticket" : "https://support.d4science.org/issues/20920",
|
||||
"concept_doi_url" : "https://doi.org/10.5072/zenodo.1139445",
|
||||
"doi_url" : "https://doi.org/10.5072/zenodo.1143590"
|
||||
} ],
|
||||
"metadata" : {
|
||||
"access_right" : "open",
|
||||
"creators" : [ {
|
||||
"affiliation" : "Istituto di Scienza e Tecnologie dell'Informazione \"A. Faedo\" - CNR, Italy",
|
||||
"name" : "Frosini, Luca",
|
||||
"orcid" : "0000-0003-3183-2291"
|
||||
} ],
|
||||
"description" : "<p><a href=\"https://www.gcube-system.org/\">gCube</a> Catalogue (gCat) Service allows any client to publish on the gCube Catalogue.</p>\n\n<p><a href=\"https://www.gcube-system.org/\">gCube</a> is an open-source software toolkit used for building and operating Hybrid Data Infrastructures enabling the dynamic deployment of Virtual Research Environments, such as the <a href=\"https://www.d4science.org/\">D4Science Infrastructure</a>, by favouring the realisation of reuse-oriented policies.</p>\n\n<p><a href=\"https://www.gcube-system.org/\">gCube</a> has been used to successfully build and operate infrastructures and virtual research environments for application domains ranging from biodiversity to environmental data management and cultural heritage.</p>\n\n<p><a href=\"https://www.gcube-system.org/\">gCube</a> offers components supporting typical data management workflows including data access, curation, processing, and visualisation on a large set of data typologies ranging from primary biodiversity data to geospatial and tabular data.</p>\n\n<p><a href=\"https://www.d4science.org/\">D4Science</a> is a Hybrid Data Infrastructure combining over 500 software components and integrating data from more than 50 different data providers into a coherent and managed system of hardware, software, and data resources. The D4Science infrastructure drastically reduces the cost of ownership, maintenance, and operation thanks to the exploitation of gCube.</p>\n\n<p> </p>",
|
||||
"grants" : [ {
|
||||
"id" : "283644"
|
||||
}, {
|
||||
"id" : "283465"
|
||||
}, {
|
||||
"id" : "10.13039/501100000780::675680"
|
||||
}, {
|
||||
"id" : "10.13039/501100000780::818194"
|
||||
}, {
|
||||
"id" : "10.13039/501100000780::654142"
|
||||
}, {
|
||||
"id" : "10.13039/501100000780::871042"
|
||||
}, {
|
||||
"id" : "10.13039/501100000780::823914"
|
||||
}, {
|
||||
"id" : "239019"
|
||||
}, {
|
||||
"id" : "288754"
|
||||
}, {
|
||||
"id" : "10.13039/501100000780::654182"
|
||||
}, {
|
||||
"id" : "10.13039/501100000780::857650"
|
||||
}, {
|
||||
"id" : "10.13039/501100000780::862409"
|
||||
}, {
|
||||
"id" : "10.13039/501100000780::731001"
|
||||
}, {
|
||||
"id" : "10.13039/501100000780::654119"
|
||||
}, {
|
||||
"id" : "212488"
|
||||
}, {
|
||||
"id" : "10.13039/501100000780::824091"
|
||||
}, {
|
||||
"id" : "10.13039/501100000780::727610"
|
||||
}, {
|
||||
"id" : "10.13039/501100000780::654024"
|
||||
} ],
|
||||
"keywords" : [ "gCube", "Catalogue", "D4Science" ],
|
||||
"license" : "EUPL-1.1",
|
||||
"publication_date" : "{{date}}",
|
||||
"title" : "gCube Catalogue (gCat) Service {{version}}",
|
||||
"upload_type" : "software",
|
||||
"version" : "{{version}}"
|
||||
}
|
||||
}
|
|
@ -19,8 +19,9 @@ public class SoftwareConceptAnalyser {
|
|||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SoftwareConceptAnalyser.class);
|
||||
|
||||
public static final String CONCEPT_FILENAME_EXTENSION = ".json";
|
||||
|
||||
protected ObjectMapper objectMapper;
|
||||
protected File jsonFile;
|
||||
|
||||
public SoftwareConceptAnalyser() {
|
||||
this.objectMapper = new ObjectMapper();
|
||||
|
@ -30,7 +31,6 @@ public class SoftwareConceptAnalyser {
|
|||
}
|
||||
|
||||
public void analyse(File jsonFile) throws Exception {
|
||||
this.jsonFile = jsonFile;
|
||||
SoftwareConcept deposition = objectMapper.readValue(jsonFile, SoftwareConcept.class);
|
||||
analyse(deposition);
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ public class SoftwareConceptAnalyser {
|
|||
String name = softwareConcept.getName();
|
||||
SoftwareVersion previous = null;
|
||||
|
||||
|
||||
List<SoftwareVersion> depositionVersions = softwareConcept.getDepositionVersions();
|
||||
for(int i=0; i<depositionVersions.size(); i++) {
|
||||
|
||||
|
@ -59,8 +60,9 @@ public class SoftwareConceptAnalyser {
|
|||
name, softwareVersion.getVersion(),
|
||||
softwareVersion.getPrevious()!=null ? softwareVersion.getPrevious().getVersion(): null);
|
||||
|
||||
SoftwareVersionAnalyser elaborateDeposition = new SoftwareVersionAnalyser(objectMapper, softwareVersion);
|
||||
elaborateDeposition.analyse();
|
||||
SoftwareVersionAnalyser softwareVersionAnalyser = new SoftwareVersionAnalyser(objectMapper, softwareVersion);
|
||||
softwareVersionAnalyser.setFirst(i==0);
|
||||
softwareVersionAnalyser.analyse();
|
||||
|
||||
previous = softwareVersion;
|
||||
|
||||
|
@ -68,12 +70,8 @@ public class SoftwareConceptAnalyser {
|
|||
}
|
||||
|
||||
logger.debug("{}", objectMapper.writeValueAsString(softwareConcept));
|
||||
if(jsonFile!=null) {
|
||||
// File directory = jsonFile.getParentFile();
|
||||
// File newJsonFile = new File(directory, "exported-"+jsonFile.getName());
|
||||
File newJsonFile = new File("exported-"+jsonFile.getName());
|
||||
objectMapper.writeValue(newJsonFile, softwareConcept);
|
||||
}
|
||||
File file = new File(name+CONCEPT_FILENAME_EXTENSION);
|
||||
objectMapper.writeValue(file, softwareConcept);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,12 +18,21 @@ public class SoftwareVersionAnalyser {
|
|||
|
||||
protected ObjectMapper objectMapper;
|
||||
protected SoftwareVersion softwareVersion;
|
||||
protected boolean first;
|
||||
|
||||
public SoftwareVersionAnalyser(ObjectMapper objectMapper, SoftwareVersion softwareVersion) {
|
||||
this.objectMapper = objectMapper;
|
||||
this.softwareVersion = softwareVersion;
|
||||
}
|
||||
|
||||
public boolean isFirst() {
|
||||
return first;
|
||||
}
|
||||
|
||||
public void setFirst(boolean first) {
|
||||
this.first = first;
|
||||
}
|
||||
|
||||
public void analyse() throws Exception {
|
||||
logger.debug("SoftwareVersion: {}", objectMapper.writeValueAsString(softwareVersion));
|
||||
|
||||
|
@ -31,18 +40,18 @@ public class SoftwareVersionAnalyser {
|
|||
for(SoftwareVersionPublisher svp: svps) {
|
||||
svp.setSoftwareVersion(softwareVersion);
|
||||
svp.setObjectMapper(objectMapper);
|
||||
svp.setFirst(first);
|
||||
svp.publish();
|
||||
}
|
||||
|
||||
|
||||
List<SoftwareVersionExporter> sves = SoftwareVersionExporter.getExporters();
|
||||
for(SoftwareVersionExporter sve: sves) {
|
||||
sve.setSoftwareVersion(softwareVersion);
|
||||
sve.setObjectMapper(objectMapper);
|
||||
sve.setFirst(first);
|
||||
sve.export();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
|||
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.TextNode;
|
||||
import org.gcube.common.software.utils.Utils;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
|
@ -354,16 +355,11 @@ public class SoftwareVersion {
|
|||
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
protected String replaceVariable(String variableName, String replace, String s) {
|
||||
return s.replaceAll("\\{\\{" + variableName + "\\}\\}", replace);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
protected String replaceVariables(String stringToAnalise) {
|
||||
String s = replaceVariable("name", softwareConcept.getName(), stringToAnalise);
|
||||
s = replaceVariable("version", version, s);
|
||||
s = replaceVariable("date", SoftwareVersion.getDateAsString(date), s);
|
||||
String s = Utils.replaceVariable("name", softwareConcept.getName(), stringToAnalise);
|
||||
s = Utils.replaceVariable("version", version, s);
|
||||
s = Utils.replaceVariable("date", SoftwareVersion.getDateAsString(date), s);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
@ -385,7 +381,7 @@ public class SoftwareVersion {
|
|||
|
||||
String codeLocationText = softwareConcept.getCodeLocationAdditionalDescription();
|
||||
codeLocationText = replaceVariables(codeLocationText);
|
||||
codeLocationText = replaceVariable("code_location", getCodeLocation().toString(), codeLocationText);
|
||||
codeLocationText = Utils.replaceVariable("code_location", getCodeLocation().toString(), codeLocationText);
|
||||
|
||||
stringWriter.append(codeLocationText);
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ public abstract class SoftwareVersionExporter {
|
|||
|
||||
protected SoftwareVersion softwareVersion;
|
||||
protected ObjectMapper objectMapper;
|
||||
protected boolean first;
|
||||
|
||||
public SoftwareVersion getSoftwareVersion() {
|
||||
return softwareVersion;
|
||||
|
@ -37,6 +38,14 @@ public abstract class SoftwareVersionExporter {
|
|||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
public boolean isFirst() {
|
||||
return first;
|
||||
}
|
||||
|
||||
public void setFirst(boolean first) {
|
||||
this.first = first;
|
||||
}
|
||||
|
||||
public abstract void export() throws Exception;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,18 @@
|
|||
package org.gcube.common.software.process.export.biblatex;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import org.gcube.common.software.model.SoftwareConcept;
|
||||
import org.gcube.common.software.model.SoftwareVersion;
|
||||
import org.gcube.common.software.process.export.SoftwareVersionExporter;
|
||||
import org.gcube.common.software.utils.FileUtils;
|
||||
import org.gcube.common.software.utils.Utils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -9,52 +20,148 @@ import org.slf4j.LoggerFactory;
|
|||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class BibLaTeXSoftwareVersionExporter extends SoftwareVersionExporter {
|
||||
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(BibLaTeXSoftwareVersionExporter.class);
|
||||
|
||||
|
||||
public static final String EXPORT_FILENAME_EXTENSION = ".bib";
|
||||
public static final String TEMPLATE_FILENAME = "biblatex.template";
|
||||
|
||||
public void export() throws Exception {
|
||||
SoftwareConcept softwareConcept = softwareVersion.getSoftwareConcept();
|
||||
String name = softwareConcept.getName();
|
||||
|
||||
switch (softwareConcept.getExport()) {
|
||||
case ALL:
|
||||
generate();
|
||||
break;
|
||||
|
||||
case UPDATE_ONLY:
|
||||
if(softwareVersion.isNewDeposition()) {
|
||||
logger.info("Skipping export for {} {}.",
|
||||
name, softwareVersion.getVersion());
|
||||
return;
|
||||
}
|
||||
generate();
|
||||
break;
|
||||
|
||||
case NEW:
|
||||
if(!softwareVersion.isNewDeposition()) {
|
||||
logger.info("Skipping export for {} {}.",
|
||||
name, softwareVersion.getVersion());
|
||||
return;
|
||||
}
|
||||
generate();
|
||||
break;
|
||||
|
||||
case NONE:
|
||||
default:
|
||||
logger.info("Skipping export for {} {}.",
|
||||
name, softwareVersion.getVersion());
|
||||
switch (softwareConcept.getExport()) {
|
||||
case ALL:
|
||||
generate();
|
||||
break;
|
||||
|
||||
case UPDATE_ONLY:
|
||||
if (softwareVersion.isNewDeposition()) {
|
||||
logger.info("Skipping export for {} {}.", name, softwareVersion.getVersion());
|
||||
return;
|
||||
}
|
||||
generate();
|
||||
break;
|
||||
|
||||
case NEW:
|
||||
if (!softwareVersion.isNewDeposition()) {
|
||||
logger.info("Skipping export for {} {}.", name, softwareVersion.getVersion());
|
||||
return;
|
||||
}
|
||||
generate();
|
||||
break;
|
||||
|
||||
case NONE:
|
||||
default:
|
||||
logger.info("Skipping export for {} {}.", name, softwareVersion.getVersion());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void generate() throws Exception {
|
||||
protected String getTemplate() throws Exception {
|
||||
File file = FileUtils.getFileFromFilename(TEMPLATE_FILENAME);
|
||||
byte[] bytes = Files.readAllBytes(file.toPath());
|
||||
String template = new String(bytes, StandardCharsets.UTF_8);
|
||||
return template;
|
||||
}
|
||||
|
||||
private String getCitationID() {
|
||||
SoftwareConcept softwareConcept = softwareVersion.getSoftwareConcept();
|
||||
String name = softwareConcept.getName().toLowerCase();
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append(name);
|
||||
stringBuffer.append("_");
|
||||
stringBuffer.append(softwareVersion.getVersion());
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
|
||||
private String getTitle(JsonNode metadata) {
|
||||
String title = metadata.get("title").asText();
|
||||
title = Utils.replaceVariable("version", softwareVersion.getVersion(), title);
|
||||
return title;
|
||||
}
|
||||
|
||||
private String getAuthors(JsonNode metadata) {
|
||||
ArrayNode arrayNode = (ArrayNode) metadata.get("creators");
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
int size = arrayNode.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
JsonNode jsonNode = arrayNode.get(i);
|
||||
stringBuffer.append("{");
|
||||
// Surname, Name
|
||||
String fullName = jsonNode.get("name").asText();
|
||||
|
||||
// Surname: nameParts[0]
|
||||
// Name: nameParts[1]
|
||||
String[] nameParts = fullName.split(",");
|
||||
stringBuffer.append(nameParts[1].trim());
|
||||
stringBuffer.append(" ");
|
||||
stringBuffer.append(nameParts[0].trim());
|
||||
|
||||
stringBuffer.append("}");
|
||||
if (i < (size - 1)) {
|
||||
stringBuffer.append(" and ");
|
||||
}
|
||||
}
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
|
||||
private String getKeywords(JsonNode metadata) {
|
||||
ArrayNode arrayNode = (ArrayNode) metadata.get("keywords");
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
int size = arrayNode.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
stringBuffer.append(arrayNode.get(i).asText());
|
||||
if (i < (size - 1)) {
|
||||
stringBuffer.append(", ");
|
||||
}
|
||||
}
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
|
||||
protected String parseTemplate(String template) {
|
||||
SoftwareConcept softwareConcept = softwareVersion.getSoftwareConcept();
|
||||
JsonNode metadata = softwareConcept.getMetadata();
|
||||
String s = Utils.replaceVariable("citation_id", getCitationID(), template);
|
||||
s = Utils.replaceVariable("title", getTitle(metadata), s);
|
||||
s = Utils.replaceVariable("doi", softwareVersion.getDOIURL().toString(), s);
|
||||
s = Utils.replaceVariable("short_description", softwareConcept.getShortDescription(), s);
|
||||
s = Utils.replaceVariable("version", softwareVersion.getVersion(), s);
|
||||
s = Utils.replaceVariable("author", getAuthors(metadata), s);
|
||||
s = Utils.replaceVariable("date", SoftwareVersion.getDateAsString(softwareVersion.getDate()), s);
|
||||
s = Utils.replaceVariable("keywords", getKeywords(metadata), s);
|
||||
return s;
|
||||
}
|
||||
|
||||
protected void generate() throws Exception {
|
||||
SoftwareConcept softwareConcept = softwareVersion.getSoftwareConcept();
|
||||
String name = softwareConcept.getName();
|
||||
logger.info("Going to export in BibLaTex format {} {}.",
|
||||
name, softwareVersion.getVersion());
|
||||
logger.info("Going to export {} {} in BibLaTex format.", name, softwareVersion.getVersion());
|
||||
|
||||
String template = getTemplate();
|
||||
String toBeExported = parseTemplate(template);
|
||||
|
||||
File exportFile = getExportFile();
|
||||
if (first && exportFile.exists()) {
|
||||
exportFile.delete();
|
||||
}
|
||||
|
||||
// TODO
|
||||
if (!exportFile.exists()) {
|
||||
exportFile.createNewFile();
|
||||
}
|
||||
|
||||
FileWriter fileWritter = new FileWriter(exportFile, true);
|
||||
BufferedWriter bw = new BufferedWriter(fileWritter);
|
||||
bw.write(toBeExported);
|
||||
bw.write("\n\n");
|
||||
bw.close();
|
||||
}
|
||||
|
||||
|
||||
protected File getExportFile() {
|
||||
String name = softwareVersion.getSoftwareConcept().getName();
|
||||
File file = new File(name + EXPORT_FILENAME_EXTENSION);
|
||||
return file;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ public abstract class SoftwareVersionPublisher {
|
|||
|
||||
protected SoftwareVersion softwareVersion;
|
||||
protected ObjectMapper objectMapper;
|
||||
protected boolean first;
|
||||
|
||||
public SoftwareVersion getSoftwareVersion() {
|
||||
return softwareVersion;
|
||||
|
@ -37,6 +38,14 @@ public abstract class SoftwareVersionPublisher {
|
|||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
public boolean isFirst() {
|
||||
return first;
|
||||
}
|
||||
|
||||
public void setFirst(boolean first) {
|
||||
this.first = first;
|
||||
}
|
||||
|
||||
public abstract void publish() throws Exception;
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package org.gcube.common.software.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
|
||||
import org.gcube.common.software.process.export.biblatex.BibLaTeXSoftwareVersionExporter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class FileUtils {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(FileUtils.class);
|
||||
|
||||
public static File getFileFromFilename(String fileName) throws Exception {
|
||||
URL jsonFileURL = BibLaTeXSoftwareVersionExporter.class.getClassLoader().getResource(fileName);
|
||||
File file = new File(jsonFileURL.toURI());
|
||||
logger.trace("File is {}", file.getAbsolutePath());
|
||||
return file;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package org.gcube.common.software.utils;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class Utils {
|
||||
|
||||
public static String replaceVariable(String variableName, String replace, String s) {
|
||||
return s.replaceAll("\\{\\{" + variableName + "\\}\\}", replace);
|
||||
}
|
||||
}
|
|
@ -1,10 +1,9 @@
|
|||
@software{{{citation_id}},
|
||||
title = {{title}},
|
||||
url = {{doi}},
|
||||
abstract = {{short_description}},
|
||||
version = {{version}},
|
||||
author = {{author}},
|
||||
date = {{date}},
|
||||
note = {{}},
|
||||
keywords = {{keywords}},
|
||||
title = {{{title}}},
|
||||
url = {{{doi}}},
|
||||
abstract = {{{short_description}}},
|
||||
version = {{{version}}},
|
||||
author = {{{author}}},
|
||||
date = {{{date}}},
|
||||
keywords = {{{keywords}}},
|
||||
}
|
|
@ -1,32 +1,22 @@
|
|||
package org.gcube.common.software.analyser;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
|
||||
import org.gcube.common.software.utils.FileUtils;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class SoftwareConceptAnalyserTest {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SoftwareConceptAnalyserTest.class);
|
||||
|
||||
protected static final String CONCEPT_FILENAME = "gcat.json";
|
||||
|
||||
public File getConceptFile() throws Exception {
|
||||
URL jsonFileURL = SoftwareConceptAnalyserTest.class.getClassLoader().getResource(CONCEPT_FILENAME);
|
||||
File jsonFile = new File(jsonFileURL.toURI());
|
||||
logger.debug("JSON Concept File is {}", jsonFile.getAbsolutePath());
|
||||
return jsonFile;
|
||||
}
|
||||
public static final String CONCEPT_FILENAME = "gcat.json";
|
||||
|
||||
@Test
|
||||
public void testUsingTestFile() throws Exception {
|
||||
SoftwareConceptAnalyser zenodoDeposit = new SoftwareConceptAnalyser();
|
||||
zenodoDeposit.analyse(getConceptFile());
|
||||
File file = FileUtils.getFileFromFilename(CONCEPT_FILENAME);
|
||||
zenodoDeposit.analyse(file);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue