Commit f6ec3b3f authored by Ubbo Veentjer's avatar Ubbo Veentjer
Browse files

Initial commit

parents
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
# TextGrid Repository Portal
The portal is a web frontend to access and browse data published in the [TextGrid-Repository](https://textgridrep.org). [TextGrid](https://textgrid.de) is a virtual research environment for the humanities. This software uses the public [TextGrid APIs](https://textgridlab.org/doc/services/index.html).
This is the third iteration of the software. Previous versions:
* JavaScript/HTML: https://projects.gwdg.de/projects/textgridrep-webseite/repository
* Liferay based: https://projects.gwdg.de/projects/liferay-textgrid/repository
## Getting Started
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
### Prerequisites
You need Java (at least in version 8) and Gradle to run a development version.
```bash
sudo apt install openjdk-8-jdk
```
Gradle needs to be in a version newer then 4.6, which is not yet available in Debian upstream. There are [instructions about installation online](https://gradle.org/install). This is with [sdkman](https://sdkman.io/)
```bash
sdk install gradle 6.0.1
```
### Installing
First get the JavaScript libaries, iamges and fonts managed with npm in place:
```bash
gradle -q copyAssets
```
Run a local version of the portal:
```bash
gradle bootRun
```
Access the portal at http://localhost:8080/ afterwards
### Configuration
Edit `src/main/resources/application.properties` to change configuration.
plugins {
id 'org.springframework.boot' version '2.2.4.RELEASE'
id 'com.github.node-gradle.node' version '2.2.0'
}
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
repositories {
mavenCentral()
maven {
url 'https://nexus.gwdg.de/repository/maven-dariah-public'
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.apache.tomcat.embed:tomcat-embed-jasper'
implementation 'javax.servlet:jstl'
implementation 'org.apache.cxf:cxf-rt-rs-client:3.3.4'
implementation 'io.jsonwebtoken:jjwt:0.9.1'
implementation 'com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider'
implementation 'info.textgrid.middleware.clients:textgrid-clients:3.4.1-SNAPSHOT'
}
/**
* node / npm dependencies
*/
node {
// Version of node to use.
version = '12.14.1'
// Version of npm to use.
npmVersion = '6.13.4'
// If true, it will download node using above parameters.
// If false, it will try to use globally installed node.
download = true
}
// execute task: gradle -q copyJS
task copyJS(type: Copy, dependsOn: npmInstall) {
from 'node_modules/jquery/dist/jquery.min.js',
'node_modules/openseadragon/build/openseadragon/openseadragon.min.js'
into 'src/main/resources/static/js'
}
task copyImages(type: Copy, dependsOn: npmInstall) {
from 'node_modules/openseadragon/build/openseadragon/images'
into 'src/main/resources/static/images/openseadragon'
}
task copyFonts(type: Copy, dependsOn: npmInstall) {
from 'node_modules/font-awesome/fonts'
into 'src/main/resources/static/fonts'
}
// execute task: gradle -q copyAssets
task copyAssets(dependsOn: [copyJS, copyImages, copyFonts])
{
"name": "textgridrep-portal",
"version": "3.0.0",
"dependencies": {
"jquery": "^1.11.2",
"openseadragon": "^2.4.1",
"font-awesome": "4.3.0"
}
}
package info.textgrid.rep;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
package info.textgrid.rep;
import javax.servlet.http.HttpServletRequest;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class TGRepErrorController implements ErrorController {
@RequestMapping("/error")
public String handleError(Model model, HttpServletRequest request) {
if(request.getAttribute("javax.servlet.error.exception") != null) {
Exception exception = (Exception) request.getAttribute("javax.servlet.error.exception");
model.addAttribute("exception", exception.getMessage());
model.addAttribute("stacktrace", exception.getStackTrace());
}
model.addAttribute("statusCode", request.getAttribute("javax.servlet.error.status_code"));
return "error";
}
@Override
public String getErrorPath() {
return "/error";
}
}
package info.textgrid.rep.advancedsearch;
import java.util.HashMap;
import java.util.Locale;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import info.textgrid.rep.shared.I18NUtils;
@Controller
public class AdvancedSearchController {
private static final Log log = LogFactory.getLog(AdvancedSearchController.class);
@GetMapping("/advanced-search")
public String render(Model model) {
HashMap<String, String> i18n = I18NUtils.i18n(new Locale("de"));
model.addAttribute("i18n", i18n);
return "advancedsearch";
}
}
package info.textgrid.rep.browse;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import javax.ws.rs.client.ClientBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
import info.textgrid.namespaces.middleware.tgsearch.ResultType;
import info.textgrid.rep.service.tgsearch.AggregatorClientService;
import info.textgrid.rep.service.tgsearch.TgrepConfigurationService;
import info.textgrid.rep.service.tgsearch.TgsearchClientService;
import info.textgrid.rep.shared.I18NUtils;
import info.textgrid.rep.shared.Utils;
import info.textgrid.rep.shared.ViewMode;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jws;
import io.jsonwebtoken.Jwts;
@Controller
public class BrowseController {
// injected service
private TgsearchClientService tgsearchClientService;
private TgrepConfigurationService tgrepConfig;
private AggregatorClientService aggregatorClient;
private static final Log log = LogFactory.getLog(BrowseController.class);
@Autowired
public BrowseController(TgsearchClientService tgsearchClientService,
AggregatorClientService aggregatorClient, TgrepConfigurationService tgrepConfig) {
this.tgsearchClientService = tgsearchClientService;
this.aggregatorClient = aggregatorClient;
this.tgrepConfig = tgrepConfig;
}
@GetMapping("/browse/{id}")
public String browse(
Model model,
@PathVariable("id") String id,
@RequestParam(value = "mode", defaultValue = "list") String mode,
@RequestParam(value = "fragment", required = false) String fragment) {
HashMap<String, String> i18n = I18NUtils.i18n(new Locale("de"));
// common variables for browse-root aggregations and browse single items
model.addAttribute("textgridHost", this.tgrepConfig.getTextgridHost());
model.addAttribute("mode", mode);
model.addAttribute("i18n", i18n);
// if no id, browse all root aggregations
if (id == null || id.equals("root")) {
List<ViewMode> viewmodes = new ArrayList<ViewMode>();
viewmodes
.add(new ViewMode(i18n.get("list"), "/browse/root?mode=list", mode.equals("list")));
viewmodes.add(new ViewMode(i18n.get("gallery"), "/browse/root?mode=gallery",
mode.equals("gallery")));
model.addAttribute("viewmodes", viewmodes);
List<ResultType> results = this.tgsearchClientService.listRootCollections().getResult();
model.addAttribute("results", results);
model.addAttribute("browseRootAggregations", true);
return "browse";
}
if (!id.startsWith("textgrid:")) {
id = "textgrid:" + id;
}
id = id.replace("_", ".");
model.addAttribute("textgridUri", id);
ResultType metadata = this.tgsearchClientService.getMetadata(id);
model.addAttribute("metadata", metadata);
// for path, todo: create a tagfile for path
model.addAttribute("result", metadata);
String format = metadata.getObject().getGeneric().getProvided().getFormat();
model.addAttribute("format", format);
if (format.contains("tg.aggregation") || format.contains("text/tg.work+xml")) {
List<ViewMode> viewmodes = new ArrayList<ViewMode>();
viewmodes
.add(new ViewMode(i18n.get("list"), Utils.browseUrl(id) + "?mode=list", mode.equals("list")));
viewmodes.add(new ViewMode(i18n.get("gallery"), Utils.browseUrl(id) + "?mode=gallery",
mode.equals("gallery")));
if (format.equals("text/tg.edition+tg.aggregation+xml")) {
viewmodes.add(new ViewMode("TEI-Corpus", Utils.browseUrl(id) + ")mode=xml", mode.equals("xml")));
}
model.addAttribute("viewmodes", viewmodes);
if (mode != null && mode.equals("xml")) {
String teiHtml = this.aggregatorClient.renderTEI(id);
String tocHtml = this.aggregatorClient.renderToc(id);
model.addAttribute("teiHtml", teiHtml);
model.addAttribute("tocHtml", tocHtml);
} else {
log.info("listing agg: " + id);
List<ResultType> results;
if (format.contains("text/tg.work+xml")) {
List<String> editionFilter =
Arrays.asList(new String[] {"format:text/tg.edition+tg.aggregation+xml"});
results = this.tgsearchClientService
.search("isEditionOf:\"" + id + "\"", "relevance", 0, 20, editionFilter, true)
.getResult();
} else {
results = this.tgsearchClientService.listAggregation(id).getResult();
}
model.addAttribute("results", results);
}
} else if (format.equals("text/xml")) {
List<ViewMode> tools = new ArrayList<ViewMode>();
// identifier@type of trier dfg-viewer mets is METSXMLID
// TODO: look into relation/tg:rootElementNamespace
if (!metadata.getObject().getGeneric().getProvided().getIdentifier().isEmpty()
&& metadata.getObject().getGeneric().getProvided().getIdentifier().get(0) != null
&& metadata.getObject().getGeneric().getProvided().getIdentifier().get(0)
.getType() != null
&& metadata.getObject().getGeneric().getProvided().getIdentifier().get(0).getType()
.equals("METSXMLID")) {
try {
String tgcrudUrl4DFGViewer = URLEncoder.encode(
tgrepConfig.getTextgridHost() + "/1.0/tgcrud-public/rest/" + id + "/data", "UTF-8");
tools.add(new ViewMode("DFG-Viewer",
"http://dfg-viewer.de/v3/?set[zoom]=min&set[mets]=" + tgcrudUrl4DFGViewer, false));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else { // assume tei-xml
String teiHtml = "";
if (fragment != "") {
teiHtml = this.aggregatorClient.renderTEIFragment(id, fragment);
} else {
teiHtml = this.aggregatorClient.renderTEI(id);
String tocHtml = this.aggregatorClient.renderToc(id);
model.addAttribute("tocHtml", tocHtml);
}
model.addAttribute("teiHtml", teiHtml);
model.addAttribute("isTEI", true);
}
try {
String xml4switchboard = URLEncoder.encode(tgrepConfig.getTextgridHost() + "/1.0/tgcrud-public/rest/" + id + "/data", "UTF-8");
//tools.add(new ViewMode("Switchboard XML", "https://switchboard.clarin-dev.eu/#/textgridrep/"+xml4switchboard+"/text%2Fxml", false));
tools.add(new ViewMode("Switchboard XML", "https://switchboard.clarin-dev.eu/#/textgridrep/"+xml4switchboard+"/application%2Ftei+xml", false));
String html4switchboard = URLEncoder.encode(tgrepConfig.getTextgridHost() + "/1.0/aggregator/html/" + id , "UTF-8");
tools.add(new ViewMode("Switchboard HTML", "https://switchboard.clarin-dev.eu/#/textgridrep/"+html4switchboard+"/text%2Fhtml", false));
String pdf4switchboard = URLEncoder.encode(tgrepConfig.getTextgridHost() + "/1.0/aggregator/pdf/" + id , "UTF-8");
tools.add(new ViewMode("Switchboard PDF", "https://switchboard.clarin-dev.eu/#/textgridrep/"+pdf4switchboard+"/application%2Fpdf", false));
String xmlc4switchboard = URLEncoder.encode(tgrepConfig.getTextgridHost() + "/1.0/aggregator/teicorpus/" + id , "UTF-8");
tools.add(new ViewMode("Switchboard TEI-Corpus", "https://switchboard.clarin-dev.eu/#/textgridrep/"+xmlc4switchboard+"/text%2Fxml", false));
String zip4switchboard = URLEncoder.encode(tgrepConfig.getTextgridHost() + "/1.0/aggregator/zip/" + id , "UTF-8");
tools.add(new ViewMode("Switchboard zip", "https://switchboard.clarin-dev.eu/#/textgridrep/"+zip4switchboard+"/application%2Fzip", false));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
tools.add(new ViewMode("Voyant v1", "#", false, "digivoy-button"));
tools.add(new ViewMode("Voyant v2", "#", false, "digivoy2-button"));
// tools.add(new ViewMode("DigiVoy Extended", "/digivoy_conf/-/digivoy_conf/"+id, false));
if (hasIiifManifest(metadata.getObject().getGeneric().getGenerated().getProject().getId())) {
tools.add(new ViewMode("Mirador",
tgrepConfig.getTextgridHost() + "/1.0/iiif/mirador/?uri=" + id, false));
tools.add(new ViewMode(
"<img style='margin-top:2px; height: 21px;' title='Drop icon on Mirador to open manifest' src='https://textgridlab.org/1.0/iiif/manifests/img/iiif-logo.svg'>",
tgrepConfig.getTextgridHost() + "/1.0/iiif/manifests/" + id + "/manifest.json", false));
}
tools.add(new ViewMode("Annotate",
"https://annotation.de.dariah.eu/AnnotationViewer/data.html?uri=" + id, false,
"annotation-button"));
model.addAttribute("tools", tools);
} else if (format.contains("image")) {
model.addAttribute("image", true);
List<ViewMode> tools = new ArrayList<ViewMode>();
tools.add(new ViewMode("Digilib",
tgrepConfig.getTextgridHost() + "/1.0/tgrep/digilib/digilib.html?fn=" + id, false));
model.addAttribute("tools", tools);
}
/*
* long userId = PortalUtil.getUserId(renderRequest); String userName =
* PortalUtil.getUserName(userId, ""); String eppn = Utils.getEppn(userId);
*
* if(Utils.userWantsAnnotation(userId)) { model.addAttribute("annotationEnabled", true);
* model.addAttribute("annotationToken", this.generateToken(prefs, eppn, userName)); }
*/
return "browse";
}
private boolean hasIiifManifest(String id) {
IIIFProjects iiip = ClientBuilder.newBuilder().build()
.register(JacksonJsonProvider.class)
.target(tgrepConfig.getTextgridHost())
.path("/1.0/iiif/manifests/projects/")
.request()
.get(IIIFProjects.class);
if (iiip.projects.contains(id)) {
return true;
}
return false;
}
/* TODO: JWT generation */
public static String tokenFromAuthstring(String authString, String secret) {
Jws<Claims> jwtres = Jwts.parser().setSigningKey(secret.getBytes()).parseClaimsJws(authString);
String tstring = jwtres.getBody().get("token").toString();
String token = tstring.substring(tstring.lastIndexOf("@") + 1);
return token;
}
}