Skip to content

Commit

Permalink
move testing methods to /api/admin/test #5028 #4137
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Sep 12, 2019
1 parent 09766f1 commit 06105e8
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 129 deletions.
4 changes: 0 additions & 4 deletions doc/sphinx-guides/source/admin/external-tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ File level explore tools are specific to the file type (content type or MIME typ

An "Explore" button will appear (on both the dataset page and the file landing page) for files that match the type that the tool has been built for. When there are multiple explore tools for a filetype, the button becomes a dropdown.

For a specific file, you can check how many tools are available using the GUI as described above or by using the API as described at :ref:`list-external-tools-for-a-file-api`.

File Level Configure Tools
++++++++++++++++++++++++++

Expand All @@ -92,8 +90,6 @@ Dataset Level Explore Tools

When a dataset level explore tool is added, an "Explore" button on the dataset page will appear. This button becomes a drop down when there are multiple tools.

You can also use the API to list dataset level tools. See :ref:`list-external-tools-for-a-dataset-api`

Dataset Level Configure Tools
+++++++++++++++++++++++++++++

Expand Down
54 changes: 0 additions & 54 deletions doc/sphinx-guides/source/api/native-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -868,33 +868,6 @@ Normally published datasets should not be deleted, but there exists a "destroy"

Calling the destroy endpoint is permanent and irreversible. It will remove the dataset and its datafiles, then re-index the parent dataverse in Solr. This endpoint requires the API token of a superuser.

.. _list-external-tools-for-a-dataset-api:

List External Tools for a Dataset
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Some installations of Dataverse have external tools enabled for datasets and there are two types:

- explore
- configure

.. note:: See :ref:`curl-examples-and-environment-variables` if you are unfamiliar with the use of ``export`` below.

.. code-block:: bash
export API_TOKEN=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
export SERVER_URL=https://demo.dataverse.org
export PERSISTENT_ID=doi:10.5072/FK2/J8SJZB
export TYPE=explore
curl -H X-Dataverse-key:$API_TOKEN \""$SERVER_URL/api/datasets/:persistentId/externalTools?persistentId=$PERSISTENT_ID&type=$TYPE"\"
The fully expanded example above (without environment variables) looks like this:

.. code-block:: bash
curl -H X-Dataverse-key:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx "https://demo.dataverse.org/api/datasets/:persistentId/externalTools?persistentId=doi:10.5072/FK2/J8SJZB&type=explore"
Files
-----

Expand Down Expand Up @@ -1050,33 +1023,6 @@ Starting the release 4.10 the size of the saved original file (for an ingested t

Note the optional "limit" parameter. Without it, the API will attempt to populate the sizes for all the saved originals that don't have them in the database yet. Otherwise it will do so for the first N such datafiles.

.. _list-external-tools-for-a-file-api:

List External Tools for a File
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Some installations of Dataverse have external tools enabled for files and there are two types:

- explore
- configure

.. note:: See :ref:`curl-examples-and-environment-variables` if you are unfamiliar with the use of ``export`` below.

.. code-block:: bash
export API_TOKEN=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
export SERVER_URL=https://demo.dataverse.org
export PERSISTENT_ID=doi:10.5072/FK2/J8SJZB
export TYPE=explore
curl -H X-Dataverse-key:$API_TOKEN \""$SERVER_URL/api/files/:persistentId/externalTools?persistentId=$PERSISTENT_ID&type=$TYPE"\"
The fully expanded example above (without environment variables) looks like this:

.. code-block:: bash
curl -H X-Dataverse-key:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx "https://demo.dataverse.org/api/files/:persistentId/externalTools?persistentId=doi:10.5072/FK2/J8SJZB&type=explore"
Builtin Users
-------------

Expand Down
38 changes: 0 additions & 38 deletions src/main/java/edu/harvard/iq/dataverse/api/Datasets.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,10 @@
import edu.harvard.iq.dataverse.privateurl.PrivateUrl;
import edu.harvard.iq.dataverse.S3PackageImporter;
import static edu.harvard.iq.dataverse.api.AbstractApiBean.error;
import edu.harvard.iq.dataverse.authorization.users.ApiToken;
import edu.harvard.iq.dataverse.batch.util.LoggingUtil;
import edu.harvard.iq.dataverse.dataaccess.StorageIO;
import edu.harvard.iq.dataverse.engine.command.exception.CommandException;
import edu.harvard.iq.dataverse.engine.command.exception.PermissionException;
import edu.harvard.iq.dataverse.engine.command.exception.UnforcedCommandException;
import edu.harvard.iq.dataverse.engine.command.impl.DeleteDataFileCommand;
import edu.harvard.iq.dataverse.engine.command.impl.UpdateDvObjectPIDMetadataCommand;
import edu.harvard.iq.dataverse.externaltools.ExternalTool;
import edu.harvard.iq.dataverse.externaltools.ExternalToolHandler;
import edu.harvard.iq.dataverse.makedatacount.DatasetExternalCitations;
import edu.harvard.iq.dataverse.makedatacount.DatasetExternalCitationsServiceBean;
import edu.harvard.iq.dataverse.makedatacount.DatasetMetrics;
Expand All @@ -101,26 +95,20 @@
import edu.harvard.iq.dataverse.util.SystemConfig;
import edu.harvard.iq.dataverse.util.json.JsonParseException;
import edu.harvard.iq.dataverse.search.IndexServiceBean;
import edu.harvard.iq.dataverse.util.DateUtil;
import static edu.harvard.iq.dataverse.util.json.JsonPrinter.*;
import static edu.harvard.iq.dataverse.util.json.NullSafeJsonBuilder.jsonObjectBuilder;
import edu.harvard.iq.dataverse.util.json.NullSafeJsonBuilder;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -1896,31 +1884,5 @@ public Response getMakeDataCountMetric(@PathParam("id") String idSupplied, @Path
}
}

@GET
@Path("{id}/externalTools")
public Response getExternalTools(@PathParam("id") String idSupplied, @QueryParam("type") String typeSupplied) {
ExternalTool.Type type;
try {
type = ExternalTool.Type.fromString(typeSupplied);
} catch (IllegalArgumentException ex) {
return error(BAD_REQUEST, ex.getLocalizedMessage());
}
Dataset dataset;
try {
dataset = findDatasetOrDie(idSupplied);
JsonArrayBuilder tools = Json.createArrayBuilder();
List<ExternalTool> datasetTools = externalToolService.findDatasetToolsByType(type);
for (ExternalTool tool : datasetTools) {
ApiToken apiToken = externalToolService.getApiToken(getRequestApiKey());
ExternalToolHandler externalToolHandler = new ExternalToolHandler(tool, dataset, apiToken);
JsonObjectBuilder toolToJson = externalToolService.getToolAsJsonWithQueryParameters(externalToolHandler);
tools.add(toolToJson);
}
return ok(tools);
} catch (WrappedResponse wr) {
return wr.getResponse();
}
}

}

