Skip to content
Snippets Groups Projects
Commit 287fcc34 authored by esikkala's avatar esikkala
Browse files

Test dynamic backend config

parent 967d6bb7
No related branches found
No related tags found
No related merge requests found
import { backendSearchConfig } from './sparql/sampo/BackendSearchConfig' // import { backendSearchConfig } from './sparql/sampo/BackendSearchConfig'
import fs from 'fs' import fs from 'fs'
import express from 'express' import express from 'express'
import path from 'path' import path from 'path'
...@@ -6,7 +6,7 @@ import bodyParser from 'body-parser' ...@@ -6,7 +6,7 @@ import bodyParser from 'body-parser'
import axios from 'axios' import axios from 'axios'
import { has, castArray } from 'lodash' import { has, castArray } from 'lodash'
import expressStaticGzip from 'express-static-gzip' import expressStaticGzip from 'express-static-gzip'
// import { createBackendSearchConfig } from './sparql/Utils' import { createBackendSearchConfig } from './sparql/Utils'
import { import {
getResultCount, getResultCount,
getPaginatedResults, getPaginatedResults,
...@@ -73,7 +73,7 @@ app.use(validator) ...@@ -73,7 +73,7 @@ app.use(validator)
app.post(`${apiPath}/faceted-search/:resultClass/paginated`, async (req, res, next) => { app.post(`${apiPath}/faceted-search/:resultClass/paginated`, async (req, res, next) => {
const { params, body } = req const { params, body } = req
try { try {
// const backendSearchConfig = await createBackendSearchConfig() const backendSearchConfig = await createBackendSearchConfig()
const data = await getPaginatedResults({ const data = await getPaginatedResults({
backendSearchConfig, backendSearchConfig,
resultClass: params.resultClass, resultClass: params.resultClass,
...@@ -95,6 +95,7 @@ app.post(`${apiPath}/faceted-search/:resultClass/all`, async (req, res, next) => ...@@ -95,6 +95,7 @@ app.post(`${apiPath}/faceted-search/:resultClass/all`, async (req, res, next) =>
const { params, body } = req const { params, body } = req
const resultFormat = 'json' const resultFormat = 'json'
try { try {
const backendSearchConfig = await createBackendSearchConfig()
const data = await getAllResults({ const data = await getAllResults({
backendSearchConfig, backendSearchConfig,
resultClass: params.resultClass, resultClass: params.resultClass,
...@@ -124,6 +125,7 @@ app.post(`${apiPath}/faceted-search/:resultClass/all`, async (req, res, next) => ...@@ -124,6 +125,7 @@ app.post(`${apiPath}/faceted-search/:resultClass/all`, async (req, res, next) =>
// GET endpoint for supporting CSV button // GET endpoint for supporting CSV button
app.get(`${apiPath}/faceted-search/:resultClass/all`, async (req, res, next) => { app.get(`${apiPath}/faceted-search/:resultClass/all`, async (req, res, next) => {
try { try {
const backendSearchConfig = await createBackendSearchConfig()
const resultFormat = req.query.resultFormat == null ? 'json' : req.query.resultFormat const resultFormat = req.query.resultFormat == null ? 'json' : req.query.resultFormat
const data = await getAllResults({ const data = await getAllResults({
backendSearchConfig, backendSearchConfig,
...@@ -149,7 +151,7 @@ app.get(`${apiPath}/faceted-search/:resultClass/all`, async (req, res, next) => ...@@ -149,7 +151,7 @@ app.get(`${apiPath}/faceted-search/:resultClass/all`, async (req, res, next) =>
app.post(`${apiPath}/faceted-search/:resultClass/count`, async (req, res, next) => { app.post(`${apiPath}/faceted-search/:resultClass/count`, async (req, res, next) => {
const { params, body } = req const { params, body } = req
try { try {
// const backendSearchConfig = await createBackendSearchConfig() const backendSearchConfig = await createBackendSearchConfig()
const data = await getResultCount({ const data = await getResultCount({
backendSearchConfig, backendSearchConfig,
resultClass: params.resultClass, resultClass: params.resultClass,
...@@ -165,6 +167,7 @@ app.post(`${apiPath}/faceted-search/:resultClass/count`, async (req, res, next) ...@@ -165,6 +167,7 @@ app.post(`${apiPath}/faceted-search/:resultClass/count`, async (req, res, next)
app.post(`${apiPath}/:resultClass/page/:uri`, async (req, res, next) => { app.post(`${apiPath}/:resultClass/page/:uri`, async (req, res, next) => {
const { params, body } = req const { params, body } = req
try { try {
const backendSearchConfig = await createBackendSearchConfig()
const data = await getByURI({ const data = await getByURI({
backendSearchConfig, backendSearchConfig,
resultClass: params.resultClass, resultClass: params.resultClass,
...@@ -182,6 +185,7 @@ app.post(`${apiPath}/:resultClass/page/:uri`, async (req, res, next) => { ...@@ -182,6 +185,7 @@ app.post(`${apiPath}/:resultClass/page/:uri`, async (req, res, next) => {
app.post(`${apiPath}/faceted-search/:facetClass/facet/:id`, async (req, res, next) => { app.post(`${apiPath}/faceted-search/:facetClass/facet/:id`, async (req, res, next) => {
const { params, body } = req const { params, body } = req
try { try {
const backendSearchConfig = await createBackendSearchConfig()
const data = await getFacet({ const data = await getFacet({
backendSearchConfig, backendSearchConfig,
facetClass: params.facetClass, facetClass: params.facetClass,
...@@ -200,6 +204,7 @@ app.post(`${apiPath}/faceted-search/:facetClass/facet/:id`, async (req, res, nex ...@@ -200,6 +204,7 @@ app.post(`${apiPath}/faceted-search/:facetClass/facet/:id`, async (req, res, nex
app.get(`${apiPath}/full-text-search`, async (req, res, next) => { app.get(`${apiPath}/full-text-search`, async (req, res, next) => {
try { try {
const backendSearchConfig = await createBackendSearchConfig()
const data = await queryJenaIndex({ const data = await queryJenaIndex({
backendSearchConfig, backendSearchConfig,
queryTerm: req.query.q, queryTerm: req.query.q,
...@@ -228,6 +233,7 @@ app.get(`${apiPath}/federated-search`, async (req, res, next) => { ...@@ -228,6 +233,7 @@ app.get(`${apiPath}/federated-search`, async (req, res, next) => {
longMax = req.query.longMax longMax = req.query.longMax
} }
try { try {
const backendSearchConfig = await createBackendSearchConfig()
const data = await getFederatedResults({ const data = await getFederatedResults({
federatedSearchDatasets: backendSearchConfig.federatedSearch.datasets, federatedSearchDatasets: backendSearchConfig.federatedSearch.datasets,
queryTerm, queryTerm,
...@@ -358,6 +364,7 @@ app.get(`${apiPath}/wfs`, async (req, res, next) => { ...@@ -358,6 +364,7 @@ app.get(`${apiPath}/wfs`, async (req, res, next) => {
app.get(`${apiPath}/void/:resultClass`, async (req, res, next) => { app.get(`${apiPath}/void/:resultClass`, async (req, res, next) => {
const { params } = req const { params } = req
try { try {
const backendSearchConfig = await createBackendSearchConfig()
const data = await getAllResults({ const data = await getAllResults({
backendSearchConfig, backendSearchConfig,
resultClass: params.resultClass, resultClass: params.resultClass,
......
...@@ -22,11 +22,6 @@ export const runSelectQuery = async ({ ...@@ -22,11 +22,6 @@ export const runSelectQuery = async ({
headers.Authorization = `Basic ${process.env.SPARQL_ENDPOINT_BASIC_AUTH}` headers.Authorization = `Basic ${process.env.SPARQL_ENDPOINT_BASIC_AUTH}`
} }
const q = querystring.stringify({ query }) const q = querystring.stringify({ query })
// console.log('sparqling')
// console.log(resultFormat)
// console.log(q)
// console.log(endpoint)
// console.log(resultMapper)
try { try {
const response = await axios({ const response = await axios({
method: 'post', method: 'post',
...@@ -35,7 +30,6 @@ export const runSelectQuery = async ({ ...@@ -35,7 +30,6 @@ export const runSelectQuery = async ({
data: q data: q
}) })
if (resultFormat === 'json') { if (resultFormat === 'json') {
// console.log(response)
let mappedResults = resultMapperConfig let mappedResults = resultMapperConfig
? resultMapper({ sparqlBindings: response.data.results.bindings, config: resultMapperConfig }) ? resultMapper({ sparqlBindings: response.data.results.bindings, config: resultMapperConfig })
: resultMapper(response.data.results.bindings) : resultMapper(response.data.results.bindings)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment