Skip to content
Snippets Groups Projects
Commit 79fb3e8e authored by esikkala's avatar esikkala
Browse files

Parameterize fetchByURI

parent 91a88ebd
No related branches found
No related tags found
No related merge requests found
...@@ -50,9 +50,9 @@ export const updatePage = (resultClass, page) => ({ ...@@ -50,9 +50,9 @@ export const updatePage = (resultClass, page) => ({
type: UPDATE_PAGE, type: UPDATE_PAGE,
resultClass, page resultClass, page
}); });
export const fetchByURI = (resultClass, facetClass, uri) => ({ export const fetchByURI = (resultClass, facetClass, variant, uri) => ({
type: FETCH_BY_URI, type: FETCH_BY_URI,
resultClass, facetClass, uri resultClass, facetClass, variant, uri
}); });
export const fetchByURIFailed = (resultClass, error, message) => ({ export const fetchByURIFailed = (resultClass, error, message) => ({
type: FETCH_RESULTS_FAILED, type: FETCH_RESULTS_FAILED,
......
...@@ -289,13 +289,13 @@ class LeafletMap extends React.Component { ...@@ -289,13 +289,13 @@ class LeafletMap extends React.Component {
} }
markerOnClick = event => { markerOnClick = event => {
this.props.fetchByURI(this.props.resultClass, this.props.facetClass, event.target.options.id,); this.props.fetchByURI(this.props.resultClass, this.props.facetClass, this.props.variant, event.target.options.id,);
}; };
createPopUpContent(result) { createPopUpContent(result) {
let popUpTemplate = `<h3>${result.prefLabel}</h3>`; let popUpTemplate = `<a target="_blank" rel="noopener noreferrer" href=${result.id}><h3>${result.prefLabel}</h3></a>`;
if (has(result, 'dataProviderUrl')) { if (has(result, 'dataProviderUrl')) {
popUpTemplate += `<p>Data provider: <a target="_blank" rel="noopener noreferrer" href=${result.dataProviderUrl}>${result.dataProviderUrl}</a></p>`; popUpTemplate += `<p>Data provider url: <a target="_blank" rel="noopener noreferrer" href=${result.dataProviderUrl}>${result.dataProviderUrl}</a></p>`;
} }
if (has(result, 'sameAs')) { if (has(result, 'sameAs')) {
popUpTemplate += `<p>Place authority: <a target="_blank" rel="noopener noreferrer" href=${result.sameAs}>${result.sameAs}</a></p>`; popUpTemplate += `<p>Place authority: <a target="_blank" rel="noopener noreferrer" href=${result.sameAs}>${result.sameAs}</a></p>`;
......
...@@ -146,7 +146,7 @@ let Main = props => { ...@@ -146,7 +146,7 @@ let Main = props => {
People People
</Typography> </Typography>
<Typography component="p"> <Typography component="p">
People related to manuscripts. People related to manuscripts and works.
</Typography> </Typography>
</CardContent> </CardContent>
</CardActionArea> </CardActionArea>
...@@ -186,7 +186,7 @@ let Main = props => { ...@@ -186,7 +186,7 @@ let Main = props => {
Places Places
</Typography> </Typography>
<Typography component="p"> <Typography component="p">
Places related to manuscripts. Places related to manuscripts and works.
</Typography> </Typography>
</CardContent> </CardContent>
</CardActionArea> </CardActionArea>
......
...@@ -75,8 +75,8 @@ const fetchByURIEpic = (action$, state$) => action$.pipe( ...@@ -75,8 +75,8 @@ const fetchByURIEpic = (action$, state$) => action$.pipe(
ofType(FETCH_BY_URI), ofType(FETCH_BY_URI),
withLatestFrom(state$), withLatestFrom(state$),
mergeMap(([action, state]) => { mergeMap(([action, state]) => {
const { resultClass, facetClass, uri } = action; const { resultClass, facetClass, variant, uri } = action;
const params = stateSlicesToUrl(null, state[`${facetClass}Facets`], null, null); const params = stateSlicesToUrl(null, state[`${facetClass}Facets`], variant, facetClass);
const requestUrl = `${apiUrl}${resultClass}/instance/${encodeURIComponent(uri)}?${params}`; const requestUrl = `${apiUrl}${resultClass}/instance/${encodeURIComponent(uri)}?${params}`;
return ajax.getJSON(requestUrl).pipe( return ajax.getJSON(requestUrl).pipe(
map(response => updateInstance({ resultClass: resultClass, instance: response })), map(response => updateInstance({ resultClass: resultClass, instance: response })),
......
import express from 'express'; import express from 'express';
import path from 'path'; import path from 'path';
import bodyParser from 'body-parser'; import bodyParser from 'body-parser';
import { getPaginatedResults, getAllResults, getPlace } from './sparql/FacetResults'; import { getPaginatedResults, getAllResults, getByURI } from './sparql/FacetResults';
import { getFacet } from './sparql/Facets'; import { getFacet } from './sparql/Facets';
const DEFAULT_PORT = 3001; const DEFAULT_PORT = 3001;
const app = express(); const app = express();
...@@ -34,7 +34,8 @@ app.get(`${apiPath}/:resultClass/paginated`, (req, res, next) => { ...@@ -34,7 +34,8 @@ app.get(`${apiPath}/:resultClass/paginated`, (req, res, next) => {
app.get(`${apiPath}/:resultClass/all`, (req, res, next) => { app.get(`${apiPath}/:resultClass/all`, (req, res, next) => {
const filters = req.query.filters == null ? null : JSON.parse(req.query.filters); const filters = req.query.filters == null ? null : JSON.parse(req.query.filters);
const variant = req.query.variant || null; const variant = req.query.variant || null;
return getAllResults(req.params.resultClass, req.query.facetClass, variant, filters).then(data => { const facetClass = req.query.facetClass || null;
return getAllResults(req.params.resultClass, facetClass, variant, filters).then(data => {
//console.log(data) //console.log(data)
res.json({ res.json({
resultCount: data.count, resultCount: data.count,
...@@ -45,16 +46,9 @@ app.get(`${apiPath}/:resultClass/all`, (req, res, next) => { ...@@ -45,16 +46,9 @@ app.get(`${apiPath}/:resultClass/all`, (req, res, next) => {
app.get(`${apiPath}/:resultClass/instance/:uri`, (req, res, next) => { app.get(`${apiPath}/:resultClass/instance/:uri`, (req, res, next) => {
const filters = req.query.filters == null ? null : JSON.parse(req.query.filters); const filters = req.query.filters == null ? null : JSON.parse(req.query.filters);
let getByURI = null; const variant = req.query.variant || null;
switch (req.params.resultClass) { const facetClass = req.query.facetClass || null;
// case 'manuscripts': return getByURI(req.params.resultClass, facetClass, variant, filters, req.params.uri).then(data => {
// getByURI = getManuscript;
// break;
case 'places':
getByURI = getPlace;
break;
}
return getByURI(filters, req.params.uri).then(data => {
res.json(data[0]); res.json(data[0]);
}).catch(next); }).catch(next);
}); });
......
...@@ -91,13 +91,27 @@ const getPaginatedData = (resultClass, page, pagesize, filters, sortBy, sortDire ...@@ -91,13 +91,27 @@ const getPaginatedData = (resultClass, page, pagesize, filters, sortBy, sortDire
return sparqlSearchEngine.doSearch(prefixes + q, endpoint, makeObjectList); return sparqlSearchEngine.doSearch(prefixes + q, endpoint, makeObjectList);
}; };
export const getPlace = (filters, uri) => { export const getByURI = (resultClass, facetClass, variant, filters, uri) => {
let q = placeQuery; let q;
q = q.replace('<PLACE_ID>', `<${uri}>`); switch (resultClass) {
if (filters == null) { case 'places':
q = q.replace('<FILTER>', '# no filters'); q = placeQuery;
break;
}
if (variant === 'productionPlaces') {
const manuscriptsProduced =
`OPTIONAL {
${generateFilter(resultClass, facetClass, filters, 'manuscript__id', null)}
?manuscript__id ^crm:P108_has_produced/crm:P7_took_place_at ?id .
?manuscript__id mmm-schema:data_provider_url ?manuscript__dataProviderUrl .
}`;
q = q.replace('<MANUSCRIPTS>', manuscriptsProduced);
} else { } else {
q = q.replace('<FILTER>', generateFilter('places', 'manuscripts', filters, 'manuscript__id', null)); q = q.replace('<MANUSCRIPTS>', '');
} }
q = q.replace('<ID>', `<${uri}>`);
// if (variant === 'productionPlaces') {
// console.log(prefixes + q)
// }
return sparqlSearchEngine.doSearch(prefixes + q, endpoint, makeObjectList); return sparqlSearchEngine.doSearch(prefixes + q, endpoint, makeObjectList);
}; };
...@@ -40,9 +40,12 @@ export const getFacet = (resultClass, facetID, sortBy, sortDirection, filters) = ...@@ -40,9 +40,12 @@ export const getFacet = (resultClass, facetID, sortBy, sortDirection, filters) =
OPTIONAL { ?id skos:prefLabel ?prefLabel_ } OPTIONAL { ?id skos:prefLabel ?prefLabel_ }
BIND(COALESCE(STR(?prefLabel_), STR(?id)) AS ?prefLabel) BIND(COALESCE(STR(?prefLabel_), STR(?id)) AS ?prefLabel)
OPTIONAL { ?id dct:source ?source } OPTIONAL { ?id dct:source ?source }
OPTIONAL { ?id gvp:broaderPreferred ?parent_ } OPTIONAL {
?id gvp:broaderPreferred ?parent_
FILTER(?parent_ != <http://ldf.fi/mmm/places/tgn_7026519>)
}
BIND(COALESCE(?parent_, '0') as ?parent) BIND(COALESCE(?parent_, '0') as ?parent)
FILTER(?id != <http://ldf.fi/mmm/places/tgn_7026519>) #FILTER(?id != <http://ldf.fi/mmm/places/tgn_7026519>)
} }
`; `;
} }
......
...@@ -54,10 +54,9 @@ export const placeQuery = ` ...@@ -54,10 +54,9 @@ export const placeQuery = `
PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/> PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/>
PREFIX mmm-schema: <http://ldf.fi/mmm/schema/> PREFIX mmm-schema: <http://ldf.fi/mmm/schema/>
PREFIX gvp: <http://vocab.getty.edu/ontology#> PREFIX gvp: <http://vocab.getty.edu/ontology#>
SELECT ?id ?prefLabel ?sameAs ?dataProviderUrl ?parent__id ?parent__prefLabel ?manuscript__id ?manuscript__dataProviderUrl SELECT ?id ?prefLabel ?sameAs ?dataProviderUrl ?parent__id ?parent__prefLabel ?manuscript__id ?manuscript__dataProviderUrl
WHERE { WHERE {
BIND (<PLACE_ID> AS ?id) BIND (<ID> AS ?id)
OPTIONAL { ?id skos:prefLabel ?prefLabel_ } OPTIONAL { ?id skos:prefLabel ?prefLabel_ }
BIND(COALESCE(?prefLabel_, ?id) AS ?prefLabel) BIND(COALESCE(?prefLabel_, ?id) AS ?prefLabel)
OPTIONAL { OPTIONAL {
...@@ -66,10 +65,6 @@ export const placeQuery = ` ...@@ -66,10 +65,6 @@ export const placeQuery = `
} }
OPTIONAL { ?id mmm-schema:data_provider_url ?dataProviderUrl } OPTIONAL { ?id mmm-schema:data_provider_url ?dataProviderUrl }
OPTIONAL { ?id owl:sameAs ?sameAs } OPTIONAL { ?id owl:sameAs ?sameAs }
OPTIONAL { <MANUSCRIPTS>
?manuscript__id ^crm:P108_has_produced/crm:P7_took_place_at ?id .
?manuscript__id mmm-schema:data_provider_url ?manuscript__dataProviderUrl .
<FILTER>
}
} }
`; `;
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