Skip to content

Commit

Permalink
generate ldv config file with inverse links disabled on binsearch
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonBin committed Sep 6, 2024
1 parent b103dfc commit 25a806d
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.aksw.sparql_integrate.cli.main;

import jakarta.servlet.ServletRegistration;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.ws.rs.core.MediaType;
import org.aksw.jenax.web.server.boot.ServletBuilder;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.GenericWebApplicationContext;

import java.io.IOException;
import java.io.PrintWriter;

public class ServletLdvConfigJs extends HttpServlet implements ServletBuilder {

private String dbEngine;

public static ServletLdvConfigJs newBuilder() {
return new ServletLdvConfigJs();
}

@Override
public WebApplicationInitializer build(GenericWebApplicationContext rootContext) {
return servletContext -> {
ServletRegistration.Dynamic servlet = servletContext.addServlet("dbEngineSetting", this);
servlet.addMapping("/dbEngineSetting");
servlet.addMapping("/dbEngineSetting/");
servlet.addMapping("/_/js2/config.js");
servlet.setLoadOnStartup(1);
};
}

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
PrintWriter writer = resp.getWriter();
if ("/_/js2/config.js".equals(req.getServletPath())) {
resp.setContentType("text/javascript;charset=utf-8");
writer.println("""
(() => {
const ldvConfig = {
endpointUrl: '/sparql',
endpointOptions: {
mode: 'cors',
credentials: 'same-origin',
method: 'POST',
},
datasetBase: window.location.origin,
exploreUrl: '@EXPLORE_URL@',
graphLookup: '@GRAPH_LOOKUP@',
reverseEnabled: '@SHOW_INVERSE@',
labelLang: 'en',
labelLangChoice: ['en', 'de', 'nl', 'fr'],
infer: false,
fileOnly: 'yes',
}
window.ldvConfig = ldvConfig
})()
""".replace("@SHOW_INVERSE@", "binsearch".equals(this.getDbEngine()) ? "no" : "yes"));
} else {
resp.setContentType(MediaType.TEXT_PLAIN);
writer.println(this.getDbEngine());
}
writer.close();
}

public ServletBuilder setDbEngine(String dbEngine) {
this.dbEngine = dbEngine;
return this;
}

public String getDbEngine() {
return dbEngine;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,8 @@ public void afterExec() {
.addServletBuilder(ServletBuilderGraphQlV2.newBuilder()
.setGraphQlExecFactory(graphQlExecFactoryV2)
)
.addServletBuilder(ServletLdvConfigJs.newBuilder()
.setDbEngine(cmd.engine))
.setPort(port).create();

server.start();
Expand Down

0 comments on commit 25a806d

Please sign in to comment.