Skip to content
Merged

wip #68

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<relativePath />
</parent>
<artifactId>dans-dataverse-client-lib-examples</artifactId>
<version>1.11.1-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
<name>DANS Dataverse Client Library Examples</name>
<inceptionYear>2021</inceptionYear>
<scm>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
public class DatasetDeleteFiles extends ExampleBase {
public static void main(String[] args) throws Exception {
String persistentId = args[0];
List<Integer> fileIds = new ArrayList<>();
List<Long> fileIds = new ArrayList<>();
for (int i = 1; i < args.length; i++) {
fileIds.add(Integer.parseInt(args[i]));
fileIds.add(Long.parseLong(args[i]));
}
var r = client.dataset(persistentId).deleteFiles(fileIds);
log.info("Response message: {}", r.getEnvelopeAsJson().toPrettyString());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2021 DANS - Data Archiving and Networked Services (info@dans.knaw.nl)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.knaw.dans.lib.dataverse.example;

import lombok.extern.slf4j.Slf4j;
import nl.knaw.dans.lib.dataverse.ExampleBase;

@Slf4j
public class FileGetMetadata extends ExampleBase {
public static void main(String[] args) throws Exception {
var r = client.file(Long.parseLong(args[0])).getMetadata();
log.info("Response message: {}", r.getEnvelopeAsJson().toPrettyString());

var checksum = r.getData().getDataFile().getChecksum();
log.info("Checksum type = {}, value = {}", checksum.getType(), checksum.getValue());
}
}
2 changes: 1 addition & 1 deletion lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<relativePath />
</parent>
<artifactId>dans-dataverse-client-lib</artifactId>
<version>1.11.1-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
<name>DANS Dataverse Client Library</name>
<inceptionYear>2021</inceptionYear>
<scm>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ public DataverseHttpResponse<HashMap> setRetentionPeriod(String json) throws IOE
return httpClientWrapper.postJsonString(subPath("files/actions/:set-retention"), json, params(emptyMap()), extraHeaders, HashMap.class);
}

public DataverseHttpResponse<String> deleteFiles(List<Integer> fileIds) throws IOException, DataverseException {
public DataverseHttpResponse<String> deleteFiles(List<Long> fileIds) throws IOException, DataverseException {
return httpClientWrapper.putJsonString(subPath("deleteFiles"), httpClientWrapper.writeValueAsString(fileIds), params(emptyMap()), extraHeaders, String.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,27 +107,27 @@ public SwordApi sword() {
return new SwordApi(httpClientWrapper);
}

public FileApi file(int id) {
public FileApi file(long id) {
return new FileApi(httpClientWrapper, String.valueOf(id), false);
}

public FileApi file(int id, String invocationId) {
public FileApi file(long id, String invocationId) {
return new FileApi(httpClientWrapper, String.valueOf(id), false, invocationId);
}

public DataAccessRequestsApi accessRequests(String pid) {
return new DataAccessRequestsApi(httpClientWrapper, pid, true);
}

public DataAccessRequestsApi accessRequests(int id) {
public DataAccessRequestsApi accessRequests(long id) {
return new DataAccessRequestsApi(httpClientWrapper, String.valueOf(id), false);
}

public DataAccessRequestsApi accessRequests(String pid, String invocationId) {
return new DataAccessRequestsApi(httpClientWrapper, pid, true, invocationId);
}

public DataAccessRequestsApi accessRequests(int id, String invocationId) {
public DataAccessRequestsApi accessRequests(long id, String invocationId) {
return new DataAccessRequestsApi(httpClientWrapper, String.valueOf(id), false, invocationId);
}

Expand All @@ -139,12 +139,12 @@ public BasicFileAccessApi basicFileAccess(String pid, String invocationId) {
return new BasicFileAccessApi(httpClientWrapper, pid, true, invocationId);
}

public BasicFileAccessApi basicFileAccess(int id) {
return new BasicFileAccessApi(httpClientWrapper, Integer.toString(id), false);
public BasicFileAccessApi basicFileAccess(long id) {
return new BasicFileAccessApi(httpClientWrapper, Long.toString(id), false);
}

public BasicFileAccessApi basicFileAccess(int id, String invocationId) {
return new BasicFileAccessApi(httpClientWrapper, Integer.toString(id), false, invocationId);
public BasicFileAccessApi basicFileAccess(long id, String invocationId) {
return new BasicFileAccessApi(httpClientWrapper, Long.toString(id), false, invocationId);
}

public SearchApi search() {
Expand Down
10 changes: 10 additions & 0 deletions lib/src/main/java/nl/knaw/dans/lib/dataverse/FileApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ public class FileApi extends AbstractTargetedApi {
super(httpClientWrapper, id, isPersistentId, invocationId, Paths.get("api/v1/files/"));
}

/**
* @return a {@link DataverseHttpResponse} object containing a {@link FileMeta} instance that contains the metadata of the requested file
* @throws IOException if an I/O error occurs during the request or response processing
* @throws DataverseException if the Dataverse API returns an error response
* @see <a href="https://guides.dataverse.org/en/latest/api/native-api.html#get-json-representation-of-a-file" target="_blank">Dataverse documentation</a>
*/
public DataverseHttpResponse<FileMeta> getMetadata() throws IOException, DataverseException {
return httpClientWrapper.get(subPath(""), params(emptyMap()), extraHeaders, FileMeta.class);
}

// TODO: https://guides.dataverse.org/en/latest/api/native-api.html#restrict-files
// TODO: https://guides.dataverse.org/en/latest/api/native-api.html#uningest-a-file
// TODO: https://guides.dataverse.org/en/latest/api/native-api.html#reingest-a-file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
package nl.knaw.dans.lib.dataverse.model;

import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = true)
public class DataMessageWithId extends DataMessage {
private String id;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
public class DataFile {
// Note that the following fields should align with those
// in dataverse src/main/java/edu/harvard/iq/dataverse/util/json/JsonPrinter.java
private int id;
private long id;
private String persistentId;
private String pidURL;
private String filename;
Expand All @@ -50,8 +50,8 @@ public class DataFile {
private String originalFileName;
@JsonProperty("UNF")
private String unf;
private int rootDataFileId;
private int previousDataFileId;
private Long rootDataFileId;
private Long previousDataFileId;
// md5 is ignored!
private Checksum checksum;
private Boolean tabularData;
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</parent>

<artifactId>dans-dataverse-client-lib-build</artifactId>
<version>1.11.1-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
<inceptionYear>2021</inceptionYear>
<name>DANS Dataverse Client Library Master Build</name>
<packaging>pom</packaging>
Expand Down
Loading