Refactored code
This commit is contained in:
parent
28c12f8436
commit
68d82b5774
10
README.md
10
README.md
|
@ -1,6 +1,10 @@
|
|||
# gCube Catalogue (gCat) API
|
||||
# gCube Software Versions Processor
|
||||
|
||||
gCube Software Versions Processor is a software which help to process software versions to made actions such as:
|
||||
|
||||
* publish the software to obtain a DOI (e.g. deposit on Zenodo);
|
||||
* export the citations (e.g. in BibLaTex format)
|
||||
|
||||
gCube Catalogue (gCat) API is a library containing classes shared across gcat* components
|
||||
|
||||
## Built With
|
||||
|
||||
|
@ -26,7 +30,7 @@ Tell people how to cite this software.
|
|||
|
||||
|
||||
@software{,
|
||||
title = {Software Deposit},
|
||||
title = {Software Versions Processor},
|
||||
author = {Frosini, Luca},
|
||||
organization = {ISTI - CNR},
|
||||
address = {Pisa, Italy},
|
||||
|
|
10
pom.xml
10
pom.xml
|
@ -6,7 +6,7 @@
|
|||
<version>1.1.0</version>
|
||||
</parent>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>software-deposit</artifactId>
|
||||
<artifactId>software-versions-processor</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<name>Zenodo Deposit</name>
|
||||
<properties>
|
||||
|
@ -65,14 +65,6 @@
|
|||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-multipart</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
-->
|
||||
|
||||
<!-- Test libraries -->
|
||||
<dependency>
|
||||
|
|
|
@ -1,79 +0,0 @@
|
|||
package org.gcube.common.deposition;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.gcube.com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import org.gcube.common.deposition.model.Deposition;
|
||||
import org.gcube.common.deposition.model.DepositionVersion;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class ElaborateDeposition {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ElaborateDeposition.class);
|
||||
|
||||
protected ObjectMapper objectMapper;
|
||||
protected File jsonFile;
|
||||
|
||||
public ElaborateDeposition() {
|
||||
this.objectMapper = new ObjectMapper();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(DepositionVersion.DATETIME_PATTERN);
|
||||
this.objectMapper.setDateFormat(sdf);
|
||||
this.objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
|
||||
}
|
||||
|
||||
public void publish(File jsonFile) throws Exception {
|
||||
this.jsonFile = jsonFile;
|
||||
Deposition deposition = objectMapper.readValue(jsonFile, Deposition.class);
|
||||
publish(deposition);
|
||||
}
|
||||
|
||||
public void publish(String json) throws Exception {
|
||||
Deposition deposition = objectMapper.readValue(json, Deposition.class);
|
||||
publish(deposition);
|
||||
}
|
||||
|
||||
public void publish(Deposition deposition) throws Exception {
|
||||
String name = deposition.getName();
|
||||
DepositionVersion previous = null;
|
||||
|
||||
List<DepositionVersion> depositionVersions = deposition.getDepositionVersions();
|
||||
for(int i=0; i<depositionVersions.size(); i++) {
|
||||
|
||||
DepositionVersion depositionVersion = depositionVersions.get(i);
|
||||
|
||||
depositionVersion.setDeposition(deposition);
|
||||
depositionVersion.setPrevious(previous);
|
||||
if((i+1)<depositionVersions.size()) {
|
||||
depositionVersion.setNext(depositionVersions.get(i+1));
|
||||
}
|
||||
|
||||
logger.trace("Going to elaborate {} {} (previous version {})",
|
||||
name, depositionVersion.getVersion(),
|
||||
depositionVersion.getPrevious()!=null ? depositionVersion.getPrevious().getVersion(): null);
|
||||
|
||||
ElaborateDepositionVersion elaborateDeposition = new ElaborateDepositionVersion(objectMapper, depositionVersion);
|
||||
elaborateDeposition.elaborate();
|
||||
|
||||
previous = depositionVersion;
|
||||
|
||||
Thread.sleep(TimeUnit.SECONDS.toMillis(1));
|
||||
}
|
||||
|
||||
logger.debug("{}", objectMapper.writeValueAsString(deposition));
|
||||
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, deposition);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package org.gcube.common.deposition;
|
||||
|
||||
public class ElaborateDepositionFile {
|
||||
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package org.gcube.common.deposition;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.gcube.common.deposition.executor.DepositionVersionExecutor;
|
||||
import org.gcube.common.deposition.model.DepositionVersion;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class ElaborateDepositionVersion {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ElaborateDeposition.class);
|
||||
|
||||
protected ObjectMapper objectMapper;
|
||||
protected DepositionVersion depositionVersion;
|
||||
|
||||
public ElaborateDepositionVersion(ObjectMapper objectMapper, DepositionVersion depositionVersion) {
|
||||
this.objectMapper = objectMapper;
|
||||
this.depositionVersion = depositionVersion;
|
||||
}
|
||||
|
||||
public void elaborate() throws Exception {
|
||||
logger.debug("DepositionVersion: {}", objectMapper.writeValueAsString(depositionVersion));
|
||||
|
||||
DepositionVersionExecutor dve = DepositionVersionExecutor.getDefaultExecutor();
|
||||
dve.setDepositionVersion(depositionVersion);
|
||||
dve.setObjectMapper(objectMapper);
|
||||
dve.deposit();
|
||||
|
||||
// TODO Export bibtext
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
package org.gcube.common.deposition.executor;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.gcube.common.deposition.executor.zenodo.ZenodoDepositionVersionExecutor;
|
||||
import org.gcube.common.deposition.model.Deposition;
|
||||
import org.gcube.common.deposition.model.DepositionVersion;
|
||||
import org.gcube.common.deposition.model.Elaborate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public abstract class DepositionVersionExecutor {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DepositionVersionExecutor.class);
|
||||
|
||||
public static DepositionVersionExecutor getDefaultExecutor() {
|
||||
return new ZenodoDepositionVersionExecutor();
|
||||
}
|
||||
|
||||
protected DepositionVersion depositionVersion;
|
||||
protected ObjectMapper objectMapper;
|
||||
|
||||
public DepositionVersion getDepositionVersion() {
|
||||
return depositionVersion;
|
||||
}
|
||||
|
||||
public void setDepositionVersion(DepositionVersion depositionVersion) {
|
||||
this.depositionVersion = depositionVersion;
|
||||
}
|
||||
|
||||
public ObjectMapper getObjectMapper() {
|
||||
return objectMapper;
|
||||
}
|
||||
|
||||
public void setObjectMapper(ObjectMapper objectMapper) {
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
public void deposit() throws Exception {
|
||||
Deposition deposition = depositionVersion.getDeposition();
|
||||
String name = deposition.getName();
|
||||
|
||||
if(deposition.getDeposit()==Elaborate.NONE) {
|
||||
logger.info("Deposit is disabled for deposition {} {}.",
|
||||
name , depositionVersion.getVersion());
|
||||
return;
|
||||
}
|
||||
|
||||
if(depositionVersion.getDOIURL()!=null) {
|
||||
|
||||
depositionVersion.setNewDeposition(false);
|
||||
|
||||
if(deposition.getDeposit()==Elaborate.ALL || deposition.getDeposit()==Elaborate.UPDATE_ONLY) {
|
||||
logger.info("Going to update deposition {} {}.",
|
||||
name , depositionVersion.getVersion());
|
||||
update();
|
||||
}else {
|
||||
logger.info("Deposition {} {} has been already deposited.",
|
||||
name , depositionVersion.getVersion());
|
||||
}
|
||||
|
||||
}else {
|
||||
if(deposition.getDeposit()==Elaborate.ALL || deposition.getDeposit()==Elaborate.NEW) {
|
||||
logger.info("Going to deposit {} {}",
|
||||
name , depositionVersion.getVersion());
|
||||
|
||||
depositionVersion.setNewDeposition(true);
|
||||
if(depositionVersion.getConceptDOIURL()==null) {
|
||||
create();
|
||||
}else {
|
||||
newVersion();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void create() throws Exception;
|
||||
|
||||
public abstract void update() throws Exception;
|
||||
|
||||
public abstract void newVersion() throws Exception;
|
||||
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package org.gcube.common.deposition.exporter;
|
||||
|
||||
import org.gcube.common.deposition.model.DepositionVersion;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public abstract class DepositionVersionExporter {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DepositionVersionExporter.class);
|
||||
|
||||
|
||||
|
||||
protected DepositionVersion depositionVersion;
|
||||
|
||||
public DepositionVersion getDepositionVersion() {
|
||||
return depositionVersion;
|
||||
}
|
||||
|
||||
public void setDepositionVersion(DepositionVersion depositionVersion) {
|
||||
this.depositionVersion = depositionVersion;
|
||||
}
|
||||
|
||||
public abstract void export() throws Exception;
|
||||
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
package org.gcube.common.software.analyser;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.gcube.com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import org.gcube.common.software.model.SoftwareConcept;
|
||||
import org.gcube.common.software.model.SoftwareVersion;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class SoftwareConceptAnalyser {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SoftwareConceptAnalyser.class);
|
||||
|
||||
protected ObjectMapper objectMapper;
|
||||
protected File jsonFile;
|
||||
|
||||
public SoftwareConceptAnalyser() {
|
||||
this.objectMapper = new ObjectMapper();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(SoftwareVersion.DATETIME_PATTERN);
|
||||
this.objectMapper.setDateFormat(sdf);
|
||||
this.objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
|
||||
}
|
||||
|
||||
public void analyse(File jsonFile) throws Exception {
|
||||
this.jsonFile = jsonFile;
|
||||
SoftwareConcept deposition = objectMapper.readValue(jsonFile, SoftwareConcept.class);
|
||||
analyse(deposition);
|
||||
}
|
||||
|
||||
public void analyse(String json) throws Exception {
|
||||
SoftwareConcept deposition = objectMapper.readValue(json, SoftwareConcept.class);
|
||||
analyse(deposition);
|
||||
}
|
||||
|
||||
public void analyse(SoftwareConcept softwareConcept) throws Exception {
|
||||
String name = softwareConcept.getName();
|
||||
SoftwareVersion previous = null;
|
||||
|
||||
List<SoftwareVersion> depositionVersions = softwareConcept.getDepositionVersions();
|
||||
for(int i=0; i<depositionVersions.size(); i++) {
|
||||
|
||||
SoftwareVersion softwareVersion = depositionVersions.get(i);
|
||||
|
||||
softwareVersion.setSoftwareConcept(softwareConcept);
|
||||
softwareVersion.setPrevious(previous);
|
||||
if((i+1)<depositionVersions.size()) {
|
||||
softwareVersion.setNext(depositionVersions.get(i+1));
|
||||
}
|
||||
|
||||
logger.trace("Going to process {} {} (previous version {})",
|
||||
name, softwareVersion.getVersion(),
|
||||
softwareVersion.getPrevious()!=null ? softwareVersion.getPrevious().getVersion(): null);
|
||||
|
||||
SoftwareVersionAnalyser elaborateDeposition = new SoftwareVersionAnalyser(objectMapper, softwareVersion);
|
||||
elaborateDeposition.analyse();
|
||||
|
||||
previous = softwareVersion;
|
||||
|
||||
Thread.sleep(TimeUnit.SECONDS.toMillis(1));
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package org.gcube.common.software.analyser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.gcube.common.software.export.SoftwareVersionExporter;
|
||||
import org.gcube.common.software.model.SoftwareVersion;
|
||||
import org.gcube.common.software.publish.SoftwareVersionPublisher;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class SoftwareVersionAnalyser {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SoftwareConceptAnalyser.class);
|
||||
|
||||
protected ObjectMapper objectMapper;
|
||||
protected SoftwareVersion softwareVersion;
|
||||
|
||||
public SoftwareVersionAnalyser(ObjectMapper objectMapper, SoftwareVersion softwareVersion) {
|
||||
this.objectMapper = objectMapper;
|
||||
this.softwareVersion = softwareVersion;
|
||||
}
|
||||
|
||||
public void analyse() throws Exception {
|
||||
logger.debug("SoftwareVersion: {}", objectMapper.writeValueAsString(softwareVersion));
|
||||
|
||||
List<SoftwareVersionPublisher> svps = SoftwareVersionPublisher.getPublishers();
|
||||
for(SoftwareVersionPublisher svp: svps) {
|
||||
svp.setSoftwareVersion(softwareVersion);
|
||||
svp.setObjectMapper(objectMapper);
|
||||
svp.publish();
|
||||
}
|
||||
|
||||
|
||||
List<SoftwareVersionExporter> sves = SoftwareVersionExporter.getExporters();
|
||||
for(SoftwareVersionExporter sve: sves) {
|
||||
sve.setSoftwareVersion(softwareVersion);
|
||||
sve.setObjectMapper(objectMapper);
|
||||
sve.export();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.common.deposition.config;
|
||||
package org.gcube.common.software.config;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
|
@ -0,0 +1,77 @@
|
|||
package org.gcube.common.software.export;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.gcube.common.software.model.ElaborationType;
|
||||
import org.gcube.common.software.model.SoftwareConcept;
|
||||
import org.gcube.common.software.model.SoftwareVersion;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public abstract class SoftwareVersionExporter {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SoftwareVersionExporter.class);
|
||||
|
||||
public static List<SoftwareVersionExporter> getExporters() {
|
||||
List<SoftwareVersionExporter> sves = new ArrayList<>();
|
||||
return sves;
|
||||
}
|
||||
|
||||
|
||||
protected SoftwareVersion softwareVersion;
|
||||
protected ObjectMapper objectMapper;
|
||||
|
||||
public SoftwareVersion getSoftwareVersion() {
|
||||
return softwareVersion;
|
||||
}
|
||||
|
||||
public void setSoftwareVersion(SoftwareVersion softwareVersion) {
|
||||
this.softwareVersion = softwareVersion;
|
||||
}
|
||||
|
||||
public ObjectMapper getObjectMapper() {
|
||||
return objectMapper;
|
||||
}
|
||||
|
||||
public void setObjectMapper(ObjectMapper objectMapper) {
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
public void export() throws Exception {
|
||||
SoftwareConcept softwareConcept = softwareVersion.getSoftwareConcept();
|
||||
String name = softwareConcept.getName();
|
||||
|
||||
if(softwareConcept.getPublish()==ElaborationType.NONE) {
|
||||
logger.info("Export is disabled for {} {}.",
|
||||
SoftwareConcept.class.getSimpleName(), name);
|
||||
return;
|
||||
}
|
||||
|
||||
if(softwareVersion.isNewDeposition()) {
|
||||
if(softwareConcept.getPublish()==ElaborationType.ALL ||
|
||||
softwareConcept.getPublish()==ElaborationType.NEW) {
|
||||
logger.info("Going to export {} {}.",
|
||||
SoftwareConcept.class.getSimpleName(),
|
||||
name, softwareVersion.getVersion());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}else {
|
||||
if(softwareConcept.getPublish()==ElaborationType.ALL ||
|
||||
softwareConcept.getPublish()==ElaborationType.UPDATE_ONLY) {
|
||||
logger.info("Going to export {} {}.",
|
||||
name, softwareVersion.getVersion());
|
||||
|
||||
}else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
package org.gcube.common.deposition.model;
|
||||
package org.gcube.common.software.model;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public enum Elaborate {
|
||||
public enum ElaborationType {
|
||||
|
||||
ALL,
|
||||
UPDATE_ONLY,
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.common.deposition.model;
|
||||
package org.gcube.common.software.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -9,10 +9,10 @@ import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
|||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class Deposition {
|
||||
public class SoftwareConcept {
|
||||
|
||||
public static final String NAME_PROPERTY_NAME = "name";
|
||||
public static final String DEPOSIT_PROPERTY_NAME = "deposit";
|
||||
public static final String PUBLISH_PROPERTY_NAME = "publish";
|
||||
public static final String EXPORT_PROPERTY_NAME = "export";
|
||||
public static final String DEFAULT_FILES_PROPERTY_NAME = "default_files";
|
||||
public static final String DEFAULT_CODE_LOCATION_PROPERTY_NAME = "default_code_location";
|
||||
|
@ -23,16 +23,16 @@ public class Deposition {
|
|||
@JsonProperty(NAME_PROPERTY_NAME)
|
||||
protected String name;
|
||||
|
||||
@JsonProperty(DEPOSIT_PROPERTY_NAME)
|
||||
@JsonProperty(PUBLISH_PROPERTY_NAME)
|
||||
@JsonFormat(shape=JsonFormat.Shape.STRING)
|
||||
protected Elaborate deposit;
|
||||
protected ElaborationType publish;
|
||||
|
||||
@JsonProperty(EXPORT_PROPERTY_NAME)
|
||||
@JsonFormat(shape=JsonFormat.Shape.STRING)
|
||||
protected Elaborate export;
|
||||
protected ElaborationType export;
|
||||
|
||||
@JsonProperty(DEFAULT_FILES_PROPERTY_NAME)
|
||||
protected List<DepositionFile> defaultFiles;
|
||||
protected List<SoftwareVersionFile> defaultFiles;
|
||||
|
||||
@JsonProperty(DEFAULT_CODE_LOCATION_PROPERTY_NAME)
|
||||
protected String defaultCodeLocation;
|
||||
|
@ -41,7 +41,7 @@ public class Deposition {
|
|||
protected String codeLocationAdditionalDescription;
|
||||
|
||||
@JsonProperty(VERSIONS_PROPERTY_NAME)
|
||||
protected List<DepositionVersion> depositionVersions;
|
||||
protected List<SoftwareVersion> depositionVersions;
|
||||
|
||||
@JsonProperty(METADATA_PROPERTY_NAME)
|
||||
protected JsonNode metadata;
|
||||
|
@ -50,15 +50,15 @@ public class Deposition {
|
|||
return name;
|
||||
}
|
||||
|
||||
public Elaborate getDeposit() {
|
||||
return deposit;
|
||||
public ElaborationType getPublish() {
|
||||
return publish;
|
||||
}
|
||||
|
||||
public Elaborate getExport() {
|
||||
return export;
|
||||
public ElaborationType getExport() {
|
||||
return publish;
|
||||
}
|
||||
|
||||
public List<DepositionFile> getDefaultFiles() {
|
||||
|
||||
public List<SoftwareVersionFile> getDefaultFiles() {
|
||||
return defaultFiles;
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ public class Deposition {
|
|||
return codeLocationAdditionalDescription;
|
||||
}
|
||||
|
||||
public List<DepositionVersion> getDepositionVersions() {
|
||||
public List<SoftwareVersion> getDepositionVersions() {
|
||||
return depositionVersions;
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.common.deposition.model;
|
||||
package org.gcube.common.software.model;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.net.MalformedURLException;
|
||||
|
@ -24,7 +24,7 @@ import org.gcube.com.fasterxml.jackson.databind.node.TextNode;
|
|||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class DepositionVersion {
|
||||
public class SoftwareVersion {
|
||||
|
||||
/**
|
||||
* DateTime Pattern to be used to serialize Dates
|
||||
|
@ -44,17 +44,16 @@ public class DepositionVersion {
|
|||
public static final String CODE_LOCATION_PROPERTY_NAME = "code_location";
|
||||
public static final String CONCEPT_DOI_URL_PROPERTY_NAME = "concept_doi_url";
|
||||
public static final String DOI_URL_PROPERTY_NAME = "doi_url";
|
||||
// public static final String UPDATE_PROPERTY_NAME = "update";
|
||||
public static final String METADATA_PROPERTY_NAME = "metadata";
|
||||
|
||||
@JsonIgnore
|
||||
protected Deposition deposition;
|
||||
protected SoftwareConcept softwareConcept;
|
||||
|
||||
@JsonIgnore
|
||||
protected DepositionVersion previous;
|
||||
protected SoftwareVersion previous;
|
||||
|
||||
@JsonIgnore
|
||||
protected DepositionVersion next;
|
||||
protected SoftwareVersion next;
|
||||
|
||||
@JsonIgnore
|
||||
protected Boolean newDeposition;
|
||||
|
@ -63,11 +62,11 @@ public class DepositionVersion {
|
|||
protected String version;
|
||||
|
||||
@JsonProperty(DATE_PROPERTY_NAME)
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DepositionVersion.DATETIME_PATTERN)
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = SoftwareVersion.DATETIME_PATTERN)
|
||||
protected Date date;
|
||||
|
||||
@JsonProperty(FILES_PROPERTY_NAME)
|
||||
protected List<DepositionFile> files;
|
||||
protected List<SoftwareVersionFile> files;
|
||||
|
||||
@JsonProperty(GCUBE_RELEASE_VERSION_PROPERTY_NAME)
|
||||
protected String gCubeReleaseVersion;
|
||||
|
@ -90,42 +89,42 @@ public class DepositionVersion {
|
|||
@JsonProperty(METADATA_PROPERTY_NAME)
|
||||
protected JsonNode metadata;
|
||||
|
||||
public DepositionVersion() {
|
||||
public SoftwareVersion() {
|
||||
this.newDeposition = false;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public Deposition getDeposition() {
|
||||
return deposition;
|
||||
public SoftwareConcept getSoftwareConcept() {
|
||||
return softwareConcept;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public void setDeposition(Deposition deposition) {
|
||||
this.deposition = deposition;
|
||||
public void setSoftwareConcept(SoftwareConcept softwareConcept) {
|
||||
this.softwareConcept = softwareConcept;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public DepositionVersion getPrevious() {
|
||||
public SoftwareVersion getPrevious() {
|
||||
return previous;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public void setPrevious(DepositionVersion previous) {
|
||||
public void setPrevious(SoftwareVersion previous) {
|
||||
this.previous = previous;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public DepositionVersion getNext() {
|
||||
public SoftwareVersion getNext() {
|
||||
return next;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public void setNext(DepositionVersion next) {
|
||||
public void setNext(SoftwareVersion next) {
|
||||
this.next = next;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public Boolean getNewDeposition() {
|
||||
public Boolean isNewDeposition() {
|
||||
return newDeposition;
|
||||
}
|
||||
|
||||
|
@ -158,10 +157,10 @@ public class DepositionVersion {
|
|||
}
|
||||
|
||||
@JsonIgnore
|
||||
protected List<DepositionFile> parseFiles(List<DepositionFile> filesToParse){
|
||||
List<DepositionFile> files = new ArrayList<>();
|
||||
for(DepositionFile f : filesToParse) {
|
||||
DepositionFile file = new DepositionFile();
|
||||
protected List<SoftwareVersionFile> parseFiles(List<SoftwareVersionFile> filesToParse){
|
||||
List<SoftwareVersionFile> files = new ArrayList<>();
|
||||
for(SoftwareVersionFile f : filesToParse) {
|
||||
SoftwareVersionFile file = new SoftwareVersionFile();
|
||||
file.setDesiredName(replaceVariables(f.getDesiredName()));
|
||||
try {
|
||||
file.setURL(replaceVariables(f.getURL().toString()));
|
||||
|
@ -174,8 +173,8 @@ public class DepositionVersion {
|
|||
}
|
||||
|
||||
@JsonIgnore
|
||||
protected void replaceVariablesInfiles(List<DepositionFile> files) {
|
||||
for(DepositionFile file : files) {
|
||||
protected void replaceVariablesInfiles(List<SoftwareVersionFile> files) {
|
||||
for(SoftwareVersionFile file : files) {
|
||||
file.setDesiredName(replaceVariables(file.getDesiredName()));
|
||||
try {
|
||||
file.setURL(replaceVariables(file.getURL().toString()));
|
||||
|
@ -186,21 +185,21 @@ public class DepositionVersion {
|
|||
}
|
||||
|
||||
@JsonIgnore
|
||||
public List<DepositionFile> getFiles() {
|
||||
public List<SoftwareVersionFile> getFiles() {
|
||||
if(files!=null) {
|
||||
return parseFiles(files);
|
||||
}
|
||||
return parseFiles(deposition.getDefaultFiles());
|
||||
return parseFiles(softwareConcept.getDefaultFiles());
|
||||
}
|
||||
|
||||
@JsonGetter(value = FILES_PROPERTY_NAME)
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
protected List<DepositionFile> getFilesForSerialization() {
|
||||
protected List<SoftwareVersionFile> getFilesForSerialization() {
|
||||
return files;
|
||||
}
|
||||
|
||||
@JsonSetter(value = FILES_PROPERTY_NAME)
|
||||
public void setFiles(List<DepositionFile> files) {
|
||||
public void setFiles(List<SoftwareVersionFile> files) {
|
||||
this.files = files;
|
||||
}
|
||||
|
||||
|
@ -232,7 +231,7 @@ public class DepositionVersion {
|
|||
}
|
||||
return new URL(replaceVariables(codeLocation.toString()));
|
||||
}
|
||||
return new URL(replaceVariables(deposition.getDefaultCodeLocation().toString()));
|
||||
return new URL(replaceVariables(softwareConcept.getDefaultCodeLocation().toString()));
|
||||
}
|
||||
|
||||
@JsonGetter(value = CODE_LOCATION_PROPERTY_NAME)
|
||||
|
@ -298,7 +297,7 @@ public class DepositionVersion {
|
|||
// if(update!=null) {
|
||||
// return update;
|
||||
// }
|
||||
// return deposition.getDefaultUpdate();
|
||||
// return softwareConcept.getDefaultUpdate();
|
||||
// }
|
||||
//
|
||||
// @JsonGetter(UPDATE_PROPERTY_NAME)
|
||||
|
@ -362,9 +361,9 @@ public class DepositionVersion {
|
|||
|
||||
@JsonIgnore
|
||||
protected String replaceVariables(String stringToAnalise) {
|
||||
String s = replaceVariable("name", deposition.getName(), stringToAnalise);
|
||||
String s = replaceVariable("name", softwareConcept.getName(), stringToAnalise);
|
||||
s = replaceVariable("version", version, s);
|
||||
s = replaceVariable("date", DepositionVersion.getDateAsString(date), s);
|
||||
s = replaceVariable("date", SoftwareVersion.getDateAsString(date), s);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
@ -374,7 +373,7 @@ public class DepositionVersion {
|
|||
return metadata;
|
||||
|
||||
}
|
||||
JsonNode jsonNode = deposition.getMetadata().deepCopy();
|
||||
JsonNode jsonNode = softwareConcept.getMetadata().deepCopy();
|
||||
jsonNode = parseJsonNode(jsonNode);
|
||||
|
||||
if(getCodeLocation()!=null) {
|
||||
|
@ -384,7 +383,7 @@ public class DepositionVersion {
|
|||
StringWriter stringWriter = new StringWriter();
|
||||
stringWriter.append(description);
|
||||
|
||||
String codeLocationText = deposition.getCodeLocationAdditionalDescription();
|
||||
String codeLocationText = softwareConcept.getCodeLocationAdditionalDescription();
|
||||
codeLocationText = replaceVariables(codeLocationText);
|
||||
codeLocationText = replaceVariable("code_location", getCodeLocation().toString(), codeLocationText);
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.common.deposition.model;
|
||||
package org.gcube.common.software.model;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
@ -9,7 +9,7 @@ import org.gcube.com.fasterxml.jackson.annotation.JsonSetter;
|
|||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class DepositionFile {
|
||||
public class SoftwareVersionFile {
|
||||
|
||||
@JsonProperty(value="url")
|
||||
protected URL url;
|
|
@ -0,0 +1,46 @@
|
|||
package org.gcube.common.software.publish;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.gcube.common.software.model.SoftwareVersion;
|
||||
import org.gcube.common.software.publish.zenodo.ZenodoSoftwareVersionPublisher;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public abstract class SoftwareVersionPublisher {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SoftwareVersionPublisher.class);
|
||||
|
||||
public static List<SoftwareVersionPublisher> getPublishers() {
|
||||
List<SoftwareVersionPublisher> svps = new ArrayList<>();
|
||||
svps.add(new ZenodoSoftwareVersionPublisher());
|
||||
return svps;
|
||||
}
|
||||
|
||||
protected SoftwareVersion softwareVersion;
|
||||
protected ObjectMapper objectMapper;
|
||||
|
||||
public SoftwareVersion getSoftwareVersion() {
|
||||
return softwareVersion;
|
||||
}
|
||||
|
||||
public void setSoftwareVersion(SoftwareVersion softwareVersion) {
|
||||
this.softwareVersion = softwareVersion;
|
||||
}
|
||||
|
||||
public ObjectMapper getObjectMapper() {
|
||||
return objectMapper;
|
||||
}
|
||||
|
||||
public void setObjectMapper(ObjectMapper objectMapper) {
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
public abstract void publish() throws Exception;
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.common.deposition.executor.zenodo;
|
||||
package org.gcube.common.software.publish.zenodo;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
|
@ -27,10 +27,12 @@ import javax.ws.rs.core.Response;
|
|||
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.common.deposition.config.Config;
|
||||
import org.gcube.common.deposition.executor.DepositionVersionExecutor;
|
||||
import org.gcube.common.deposition.model.DepositionFile;
|
||||
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
|
||||
import org.gcube.common.software.config.Config;
|
||||
import org.gcube.common.software.model.ElaborationType;
|
||||
import org.gcube.common.software.model.SoftwareConcept;
|
||||
import org.gcube.common.software.model.SoftwareVersionFile;
|
||||
import org.gcube.common.software.publish.SoftwareVersionPublisher;
|
||||
import org.glassfish.jersey.client.ClientProperties;
|
||||
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
|
||||
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
||||
|
@ -41,9 +43,9 @@ import org.slf4j.LoggerFactory;
|
|||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class ZenodoDepositionVersionExecutor extends DepositionVersionExecutor {
|
||||
public class ZenodoSoftwareVersionPublisher extends SoftwareVersionPublisher {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ZenodoDepositionVersionExecutor.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(ZenodoSoftwareVersionPublisher.class);
|
||||
|
||||
public static final String GUCBE_ZENODO_SOFTWARE_DEPOSIT = "gCubeSoftwareDeposit";
|
||||
|
||||
|
@ -82,7 +84,7 @@ public class ZenodoDepositionVersionExecutor extends DepositionVersionExecutor {
|
|||
return map;
|
||||
}
|
||||
|
||||
public ZenodoDepositionVersionExecutor() {
|
||||
public ZenodoSoftwareVersionPublisher() {
|
||||
try {
|
||||
this.zenodoBaseURL = new URL(Config.getProperties().getProperty("zenodo_base_url"));
|
||||
this.accessToken = Config.getProperties().getProperty("zenodo_access_token");
|
||||
|
@ -91,7 +93,7 @@ public class ZenodoDepositionVersionExecutor extends DepositionVersionExecutor {
|
|||
}
|
||||
}
|
||||
|
||||
protected File downloadFile(DepositionFile df) throws IOException {
|
||||
protected File downloadFile(SoftwareVersionFile df) throws IOException {
|
||||
File file = new File(df.getDesiredName());
|
||||
|
||||
Path path = Paths.get(df.getDesiredName());
|
||||
|
@ -112,7 +114,7 @@ public class ZenodoDepositionVersionExecutor extends DepositionVersionExecutor {
|
|||
}
|
||||
|
||||
protected void addFilesToDeposition(List<File> files ) throws Exception {
|
||||
String depositID = getZenodoIDFromDOIURL(depositionVersion.getDOIURL());
|
||||
String depositID = getZenodoIDFromDOIURL(softwareVersion.getDOIURL());
|
||||
String newFilePath = DEPOSTION_FILES_PATH.replace(":id", depositID);
|
||||
URL url = new URL(zenodoBaseURL, newFilePath);
|
||||
|
||||
|
@ -147,17 +149,17 @@ public class ZenodoDepositionVersionExecutor extends DepositionVersionExecutor {
|
|||
gxHTTPStringRequest.header("Content-Type", "application/json");
|
||||
gxHTTPStringRequest.header("Accept", "application/json");
|
||||
|
||||
String id = getZenodoIDFromDOIURL(depositionVersion.getDOIURL());
|
||||
String id = getZenodoIDFromDOIURL(softwareVersion.getDOIURL());
|
||||
gxHTTPStringRequest.path(DEPOSITION_PATH.replace(":id", id));
|
||||
|
||||
ObjectNode body = objectMapper.createObjectNode();
|
||||
body.set(METADATA_FIELD_NAME, depositionVersion.getMetadata());
|
||||
body.set(METADATA_FIELD_NAME, softwareVersion.getMetadata());
|
||||
|
||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.put(objectMapper.writeValueAsString(body));
|
||||
getResponse(httpURLConnection);
|
||||
}
|
||||
|
||||
protected void publish() throws Exception {
|
||||
protected void publishToZenodo() throws Exception {
|
||||
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(zenodoBaseURL.toString());
|
||||
gxHTTPStringRequest.isExternalCall(true);
|
||||
gxHTTPStringRequest.from(GUCBE_ZENODO_SOFTWARE_DEPOSIT);
|
||||
|
@ -165,7 +167,7 @@ public class ZenodoDepositionVersionExecutor extends DepositionVersionExecutor {
|
|||
gxHTTPStringRequest.header("Content-Type", "application/json");
|
||||
gxHTTPStringRequest.header("Accept", "application/json");
|
||||
|
||||
String id = getZenodoIDFromDOIURL(depositionVersion.getDOIURL());
|
||||
String id = getZenodoIDFromDOIURL(softwareVersion.getDOIURL());
|
||||
gxHTTPStringRequest.path(DEPOSTION_PUBLISH_PATH.replace(":id", id));
|
||||
|
||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.post();
|
||||
|
@ -174,7 +176,7 @@ public class ZenodoDepositionVersionExecutor extends DepositionVersionExecutor {
|
|||
|
||||
protected void finalize() throws Exception {
|
||||
List<File> files = new ArrayList<>();
|
||||
for(DepositionFile df : depositionVersion.getFiles()) {
|
||||
for(SoftwareVersionFile df : softwareVersion.getFiles()) {
|
||||
File file = downloadFile(df);
|
||||
files.add(file);
|
||||
Thread.sleep(TimeUnit.SECONDS.toMillis(1));
|
||||
|
@ -187,7 +189,7 @@ public class ZenodoDepositionVersionExecutor extends DepositionVersionExecutor {
|
|||
updateMetadata();
|
||||
|
||||
// Publish the version
|
||||
publish();
|
||||
publishToZenodo();
|
||||
|
||||
for(File file : files) {
|
||||
if(!file.exists()) {
|
||||
|
@ -260,7 +262,6 @@ public class ZenodoDepositionVersionExecutor extends DepositionVersionExecutor {
|
|||
return new URL(ZENODO_DOI_URL_BASE_PATH + id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create() throws Exception {
|
||||
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(zenodoBaseURL.toString());
|
||||
gxHTTPStringRequest.isExternalCall(true);
|
||||
|
@ -271,28 +272,27 @@ public class ZenodoDepositionVersionExecutor extends DepositionVersionExecutor {
|
|||
gxHTTPStringRequest.path(DEPOSITIONS_COLLECTION_PATH);
|
||||
|
||||
ObjectNode body = objectMapper.createObjectNode();
|
||||
body.set(METADATA_FIELD_NAME, depositionVersion.getMetadata());
|
||||
body.set(METADATA_FIELD_NAME, softwareVersion.getMetadata());
|
||||
|
||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.post(objectMapper.writeValueAsString(body));
|
||||
response = getResponse(httpURLConnection);
|
||||
|
||||
URL conceptDOIURL = createZenodoDOIURLFromID(response.get("conceptrecid").asText());
|
||||
depositionVersion.setConceptDOIURL(conceptDOIURL);
|
||||
softwareVersion.setConceptDOIURL(conceptDOIURL);
|
||||
URL doiURL = new URL(ZENODO_DOI_URL_BASE_PATH + response.get("id").asText());
|
||||
depositionVersion.setDOIURL(doiURL);
|
||||
softwareVersion.setDOIURL(doiURL);
|
||||
|
||||
finalize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() throws Exception {
|
||||
// Enabled deposition edit
|
||||
// Enabled softwareConcept edit
|
||||
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(zenodoBaseURL.toString());
|
||||
gxHTTPStringRequest.isExternalCall(true);
|
||||
gxHTTPStringRequest.from(GUCBE_ZENODO_SOFTWARE_DEPOSIT);
|
||||
gxHTTPStringRequest.queryParams(getAccessTokenQueryParamters());
|
||||
gxHTTPStringRequest.header("Accept", "application/json");
|
||||
String id = getZenodoIDFromDOIURL(depositionVersion.getDOIURL());
|
||||
String id = getZenodoIDFromDOIURL(softwareVersion.getDOIURL());
|
||||
gxHTTPStringRequest.path(DEPOSTION_EDIT_PATH.replace(":id", id));
|
||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.post();
|
||||
getResponse(httpURLConnection);
|
||||
|
@ -301,7 +301,7 @@ public class ZenodoDepositionVersionExecutor extends DepositionVersionExecutor {
|
|||
updateMetadata();
|
||||
|
||||
// Publish the version
|
||||
publish();
|
||||
publishToZenodo();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -322,7 +322,6 @@ public class ZenodoDepositionVersionExecutor extends DepositionVersionExecutor {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void newVersion() throws Exception {
|
||||
|
||||
// Reading Record using conceptID to get the latest published version
|
||||
|
@ -332,7 +331,7 @@ public class ZenodoDepositionVersionExecutor extends DepositionVersionExecutor {
|
|||
gxHTTPStringRequest.queryParams(getAccessTokenQueryParamters());
|
||||
gxHTTPStringRequest.header("Content-Type", "application/json");
|
||||
gxHTTPStringRequest.header("Accept", "application/json");
|
||||
String conceptID = getZenodoIDFromDOIURL(depositionVersion.getConceptDOIURL());
|
||||
String conceptID = getZenodoIDFromDOIURL(softwareVersion.getConceptDOIURL());
|
||||
gxHTTPStringRequest.path(RECORD_PATH.replace(":id", conceptID));
|
||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
|
||||
JsonNode jsonNode = getResponse(httpURLConnection);
|
||||
|
@ -341,16 +340,16 @@ public class ZenodoDepositionVersionExecutor extends DepositionVersionExecutor {
|
|||
/*
|
||||
* Comparing obtained latestDOI and its declared version with the previuos version DOI and its declared version.
|
||||
* If they differs the configuration is not up to date and must be fixed
|
||||
* this should avoid errors on deposition.
|
||||
* this should avoid errors on softwareConcept.
|
||||
*/
|
||||
String latestVersionDOI = jsonNode.get("links").get("doi").asText();
|
||||
String previousVersionDOI = depositionVersion.getPrevious().getDOIURL().toString();
|
||||
String previousVersionDOI = softwareVersion.getPrevious().getDOIURL().toString();
|
||||
if(previousVersionDOI.compareTo(latestVersionDOI)!=0) {
|
||||
logger.error("Zenodo obtained latest DOI {} != {} DOI from previous version", latestVersionDOI, previousVersionDOI);
|
||||
throw new RuntimeException("It seems that your json is not up to date with Zenodo.");
|
||||
}
|
||||
String latestVersionVersion = jsonNode.get("metadata").get("version").asText();
|
||||
String previousVersionVersion = depositionVersion.getPrevious().getVersion().toString();
|
||||
String previousVersionVersion = softwareVersion.getPrevious().getVersion().toString();
|
||||
if(latestVersionVersion.compareTo(previousVersionVersion)!=0) {
|
||||
logger.error("Zenodo obtained latest Version {} != {} Versoin from previous version", latestVersionVersion, previousVersionVersion);
|
||||
throw new RuntimeException("It seems that your json is not up to date with Zenodo.");
|
||||
|
@ -386,12 +385,52 @@ public class ZenodoDepositionVersionExecutor extends DepositionVersionExecutor {
|
|||
|
||||
// The reserved DOI of this created new version will be
|
||||
URL doiURL = new URL(response.get("doi_url").asText());
|
||||
depositionVersion.setDOIURL(doiURL);
|
||||
softwareVersion.setDOIURL(doiURL);
|
||||
|
||||
// Remove previous depositionFiles
|
||||
deletePreviousFiles();
|
||||
|
||||
finalize();
|
||||
}
|
||||
|
||||
public void publish() throws Exception {
|
||||
SoftwareConcept softwareConcept = softwareVersion.getSoftwareConcept();
|
||||
String name = softwareConcept.getName();
|
||||
|
||||
if(softwareConcept.getPublish()==ElaborationType.NONE) {
|
||||
logger.info("Deposit is disabled for softwareConcept {} {}.",
|
||||
name , softwareVersion.getVersion());
|
||||
return;
|
||||
}
|
||||
|
||||
if(softwareVersion.getDOIURL()!=null) {
|
||||
|
||||
softwareVersion.setNewDeposition(false);
|
||||
|
||||
if(softwareConcept.getPublish()==ElaborationType.ALL ||
|
||||
softwareConcept.getPublish()==ElaborationType.UPDATE_ONLY) {
|
||||
logger.info("Going to update SoftwareConcept {} {}.",
|
||||
name , softwareVersion.getVersion());
|
||||
update();
|
||||
}else {
|
||||
logger.info("SoftwareConcept {} {} has been already deposited.",
|
||||
name , softwareVersion.getVersion());
|
||||
}
|
||||
|
||||
}else {
|
||||
if(softwareConcept.getPublish()==ElaborationType.ALL ||
|
||||
softwareConcept.getPublish()==ElaborationType.NEW) {
|
||||
logger.info("Going to deposit {} {}",
|
||||
name , softwareVersion.getVersion());
|
||||
|
||||
softwareVersion.setNewDeposition(true);
|
||||
if(softwareVersion.getConceptDOIURL()==null) {
|
||||
create();
|
||||
}else {
|
||||
newVersion();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package org.gcube.common.deposition;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class ElaborateDepositionTest {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ElaborateDepositionTest.class);
|
||||
|
||||
protected static final String ZENODO_DEPOSIT_JSON_FILENAME = "gcat-deposit.json";
|
||||
|
||||
public File getZenodoDepositFile() throws Exception {
|
||||
URL jsonFileURL = ElaborateDepositionTest.class.getClassLoader().getResource(ZENODO_DEPOSIT_JSON_FILENAME);
|
||||
File jsonFile = new File(jsonFileURL.toURI());
|
||||
return jsonFile;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUsingTestFile() throws Exception {
|
||||
ElaborateDeposition zenodoDeposit = new ElaborateDeposition();
|
||||
zenodoDeposit.publish(getZenodoDepositFile());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package org.gcube.common.software.analyser;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUsingTestFile() throws Exception {
|
||||
SoftwareConceptAnalyser zenodoDeposit = new SoftwareConceptAnalyser();
|
||||
zenodoDeposit.analyse(getConceptFile());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "gcat",
|
||||
"deposit": "NONE",
|
||||
"publish": "NONE",
|
||||
"export": "ALL",
|
||||
"default_files":
|
||||
[
|
Loading…
Reference in New Issue