31 changes: 0 additions & 31 deletions src/main/java/edu/harvard/iq/dataverse/api/Files.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import edu.harvard.iq.dataverse.FileMetadata;
import edu.harvard.iq.dataverse.UserNotificationServiceBean;
import static edu.harvard.iq.dataverse.api.AbstractApiBean.error;
import edu.harvard.iq.dataverse.authorization.users.ApiToken;
import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser;
import edu.harvard.iq.dataverse.authorization.users.User;
import edu.harvard.iq.dataverse.datasetutility.AddReplaceFileHelper;
Expand All @@ -32,8 +31,6 @@
import edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetVersionCommand;
import edu.harvard.iq.dataverse.export.ExportException;
import edu.harvard.iq.dataverse.export.ExportService;
import edu.harvard.iq.dataverse.externaltools.ExternalTool;
import edu.harvard.iq.dataverse.externaltools.ExternalToolHandler;
import edu.harvard.iq.dataverse.ingest.IngestRequest;
import edu.harvard.iq.dataverse.ingest.IngestServiceBean;
import edu.harvard.iq.dataverse.makedatacount.MakeDataCountLoggingServiceBean;
Expand All @@ -51,9 +48,6 @@
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.inject.Inject;
import javax.json.Json;
import javax.json.JsonArrayBuilder;
import javax.json.JsonObjectBuilder;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
Expand Down Expand Up @@ -621,29 +615,4 @@ private void exportDatasetMetadata(SettingsServiceBean settingsServiceBean, Data
}
}

@Path("{id}/externalTools")
@GET
public Response getExternalTools(@PathParam("id") String idSupplied, @QueryParam("type") String typeSupplied) {
ExternalTool.Type type;
try {
type = ExternalTool.Type.fromString(typeSupplied);
} catch (IllegalArgumentException ex) {
return error(BAD_REQUEST, ex.getLocalizedMessage());
}
try {
DataFile dataFile = findDataFileOrDie(idSupplied);
JsonArrayBuilder tools = Json.createArrayBuilder();
List<ExternalTool> datasetTools = externalToolService.findFileToolsByTypeAndContentType(type, dataFile.getContentType());
for (ExternalTool tool : datasetTools) {
ApiToken apiToken = externalToolService.getApiToken(getRequestApiKey());
ExternalToolHandler externalToolHandler = new ExternalToolHandler(tool, dataFile, apiToken, dataFile.getFileMetadata());
JsonObjectBuilder toolToJson = externalToolService.getToolAsJsonWithQueryParameters(externalToolHandler);
tools.add(toolToJson);
}
return ok(tools);
} catch (WrappedResponse wr) {
return wr.getResponse();
}
}

}
74 changes: 74 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/api/TestApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package edu.harvard.iq.dataverse.api;

