Added JSON Parsing faciliteis
This commit is contained in:
parent
ed65a6879e
commit
c669ee2971
|
@ -15,7 +15,7 @@
|
|||
|
||||
<properties>
|
||||
<distroDirectory>${project.basedir}/distro</distroDirectory>
|
||||
<gitBaseUrl>https://code-repo.d4science.org/gCubeSystem/</gitBaseUrl>
|
||||
<gitBaseUrl>https://code-repo.d4science.org/gCubeSystem/</gitBaseUrl>
|
||||
</properties>
|
||||
|
||||
|
||||
|
@ -60,6 +60,20 @@
|
|||
<version>1.14.8</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.jayway.jsonpath</groupId>
|
||||
<artifactId>json-path</artifactId>
|
||||
<version>2.4.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package org.gcube.data.publishing.ckan2zenodo;
|
||||
|
||||
public interface Transformer {
|
||||
public interface Ckan2Zenodo {
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package org.gcube.data.publishing.ckan2zenodo;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
import org.gcube.data.publishing.ckan2zenodo.clients.GCat;
|
||||
import org.gcube.data.publishing.ckan2zenodo.clients.Zenodo;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.CkanItemDescriptor;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.zenodo.ZenodoDeposition;
|
||||
|
||||
public class Ckan2ZenodoImpl {
|
||||
|
||||
|
||||
public static void publish(String itemName) throws MalformedURLException {
|
||||
// looking for gcat..
|
||||
GCat gCat=new GCat();
|
||||
// looking for item
|
||||
CkanItemDescriptor desc=gCat.getByID(itemName);
|
||||
|
||||
//transforming
|
||||
// ZenodoDeposition deposition=TransformerManager.transform(desc);
|
||||
|
||||
// publishing / update to zenodo
|
||||
Zenodo z=new Zenodo(getZenodoToken());
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static final String getZenodoToken() {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package org.gcube.data.publishing.ckan2zenodo;
|
||||
|
||||
public class TransformerManager {
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -8,16 +8,12 @@ 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 static CkanItemDescriptor getByID(String itemName) throws MalformedURLException {
|
||||
return new CkanItemDescriptor(itemName,new Item().read(itemName));
|
||||
}
|
||||
|
||||
|
||||
public void updateItem(CkanItemDescriptor toUpdate) throws MalformedURLException {
|
||||
public static void updateItem(CkanItemDescriptor toUpdate) throws MalformedURLException {
|
||||
new Item().update(toUpdate.getItemName(), toUpdate.getContent());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ public class Zenodo {
|
|||
|
||||
private static final String DEPOSITION_BASE_URL="deposit/depositions";
|
||||
|
||||
private static final String AUTH="Authentication";
|
||||
private static final String AUTH="Authorization";
|
||||
private static final String BEARER="Bearer ";
|
||||
|
||||
@NonNull
|
||||
|
@ -50,6 +50,8 @@ public class Zenodo {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
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));
|
||||
|
@ -57,5 +59,7 @@ public class Zenodo {
|
|||
return resp.readEntity(String.class);
|
||||
}
|
||||
|
||||
|
||||
public ZenodoDeposition publishOrUpdate(ZenodoDeposition d) {
|
||||
throw new RuntimeException("Implement This");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +1,46 @@
|
|||
package org.gcube.data.publishing.ckan2zenodo.model;
|
||||
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
import com.jayway.jsonpath.ReadContext;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Data
|
||||
@RequiredArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CkanItemDescriptor {
|
||||
|
||||
private static final String PROFILE="$.extras[?(@.key=='system:type')].value";
|
||||
|
||||
|
||||
|
||||
@NonNull
|
||||
@Getter
|
||||
private String itemName;
|
||||
@NonNull
|
||||
@Getter
|
||||
private String content;
|
||||
|
||||
|
||||
public String readField(String jsonContent,String field) {
|
||||
throw new RuntimeException("Implement this");
|
||||
@Getter(lazy=true)
|
||||
private final ReadContext document=document();
|
||||
|
||||
|
||||
private ReadContext document() {
|
||||
return JsonPath.parse(content);
|
||||
}
|
||||
|
||||
public void writeField(String fieldName,String fieldValue) {
|
||||
throw new RuntimeException("Implement this");
|
||||
|
||||
public String getProfile() {
|
||||
List<String> values=getDocument().read(PROFILE);
|
||||
return values.get(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package org.gcube.tests;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.data.publishing.ckan2zenodo.clients.GCat;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.CkanItemDescriptor;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class GCatTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void getProfile() throws MalformedURLException {
|
||||
TokenSetter.set("/pred4s/preprod/preVRE");
|
||||
System.out.println(SecurityTokenProvider.instance.get());
|
||||
CkanItemDescriptor item=GCat.getByID("sampleontable_in_prevre");
|
||||
|
||||
|
||||
System.out.println(item.getProfile());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package org.gcube.tests;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class TokenSetter {
|
||||
|
||||
|
||||
|
||||
private static Properties props=new Properties();
|
||||
|
||||
static{
|
||||
try {
|
||||
props.load(TokenSetter.class.getResourceAsStream("/tokens.properties"));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("YOU NEED TO SET TOKEN FILE IN CONFIGURATION");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void set(String scope){
|
||||
if(!props.containsKey(scope)) throw new RuntimeException("No token found for scope : "+scope);
|
||||
SecurityTokenProvider.instance.set(props.getProperty(scope));
|
||||
ScopeProvider.instance.set(scope);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package org.gcube.tests;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.gcube.data.publishing.ckan2zenodo.clients.Zenodo;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.faults.ZenodoException;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ZenodoTests {
|
||||
|
||||
@Test
|
||||
public void readFromZenodo() throws IOException, ZenodoException {
|
||||
String key=Files.readAllLines(Paths.get("/home/fabio/workspaces/zenodo.key")).get(0);
|
||||
|
||||
System.out.println(new Zenodo(key).readDeposition("10"));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue