Skip to content

Commit

Permalink
Merge pull request #415 from opendata-mvcr/issue-393
Browse files Browse the repository at this point in the history
Issue #393
  • Loading branch information
bindeali authored Feb 24, 2022
2 parents 7d72fad + bd4f081 commit 26727e2
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 264 deletions.
7 changes: 3 additions & 4 deletions src/components/modals/NewElemForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ export const NewElemForm: React.FC<Props> = (props) => {
(pkg) => pkg === event.currentTarget.value
);
if (pkg) props.setSelectedVocabulary(pkg);
else
console.error(`Vocabulary ${pkg} not found within the vocabulary list.`);
props.setErrorText(
checkNames(
WorkspaceVocabularies[props.selectedVocabulary].glossary,
Expand Down Expand Up @@ -127,10 +129,7 @@ export const NewElemForm: React.FC<Props> = (props) => {
</Form.Label>
<Form.Control
as="select"
value={getLabelOrBlank(
WorkspaceVocabularies[props.selectedVocabulary].labels,
props.projectLanguage
)}
value={props.selectedVocabulary}
onChange={(event) => handleChangeSelect(event)}
disabled={
Object.keys(WorkspaceVocabularies).filter(
Expand Down
4 changes: 2 additions & 2 deletions src/function/FunctionEditVars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ export function initProjectSettings() {
AppSettings.description = initLanguageObject("");
}

export function initLanguageObject(def: any) {
let result: { [key: string]: any } = {};
export function initLanguageObject(def: string): { [key: string]: string } {
const result: { [key: string]: string } = {};
for (const code in Languages) {
result[code] = def;
}
Expand Down
32 changes: 0 additions & 32 deletions src/graph/linkTool/LinkInfo.ts

This file was deleted.

168 changes: 128 additions & 40 deletions src/interface/ContextInterface.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import {
AppSettings,
Diagrams,
WorkspaceElements,
WorkspaceLinks,
WorkspaceTerms,
WorkspaceVocabularies,
} from "../config/Variables";
import { processQuery, processTransaction } from "./TransactionInterface";
import { fetchConcepts, fetchVocabulary } from "../queries/get/FetchQueries";
import { getElementsConfig, getLinksConfig } from "../queries/get/InitQueries";
import {
getElementsConfig,
getLinksConfig,
getSettings,
} from "../queries/get/InitQueries";
import {
fetchReadOnlyTerms,
fetchVocabularies,
Expand All @@ -21,12 +26,89 @@ import {
} from "../queries/update/UpdateLinkQueries";
import { initConnections } from "../function/FunctionRestriction";
import { insertNewCacheTerms } from "../function/FunctionCache";
import { addToFlexSearch } from "../function/FunctionCreateVars";
import { addDiagram, addToFlexSearch } from "../function/FunctionCreateVars";
import { ContextLoadingStrategy, Representation } from "../config/Enum";
import { Locale } from "../config/Locale";
import { updateLegacyWorkspace } from "../queries/update/legacy/UpdateLegacyWorkspaceQueries";
import { reconstructApplicationContextWithDiagrams } from "../queries/update/UpdateReconstructAppContext";
import { updateWorkspaceContext } from "../queries/update/UpdateMiscQueries";
import { updateCreateDiagram } from "../queries/update/UpdateDiagramQueries";
import { finishUpdatingLegacyWorkspace } from "../queries/update/legacy/FinishUpdatingLegacyWorkspaceQueries";

export function retrieveInfoFromURLParameters(): boolean {
const isURL = require("is-url");
const urlParams = new URLSearchParams(window.location.search);
const contextURI = urlParams.get("workspace");
if (contextURI && isURL(contextURI)) {
AppSettings.contextIRI = decodeURIComponent(contextURI);
return true;
} else {
console.error("Unable to parse workspace IRI from the URL.");
return false;
}
}

export async function getContext(
contextIRI: string,
contextEndpoint: string
): Promise<boolean> {
export async function updateContexts(): Promise<boolean> {
const strategy = await getSettings(AppSettings.contextEndpoint);
switch (strategy) {
case ContextLoadingStrategy.UPDATE_LEGACY_WORKSPACE:
const queries = await updateLegacyWorkspace(
AppSettings.contextIRI,
AppSettings.contextEndpoint
);
const ret = await processTransaction(
AppSettings.contextEndpoint,
qb.constructQuery(qb.combineQueries(...queries))
);
if (!ret) return false;
break;
case ContextLoadingStrategy.RECONSTRUCT_WORKSPACE:
const ret2 = await processTransaction(
AppSettings.contextEndpoint,
qb.constructQuery(await reconstructApplicationContextWithDiagrams())
);
if (!ret2) return false;
break;
case ContextLoadingStrategy.DEFAULT:
break;
default:
return false;
}
if (AppSettings.initWorkspace) {
const queries = [updateWorkspaceContext()];
if (Object.keys(Diagrams).length === 0) {
const id = addDiagram(
Locale[AppSettings.interfaceLanguage].untitled,
true,
Representation.COMPACT,
0
);
queries.push(updateCreateDiagram(id));
}
const ret = await processTransaction(
AppSettings.contextEndpoint,
qb.constructQuery(...queries)
);
if (!ret) return false;
}
AppSettings.selectedDiagram = Object.keys(Diagrams).reduce((a, b) =>
Diagrams[a].index < Diagrams[b].index ? a : b
);
if (
!AppSettings.initWorkspace &&
ContextLoadingStrategy.UPDATE_LEGACY_WORKSPACE === strategy
) {
const queries = await finishUpdatingLegacyWorkspace();
const ret = await processTransaction(
AppSettings.contextEndpoint,
qb.constructQuery(qb.combineQueries(...queries))
);
if (!ret) return false;
}
return true;
}

export async function retrieveVocabularyData(): Promise<boolean> {
await fetchVocabularies(
AppSettings.contextEndpoint,
AppSettings.cacheContext
Expand All @@ -40,7 +122,7 @@ export async function getContext(
"PREFIX dcterms: <http://purl.org/dc/terms/>",
"select ?vocab ?scheme ?label ?title ?vocabLabel ?vocabIRI",
"where {",
"BIND(<" + contextIRI + "> as ?contextIRI) . ",
"BIND(<" + AppSettings.contextIRI + "> as ?contextIRI) . ",
"OPTIONAL {?contextIRI rdfs:label ?label. }",
"OPTIONAL {?contextIRI dcterms:title ?title. }",
"graph ?contextIRI {",
Expand All @@ -53,59 +135,65 @@ export async function getContext(
"?vocabIRI dcterms:title ?vocabLabel .",
"}",
"}",
].join(" ");
const responseInit: { [key: string]: any }[] = await processQuery(
contextEndpoint,
vocabularyQ
)
.then((response) => response.json())
.then((data) => {
return data.results.bindings;
})
.catch(() => false);
if (responseInit.length === 0) return false;
let vocabularies: {
].join(`
`);
const vocabularies: {
[key: string]: {
names: { [key: string]: string };
terms: any;
terms: typeof WorkspaceTerms;
graph: string;
glossary: string;
};
} = {};
if (responseInit)
for (const result of responseInit) {
if (!(result.vocabIRI.value in vocabularies)) {
vocabularies[result.vocabIRI.value] = {
names: {},
terms: {},
graph: result.vocab.value,
glossary: result.scheme.value,
};
const responseInit: boolean = await processQuery(
AppSettings.contextEndpoint,
vocabularyQ
)
.then((response) => response.json())
.then((data) => {
if (data.results.bindings.length === 0) return false;
for (const result of data.results.bindings) {
if (!(result.vocabIRI.value in vocabularies)) {
vocabularies[result.vocabIRI.value] = {
names: {},
terms: {},
graph: result.vocab.value,
glossary: result.scheme.value,
};
}
vocabularies[result.vocabIRI.value].names[
result.vocabLabel["xml:lang"]
] = result.vocabLabel.value;
if (result.label)
AppSettings.name[result.label["xml:lang"]] = result.label.value;
if (result.title)
AppSettings.name[result.title["xml:lang"]] = result.title.value;
}
vocabularies[result.vocabIRI.value].names[result.vocabLabel["xml:lang"]] =
result.vocabLabel.value;
if (result.label)
AppSettings.name[result.label["xml:lang"]] = result.label.value;
if (result.title)
AppSettings.name[result.title["xml:lang"]] = result.title.value;
}
return true;
})
.catch(() => false);
if (!responseInit) return false;
await fetchVocabulary(
Object.keys(vocabularies).map((vocab) => vocabularies[vocab].glossary),
false,
contextEndpoint
AppSettings.contextEndpoint
).catch(() => false);
for (const vocab in vocabularies) {
await fetchConcepts(
contextEndpoint,
AppSettings.contextEndpoint,
vocabularies[vocab].glossary,
vocabularies[vocab].terms,
vocab,
vocabularies[vocab].graph
).catch(() => false);
);
WorkspaceVocabularies[vocab].readOnly = false;
WorkspaceVocabularies[vocab].graph = vocabularies[vocab].graph;
Object.assign(WorkspaceTerms, vocabularies[vocab].terms);
}
return true;
}

export async function retrieveContextData(): Promise<boolean> {
if (!(await getElementsConfig(AppSettings.contextEndpoint))) return false;
if (!(await getLinksConfig(AppSettings.contextEndpoint))) return false;
const missingTerms: string[] = Object.keys(WorkspaceElements).filter(
Expand Down Expand Up @@ -151,7 +239,7 @@ export async function getContext(
AppSettings.contextEndpoint,
qb.constructQuery(
updateProjectLink(false, ...connectionsToInitialize),
updateDeleteProjectLink(...connectionsToDelete)
updateDeleteProjectLink(true, ...connectionsToDelete)
)
);
}
Loading

0 comments on commit 26727e2

Please sign in to comment.