Clients basic implementation
This commit is contained in:
parent
5f825a1cb2
commit
ed65a6879e
|
@ -1,27 +1,66 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.gcube.tools</groupId>
|
||||
<artifactId>maven-parent</artifactId>
|
||||
<version>1.1.0</version>
|
||||
</parent>
|
||||
<groupId>org.gcube.data.publishing</groupId>
|
||||
<artifactId>ckan2zenodo-library</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>CKAN 2 Zenodo Library</name>
|
||||
<description>Library to publish d4science CKAN items into Zenodo</description>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<!-- EXTERNAL -->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.gcube.tools</groupId>
|
||||
<artifactId>maven-parent</artifactId>
|
||||
<version>1.1.0</version>
|
||||
</parent>
|
||||
<groupId>org.gcube.data.publishing</groupId>
|
||||
<artifactId>ckan2zenodo-library</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>CKAN 2 Zenodo Library</name>
|
||||
<description>Library to publish d4science CKAN items into Zenodo</description>
|
||||
|
||||
|
||||
<properties>
|
||||
<distroDirectory>${project.basedir}/distro</distroDirectory>
|
||||
<gitBaseUrl>https://code-repo.d4science.org/gCubeSystem/</gitBaseUrl>
|
||||
</properties>
|
||||
|
||||
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:${gitBaseUrl}/${project.artifactId}.git</connection>
|
||||
<developerConnection>scm:git:${gitBaseUrl}/${project.artifactId}.git</developerConnection>
|
||||
<url>${gitBaseUrl}/${project.artifactId}.git</url>
|
||||
</scm>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>gcube-bom</artifactId>
|
||||
<version>1.3.1</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>gcube-smartgears-bom</artifactId>
|
||||
<version>1.0.2</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.data-publishing</groupId>
|
||||
<artifactId>gcat-client</artifactId>
|
||||
<version>[1.2.0,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
<!-- EXTERNAL -->
|
||||
<!-- lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.14.8</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
|
@ -0,0 +1,23 @@
|
|||
package org.gcube.data.publishing.ckan2zenodo.clients;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.CkanItemDescriptor;
|
||||
import org.gcube.gcat.client.Item;
|
||||
|
||||
public class GCat {
|
||||
|
||||
|
||||
public CkanItemDescriptor getByID(String itemName) throws MalformedURLException {
|
||||
CkanItemDescriptor toReturn=new CkanItemDescriptor();
|
||||
toReturn.setContent(new Item().read(itemName));
|
||||
toReturn.setItemName(itemName);
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
public void updateItem(CkanItemDescriptor toUpdate) throws MalformedURLException {
|
||||
new Item().update(toUpdate.getItemName(), toUpdate.getContent());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package org.gcube.data.publishing.ckan2zenodo.clients;
|
||||
|
||||
import javax.ws.rs.client.Client;
|
||||
import javax.ws.rs.client.ClientBuilder;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.faults.ZenodoException;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.zenodo.ZenodoDeposition;
|
||||
import org.glassfish.jersey.client.ClientProperties;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class Zenodo {
|
||||
|
||||
private static final String BASE_URL="https://zenodo.org/api/";
|
||||
|
||||
private static final String CONTENT_TYPE="application/json";
|
||||
|
||||
private static final String DEPOSITION_BASE_URL="deposit/depositions";
|
||||
|
||||
private static final String AUTH="Authentication";
|
||||
private static final String BEARER="Bearer ";
|
||||
|
||||
@NonNull
|
||||
private String tokenValue;
|
||||
|
||||
|
||||
Client client;
|
||||
|
||||
private synchronized Client getWebClient() {
|
||||
if(client==null)
|
||||
client = ClientBuilder.newClient(
|
||||
// new ClientConfig().register(new HTTPBasicProvider(username, password))
|
||||
)
|
||||
.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
|
||||
return client;
|
||||
}
|
||||
|
||||
public ZenodoDeposition readDeposition(String id) throws ZenodoException {
|
||||
|
||||
// String respString=null;
|
||||
return getWebClient().target(BASE_URL).
|
||||
path(DEPOSITION_BASE_URL).path(id).request(CONTENT_TYPE)
|
||||
.header(AUTH, BEARER+tokenValue)
|
||||
.get(ZenodoDeposition.class);
|
||||
// respString=check(resp);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static String check(Response resp) throws ZenodoException {
|
||||
if(resp.getStatus()<200||resp.getStatus()>=300) {
|
||||
throw new ZenodoException("RESP STATUS IS "+resp.getStatus()+". Message : "+resp.readEntity(String.class));
|
||||
}else
|
||||
return resp.readEntity(String.class);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,12 +1,24 @@
|
|||
package org.gcube.data.publishing.ckan2zenodo.model;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class CkanItemDescriptor {
|
||||
|
||||
@NonNull
|
||||
private String itemId;
|
||||
private String itemName;
|
||||
@NonNull
|
||||
private String content;
|
||||
|
||||
|
||||
public String readField(String jsonContent,String field) {
|
||||
throw new RuntimeException("Implement this");
|
||||
}
|
||||
|
||||
public void writeField(String fieldName,String fieldValue) {
|
||||
throw new RuntimeException("Implement this");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package org.gcube.data.publishing.ckan2zenodo.model.faults;
|
||||
|
||||
public class ZenodoException extends Exception{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 4687842770251881142L;
|
||||
|
||||
public ZenodoException() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public ZenodoException(String arg0, Throwable arg1, boolean arg2, boolean arg3) {
|
||||
super(arg0, arg1, arg2, arg3);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public ZenodoException(String arg0, Throwable arg1) {
|
||||
super(arg0, arg1);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public ZenodoException(String arg0) {
|
||||
super(arg0);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public ZenodoException(Throwable arg0) {
|
||||
super(arg0);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -10,15 +10,58 @@ import lombok.NoArgsConstructor;
|
|||
@NoArgsConstructor
|
||||
public class DepositionMetadata {
|
||||
|
||||
private String upload_type; // TODO ENUM
|
||||
private String publication_type; //TODO ENUM
|
||||
private String image_type; //TODO ENUM
|
||||
public static enum UploadType{
|
||||
publication,
|
||||
poster,
|
||||
presentation,
|
||||
dataset,
|
||||
image,
|
||||
video,
|
||||
software,
|
||||
lesson,
|
||||
other
|
||||
}
|
||||
|
||||
public static enum PublicationType{
|
||||
annotationcollection,
|
||||
book,
|
||||
section,
|
||||
conferencepaper,
|
||||
datamanagementplan,
|
||||
article,
|
||||
patent,
|
||||
preprint,
|
||||
deliverable,
|
||||
milestone,
|
||||
proposal,
|
||||
report,
|
||||
softwaredocumentation,
|
||||
taxonomictreatment,
|
||||
techincalnote,
|
||||
thesis,
|
||||
workingpaper,
|
||||
other
|
||||
}
|
||||
|
||||
public static enum ImageType{
|
||||
figure,
|
||||
plot,
|
||||
drawing,
|
||||
diagram,
|
||||
photo,
|
||||
other
|
||||
}
|
||||
|
||||
|
||||
private UploadType upload_type;
|
||||
private PublicationType publication_type;
|
||||
private ImageType image_type;
|
||||
private Date publication_date;
|
||||
private String title;
|
||||
private ArrayList<Creator> creators;
|
||||
private String description; // TODO HTML
|
||||
private String access_rights;
|
||||
private String license; // TODO ENUM
|
||||
private String license; // TODO ENUM https://licenses.opendefinition.org/licenses/groups/all.json
|
||||
private Date embargo_date;
|
||||
private String access_conditions; // TODO HTML
|
||||
private String doi;
|
||||
|
|
Loading…
Reference in New Issue