Skip to content

Commit 199d620

Browse files
author
Ankur Gupta
committed
Zenodo Interface
1 parent cacfa72 commit 199d620

File tree

2 files changed

+54
-55
lines changed

2 files changed

+54
-55
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package de.tud.cs.stg.zenodo;
2+
3+
import java.io.IOException;
4+
import java.util.List;
5+
6+
public interface ZenodoAPI {
7+
8+
public boolean test();
9+
public Deposition getDeposition(Integer id);
10+
public List<Deposition> getDepositions();
11+
public Deposition updateDeposition(Deposition deposition);
12+
public void deleteDeposition(Integer id);
13+
public Deposition createDeposition(final Metadata m) throws UnsupportedOperationException, IOException ;
14+
public List<DepositionFile> getFiles(Integer depositionId);
15+
public DepositionFile uploadFile(final FileMetadata f, Integer depositionId) throws UnsupportedOperationException, IOException;
16+
public boolean discard(Integer id);
17+
18+
}

src/main/java/de/tud/cs/stg/zenodo/ZenodoClient.java

Lines changed: 36 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/**
2626
* Created by benhermann on 31.05.17.
2727
*/
28-
public class ZenodoClient {
28+
public class ZenodoClient implements ZenodoAPI {
2929

3030
private static final String productionToken = "E7MJ0NJUzEwLKk9FH5f3xcaj2DgSgxZpR83kEn2EneMuR42YkeD7dM3Znn6b";
3131
private static final String sandboxToken = "HWiH1QCdIj81fj0a9vB9knBzfH8puk55NXiEZqkumpILavP2BHgKnjgUEyc9";
@@ -185,25 +185,6 @@ public Deposition createDeposition(final Metadata m) throws UnsupportedOperation
185185
return null;
186186
}
187187

188-
public Deposition createDepositionwithVersion(final Metadata m, Integer depositionId) {
189-
HttpRequestWithBody post = preparePostRequest(baseURL + API.Deposit.NewVersion);
190-
post.routeParam("id", depositionId.toString());
191-
String data = "{}";
192-
if (m != null)
193-
data = objectMapper.writeValue(new Object() {
194-
public Metadata metadata = m;
195-
});
196-
RequestBodyEntity completePost = post.body(data);
197-
try {
198-
HttpResponse<Deposition> response = completePost.asObject(Deposition.class);
199-
return response.getBody();
200-
201-
} catch (UnirestException e) {
202-
e.printStackTrace();
203-
}
204-
return null;
205-
}
206-
207188
/**
208189
* Created by agupta on 19.11.18. to get the list of files for a particular
209190
* deposition
@@ -293,40 +274,40 @@ private HttpRequestWithBody prepareDeleteRequest(String url) {
293274
"Bearer " + token);
294275
}
295276

296-
public static void main(String[] args) throws UnsupportedOperationException, IOException, UnirestException {
297-
ZenodoClient client = new ZenodoClient(sandboxURL, sandboxToken);
298-
System.out.println(client.test());
299-
300-
// Metadata firstTry = new Metadata(Metadata.UploadType.DATASET,
301-
// new Date(),
302-
// "API test",
303-
// "API test",
304-
// "1.0",
305-
// Metadata.AccessRight.CLOSED);
277+
// public static void main(String[] args) throws UnsupportedOperationException, IOException, UnirestException {
278+
// ZenodoClient client = new ZenodoClient(sandboxURL, sandboxToken);
279+
// System.out.println(client.test());
280+
//
281+
//// Metadata firstTry = new Metadata(Metadata.UploadType.DATASET,
282+
//// new Date(),
283+
//// "API test",
284+
//// "API test",
285+
//// "1.0",
286+
//// Metadata.AccessRight.CLOSED);
287+
////
288+
//// Deposition deposition = client.createDeposition(firstTry);
289+
//
290+
// HttpResponse<JsonNode> jsonResponse = Unirest.post("https://sandbox.zenodo.org/"+API.Deposit.Files).routeParam("id", Integer.toString(252680))
291+
// .header("Authorization", "Bearer "+ sandboxToken)
292+
// .header("accept", "application/json")
293+
// .field("filename", "archive.zip")
294+
// .field("file", new File("/home/ankur/SHK/zenodo/archive.zip"))
295+
// .asJson();
296+
// System.out.println(jsonResponse.getStatus());
297+
//// FileMetadata firstFile = new FileMetadata(new File("/home/ankur/SHK/zenodo/archive.zip"));
298+
//// DepositionFile newFile = client.uploadFile(firstFile,252119);
299+
//// System.out.println("File Uploaded " + newFile.id + " " + newFile.filename);
300+
// List<Deposition> depositions = client.getDepositions();
301+
// for (Deposition d : depositions)
302+
// System.out.println(d.title + " " + d.created + " " + d.id);
303+
//
304+
// List<DepositionFile> files = client.getFiles(252123);
305+
// for (DepositionFile f : files) {
306+
// System.out.println(f.filename + " " + f.id + " " + f.filesize + " " + f.links.download);
307+
// }
306308
//
307-
// Deposition deposition = client.createDeposition(firstTry);
308-
309-
HttpResponse<JsonNode> jsonResponse = Unirest.post("https://sandbox.zenodo.org/"+API.Deposit.Files).routeParam("id", Integer.toString(252680))
310-
.header("Authorization", "Bearer "+ sandboxToken)
311-
.header("accept", "application/json")
312-
.field("filename", "archive.zip")
313-
.field("file", new File("/home/ankur/SHK/zenodo/archive.zip"))
314-
.asJson();
315-
System.out.println(jsonResponse.getStatus());
316-
// FileMetadata firstFile = new FileMetadata(new File("/home/ankur/SHK/zenodo/archive.zip"));
317-
// DepositionFile newFile = client.uploadFile(firstFile,252119);
318-
// System.out.println("File Uploaded " + newFile.id + " " + newFile.filename);
319-
List<Deposition> depositions = client.getDepositions();
320-
for (Deposition d : depositions)
321-
System.out.println(d.title + " " + d.created + " " + d.id);
322-
323-
List<DepositionFile> files = client.getFiles(252123);
324-
for (DepositionFile f : files) {
325-
System.out.println(f.filename + " " + f.id + " " + f.filesize + " " + f.links.download);
326-
}
327-
328-
329-
330-
331-
}
309+
//
310+
//
311+
//
312+
// }
332313
}

0 commit comments

Comments
 (0)