Basic mapping implementation
This commit is contained in:
parent
c56d2d53a2
commit
7553dd1964
|
@ -1,16 +1,81 @@
|
|||
package org.gcube.data.publishing.ckan2zenodo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.CkanItemDescriptor;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.zenodo.Contributor;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.zenodo.DepositionMetadata;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.zenodo.RelatedIdentifier;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.zenodo.DepositionMetadata.AccessRights;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.zenodo.ZenodoDeposition;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class Transformer {
|
||||
|
||||
private HashMap<String,String> mappings=new HashMap<>();
|
||||
|
||||
public ZenodoDeposition transform(CkanItemDescriptor toTransform) {
|
||||
ZenodoDeposition dep=new ZenodoDeposition();
|
||||
|
||||
public ZenodoDeposition transform(CkanItemDescriptor toTransform, ZenodoDeposition deposition) {
|
||||
log.debug("Transforming "+toTransform+". Existing Deposition is : "+deposition);
|
||||
|
||||
// dep.set
|
||||
throw new RuntimeException("Implment this");
|
||||
if(deposition==null) deposition=new ZenodoDeposition();
|
||||
|
||||
// default mappings
|
||||
DepositionMetadata meta=deposition.getMetadata();
|
||||
if(meta==null)
|
||||
meta=new DepositionMetadata();
|
||||
|
||||
meta.setTitle(toTransform.getTitle());
|
||||
meta.setDescription(toTransform.getNotes());
|
||||
|
||||
// Access Right
|
||||
if(toTransform.isOpen())
|
||||
meta.setAccess_right(AccessRights.open);
|
||||
else {
|
||||
meta.setAccess_right(AccessRights.restricted);
|
||||
meta.setAccess_conditions("Visit the VRE "+toTransform.getVRE()+" to access it.");
|
||||
}
|
||||
|
||||
meta.setLicense(toTransform.getLicenseId());
|
||||
|
||||
meta.setKeywords(new ArrayList<String>(toTransform.getTags()));
|
||||
|
||||
//Related Identifiers
|
||||
String itemUrl=toTransform.getItemUrl();
|
||||
ArrayList<RelatedIdentifier> relatedIdentifiers=new ArrayList<>();
|
||||
if(itemUrl!=null) relatedIdentifiers.add(new RelatedIdentifier(itemUrl,RelatedIdentifier.Relation.compiles));
|
||||
|
||||
//Contributors
|
||||
ArrayList<Contributor> contributors=new ArrayList<>();
|
||||
String authorName=toTransform.getAuthor();
|
||||
if(authorName!=null) {
|
||||
Contributor author=new Contributor(Contributor.Type.Producer);
|
||||
author.setName(authorName);
|
||||
contributors.add(author);
|
||||
}
|
||||
|
||||
String maintainerName=toTransform.getAuthor();
|
||||
if(maintainerName!=null) {
|
||||
Contributor maintainer=new Contributor(Contributor.Type.DataCurator);
|
||||
maintainer.setName(maintainerName);
|
||||
contributors.add(maintainer);
|
||||
}
|
||||
meta.setContributors(contributors);
|
||||
|
||||
meta.setVersion(toTransform.getVersion());
|
||||
|
||||
|
||||
// Dates
|
||||
|
||||
|
||||
deposition.setMetadata(meta);
|
||||
|
||||
// profile specific mappings
|
||||
|
||||
return deposition;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,11 @@ package org.gcube.data.publishing.ckan2zenodo.model.zenodo;
|
|||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
public class RelatedIdentifier {
|
||||
|
||||
public static enum Relation{
|
||||
|
|
|
@ -8,16 +8,15 @@ import org.junit.BeforeClass;
|
|||
import org.junit.Test;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
public class ParsingTests {
|
||||
|
||||
static ObjectMapper mapper=new ObjectMapper();
|
||||
static ObjectMapper mapper=null;
|
||||
@BeforeClass
|
||||
public static void init () {
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
|
||||
mapper=TestCommons.getMapper();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
package org.gcube.tests;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.ZenodoCredentials;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
|
||||
public class TestCommons {
|
||||
|
||||
static ZenodoCredentials loadCredentials() throws IOException {
|
||||
String BASE_URL="https://sandbox.zenodo.org/api/";
|
||||
|
||||
String key=Files.readAllLines(Paths.get("/home/fabio/workspaces/zenodo.key")).get(0);
|
||||
|
||||
System.out.println("Using key : "+key);
|
||||
return new ZenodoCredentials(key,BASE_URL);
|
||||
}
|
||||
|
||||
|
||||
static String convertStreamToString(java.io.InputStream is) {
|
||||
java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
|
||||
return s.hasNext() ? s.next() : "";
|
||||
}
|
||||
|
||||
|
||||
static ObjectMapper getMapper() {
|
||||
ObjectMapper mapper=new ObjectMapper();
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
|
||||
mapper.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false);
|
||||
mapper.setSerializationInclusion(Include.NON_NULL);
|
||||
return mapper;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package org.gcube.tests;
|
||||
|
||||
import org.gcube.data.publishing.ckan2zenodo.Fixer;
|
||||
import org.gcube.data.publishing.ckan2zenodo.Transformer;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.CkanItemDescriptor;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.zenodo.ZenodoDeposition;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
public class TransformationTests {
|
||||
|
||||
static ObjectMapper mapper=null;
|
||||
@BeforeClass
|
||||
public static void init () {
|
||||
mapper=TestCommons.getMapper();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void transform() throws JsonProcessingException {
|
||||
|
||||
String json=TestCommons.convertStreamToString(this.getClass().getResourceAsStream("/simpleItem.json"));
|
||||
Transformer defaultTransformer=new Transformer();
|
||||
CkanItemDescriptor desc=new CkanItemDescriptor("sampleontable_in_prevre", json);
|
||||
System.out.println("Going to transform : "+desc.getContent());
|
||||
System.out.println("Result : ");
|
||||
ZenodoDeposition dep=defaultTransformer.transform(desc, null);
|
||||
System.out.println(dep);
|
||||
System.out.println("As JSON : ");
|
||||
System.out.println(Fixer.fixSending(mapper.writeValueAsString(dep)));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -6,7 +6,9 @@ import java.nio.file.Paths;
|
|||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
||||
import org.gcube.data.publishing.ckan2zenodo.Transformer;
|
||||
import org.gcube.data.publishing.ckan2zenodo.clients.Zenodo;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.CkanItemDescriptor;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.ZenodoCredentials;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.faults.ZenodoException;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.zenodo.Creator;
|
||||
|
@ -21,16 +23,12 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|||
|
||||
public class ZenodoTests {
|
||||
|
||||
private static ZenodoCredentials credentials;
|
||||
private static ZenodoCredentials credentials;
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static final void init() throws IOException {
|
||||
String BASE_URL="https://sandbox.zenodo.org/api/";
|
||||
|
||||
String key=Files.readAllLines(Paths.get("/home/fabio/workspaces/zenodo.key")).get(0);
|
||||
|
||||
System.out.println("Using key : "+key);
|
||||
credentials=new ZenodoCredentials(key,BASE_URL);
|
||||
credentials=TestCommons.loadCredentials();
|
||||
}
|
||||
|
||||
|
||||
|
@ -61,4 +59,15 @@ public class ZenodoTests {
|
|||
System.out.println(z.updateMetadata(dep.getId(),dep.getMetadata()));
|
||||
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void createFromSimpleItem() throws JsonProcessingException, ZenodoException {
|
||||
// Zenodo z=new Zenodo(credentials);
|
||||
// String json=TestCommons.convertStreamToString(this.getClass().getResourceAsStream("/simpleItem.json"));
|
||||
// Transformer defaultTransformer=new Transformer();
|
||||
// CkanItemDescriptor desc=new CkanItemDescriptor("sampleontable_in_prevre", json);
|
||||
// ZenodoDeposition dep=z.createNew();
|
||||
// defaultTransformer.transform(desc, dep);
|
||||
// System.out.println(z.updateMetadata(dep.getId(), dep.getMetadata()));
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -0,0 +1,173 @@
|
|||
{
|
||||
"rating": 0.0,
|
||||
"license_title": "Creative Commons Attribution-NonCommercial-ShareAlike 4.0",
|
||||
"maintainer": null,
|
||||
"searchable": "true",
|
||||
"relationships_as_object": [],
|
||||
"private": true,
|
||||
"maintainer_email": null,
|
||||
"num_tags": 4,
|
||||
"id": "a5a7db8c-9b11-4522-bf5c-17baf59f2e9d",
|
||||
"metadata_created": "2019-06-05T16:08:38.579293",
|
||||
"metadata_modified": "2019-07-01T13:25:49.169770",
|
||||
"author": "fabio_sinibaldi",
|
||||
"author_email": "fabio_sinibaldi@gcube.ckan.org",
|
||||
"state": "active",
|
||||
"version": null,
|
||||
"creator_user_id": "7d9008ef-2328-4fd7-8995-2c697faa7201",
|
||||
"type": "dataset",
|
||||
"resources": [
|
||||
{
|
||||
"mimetype": null,
|
||||
"cache_url": null,
|
||||
"hash": "",
|
||||
"description": "Link to the GUI designed to operate with DataMiner",
|
||||
"name": "Gateway Link",
|
||||
"format": "HTTP",
|
||||
"url": "https://pre.d4science.org/group/prevre/dataminer-manager?OperatorId=org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.SAMPLEONTABLE",
|
||||
"datastore_active": false,
|
||||
"cache_last_updated": null,
|
||||
"package_id": "a5a7db8c-9b11-4522-bf5c-17baf59f2e9d",
|
||||
"created": "2019-07-01T13:25:48.958747",
|
||||
"state": "active",
|
||||
"mimetype_inner": null,
|
||||
"last_modified": null,
|
||||
"position": 0,
|
||||
"revision_id": "6d36b2ae-aedc-4c3d-bb8a-a9afeea273df",
|
||||
"url_type": null,
|
||||
"id": "1a27d3d7-12e9-4367-b618-3f82dde5909e",
|
||||
"resource_type": null,
|
||||
"size": null
|
||||
},
|
||||
{
|
||||
"mimetype": null,
|
||||
"cache_url": null,
|
||||
"hash": "",
|
||||
"description": "WPS Link to the DataMiner Process",
|
||||
"name": "WPS Link",
|
||||
"format": "WPS",
|
||||
"url": "https://dataminer1-pre.d4science.org/wps/WebProcessingService?Request=DescribeProcess&Version=1.0.0&Service=WPS&Identifier=org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.SAMPLEONTABLE",
|
||||
"datastore_active": false,
|
||||
"cache_last_updated": null,
|
||||
"package_id": "a5a7db8c-9b11-4522-bf5c-17baf59f2e9d",
|
||||
"created": "2019-07-01T13:25:49.192891",
|
||||
"state": "active",
|
||||
"mimetype_inner": null,
|
||||
"last_modified": null,
|
||||
"position": 1,
|
||||
"revision_id": "6d36b2ae-aedc-4c3d-bb8a-a9afeea273df",
|
||||
"url_type": null,
|
||||
"id": "d190c17e-0065-448f-af8d-b37ebe911c76",
|
||||
"resource_type": null,
|
||||
"size": null
|
||||
}],
|
||||
"num_resources": 2,
|
||||
"tags": [
|
||||
{
|
||||
"vocabulary_id": null,
|
||||
"state": "active",
|
||||
"display_name": "Analytics",
|
||||
"id": "b9408e0e-5a78-47b6-825f-fd6458af73d6",
|
||||
"name": "Analytics"
|
||||
},
|
||||
{
|
||||
"vocabulary_id": null,
|
||||
"state": "active",
|
||||
"display_name": "Databases",
|
||||
"id": "6db27a4c-71ff-448d-ad8d-3e1ee35440dd",
|
||||
"name": "Databases"
|
||||
},
|
||||
{
|
||||
"vocabulary_id": null,
|
||||
"state": "active",
|
||||
"display_name": "WPS",
|
||||
"id": "195bab7c-04c6-4892-b35f-1248b4414304",
|
||||
"name": "WPS"
|
||||
},
|
||||
{
|
||||
"vocabulary_id": null,
|
||||
"state": "active",
|
||||
"display_name": "preVRE",
|
||||
"id": "22a50ee0-82e9-4092-a589-5f749d5edbb7",
|
||||
"name": "preVRE"
|
||||
}],
|
||||
"groups": [],
|
||||
"license_id": "CC-BY-NC-SA-4.0",
|
||||
"relationships_as_subject": [],
|
||||
"organization":
|
||||
{
|
||||
"description": "The preVRE organisation",
|
||||
"created": "2019-05-02T12:41:26.149836",
|
||||
"title": "preVRE",
|
||||
"name": "prevre",
|
||||
"is_organization": true,
|
||||
"state": "active",
|
||||
"image_url": "https://pre.d4science.org/image/layout_set_logo?img_id=12949941",
|
||||
"revision_id": "a44aebb5-5f88-4d53-94d2-bfb17b8d340b",
|
||||
"type": "organization",
|
||||
"id": "46ce33da-dbc1-4116-b41d-eb961435a53d",
|
||||
"approval_status": "approved"
|
||||
},
|
||||
"name": "sampleontable_in_prevre",
|
||||
"isopen": false,
|
||||
"url": null,
|
||||
"notes": "Algorithm that allows to perform a sample operation on a table",
|
||||
"owner_org": "46ce33da-dbc1-4116-b41d-eb961435a53d",
|
||||
"extras": [
|
||||
{
|
||||
"key": "DataMiner Process:Input Parameter",
|
||||
"value": "TableName [OBJECT] : The name of the table"
|
||||
},
|
||||
{
|
||||
"key": "DataMiner Process:Input Parameter",
|
||||
"value": "ResourceName [OBJECT] : The name of the resource"
|
||||
},
|
||||
{
|
||||
"key": "DataMiner Process:Input Parameter",
|
||||
"value": "SchemaName [OBJECT] : The name of the schema"
|
||||
},
|
||||
{
|
||||
"key": "DataMiner Process:Input Parameter",
|
||||
"value": "DatabaseName [OBJECT] : The name of the database"
|
||||
},
|
||||
{
|
||||
"key": "DataMiner Process:Output Parameter",
|
||||
"value": "non_deterministic_output [FILE] : NonDeterministicOutput"
|
||||
},
|
||||
{
|
||||
"key": "DataMiner Process:Process Author",
|
||||
"value": "Sinibaldi,Fabio"
|
||||
},
|
||||
{
|
||||
"key": "DataMiner Process:Process Maintainer",
|
||||
"value": "Sinibaldi,Fabio"
|
||||
},
|
||||
{
|
||||
"key": "Input Parameter",
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"key": "Item URL",
|
||||
"value": "http://data-pre.d4science.org/ctlg/preVRE/sampleontable_in_prevre"
|
||||
},
|
||||
{
|
||||
"key": "Output Parameter",
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"key": "Process Author",
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"key": "Process Maintainer",
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"key": "system:type",
|
||||
"value": "DataMiner Process"
|
||||
}],
|
||||
"license_url": "https://creativecommons.org/licenses/by-nc-sa/4.0/",
|
||||
"ratings_count": 0,
|
||||
"title": "Sampleontable in preVRE",
|
||||
"revision_id": "44b644e5-ebdd-485c-8271-50d81d0407aa"
|
||||
}
|
Loading…
Reference in New Issue