Commit 48afd9ef authored by Petter Goksøyr Åsen's avatar Petter Goksøyr Åsen
Browse files

DEICH-5603 fetch work data from euler; fix in redia-api

parent a9eed2fe
......@@ -38,14 +38,11 @@ const publicationLinkScore = binding => {
return score;
};
async function decorateRelation(key, publicationId, relation) {
const query = sparqlQueries.decorateRelation(publicationId, relation.uri);
return fetch(virtuosoEndpoint, {
method: "POST",
body: `query=${encodeURIComponent(query)}`,
async function decorateRelation(key, publicationId, relation, deichmanCallId) {
Please register or sign in to reply
const url = `${INTERNAL_URL_EULER}/api/authorities/decorateRelation?id=${publicationId}&relation=${encodeURIComponent(relation.uri)}`;
return fetch(url, {
headers: {
Accept: "application/sparql-results+json",
"Content-Type": "application/x-www-form-urlencoded"
"Deichman-CallID": deichmanCallId
}
})
.then(res => {
......@@ -56,30 +53,42 @@ async function decorateRelation(key, publicationId, relation) {
})
.then(json => {
let selected = false;
json.results.bindings.forEach(binding => {
(json || []).forEach(binding => {
const score = publicationLinkScore(binding);
if (!selected || score > selected.score) {
if (binding.targetPub) {
selected = {
score,
publicationId: binding.targetPub.value.replace(
publicationId: binding.targetPub.replace(
"http://data.deichman.no/publication/",
""
),
mainTitle: binding.targetMainTitle.value
mainTitle: binding.targetMainTitle
};
if (binding.targetSubtitle) {
selected.subtitle = binding.targetSubtitle;
}
if (binding.targetPartNumber) {
selected.partNumber = binding.targetPartNumber;
}
if (binding.targetPartTitle) {
selected.partTitle = binding.targetPartTitle;
}
}
}
});
relation.publicationId = selected.publicationId;
relation.mainTitle = selected.mainTitle;
relation.subtitle = selected.subtitle;
relation.partNumber = selected.partNumber;
relation.partTitle = selected.partTitle;
if (
!selected &&
json.results.bindings.length > 0 &&
json.results.bindings[0].workMainTitle
json.length > 0 &&
json[0].workMainTitle
) {
// Related work has no publications yet, so we use the title from the work.
relation.mainTitle = json.results.bindings[0].workMainTitle.value;
relation.mainTitle = json[0].workMainTitle;
}
return { key, relation };
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment