Skip to content

Commit

Permalink
Revert "Delete inactive connections and read active connections prope…
Browse files Browse the repository at this point in the history
…rly"

This reverts commit bb37b23.
  • Loading branch information
bindeali committed Sep 19, 2024
1 parent bb37b23 commit c7333e0
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 30 deletions.
4 changes: 1 addition & 3 deletions src/function/FunctionLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
32 changes: 29 additions & 3 deletions src/interface/ContextInterface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,33 @@ export async function retrieveContextData(): Promise<boolean> {
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") ||
Expand All @@ -295,9 +321,9 @@ export async function retrieveContextData(): Promise<boolean> {
}
}
return await processTransaction(
qb.constructQuery(
AppSettings.contextEndpoint,
...updateProjectLinkParallel(connections)
AppSettings.contextEndpoint,
...updateProjectLinkParallel(...connections.add).map((t) =>
qb.constructQuery(t)
)
);
}
Expand Down
5 changes: 1 addition & 4 deletions src/queries/get/InitQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export async function getLinksConfig(
const getLinks = async (): Promise<boolean> => {
const query = [
"PREFIX og: <http://onto.fel.cvut.cz/ontologies/application/ontoGrapher/>",
"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 .",
Expand All @@ -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("> <")}>}`,
"}",
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 3 additions & 8 deletions src/queries/update/UpdateConnectionQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
16 changes: 4 additions & 12 deletions src/queries/update/UpdateLinkQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c7333e0

Please sign in to comment.