Skip to content

Commit

Permalink
Added embedded viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosjepard committed Nov 12, 2024
1 parent 6b0a74a commit e97d6dd
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -524,18 +524,31 @@ public class ViewerConstants {
/**
* Template Engine
*/

public static final String OPEN_TEMPLATE_ENGINE = "{{";
public static final String CLOSE_TEMPLATE_ENGINE = "}}";
public static final String TEMPLATE_UV_LINK = "uv_link";
public static final String TEMPLATE_LOB_DOWNLOAD_LABEL = "download_label";
public static final String TEMPLATE_LOB_DOWNLOAD_LINK = "download_link";
public static final String TEMPLATE_LOB_ROW_INDEX = "row_index";
public static final String TEMPLATE_LOB_COLUMN_INDEX = "column_index";
public static final String TEMPLATE_LOB_AUTO_DETECTED_MIME_TYPE = "auto_detected_mime_type";
public static final String TEMPLATE_LOB_AUTO_DETECTED_EXTENSION = "auto_detected_extension";
public static final String DEFAULT_VIEWER_DOWNLOAD_LABEL_TEMPLATE = "<a href=\""
+ ViewerConstants.OPEN_TEMPLATE_ENGINE
+ ViewerConstants.TEMPLATE_UV_LINK + ViewerConstants.CLOSE_TEMPLATE_ENGINE + ViewerConstants.OPEN_TEMPLATE_ENGINE
+ ViewerConstants.TEMPLATE_LOB_DOWNLOAD_LINK + ViewerConstants.CLOSE_TEMPLATE_ENGINE + "\">"
+ ViewerConstants.OPEN_TEMPLATE_ENGINE + ViewerConstants.TEMPLATE_LOB_DOWNLOAD_LABEL
+ ViewerConstants.CLOSE_TEMPLATE_ENGINE + "</a>";
public static final String DEFAULT_DOWNLOAD_LABEL_TEMPLATE = "<a href=\"" + ViewerConstants.OPEN_TEMPLATE_ENGINE
+ ViewerConstants.TEMPLATE_LOB_DOWNLOAD_LINK + ViewerConstants.CLOSE_TEMPLATE_ENGINE + "\">"
+ ViewerConstants.OPEN_TEMPLATE_ENGINE + ViewerConstants.TEMPLATE_LOB_DOWNLOAD_LABEL
+ ViewerConstants.CLOSE_TEMPLATE_ENGINE + "</a>";
public static final String DEFAULT_DETAILED_VIEWER_LABEL_TEMPLATE = "<iframe class=\"embedded-viewer\" src=\""
+ ViewerConstants.OPEN_TEMPLATE_ENGINE + ViewerConstants.TEMPLATE_UV_LINK + ViewerConstants.CLOSE_TEMPLATE_ENGINE
+ ViewerConstants.OPEN_TEMPLATE_ENGINE + ViewerConstants.TEMPLATE_LOB_DOWNLOAD_LINK
+ ViewerConstants.CLOSE_TEMPLATE_ENGINE + "\">" + ViewerConstants.OPEN_TEMPLATE_ENGINE
+ ViewerConstants.TEMPLATE_LOB_DOWNLOAD_LABEL + ViewerConstants.CLOSE_TEMPLATE_ENGINE + "</iframe>";

/**
* SIARD prefixes
Expand Down Expand Up @@ -571,4 +584,12 @@ public class ViewerConstants {
*/
private ViewerConstants() {
}

/**
* External viewer information
*/

public static final String UV_EXTERNAL_VIEWER_SERVICE_NAME = "ui.viewer.universalViewer.service_name";
public static final String PRESENTATION_EXTERNAL_SERVICE_NAME = "ui.viewer.presentation.service_name";
public static final String VIEWER_ENABLED = "ui.viewer.enabled";
}
Original file line number Diff line number Diff line change
Expand Up @@ -287,16 +287,14 @@ public SafeHtml getValue(ViewerRow row) {
String template = configColumn.getSearchStatus().getList().getTemplate().getTemplate();
if (template != null && !template.isEmpty()) {
String json = JSOUtils.cellsToJson(cells, nestedTable);
GWT.log("json -> " + json);
String blob = getBlobKey(configColumn.getTypeName());
if (!blob.isEmpty() && json.contains(blob)) {
String tempTemplate = template.replace("{{" + blob + "}}", "");
tempTemplate = tempTemplate.replace("}{", "} {");
if (tempTemplate.isEmpty())
tempTemplate = messages.row_downloadLOB();
template = "<a href=\"" + com.google.gwt.core.client.GWT.getHostPageBaseURL() + "{{" + blob + "}}\">"
+
tempTemplate + "</a>";
+ tempTemplate + "</a>";
String s = JavascriptUtils.compileTemplate(template, json);
aggregationList.add(s);
}
Expand All @@ -320,7 +318,6 @@ public SafeHtml getValue(ViewerRow row) {
} else {
if (!aggregationList.isEmpty()) {
ret = SafeHtmlUtils.fromSafeConstant(aggregationList.get(0));
GWT.log("ret -> " + ret.asString());
}
}
}
Expand Down Expand Up @@ -432,6 +429,7 @@ private SafeHtml getLobDownload(ViewerDatabase database, ColumnStatus configColu
String template = configColumn.getSearchStatus().getList().getTemplate().getTemplate();
if (template != null && !template.isEmpty()) {
String json = JSOUtils.cellsToJson(ViewerConstants.TEMPLATE_LOB_DOWNLOAD_LABEL, messages.row_downloadLOB(),
ViewerConstants.TEMPLATE_UV_LINK, RestUtils.createUVLob(),
ViewerConstants.TEMPLATE_LOB_DOWNLOAD_LINK, RestUtils.createExportLobUri(database.getUuid(),
table.getSchemaName(), table.getName(), row.getUuid(), columnIndex));
return SafeHtmlUtils.fromSafeConstant(JavascriptUtils.compileTemplate(template, json));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.util.TreeMap;
import java.util.TreeSet;

import com.databasepreservation.common.client.models.structure.ViewerPrimaryKey;
import org.roda.core.data.v2.index.sublist.Sublist;

import com.databasepreservation.common.client.ClientConfigurationManager;
Expand Down Expand Up @@ -335,6 +334,7 @@ private void getCellHTML(ViewerColumn column, Set<Ref> relatedTo, Set<Ref> refer
String template = columnStatus.getDetailsStatus().getTemplateStatus().getTemplate();
if (template != null && !template.isEmpty()) {
String json = JSOUtils.cellsToJson(ViewerConstants.TEMPLATE_LOB_DOWNLOAD_LABEL, messages.row_downloadLOB(),
ViewerConstants.TEMPLATE_UV_LINK, RestUtils.createUVLob(),
ViewerConstants.TEMPLATE_LOB_DOWNLOAD_LINK, RestUtils.createExportLobUri(database.getUuid(),
table.getSchemaName(), table.getName(), row.getUuid(), columnStatus.getColumnIndex()));
safeHtml = SafeHtmlUtils.fromSafeConstant(JavascriptUtils.compileTemplate(template, json));
Expand All @@ -350,6 +350,7 @@ private void getCellHTML(ViewerColumn column, Set<Ref> relatedTo, Set<Ref> refer
String template = columnStatus.getDetailsStatus().getTemplateStatus().getTemplate();
if (template != null && !template.isEmpty()) {
String json = JSOUtils.cellsToJson(ViewerConstants.TEMPLATE_LOB_DOWNLOAD_LABEL, messages.row_downloadLOB(),
ViewerConstants.TEMPLATE_UV_LINK, RestUtils.createUVLob(),
ViewerConstants.TEMPLATE_LOB_DOWNLOAD_LINK, RestUtils.createExportLobUri(database.getUuid(),
table.getSchemaName(), table.getName(), row.getUuid(), columnStatus.getColumnIndex()));
safeHtml = SafeHtmlUtils.fromSafeConstant(JavascriptUtils.compileTemplate(template, json));
Expand Down Expand Up @@ -420,15 +421,12 @@ private void getNestedHTML(ColumnStatus columnStatus) {
null, false, new ArrayList<>());
CollectionService.Util.call((IndexResult<ViewerRow> result) -> {
if (result.getTotalCount() >= 1) {
GWT.log("count -> " +result.getTotalCount());
RowField rowField;
String json = JSOUtils.cellsToJson(result.getResults().get(0).getCells(), nestedTable);
String s = JavascriptUtils.compileTemplate(template, json);
if (columnStatus.getTypeName().contains("BINARY LARGE OBJECT")) {
String templateLob = "<a href=\"{{download_link}}\">{{download_label}}</a>";
GWT.log("collumn status ->" + columnStatus.toString());
int originalCollumnIndex = 0;
GWT.log("collumn status -> " + result.getResults().get(0).getCells());

//loop to find the original column index
for (Map.Entry<String, ViewerCell> entry : result.getResults().get(0).getCells().entrySet()) {
Expand All @@ -442,9 +440,8 @@ private void getNestedHTML(ColumnStatus columnStatus) {
rowField = RowField.createInstance(new Label(s).getText(), new HTML(messages.rowPanelTextForLobUnavailable()));
} else {
SafeHtml safeHtml = SafeHtmlUtils.EMPTY_SAFE_HTML;
GWT.log("uuid -> " + result.getResults().get(0).toString());
GWT.log("id -> " + columnStatus.getId());
json = JSOUtils.cellsToJson(ViewerConstants.TEMPLATE_LOB_DOWNLOAD_LABEL, messages.row_downloadLOB(),
ViewerConstants.TEMPLATE_UV_LINK, RestUtils.createUVLob(),
ViewerConstants.TEMPLATE_LOB_DOWNLOAD_LINK, RestUtils.createExportLobUri(database.getUuid(),
nestedTable.getSchemaName(), nestedTable.getName(), result.getResults().get(0).getUuid(), originalCollumnIndex));
safeHtml = SafeHtmlUtils.fromSafeConstant(JavascriptUtils.compileTemplate(templateLob, json));
Expand All @@ -457,7 +454,6 @@ private void getNestedHTML(ColumnStatus columnStatus) {
}

rowField.addColumnDescription(columnStatus.getCustomDescription());
GWT.log("rowField -> " + rowField.toString());
panel.add(rowField);
}
}).findRows(database.getUuid(), database.getUuid(), nestedTable.getSchemaName(), nestedTable.getName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
*/
package com.databasepreservation.common.client.common.visualization.browse.configuration.columns.helpers;

import static com.databasepreservation.common.client.ViewerConstants.DEFAULT_DETAILED_VIEWER_LABEL_TEMPLATE;
import static com.databasepreservation.common.client.ViewerConstants.DEFAULT_DOWNLOAD_LABEL_TEMPLATE;
import static com.databasepreservation.common.client.ViewerConstants.DEFAULT_VIEWER_DOWNLOAD_LABEL_TEMPLATE;

import com.databasepreservation.common.client.ClientConfigurationManager;
import com.databasepreservation.common.client.ViewerConstants;
import com.databasepreservation.common.client.common.utils.ApplicationTypeActions;
import com.databasepreservation.common.client.models.status.collection.ColumnStatus;
Expand All @@ -19,7 +22,12 @@
import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.*;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

import config.i18n.client.ClientMessages;

Expand Down Expand Up @@ -87,7 +95,11 @@ public static ColumnOptionsPanel createInstance(TableStatus tableConfiguration,
public TemplateStatus getSearchTemplate() {
TemplateStatus templateStatus = new TemplateStatus();
if (ViewerStringUtils.isBlank(this.displayList.getText())) {
templateStatus.setTemplate(DEFAULT_DOWNLOAD_LABEL_TEMPLATE);
if (ClientConfigurationManager.getBoolean(false, ViewerConstants.VIEWER_ENABLED)) {
templateStatus.setTemplate(DEFAULT_VIEWER_DOWNLOAD_LABEL_TEMPLATE);
} else {
templateStatus.setTemplate(DEFAULT_DOWNLOAD_LABEL_TEMPLATE);
}
} else {
templateStatus.setTemplate(this.displayList.getText());
}
Expand All @@ -99,7 +111,11 @@ public TemplateStatus getSearchTemplate() {
public TemplateStatus getDetailsTemplate() {
TemplateStatus templateStatus = new TemplateStatus();
if (ViewerStringUtils.isBlank(this.detailsList.getText())) {
templateStatus.setTemplate(DEFAULT_DOWNLOAD_LABEL_TEMPLATE);
if (ClientConfigurationManager.getBoolean(false, ViewerConstants.VIEWER_ENABLED)) {
templateStatus.setTemplate(DEFAULT_DETAILED_VIEWER_LABEL_TEMPLATE);
} else {
templateStatus.setTemplate(DEFAULT_DOWNLOAD_LABEL_TEMPLATE);
}
} else {
templateStatus.setTemplate(this.detailsList.getText());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
package com.databasepreservation.common.client.common.visualization.browse.configuration.columns.helpers;

import static com.databasepreservation.common.client.ViewerConstants.DEFAULT_DOWNLOAD_LABEL_TEMPLATE;
import static com.databasepreservation.common.client.ViewerConstants.DEFAULT_VIEWER_DOWNLOAD_LABEL_TEMPLATE;

import com.databasepreservation.common.client.ClientConfigurationManager;
import com.databasepreservation.common.client.ViewerConstants;
import com.databasepreservation.common.client.models.status.collection.ColumnStatus;
import com.databasepreservation.common.client.models.status.collection.TableStatus;
Expand Down Expand Up @@ -119,7 +121,7 @@ public String getApplicationType() {

private void buildDetailedViewTemplatePanel(ColumnStatus columnConfiguration) {
templateToDetailedView = new ColumnTemplateOptions(messages.columnManagementLabelForTemplateDetail(),
ColumnOptionUtils.getDefaultTextOrValue(columnConfiguration.getSearchStatus().getList().getTemplate()), true);
ColumnOptionUtils.getDefaultTextOrValue(columnConfiguration.getDetailsStatus().getTemplateStatus()), true);

templateToDetailedView.addStyleNameToLabel("form-label");
templateToDetailedView.addStyleNameToTextBox("form-textbox");
Expand Down Expand Up @@ -163,9 +165,14 @@ private void buildMIMETypeTextBox(ColumnStatus columnConfiguration) {
private TemplateStatus getTemplateStatus(ColumnTemplateOptions options) {
TemplateStatus templateStatus = new TemplateStatus();

GWT.log(options.toString());
String str = options.getText();
if (ViewerStringUtils.isBlank(str)) {
templateStatus.setTemplate(DEFAULT_DOWNLOAD_LABEL_TEMPLATE);
if (ClientConfigurationManager.getBoolean(false, ViewerConstants.VIEWER_ENABLED)) {
templateStatus.setTemplate(DEFAULT_VIEWER_DOWNLOAD_LABEL_TEMPLATE);
} else {
templateStatus.setTemplate(DEFAULT_DOWNLOAD_LABEL_TEMPLATE);
}
} else {
templateStatus.setTemplate(str);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@
*/
package com.databasepreservation.common.client.common.visualization.browse.configuration.columns.helpers;

import static com.databasepreservation.common.client.ViewerConstants.DEFAULT_DETAILED_VIEWER_LABEL_TEMPLATE;
import static com.databasepreservation.common.client.ViewerConstants.DEFAULT_DOWNLOAD_LABEL_TEMPLATE;

import com.databasepreservation.common.client.ClientConfigurationManager;
import com.databasepreservation.common.client.ViewerConstants;
import com.databasepreservation.common.client.models.status.collection.ColumnStatus;
import com.databasepreservation.common.client.models.status.collection.TableStatus;
import com.databasepreservation.common.client.models.status.collection.TemplateStatus;
import com.databasepreservation.common.client.tools.ViewerStringUtils;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;

import static com.databasepreservation.common.client.ViewerConstants.DEFAULT_DOWNLOAD_LABEL_TEMPLATE;

/**
* @author Miguel Guimarães <mguimaraes@keep.pt>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.ArrayList;
import java.util.List;

import com.databasepreservation.common.client.ClientConfigurationManager;
import com.databasepreservation.common.client.ViewerConstants;
import com.databasepreservation.common.client.common.utils.UriQueryUtils;
import com.databasepreservation.common.client.index.FindRequest;
Expand Down Expand Up @@ -61,6 +62,15 @@ public static String createExportLobUri(String databaseUUID, String schemaName,
+ columnIndex;
}

public static String createUVLob() {
return ClientConfigurationManager.getStringWithDefault("uv", ViewerConstants.UV_EXTERNAL_VIEWER_SERVICE_NAME)
+ "/#?iiifManifestId=" + GWT.getHostPageBaseURL() + ClientConfigurationManager.getStringWithDefault(
"presentation", ViewerConstants.PRESENTATION_EXTERNAL_SERVICE_NAME)
+ "/manifest?downloadLink=";
}



public static String createExportTableUri(String databaseUUID, String schemaName, String tableName,
FindRequest findRequest, String zipFilename, String filename, boolean descriptions, boolean lobs,
List<String> fieldsToHeader) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ public class ViewerConfiguration extends ViewerAbstractConfiguration {

public static final String PROPERTY_BLOB_PREFIX_NAME = "ui.blob.prefix.name";

public static final String UV_EXTERNAL_VIEWER_SERVICE_NAME = "ui.viewer.universalViewer.service_name";
public static final String PRESENTATION_EXTERNAL_SERVICE_NAME = "ui.viewer.presentation.service_name";
public static final String VIEWER_ENABLED = "ui.viewer.enabled";

private static boolean instantiatedWithoutErrors = true;
private static String applicationEnvironment = ViewerConstants.APPLICATION_ENV_SERVER;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
*/
package com.databasepreservation.common.utils;

import static com.databasepreservation.common.client.ViewerConstants.DEFAULT_DETAILED_VIEWER_LABEL_TEMPLATE;
import static com.databasepreservation.common.client.ViewerConstants.DEFAULT_DOWNLOAD_LABEL_TEMPLATE;
import static com.databasepreservation.common.client.ViewerConstants.DEFAULT_VIEWER_DOWNLOAD_LABEL_TEMPLATE;

import java.util.ArrayList;
import java.util.List;

Expand All @@ -31,6 +35,7 @@
import com.databasepreservation.common.client.models.structure.ViewerMetadata;
import com.databasepreservation.common.client.models.structure.ViewerTable;
import com.databasepreservation.common.client.models.structure.ViewerType;
import com.databasepreservation.common.server.ViewerConfiguration;

/**
* @author Miguel Guimarães <mguimaraes@keep.pt>
Expand Down Expand Up @@ -119,9 +124,17 @@ public static ColumnStatus getColumnStatus(ViewerColumn column, boolean show, in
if (column.getType() != null && (column.getType().getDbType().equals(ViewerType.dbTypes.BINARY)
|| column.getType().getDbType().equals(ViewerType.dbTypes.CLOB))) {
final TemplateStatus template = getTemplateStatus();
template.setTemplate(ViewerConstants.DEFAULT_DOWNLOAD_LABEL_TEMPLATE);
final TemplateStatus detailedTemplate = getTemplateStatus();
if (ViewerConfiguration.getInstance().getViewerConfigurationAsBoolean(false,
ViewerConfiguration.VIEWER_ENABLED)) {
template.setTemplate(DEFAULT_VIEWER_DOWNLOAD_LABEL_TEMPLATE);
detailedTemplate.setTemplate(DEFAULT_DETAILED_VIEWER_LABEL_TEMPLATE);
} else {
template.setTemplate(DEFAULT_DOWNLOAD_LABEL_TEMPLATE);
detailedTemplate.setTemplate(DEFAULT_DOWNLOAD_LABEL_TEMPLATE);
}
status.updateSearchListTemplate(template);
status.updateDetailsTemplate(template);
status.updateDetailsTemplate(detailedTemplate);
}

return status;
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/com/databasepreservation/common/public/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -3462,4 +3462,16 @@ rgba(0, 0, 0, .125);
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}

/************************************************
* Universal embedded viewer
************************************************/

.embedded-viewer {
height: 1000px;
width: 1000px;
display: inline-block;
vertical-align: top;
margin-left: -6%;
}
9 changes: 9 additions & 0 deletions src/main/resources/config/dbvtk-viewer.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ui.sharedProperties.whitelist.configuration.prefix=lists
ui.sharedProperties.whitelist.configuration.prefix=ui.lists
ui.sharedProperties.whitelist.configuration.prefix=ui.header
ui.sharedProperties.whitelist.configuration.prefix=ui.interface
ui.sharedProperties.whitelist.configuration.prefix=ui.viewer
ui.sharedProperties.whitelist.configuration.prefix=ui.disable
ui.sharedProperties.whitelist.configuration.prefix=ui.plugin
ui.sharedProperties.whitelist.configuration.prefix=ui.reference
Expand Down Expand Up @@ -163,3 +164,11 @@ ui.lists.DatabaseList_all.search.selectedInfo.label.default.i18n=lists.label.Dat
# Show schema name in reference table
##############################################
ui.reference.table.show.schema.name=true

###############################################
# Universal Viewer and presentation addresses
##############################################
ui.viewer.enabled=true
ui.viewer.universalViewer.service_name=uv
ui.viewer.presentation.service_name=presentation

0 comments on commit e97d6dd

Please sign in to comment.