Skip to content

Commit

Permalink
support multiple types, remove hasPreviewMode #6919
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Oct 21, 2020
1 parent e5eacae commit 767882b
Show file tree
Hide file tree
Showing 16 changed files with 281 additions and 127 deletions.
10 changes: 8 additions & 2 deletions doc/release-notes/6919-preview-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ Newly-supported use cases in this release include:

### Converting Explore External Tools to Preview Only

Optionally, you can convert existing tools in the `externaltool` database table from type "explore" to "preview". The only known preview tools are the [dataverse-previewers][]. Tools of type "explore" that have `hasPreviewMode` set to true will continue to be displayed in the Preview tab.
When the war file is deployed, a SQL migration script will convert [dataverse-previewers][] to have both "explore" and "preview" types so that they will continue to be displayed in the Preview tab.

If you would prefer that these tools be preview only, you can delete the tools, adjust the JSON manifests (changing "explore" to "preview"), and re-add them.

[dataverse-previewers]: https://github.com/GlobalDataverseCommunityConsortium/dataverse-previewers

## Notes for Tool Developers and Integrators

### Preview Only External Tools

A new external tool type called "preview" has been added that prevents the tool from being displayed under "Explore Options" under the "Access File" button on the file landing page (#6919).
A new external tool type called "preview" has been added that prevents the tool from being displayed under "Explore Options" under the "Access File" button on the file landing page (#6919). This "preview" type replaces "hasPreviewMode", which has been removed.

### Multiple Types for External Tools

External tools now support multiple types. In practice, the types "explore" and "preview" are the only combination that makes a difference in the UI as opposed to only having only one or the other type (see "preview only" above). Multiple types are specified in the JSON manifest with an array in "types". The older, single "type" is still supported but should be considered deprecated.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"displayName": "Dynamic Dataset Tool",
"description": "Dazzles! Dizzying!",
"scope": "dataset",
"type": "explore",
"types": [
"explore"
],
"toolUrl": "https://dynamicdatasettool.com/v2",
"toolParameters": {
"queryParameters": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"description": "Fabulous Fun for Files!",
"toolName": "fabulous",
"scope": "file",
"type": "explore",
"types": [
"explore",
"preview"
],
"toolUrl": "https://fabulousfiletool.com",
"contentType": "text/tab-separated-values",
"toolParameters": {
Expand Down
2 changes: 0 additions & 2 deletions doc/sphinx-guides/source/admin/external-tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ File level preview tools allow the user to see a preview of the file contents wi

When a file has a preview available, a preview icon will appear next to that file in the file listing on the dataset page. On the file page itself, the preview will appear in a Preview tab either immediately or once a guestbook has been filled in or terms, if any, have been agreed to.

File level explore tools can also show previews if they have been designed to show a simplified view for embedding in the file page and if the ``hasPreviewMode`` parameter is set to ``true``.

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

Expand Down
6 changes: 2 additions & 4 deletions doc/sphinx-guides/source/api/external-tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Let's look at two examples of external tool manifests (one at the file level and
External Tools for Files
^^^^^^^^^^^^^^^^^^^^^^^^

:download:`fabulousFileTool.json <../_static/installation/files/root/external-tools/fabulousFileTool.json>` is a file level explore tool that operates on tabular files:
:download:`fabulousFileTool.json <../_static/installation/files/root/external-tools/fabulousFileTool.json>` is a file level both an "explore" tool and a "preview" tool that operates on tabular files:

.. literalinclude:: ../_static/installation/files/root/external-tools/fabulousFileTool.json

Expand Down Expand Up @@ -86,12 +86,10 @@ Terminology

scope Whether the external tool appears and operates at the **file** level or the **dataset** level. Note that a file level tool much also specify the type of file it operates on (see "contentType" below).

type Whether the external tool is an **explore** tool, a **preview** tool or a **configure** tool. Configure tools require an API token because they make changes to data files (files within datasets). Configure tools are currently not supported at the dataset level.
types Whether the external tool is an **explore** tool, a **preview** tool, a **configure** tool or any combination of these (multiple types are supported for a single tool). Configure tools require an API token because they make changes to data files (files within datasets). Configure tools are currently not supported at the dataset level. The older "type" keyword that allows you to pass a single type as a string is deprecated but still supported.

toolUrl The **base URL** of the tool before query parameters are added.

hasPreviewMode A boolean that indicates whether tool has a preview mode which can be embedded in the File Page. Since this view is designed for embedding within Dataverse, the preview mode for a tool will typically be a view without headers or other options that may be included with a tool that is designed to be launched in a new window.

contentType File level tools operate on a specific **file type** (content type or MIME type such as "application/pdf") and this must be specified. Dataset level tools do not use contentType.

toolParameters **Query parameters** are supported and described below.
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -5423,11 +5423,6 @@ public List<DatasetField> getDatasetSummaryFields() {

public boolean isShowPreviewButton(Long fileId) {
List<ExternalTool> previewTools = getPreviewToolsForDataFile(fileId);
for (ExternalTool externalTool : getExploreToolsForDataFile(fileId)) {
if (externalTool.getHasPreviewMode()) {
previewTools.add(externalTool);
}
}
return previewTools.size() > 0;
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/FilePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ public void setDatasetVersionId(Long datasetVersionId) {
}

private List<ExternalTool> addMapLayerAndSortExternalTools(){
List<ExternalTool> retList = externalToolService.findFileToolsByTypeContentTypeAndAvailablePreview(ExternalTool.Type.EXPLORE, file.getContentType());
List<ExternalTool> retList = externalToolService.findFileToolsByTypeAndContentType(ExternalTool.Type.PREVIEW, file.getContentType());

if(!retList.isEmpty()){
retList.forEach((et) -> {
et.setWorldMapTool(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Logger;
import javax.json.Json;
import javax.json.JsonArrayBuilder;
import javax.json.JsonObjectBuilder;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Transient;

/**
Expand All @@ -28,12 +33,12 @@ public class ExternalTool implements Serializable {

public static final String DISPLAY_NAME = "displayName";
public static final String DESCRIPTION = "description";
public static final String TYPE = "type";
public static final String LEGACY_SINGLE_TYPE = "type";
public static final String TYPES = "types";
public static final String SCOPE = "scope";
public static final String TOOL_URL = "toolUrl";
public static final String TOOL_PARAMETERS = "toolParameters";
public static final String CONTENT_TYPE = "contentType";
public static final String HAS_PREVIEW_MODE = "hasPreviewMode";
public static final String TOOL_NAME = "toolName";

@Id
Expand Down Expand Up @@ -61,11 +66,11 @@ public class ExternalTool implements Serializable {
private String description;

/**
* Whether the tool is an "explore" tool or a "configure" tool, for example.
* A tool can be multiple types, "explore", "configure", "preview", etc.
*/
@Column(nullable = false)
@Enumerated(EnumType.STRING)
private Type type;
@OneToMany(mappedBy = "externalTool", cascade = CascadeType.ALL)
@JoinColumn(nullable = false)
private List<ExternalToolType> externalToolTypes;

/**
* Whether the tool operates at the dataset or file level.
Expand All @@ -90,12 +95,7 @@ public class ExternalTool implements Serializable {
*/
@Column(nullable = true, columnDefinition = "TEXT")
private String contentType;

@Column(nullable = false)
private boolean hasPreviewMode;



@Transient
private boolean worldMapTool;

Expand All @@ -121,28 +121,15 @@ public void setWorldMapTool(boolean worldMapTool) {
public ExternalTool() {
}

public ExternalTool(String displayName, String toolName, String description, Type type, Scope scope, String toolUrl, String toolParameters, String contentType) {
this.displayName = displayName;
this.toolName = toolName;
this.description = description;
this.type = type;
this.scope = scope;
this.toolUrl = toolUrl;
this.toolParameters = toolParameters;
this.contentType = contentType;
this.hasPreviewMode = false;
}

public ExternalTool(String displayName, String toolName, String description, Type type, Scope scope, String toolUrl, String toolParameters, String contentType, boolean hasPreviewMode) {
public ExternalTool(String displayName, String toolName, String description, List<ExternalToolType> externalToolTypes, Scope scope, String toolUrl, String toolParameters, String contentType) {
this.displayName = displayName;
this.toolName = toolName;
this.description = description;
this.type = type;
this.externalToolTypes = externalToolTypes;
this.scope = scope;
this.toolUrl = toolUrl;
this.toolParameters = toolParameters;
this.contentType = contentType;
this.hasPreviewMode = hasPreviewMode;
}

public enum Type {
Expand Down Expand Up @@ -230,8 +217,23 @@ public void setDescription(String description) {
this.description = description;
}

public Type getType() {
return type;
public List<ExternalToolType> getExternalToolTypes() {
return externalToolTypes;
}

public void setExternalToolTypes(List<ExternalToolType> externalToolTypes) {
this.externalToolTypes = externalToolTypes;
}

public boolean isExploreTool() {
boolean isExploreTool = false;
for (ExternalToolType externalToolType : externalToolTypes) {
if (externalToolType.getType().equals(Type.EXPLORE)) {
isExploreTool = true;
break;
}
}
return isExploreTool;
}

public Scope getScope() {
Expand Down Expand Up @@ -261,15 +263,7 @@ public String getContentType() {
public void setContentType(String contentType) {
this.contentType = contentType;
}

public boolean getHasPreviewMode() {
return type.equals(ExternalTool.Type.PREVIEW) || hasPreviewMode;
}

public void setHasPreviewMode(boolean hasPreviewMode) {
this.hasPreviewMode = hasPreviewMode;
}

public JsonObjectBuilder toJson() {
JsonObjectBuilder jab = Json.createObjectBuilder();
jab.add("id", getId());
Expand All @@ -278,17 +272,16 @@ public JsonObjectBuilder toJson() {
jab.add(TOOL_NAME, getToolName());
}
jab.add(DESCRIPTION, getDescription());
jab.add(TYPE, getType().text);
JsonArrayBuilder types = Json.createArrayBuilder();
for (ExternalToolType externalToolType : externalToolTypes) {
types.add(externalToolType.getType().text);
}
jab.add(TYPES, types);
jab.add(SCOPE, getScope().text);
jab.add(TOOL_URL, getToolUrl());
jab.add(TOOL_PARAMETERS, getToolParameters());
if (getContentType() != null) {
jab.add(CONTENT_TYPE, getContentType());
}
if (getHasPreviewMode()) {
jab.add(HAS_PREVIEW_MODE, getHasPreviewMode());
} else {

}
return jab;
}
Expand Down
Loading

0 comments on commit 767882b

Please sign in to comment.