Skip to content

Commit

Permalink
VLO adapted to use VCR plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
twagoo committed Aug 4, 2022
1 parent 9b7d8e2 commit aafaa8d
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 5 deletions.
13 changes: 13 additions & 0 deletions vlo-commons/src/main/java/eu/clarin/cmdi/vlo/PIDUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@ public static boolean isUrnNbn(String uri) {
}
}

/**
*
* @param uri
* @return whether the provided URI is a handle
*/
public static boolean isActionableLink(String uri) {
if (uri == null) {
return false;
} else {
return ACTIONABLE_LINK_PATTERN.matcher(uri).matches();
}
}

public static Optional<PIDType> getType(String uri) {
if (isPid(uri)) {
if (isHandle(uri)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public final class JavaScriptResources {
private final static JavaScriptResourceReference FIELDS_TABLE = new JavaScriptResourceReference(RecordPage.class, "vlo-fields-table.js");
private final static JavaScriptResourceReference HISTORY_API = new JavaScriptResourceReference(HistoryApiAjaxRequestTargetListener.class, "vlo-historyapi.js");

private final static ResourceReference VCR_PLUGIN_JS = new ContextRelativeResourceReference("assets/vcr-plugin/dist/vcr-integration.js");

private final static ResourceReference BOOTSTRAP_TOC = new ContextRelativeResourceReference("assets/bootstrap-toc/bootstrap-toc.js");
private final static ResourceReference BOOTSTRAP_TOUR = new ContextRelativeResourceReference("assets/bootstrap-tour/bootstrap-tourist.js", false);

Expand Down Expand Up @@ -86,6 +88,10 @@ public static ResourceReference getFieldsTableJS() {
return FIELDS_TABLE;
}

public static ResourceReference getVcrPluginJS() {
return VCR_PLUGIN_JS;
}

public static ResourceReference getBootstrapToc() {
return BOOTSTRAP_TOC;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (C) 2022 CLARIN
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.clarin.cmdi.vlo.wicket.model;

import eu.clarin.cmdi.vlo.PIDUtils;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

/**
*
* @author CLARIN ERIC <clarin@clarin.eu>
*/
public class ActionableLinkModel extends Model<String> {

private final IModel<String> wrappedModel;

public ActionableLinkModel(IModel<String> wrappedModel) {
this.wrappedModel = wrappedModel;
}

@Override
public String getObject() {
final String wrappedObject = wrappedModel.getObject();
if (wrappedObject == null) {
return null;
} else {
if (PIDUtils.isPid(wrappedObject)) {
return PIDUtils.getActionableLinkForPid(wrappedObject);
} else if (PIDUtils.isActionableLink(wrappedObject)) {
return wrappedObject;
} else {
return null;
}
}
}

@Override
public void detach() {
super.detach();
wrappedModel.detach();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
*/
package eu.clarin.cmdi.vlo.wicket.model;

import static eu.clarin.cmdi.vlo.FacetConstants.DOI_RESOLVER_URL;
import static eu.clarin.cmdi.vlo.FacetConstants.HANDLE_PROXY;
import static eu.clarin.cmdi.vlo.FacetConstants.URN_NBN_RESOLVER_URL;
import eu.clarin.cmdi.vlo.PIDUtils;
import java.util.regex.Pattern;
import org.apache.wicket.model.IModel;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@
<link rel="icon" href="images/favicon.png" type="image/png"/>
<link wicket:id="canonicalUrl" rel="canonical" />
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">

<script script type="text/javascript">
window.vcrIntegrationConfiguration = {
'queueControlPosition': 'bottom-right',
'logLevel': 'info',
// 'doNotInitialize': true
};
</script>
</head>
<body class="non-js">
<header wicket:id="header" id="header" role="banner">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public void renderHead(IHeaderResponse response) {
response.render(JavaScriptHeaderItem.forReference(JavaScriptResources.getHistoryApiJS(), true));
response.render(JavaScriptHeaderItem.forReference(JavaScriptResources.getClipBoardJS(), true));
response.render(JavaScriptHeaderItem.forReference(JavaScriptResources.getVloClipboardJS(), true));
response.render(JavaScriptHeaderItem.forReference(JavaScriptResources.getVcrPluginJS(), true));

if (bottomSnippet != null) {
response.render(JavaScriptHeaderItem.forScript(bottomSnippet, "bottomSnippet"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ <h3>
<div class="row">
<div class="col-md-2 col-md-push-10">
<div wicket:id="licenseInfo" class="searchresult-licenseInfo">[LICENSE INFO]</div>
<a wicket:id="addToVcrQueueLink" class="btn btn-default"><span class="glyphicon glyphicon-plus-sign"></span> VCR</a>
</div>
<div class="col-md-10 col-md-pull-2">
<p class="searchresultmoreless">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import eu.clarin.cmdi.vlo.wicket.LandingPageShortLinkLabelConverter;
import com.google.common.collect.Ordering;
import eu.clarin.cmdi.vlo.FieldKey;
import eu.clarin.cmdi.vlo.JavaScriptResources;
import eu.clarin.cmdi.vlo.ResourceAvailabilityScore;
import eu.clarin.cmdi.vlo.config.FieldNameService;
import eu.clarin.cmdi.vlo.config.VloConfig;
Expand All @@ -35,12 +36,14 @@
import eu.clarin.cmdi.vlo.wicket.components.ResourceTypeIcon;
import eu.clarin.cmdi.vlo.wicket.components.SingleValueSolrFieldLabel;
import eu.clarin.cmdi.vlo.wicket.components.SolrFieldLabel;
import eu.clarin.cmdi.vlo.wicket.model.ActionableLinkModel;
import eu.clarin.cmdi.vlo.wicket.model.PIDLinkModel;
import eu.clarin.cmdi.vlo.wicket.model.SolrDocumentExpansionPairModel;
import eu.clarin.cmdi.vlo.wicket.model.SolrFieldModel;
import eu.clarin.cmdi.vlo.wicket.model.SolrFieldStringModel;
import eu.clarin.cmdi.vlo.wicket.pages.RecordPage;
import eu.clarin.cmdi.vlo.wicket.model.IsPidModel;
import eu.clarin.cmdi.vlo.wicket.model.NullFallbackModel;
import eu.clarin.cmdi.vlo.wicket.model.RecordMetadataLinksCountModel;
import eu.clarin.cmdi.vlo.wicket.model.ResourceInfoModel;
import eu.clarin.cmdi.vlo.wicket.provider.ResouceTypeCountDataProvider;
Expand All @@ -52,6 +55,8 @@
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.behavior.Behavior;
import org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxFallbackLink;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.ExternalLink;
Expand Down Expand Up @@ -209,6 +214,17 @@ protected IModel<String> getResourceRestrictedTooltip() {
);

add(new SearchResultItemLicensePanel("licenseInfo", documentModel, selectionModel, availabilityOrdering));
add(new WebMarkupContainer("addToVcrQueueLink")
.add(new AttributeModifier("data-vcr-url",
new NullFallbackModel(
//TODO: wrap model with filter that only allows valid URLs and PIDs!
new ActionableLinkModel(
new SolrFieldStringModel(documentModel, fieldNameService.getFieldName(FieldKey.SELF_LINK))),
new SolrFieldStringModel(documentModel, fieldNameService.getFieldName(FieldKey.COMPLETE_METADATA)))))
.add(new AttributeModifier("data-vcr-title", new NullFallbackModel(
new SolrFieldStringModel(documentModel, fieldNameService.getFieldName(FieldKey.NAME)),
new StringResourceModel("searchpage.unnamedrecord", this))))
);

add(new WebMarkupContainer("scoreContainer")
.add(new Label("score", new SolrFieldStringModel(documentModel, fieldNameService.getFieldName(FieldKey.SOLR_SCORE))))
Expand Down

0 comments on commit aafaa8d

Please sign in to comment.