Implementing component
This commit is contained in:
parent
2fca8b6e3b
commit
bca053f8ec
|
@ -1,7 +1,6 @@
|
|||
package org.gcube.common.deposition;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.gcube.common.deposition.model.Deposition;
|
||||
|
@ -18,13 +17,8 @@ public class ElaborateDeposition {
|
|||
|
||||
protected ObjectMapper objectMapper;
|
||||
|
||||
protected URL baseURL;
|
||||
protected String accessToken;
|
||||
|
||||
public ElaborateDeposition(URL baseURL, String accessToken) {
|
||||
public ElaborateDeposition() {
|
||||
this.objectMapper = new ObjectMapper();
|
||||
this.baseURL = baseURL;
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
|
||||
public void publish(File jsonFile) throws Exception {
|
||||
|
@ -45,7 +39,7 @@ public class ElaborateDeposition {
|
|||
depositionVersion.setDeposition(deposition);
|
||||
depositionVersion.setPrevious(previous);
|
||||
|
||||
logger.debug("Going to elaborate {} {}, previous version {}",
|
||||
logger.trace("Going to elaborate {} {} (previous version {})",
|
||||
name, depositionVersion.getVersion(),
|
||||
depositionVersion.getPrevious()!=null ? depositionVersion.getPrevious().getVersion(): null);
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.gcube.common.deposition;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.gcube.common.deposition.config.Config;
|
||||
import org.gcube.common.deposition.executor.DepositionVersionExecutor;
|
||||
import org.gcube.common.deposition.model.DepositionVersion;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -20,38 +21,60 @@ public class ElaborateDepositionVersion {
|
|||
}
|
||||
|
||||
protected JsonNode getMetadata() {
|
||||
// TODO replace variables in metadata and add variables part is any
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void addDefaultsToDepositionVersion() {
|
||||
// TODO add the missing content with
|
||||
}
|
||||
|
||||
public void elaborate() {
|
||||
String name = depositionVersion.getDeposition().getName();
|
||||
|
||||
addDefaultsToDepositionVersion();
|
||||
|
||||
DepositionVersionExecutor dve = DepositionVersionExecutor.getDefaultExecutor();
|
||||
dve.setMetadata(getMetadata());
|
||||
|
||||
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);
|
||||
|
||||
DepositionVersionExecutor dve = DepositionVersionExecutor.getDefaultExecutor();
|
||||
dve.setMetadata(getMetadata());
|
||||
boolean updateEnabled = false;
|
||||
|
||||
try {
|
||||
String updatedDeposit = Config.getProperties().getProperty("update_deposit");
|
||||
updateEnabled = Boolean.valueOf(updatedDeposit);
|
||||
}catch (Exception e) {
|
||||
updateEnabled = false;
|
||||
}
|
||||
|
||||
logger.trace("Deposition update {}", updateEnabled ? "enabled" : "disabled");
|
||||
|
||||
if(updateEnabled) {
|
||||
logger.info("Going to update deposition {} {}.",
|
||||
name , depositionVersion.getVersion());
|
||||
dve.setDOIURL(depositionVersion.getDOIURL());
|
||||
dve.update();
|
||||
}else {
|
||||
logger.info("Deposition {} {} has been already deposited.",
|
||||
name , depositionVersion.getVersion());
|
||||
}
|
||||
|
||||
}else {
|
||||
logger.info("Going to deposit {} {}",
|
||||
name , depositionVersion.getVersion());
|
||||
|
||||
if(depositionVersion.getConceptDOIURL()==null) {
|
||||
dve.create();
|
||||
}else {
|
||||
dve.setDOIURL(depositionVersion.getConceptDOIURL());
|
||||
dve.newVersion();
|
||||
}
|
||||
|
||||
// TODO Add files
|
||||
// TODO Update deposit metadata
|
||||
|
||||
// TODO Publish the version
|
||||
|
||||
// Save content
|
||||
|
||||
// TODO Save content
|
||||
// TODO Export bibtext
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package org.gcube.common.deposition.config;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.gcube.common.deposition.executor.zenodo.ZenodoDepositionVersionExecutor;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class Config {
|
||||
|
||||
protected static Properties properties;
|
||||
protected static final String PROPERTIES_FILENAME = "config.properties";
|
||||
|
||||
static {
|
||||
properties = new Properties();
|
||||
InputStream input = ZenodoDepositionVersionExecutor.class.getClassLoader().getResourceAsStream(PROPERTIES_FILENAME);
|
||||
|
||||
try {
|
||||
// load the properties file
|
||||
properties.load(input);
|
||||
} catch(IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Properties getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,8 @@
|
|||
package org.gcube.common.deposition.executor.zenodo;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import org.gcube.common.deposition.config.Config;
|
||||
import org.gcube.common.deposition.executor.DepositionVersionExecutor;
|
||||
|
||||
/**
|
||||
|
@ -7,8 +10,16 @@ import org.gcube.common.deposition.executor.DepositionVersionExecutor;
|
|||
*/
|
||||
public class ZenodoDepositionVersionExecutor extends DepositionVersionExecutor {
|
||||
|
||||
protected URL zenodoBaseURL;
|
||||
protected String accessToken;
|
||||
|
||||
public ZenodoDepositionVersionExecutor() {
|
||||
|
||||
try {
|
||||
this.zenodoBaseURL = new URL(Config.getProperties().getProperty("zenodo_base_url"));
|
||||
this.accessToken = Config.getProperties().getProperty("zenodo_access_token");
|
||||
}catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void finalize() {
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
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.gcube.common.deposition.ElaborateDeposition;
|
||||
import org.junit.Test;
|
||||
|
@ -14,23 +11,8 @@ import org.junit.Test;
|
|||
*/
|
||||
public class DepositTest {
|
||||
|
||||
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 = DepositTest.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 = DepositTest.class.getClassLoader().getResource(ZENODO_DEPOSIT_JSON_FILENAME);
|
||||
File jsonFile = new File(jsonFileURL.toURI());
|
||||
|
@ -39,9 +21,7 @@ public class DepositTest {
|
|||
|
||||
@Test
|
||||
public void testUsingTestFile() throws Exception {
|
||||
URL zenodoBaseURL = new URL(properties.getProperty("zenodo_base_url"));
|
||||
String accessToken = properties.getProperty("zenodo_access_token");
|
||||
ElaborateDeposition zenodoDeposit = new ElaborateDeposition(zenodoBaseURL, accessToken);
|
||||
ElaborateDeposition zenodoDeposit = new ElaborateDeposition();
|
||||
zenodoDeposit.publish(getZenodoDepositFile());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue