From c7333e0640c91024f0caf2ea4489a46e11463e56 Mon Sep 17 00:00:00 2001 From: bindeali <56399637+bindeali@users.noreply.github.com> Date: Thu, 19 Sep 2024 11:13:19 +0200 Subject: [PATCH] Revert "Delete inactive connections and read active connections properly" This reverts commit bb37b230e60557eae2599fc9803ec981a8f28c1c. --- src/function/FunctionLink.ts | 4 +-- src/interface/ContextInterface.tsx | 32 +++++++++++++++++-- src/queries/get/InitQueries.ts | 5 +-- src/queries/update/UpdateConnectionQueries.ts | 11 ++----- src/queries/update/UpdateLinkQueries.ts | 16 +++------- 5 files changed, 38 insertions(+), 30 deletions(-) diff --git a/src/function/FunctionLink.ts b/src/function/FunctionLink.ts index 06686136..7fb2c4f2 100644 --- a/src/function/FunctionLink.ts +++ b/src/function/FunctionLink.ts @@ -335,9 +335,7 @@ export function deleteLink(id: string): string[] { const queries: string[] = []; if (!(WorkspaceLinks[id].iri in Links) && WorkspaceLinks[id].type === LinkType.DEFAULT && - WorkspaceLinks[id].active && - WorkspaceLinks[id].iri in WorkspaceTerms && - WorkspaceLinks[id].iri in WorkspaceElements) { + WorkspaceLinks[id].active) { queries.push(...removeElement(WorkspaceLinks[id].iri)); } const deleteLinks = getUnderlyingFullConnections(id as string); diff --git a/src/interface/ContextInterface.tsx b/src/interface/ContextInterface.tsx index 0b4b0840..e0646253 100644 --- a/src/interface/ContextInterface.tsx +++ b/src/interface/ContextInterface.tsx @@ -275,7 +275,33 @@ export async function retrieveContextData(): Promise { console.warn( `Link ID ${id} ( ${WorkspaceLinks[id].source} -- ${WorkspaceLinks[id].iri} -> ${WorkspaceLinks[id].target} ) deactivated due to its statement counterpart(s) missing.` ); + if ( + WorkspaceLinks[id].iri === parsePrefix("z-sgov-pojem", "je-vlastností") && + WorkspaceLinks[id].source in WorkspaceElements && + WorkspaceElements[WorkspaceLinks[id].source].vocabulary !== undefined && + WorkspaceElements[WorkspaceLinks[id].source].vocabulary! in + WorkspaceVocabularies && + WorkspaceVocabularies[ + WorkspaceElements[WorkspaceLinks[id].source].vocabulary! + ].readOnly + ) { + continue; + } + + if ( + WorkspaceLinks[id].iri === parsePrefix("z-sgov-pojem", "má-vlastnost") && + WorkspaceLinks[id].target in WorkspaceElements && + WorkspaceElements[WorkspaceLinks[id].target].vocabulary !== undefined && + WorkspaceElements[WorkspaceLinks[id].target].vocabulary! in + WorkspaceVocabularies && + WorkspaceVocabularies[ + WorkspaceElements[WorkspaceLinks[id].target].vocabulary! + ].readOnly + ) { + continue; + } WorkspaceLinks[id].active = false; + // Really poorly thought out hack! if ( WorkspaceLinks[id].iri === parsePrefix("z-sgov-pojem", "má-vztažený-prvek-1") || @@ -295,9 +321,9 @@ export async function retrieveContextData(): Promise { } } return await processTransaction( - qb.constructQuery( - AppSettings.contextEndpoint, - ...updateProjectLinkParallel(connections) + AppSettings.contextEndpoint, + ...updateProjectLinkParallel(...connections.add).map((t) => + qb.constructQuery(t) ) ); } diff --git a/src/queries/get/InitQueries.ts b/src/queries/get/InitQueries.ts index b9761d28..c6d949a1 100644 --- a/src/queries/get/InitQueries.ts +++ b/src/queries/get/InitQueries.ts @@ -252,7 +252,7 @@ export async function getLinksConfig( const getLinks = async (): Promise => { const query = [ "PREFIX og: ", - "select distinct ?id ?iri ?sourceID ?targetID ?sourceCard1 ?sourceCard2 ?targetCard1 ?targetCard2 ?type ?link ?active where {", + "select distinct ?id ?iri ?sourceID ?targetID ?sourceCard1 ?sourceCard2 ?targetCard1 ?targetCard2 ?type ?link where {", "graph ?graph {", "?link a og:link .", "?link og:id ?id .", @@ -264,7 +264,6 @@ export async function getLinksConfig( "?link og:sourceCardinality2 ?sourceCard2 .", "?link og:targetCardinality1 ?targetCard1 .", "?link og:targetCardinality2 ?targetCard2 .", - "optional {?link og:active ?active.}", "}", `values ?graph {<${diagramGraphs.join("> <")}>}`, "}", @@ -305,8 +304,6 @@ export async function getLinksConfig( sourceCardinality: sourceCard, targetCardinality: targetCard, }; - if (result.active) - links[result.id.value].active = result.active.value === "true" } } return true; diff --git a/src/queries/update/UpdateConnectionQueries.ts b/src/queries/update/UpdateConnectionQueries.ts index ff471854..30eb9334 100644 --- a/src/queries/update/UpdateConnectionQueries.ts +++ b/src/queries/update/UpdateConnectionQueries.ts @@ -303,12 +303,8 @@ function updateGeneralizationLink(ids: string[]): string { const inserts: string[] = []; for (const id of ids) { const iri = WorkspaceLinks[id].source; - if (!(iri in WorkspaceTerms)) { - console.warn(`Cannot check whether link ${id} is read-only or not, skipping it.`); - continue; - } const vocabulary = getVocabularyFromScheme(WorkspaceTerms[iri].inScheme); - if (checkReadOnlyVocabulary(vocabulary)) continue; + checkReadOnlyVocabulary(vocabulary); const contextIRI = WorkspaceVocabularies[vocabulary].graph; const subClassOf: string[] = getActiveSourceConnections( WorkspaceLinks[id].source @@ -401,12 +397,11 @@ export function isNumber(str: string) { return !isNaN(parseInt(str, 10)); } -function checkReadOnlyVocabulary(vocabulary: string): boolean { +function checkReadOnlyVocabulary(vocabulary: string) { if (WorkspaceVocabularies[vocabulary].readOnly) - console.error( + throw new Error( `Attempted to write to read-only graph ${WorkspaceVocabularies[vocabulary].graph}` ); - return WorkspaceVocabularies[vocabulary].readOnly } function getNumber(str: string) { diff --git a/src/queries/update/UpdateLinkQueries.ts b/src/queries/update/UpdateLinkQueries.ts index 89e15a4f..ea0f4efb 100644 --- a/src/queries/update/UpdateLinkQueries.ts +++ b/src/queries/update/UpdateLinkQueries.ts @@ -2,7 +2,6 @@ import { AppSettings, Diagrams, WorkspaceLinks } from "../../config/Variables"; import { qb } from "../QueryBuilder"; import { DELETE, INSERT } from "@tpluscode/sparql-builder"; import { LinkConfig } from "./UpdateConnectionQueries"; -import { deleteLink } from "../../function/FunctionLink"; export function updateProjectLinkVertex( id: string, @@ -167,15 +166,14 @@ export function updateProjectLink(del: boolean, ...ids: string[]): string { return qb.combineQueries(...(del ? [deletes, ...insert] : [...insert])); } -export function updateProjectLinkParallel(connections: { del: string[], add: string[] }): string[] { - const queries: string[] = []; +export function updateProjectLinkParallel(...ids: string[]): string[] { const insertBody: string[] = []; const insert: string[] = []; const diagrams = Object.values(Diagrams) .filter((diag) => !diag.toBeDeleted) .map((diagram) => diagram.graph); - if (connections.add.length === 0 && connections.del.length === 0) return []; - for (const id of connections.add) { + if (ids.length === 0) return []; + for (const id of ids) { checkLink(id); const linkIRI = qb.i(WorkspaceLinks[id].linkIRI); @@ -214,13 +212,7 @@ export function updateProjectLinkParallel(connections: { del: string[], add: str INSERT.DATA`${qb.g(diagram, insertBody)}`.build() ) ); - queries.push(...insert); - - for (const id of connections.del) { - queries.push(...deleteLink(id)) - } - - return queries; + return insert; } function checkLink(id: string) {