import edu.harvard.iq.dataverse.DataFile;
import edu.harvard.iq.dataverse.Dataset;
import static edu.harvard.iq.dataverse.api.AbstractApiBean.error;
import edu.harvard.iq.dataverse.authorization.users.ApiToken;
import edu.harvard.iq.dataverse.externaltools.ExternalTool;
import edu.harvard.iq.dataverse.externaltools.ExternalToolHandler;
import java.util.List;
import javax.json.Json;
import javax.json.JsonArrayBuilder;
import javax.json.JsonObjectBuilder;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;

@Path("admin/test")
public class TestApi extends AbstractApiBean {

@GET
@Path("datasets/{id}/externalTools")
public Response getExternalToolsforFile(@PathParam("id") String idSupplied, @QueryParam("type") String typeSupplied) {
ExternalTool.Type type;
try {
type = ExternalTool.Type.fromString(typeSupplied);
} catch (IllegalArgumentException ex) {
return error(BAD_REQUEST, ex.getLocalizedMessage());
}
Dataset dataset;
try {
dataset = findDatasetOrDie(idSupplied);
JsonArrayBuilder tools = Json.createArrayBuilder();
List<ExternalTool> datasetTools = externalToolService.findDatasetToolsByType(type);
for (ExternalTool tool : datasetTools) {
ApiToken apiToken = externalToolService.getApiToken(getRequestApiKey());
ExternalToolHandler externalToolHandler = new ExternalToolHandler(tool, dataset, apiToken);
JsonObjectBuilder toolToJson = externalToolService.getToolAsJsonWithQueryParameters(externalToolHandler);
tools.add(toolToJson);
}
return ok(tools);
} catch (WrappedResponse wr) {
return wr.getResponse();
}
}

@Path("files/{id}/externalTools")
@GET
public Response getExternalToolsForFile(@PathParam("id") String idSupplied, @QueryParam("type") String typeSupplied) {
ExternalTool.Type type;
try {
type = ExternalTool.Type.fromString(typeSupplied);
} catch (IllegalArgumentException ex) {
return error(BAD_REQUEST, ex.getLocalizedMessage());
}
try {
DataFile dataFile = findDataFileOrDie(idSupplied);
JsonArrayBuilder tools = Json.createArrayBuilder();
List<ExternalTool> datasetTools = externalToolService.findFileToolsByTypeAndContentType(type, dataFile.getContentType());
for (ExternalTool tool : datasetTools) {
ApiToken apiToken = externalToolService.getApiToken(getRequestApiKey());
ExternalToolHandler externalToolHandler = new ExternalToolHandler(tool, dataFile, apiToken, dataFile.getFileMetadata());
JsonObjectBuilder toolToJson = externalToolService.getToolAsJsonWithQueryParameters(externalToolHandler);
tools.add(toolToJson);
}
return ok(tools);
} catch (WrappedResponse wr) {
return wr.getResponse();
}
}

}
4 changes: 2 additions & 2 deletions src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -1778,7 +1778,7 @@ static Response getExternalToolsForDataset(String idOrPersistentIdOfDataset, Str
requestSpecification = given()
.header(UtilIT.API_TOKEN_HTTP_HEADER, apiToken);
}
return requestSpecification.get("/api/datasets/" + idInPath + "/externalTools?type=" + type + optionalQueryParam);
return requestSpecification.get("/api/admin/test/datasets/" + idInPath + "/externalTools?type=" + type + optionalQueryParam);
}

static Response getExternalToolsForFile(String idOrPersistentIdOfFile, String type, String apiToken) {
Expand All @@ -1793,7 +1793,7 @@ static Response getExternalToolsForFile(String idOrPersistentIdOfFile, String ty
requestSpecification = given()
.header(UtilIT.API_TOKEN_HTTP_HEADER, apiToken);
}
return requestSpecification.get("/api/files/" + idInPath + "/externalTools?type=" + type + optionalQueryParam);
return requestSpecification.get("/api/admin/test/files/" + idInPath + "/externalTools?type=" + type + optionalQueryParam);
}

static Response submitFeedback(JsonObjectBuilder job) {
Expand Down

0 comments on commit 06105e8

Please sign in to comment.