Skip to content

Commit 8dae6af

Browse files
committed
PATCH-4: DD-1988 - Fix /api/admin/validate/dataset/files/{id} error response IQSS#11749
1 parent a310177 commit 8dae6af

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

  • src/main/java/edu/harvard/iq/dataverse/api

src/main/java/edu/harvard/iq/dataverse/api/Admin.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,15 @@ public Response validateDataset(@PathParam("id") String id, @QueryParam("variabl
12431243
@Produces({"application/json"})
12441244
public Response validateDatasetDatafiles(@PathParam("id") String id) {
12451245

1246-
// Streaming output: the API will start producing
1246+
Dataset dataset;
1247+
// First check if the dataset exists before starting the streaming output
1248+
try {
1249+
dataset = findDatasetOrDie(id);
1250+
} catch (WrappedResponse wr) {
1251+
return wr.getResponse(); // This will return the proper 404 Not Found response
1252+
}
1253+
1254+
// Streaming output: the API will start producing
12471255
// the output right away, as it goes through the list
12481256
// of the datafiles in the dataset.
12491257
// The streaming mechanism is modeled after validate/datasets API.
@@ -1252,23 +1260,13 @@ public Response validateDatasetDatafiles(@PathParam("id") String id) {
12521260
@Override
12531261
public void write(OutputStream os) throws IOException,
12541262
WebApplicationException {
1255-
Dataset dataset;
1256-
1257-
try {
1258-
dataset = findDatasetOrDie(id);
1259-
} catch (Exception ex) {
1260-
throw new IOException(ex.getMessage());
1261-
}
12621263

12631264
os.write("{\"dataFiles\": [\n".getBytes());
12641265

12651266
boolean wroteObject = false;
12661267
for (DataFile dataFile : dataset.getFiles()) {
1267-
// Potentially, there's a godzillion datasets in this Dataverse.
1268-
// This is why we go through the list of ids here, and instantiate
1269-
// only one dataset at a time.
1268+
12701269
boolean success = false;
1271-
boolean constraintViolationDetected = false;
12721270

12731271
JsonObjectBuilder output = Json.createObjectBuilder();
12741272
output.add("datafileId", dataFile.getId());

0 commit comments

Comments
 (0)