Implementing solution

This commit is contained in:
Luca Frosini 2023-01-02 17:54:58 +01:00
parent b96575f603
commit bf7418b9be
10 changed files with 644 additions and 27 deletions

13
pom.xml
View File

@ -52,5 +52,18 @@
<artifactId>gxHTTP</artifactId>
</dependency>
<!-- Test libraries -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,42 @@
package org.gcube.common.zenodo;
import java.net.MalformedURLException;
import java.net.URL;
import org.gcube.com.fasterxml.jackson.annotation.JsonProperty;
import org.gcube.com.fasterxml.jackson.annotation.JsonSetter;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class DepositionFile {
@JsonProperty(value="url")
protected URL url;
@JsonProperty(value="desired_name")
protected String desiredName;
public URL getUrl() {
return url;
}
public void setURL(URL url) {
this.url = url;
}
@JsonSetter(value="url")
public void setURL(String url) throws MalformedURLException {
this.url = new URL(url);
}
public String getDesiredName() {
return desiredName;
}
public void setDesiredName(String desiredName) {
this.desiredName = desiredName;
}
}

View File

@ -0,0 +1,151 @@
package org.gcube.common.zenodo;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonProperty;
import org.gcube.com.fasterxml.jackson.annotation.JsonSetter;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class DepositionVersion {
@JsonIgnore
protected ZenodoDeposition zenodoDeposition;
@JsonIgnore
protected DepositionVersion previous;
@JsonProperty(value = "version")
protected String version;
@JsonProperty(value = "date")
protected String date;
@JsonProperty(value = "files")
protected List<DepositionFile> files;
@JsonProperty(value = "gcube_release_version")
protected String gCubeReleaseVersion;
@JsonProperty(value = "release_ticket")
protected URL releaseTicket;
protected Boolean noCodeLocation;
@JsonProperty(value = "code_location")
protected URL codeLocation;
@JsonProperty(value = "doi_url")
protected URL doiURL;
public DepositionVersion() {
this.noCodeLocation = false;
}
@JsonIgnore
public ZenodoDeposition getZenodoDeposition() {
return zenodoDeposition;
}
@JsonIgnore
public void setZenodoDeposition(ZenodoDeposition zenodoDeposition) {
this.zenodoDeposition = zenodoDeposition;
}
@JsonIgnore
public DepositionVersion getPrevious() {
return previous;
}
@JsonIgnore
public void setPrevious(DepositionVersion previous) {
this.previous = previous;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public List<DepositionFile> getFiles() {
return files;
}
public String getgCubeReleaseVersion() {
return gCubeReleaseVersion;
}
public void setgCubeReleaseVersion(String gCubeReleaseVersion) {
this.gCubeReleaseVersion = gCubeReleaseVersion;
}
public URL getReleaseTicket() {
return releaseTicket;
}
public void setReleaseTicket(URL releaseTicket) {
this.releaseTicket = releaseTicket;
}
public Boolean getNoCodeLocation() {
return noCodeLocation;
}
public void setNoCodeLocation(Boolean noCodeLocation) {
this.noCodeLocation = noCodeLocation;
}
public URL getCodeLocation() {
return codeLocation;
}
public void setCodeLocation(URL codeLocation) {
this.codeLocation = codeLocation;
}
@JsonSetter("code_location")
public void setCodeLocation(String codeLocation) {
try {
if(codeLocation==null) {
this.noCodeLocation = true;
}
this.codeLocation = new URL(codeLocation);
}catch (Exception e) {
this.codeLocation = null;
}
}
public URL getDOIURL() {
return doiURL;
}
public void setDOIURL(URL doiURL) {
this.doiURL = doiURL;
}
@JsonSetter("doi-url")
public void setDOIURL(String doiURL) throws MalformedURLException {
try {
this.doiURL = new URL(doiURL);
}catch (Exception e) {
this.doiURL = null;
}
}
}

View File

@ -0,0 +1,49 @@
package org.gcube.common.zenodo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class ElaborateDeposition {
private static final Logger logger = LoggerFactory.getLogger(ElaborateZenodoDeposit.class);
protected DepositionVersion depositionVersion;
public ElaborateDeposition(DepositionVersion depositionVersion) {
this.depositionVersion = depositionVersion;
}
public void elaborate() {
String name = depositionVersion.getZenodoDeposition().getName();
if(depositionVersion.getDOIURL()!=null) {
logger.debug("{} {} already deposited (previous version is {}).",
name , depositionVersion.getVersion(),
depositionVersion.getPrevious()!=null ? depositionVersion.getPrevious().getVersion(): null);
}else {
logger.debug("Going to deposit {} {} (previous version is {})",
name , depositionVersion.getVersion(),
depositionVersion.getPrevious()!=null ? depositionVersion.getPrevious().getVersion(): null);
if(depositionVersion.getPrevious()==null) {
// TODO New deposit on Zenodo
}else {
// TODO New version on Zenodo from previous using the id in the DOI
// TODO Remove previous files
}
// TODO Add files
// TODO Update deposit metadata
// TODO Publish the version
// Save content
}
}
}

View File

@ -0,0 +1,58 @@
package org.gcube.common.zenodo;
import java.io.File;
import java.net.URL;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class ElaborateZenodoDeposit {
private static final Logger logger = LoggerFactory.getLogger(ElaborateZenodoDeposit.class);
protected ObjectMapper objectMapper;
protected URL baseURL;
protected String accessToken;
public ElaborateZenodoDeposit(URL baseURL, String accessToken) {
this.objectMapper = new ObjectMapper();
this.baseURL = baseURL;
this.accessToken = accessToken;
}
public void publish(File jsonFile) throws Exception {
ZenodoDeposition zenodoDeposition = objectMapper.readValue(jsonFile, ZenodoDeposition.class);
publish(zenodoDeposition);
}
public void publish(String json) throws Exception {
ZenodoDeposition zenodoDeposition = objectMapper.readValue(json, ZenodoDeposition.class);
publish(zenodoDeposition);
}
public void publish(ZenodoDeposition zenodoDeposition) throws Exception {
String name = zenodoDeposition.getName();
DepositionVersion previous = null;
for(DepositionVersion depositionVersion : zenodoDeposition.getDepositionVersions()) {
depositionVersion.setZenodoDeposition(zenodoDeposition);
depositionVersion.setPrevious(previous);
logger.debug("Going to elaborate {} {}, previous version {}",
name, depositionVersion.getVersion(),
depositionVersion.getPrevious()!=null ? depositionVersion.getPrevious().getVersion(): null);
ElaborateDeposition elaborateDeposition = new ElaborateDeposition(depositionVersion);
elaborateDeposition.elaborate();
previous = depositionVersion;
}
}
}

View File

@ -1,27 +0,0 @@
package org.gcube.common.zenodo;
import java.io.File;
import java.net.URL;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class ZenodoDeposit {
protected URL baseURL;
protected String accessToken;
public ZenodoDeposit(URL baseURL, String accessToken) {
this.baseURL = baseURL;
this.accessToken = accessToken;
}
public String publish(File jsonFile) {
return null;
}
public String publish(String json) {
return null;
}
}

View File

@ -0,0 +1,83 @@
package org.gcube.common.zenodo;
import java.util.List;
import org.gcube.com.fasterxml.jackson.annotation.JsonProperty;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class ZenodoDeposition {
@JsonProperty(value = "name")
protected String name;
@JsonProperty(value = "default_files")
protected List<DepositionFile> defaultFiles;
@JsonProperty(value = "default_code_location")
protected String defaultCodeLocation;
@JsonProperty(value = "code_location_text")
protected String codeLocationAdditionalDescription;
@JsonProperty(value = "versions")
protected List<DepositionVersion> depositionVersions;
@JsonProperty(value = "metadata")
protected JsonNode metadata;
public static String parseRawString(String rawString, String name, String version, String date) {
String s = rawString.replaceAll("{{name}}", name);
s = s.replaceAll("{{version}}", version);
s = s.replaceAll("{{date}}", date);
return s;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<DepositionFile> getDefaultFiles() {
return defaultFiles;
}
public void setDefaultFiles(List<DepositionFile> defaultFiles) {
this.defaultFiles = defaultFiles;
}
public String getDefaultCodeLocation() {
return defaultCodeLocation;
}
public void setDefaultCodeLocation(String defaultCodeLocation) {
this.defaultCodeLocation= defaultCodeLocation;
}
public String getCodeLocationAdditionalDescription() {
return codeLocationAdditionalDescription;
}
public void setCodeLocationAdditionalDescription(String codeLocationAdditionalDescription) {
this.codeLocationAdditionalDescription = codeLocationAdditionalDescription;
}
public List<DepositionVersion> getDepositionVersions() {
return depositionVersions;
}
public JsonNode getMetadata() {
return metadata;
}
public void setMetadata(JsonNode metadata) {
this.metadata = metadata;
}
}

View File

@ -0,0 +1,47 @@
package org.gcube.common.zenodo;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Properties;
import org.junit.Test;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class ZenodoDepositTest {
protected static Properties properties;
protected static final String PROPERTIES_FILENAME = "zenodo.properties";
protected static final String ZENODO_DEPOSIT_JSON_FILENAME = "zenodo-deposit.json";
static {
properties = new Properties();
InputStream input = ZenodoDepositTest.class.getClassLoader().getResourceAsStream(PROPERTIES_FILENAME);
try {
// load the properties file
properties.load(input);
} catch(IOException e) {
throw new RuntimeException(e);
}
}
public File getZenodoDepositFile() throws Exception {
URL jsonFileURL = ZenodoDepositTest.class.getClassLoader().getResource(ZENODO_DEPOSIT_JSON_FILENAME);
File jsonFile = new File(jsonFileURL.toURI());
return jsonFile;
}
@Test
public void testUsingTestFile() throws Exception {
URL zenodoBaseURL = new URL(properties.getProperty("zenodo_base_url"));
String accessToken = properties.getProperty("zenodo_access_token");
ElaborateZenodoDeposit zenodoDeposit = new ElaborateZenodoDeposit(zenodoBaseURL, accessToken);
zenodoDeposit.publish(getZenodoDepositFile());
}
}

View File

@ -1 +1,2 @@
/config.properties
/zenodo.properties

View File

@ -0,0 +1,200 @@
{
"name": "gcat",
"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=\"{{default_code_location}}\">{{default_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"
}
],
"release_ticket": null,
"code_location": null,
"doi_url": "https://doi.org/10.5072/zenodo.1139446"
},
{
"version": "1.1.0",
"date": "2019-02-26",
"gcube_release_version": "4.13.1",
"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"
}
],
"release_ticket": "https://support.d4science.org/issues/12988",
"code_location": null,
"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"
}
],
"release_ticket": null,
"code_location": null,
"doi_url": "https://doi.org/10.5072/zenodo.1140750"
},
{
"version": "1.3.0",
"date": "2019-06-27",
"gcube_release_version": "4.14.0",
"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"
}
],
"release_ticket": "https://support.d4science.org/issues/16743",
"code_location": null
},
{
"version": "1.4.0",
"date": "2019-11-20",
"gcube_release_version": "4.15.0",
"release_ticket": "https://support.d4science.org/issues/17294"
},
{
"version": "1.4.1",
"date": "2019-12-20",
"gcube_release_version": "4.18.0",
"release_ticket": "https://support.d4science.org/issues/18335"
},
{
"version": "1.4.2",
"date": "2020-02-14",
"gcube_release_version": "4.20.0",
"release_ticket": "https://support.d4science.org/issues/18507"
},
{
"version": "1.4.3",
"date": "2020-06-16",
"gcube_release_version": "4.23.0",
"release_ticket": "https://support.d4science.org/issues/19322"
},
{
"version": "1.4.4",
"date": "2021-02-24",
"gcube_release_version": "5.0.0",
"release_ticket": "https://support.d4science.org/issues/20648"
},
{
"version": "1.4.5",
"date": "2021-05-31",
"gcube_release_version": "5.1.0",
"release_ticket": "https://support.d4science.org/issues/20920"
}
],
"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>&nbsp;</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}}"
}
}