Skip to content

Commit

Permalink
WIP: 7cd00e8 simplify context menu api to use iriArray insteaf of sel…
Browse files Browse the repository at this point in the history
…ectedRowModel
  • Loading branch information
pogi7 committed May 8, 2024
2 parents c12dd84 + f576f8e commit 0ffc45a
Show file tree
Hide file tree
Showing 56 changed files with 7,695 additions and 5,991 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ Look at the OML Vision Docs [Changelog](http://www.opencaesar.io/oml-vision-docs

## v0.3.0 - Venus

### Added
- Property View: execute commands from property sheet https://github.com/opencaesar/oml-vision/pull/58
- Table, Tree, and Diagram Views: execute commands from a context/right click menu file https://github.com/opencaesar/oml-vision/pull/54
- Wizard View: Add deletion wizards and the ability to delete OML instances and relations https://github.com/opencaesar/oml-vision/pull/70


## v0.2.6 - Rembrandt Basin

### Added
Expand Down
25 changes: 13 additions & 12 deletions commands/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export enum Commands {
GENERATE_TABLE_DATA = 'generateTableData',
UPDATE_CM_STATE = 'updateCmState',
REFRESH_TABLE_DATA = 'refreshTableData',
GET_ELEMENT_DEPENDENCIES = 'getElementDependencies',
GET_ELEMENT_RELATIONS = 'getElementRelations',
EXECUTE_CREATE_ELEMENTS = 'executeCreateElements',
EXECUTE_DELETE_ELEMENTS = 'executeDeleteElements',
CREATE_FCR = 'createFCR',
Expand Down Expand Up @@ -44,7 +44,7 @@ export enum Commands {
CREATE_FILTERED_DIAGRAM = 'createFilteredDiagram',
LOADED_PROPERTY_SHEET = 'loadedPropertySheet',
LOADED_TABLE_DATA = 'loadedTableData',
LOADED_ELEMENT_DEPENDENCIES = 'loadedElementDependencies',
LOADED_ELEMENT_RELATIONS = 'loadedElementRelations',
DELETED_ELEMENTS = 'deletedElements',
CREATED_ELEMENT = 'createdElement',
CLONED_ELEMENTS = 'clonedElements',
Expand Down Expand Up @@ -82,12 +82,12 @@ export type CommandStructures = {
payload: { aIri: string; fse_lifecycleState: string }[];
};
[Commands.REFRESH_TABLE_DATA]: {};
[Commands.GET_ELEMENT_DEPENDENCIES]: {
payload: { webviewPath: string; iriArray: string[]; labelArray: string[] };
[Commands.GET_ELEMENT_RELATIONS]: {
payload: { webviewPath: string; iriArray: string[]; labelArray?: string[] };
wizardId?: string;
};
[Commands.EXECUTE_DELETE_ELEMENTS]: {
payload: { webviewPath: string; IRIsToDelete: string[] };
payload: { webviewPath: string; IRIsToDelete: ITableData[] };
wizardId?: string;
};
[Commands.CREATE_FCR]: {
Expand Down Expand Up @@ -158,12 +158,11 @@ export type CommandStructures = {
errorMessage?: string;
payload?: Record<string, ITableData[]>;
};
[Commands.LOADED_ELEMENT_DEPENDENCIES]: {
[Commands.LOADED_ELEMENT_RELATIONS]: {
errorMessage?: string;
wizardId: string;
payload: {
relationIRIs?: Record<string, any>[];
IRIsToDelete?: string[];
IRIsToDelete?: Record<string, any>[];
};
};
[Commands.DELETED_ELEMENTS]: {
Expand Down Expand Up @@ -191,19 +190,21 @@ export type CommandStructures = {
};
[Commands.CREATE_QUERY]: {
query: string;
parameters: string[]
selectedElements?: string[]
};
[Commands.READ_QUERY]: {
query: string;
parameters: string[]
selectedElements?: string[]
};
[Commands.UPDATE_QUERY]: {
query: string;
parameters: string[]
selectedElements?: string[]
before_parameters?: Object
after_parameters?: Object
};
[Commands.DELETE_QUERY]: {
query: string;
parameters: string[]
selectedElements?: string[]
};
};

Expand Down
1 change: 1 addition & 0 deletions commands/src/interfaces/ViewpointPaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// TODO: Remove in v1.0.0 of OML Vision
export enum ViewpointPaths {
PropertyPanel = 'propertyLayouts.json',
WizardPanel = 'wizardLayouts.json',
TablePanel = 'tableLayouts.json',
TreePanel = 'treeLayouts.json',
DiagramPanel = 'diagramLayouts.json',
Expand Down
39 changes: 32 additions & 7 deletions commands/src/propertyPanelMessageHandler.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { Commands, CommandStructures } from './commands';
import * as vscode from 'vscode';
import { PropertyPanelProvider } from '../../controller/src/panels/PropertyPanelProvider';
import { Commands, CommandStructures } from "./commands";
import * as vscode from "vscode";
import { PropertyPanelProvider } from "../../controller/src/panels/PropertyPanelProvider";
import { TablePanel } from "../../controller/src/panels/TablePanel";
import { SparqlClient } from "../../controller/src/sparql/SparqlClient";

/**
* Handles commands that are sent to a Panel (Property Page)
* https://code.visualstudio.com/api/ux-guidelines/overview#panel
*/
export function handlePropertyPanelMessage(
message: CommandStructures[Commands] & { command: Commands; },
message: CommandStructures[Commands] & { command: Commands },
PropertyPanelInstance: PropertyPanelProvider
) {

let specificMessage;
let specificMessage: any;
switch (message.command) {
case Commands.ALERT:
const alertMessage = message as CommandStructures[Commands.ALERT];
Expand Down Expand Up @@ -56,6 +57,26 @@ export function handlePropertyPanelMessage(
}
return;

case Commands.UPDATE_QUERY:
specificMessage = message as CommandStructures[Commands.UPDATE_QUERY];
if (
specificMessage.before_parameters &&
specificMessage.after_parameters
) {
if (specificMessage.selectedElements) {
specificMessage.selectedElements.forEach((param: any) => {
SparqlClient(
specificMessage.query,
"update",
param,
specificMessage.before_parameters,
specificMessage.after_parameters
);
});
}
}
break;

case Commands.GENERATE_PROPERTY_SHEET:
specificMessage =
message as CommandStructures[Commands.GENERATE_PROPERTY_SHEET];
Expand All @@ -65,7 +86,11 @@ export function handlePropertyPanelMessage(
);
return;

case Commands.REFRESH_TABLE_DATA:
TablePanel.updateTables();
break;

default:
throw new Error(`Unhandled command: ${message.command}`);
}
}
}
66 changes: 47 additions & 19 deletions commands/src/tablePanelMessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import * as vscode from "vscode";
import { generateTableData } from "../../controller/src/sparql/data-manager/generateDataUtils";
import { TablePanel } from "../../controller/src/panels/TablePanel";
import { SparqlClient } from "../../controller/src/sparql/SparqlClient";
import { getElementRelations } from "../../controller/src/sparql/data-manager/getElementRelations";
import { executeDeleteElements } from "../../controller/src/sparql/data-manager/executeDeleteElements";

/**
* Handles commands that are sent to a Editor (Table, Tree, or Diagram)
Expand Down Expand Up @@ -86,21 +88,31 @@ export function handleTablePanelMessage(
TablePanel.updateTables();
break;

case Commands.GET_ELEMENT_DEPENDENCIES:
case Commands.GET_ELEMENT_RELATIONS:
specificMessage =
message as CommandStructures[Commands.GET_ELEMENT_DEPENDENCIES];
const {
webviewPath: depWebviewPath,
iriArray = [],
labelArray = [],
} = specificMessage.payload;
message as CommandStructures[Commands.GET_ELEMENT_RELATIONS];

// Refer to the CommandStructures[Commands.GET_ELEMENT_RELATIONS] to see how the parameters are structured
getElementRelations(
specificMessage.payload.webviewPath,
specificMessage.wizardId,
specificMessage.payload.iriArray,
specificMessage.payload.labelArray
);
break;

case Commands.EXECUTE_DELETE_ELEMENTS:
specificMessage =
message as CommandStructures[Commands.EXECUTE_DELETE_ELEMENTS];
const { webviewPath: delWebviewPath, IRIsToDelete = [] } =
specificMessage.payload;

// Refer to the CommandStructures[Commands.EXECUTE_DELETE_ELEMENTS] to see how the parameters are structured
executeDeleteElements(
specificMessage.payload.webviewPath,
specificMessage.wizardId,
specificMessage.payload.IRIsToDelete,
)
break;

case Commands.CREATE_FCR:
Expand All @@ -116,30 +128,46 @@ export function handleTablePanelMessage(

case Commands.CREATE_QUERY:
specificMessage = message as CommandStructures[Commands.CREATE_QUERY];
specificMessage.parameters.forEach((param: any) => {
SparqlClient(specificMessage.query, "update", param);
});
if (specificMessage.selectedElements) {
specificMessage.selectedElements.forEach((param: any) => {
SparqlClient(specificMessage.query, "update", param);
});
} else {
SparqlClient(specificMessage.query, "update", specificMessage);
}
break;

case Commands.READ_QUERY:
specificMessage = message as CommandStructures[Commands.READ_QUERY];
specificMessage.parameters.forEach((param: any) => {
SparqlClient(specificMessage.query, "query", param);
});
if (specificMessage.selectedElements) {
specificMessage.selectedElements.forEach((param: any) => {
SparqlClient(specificMessage.query, "query", param);
});
} else {
SparqlClient(specificMessage.query, "query", specificMessage);
}
break;

case Commands.UPDATE_QUERY:
specificMessage = message as CommandStructures[Commands.UPDATE_QUERY];
specificMessage.parameters.forEach((param: any) => {
SparqlClient(specificMessage.query, "update", param);
});
if (specificMessage.selectedElements) {
specificMessage.selectedElements.forEach((param: any) => {
SparqlClient(specificMessage.query, "update", param);
});
} else {
SparqlClient(specificMessage.query, "update", specificMessage);
}
break;

case Commands.DELETE_QUERY:
specificMessage = message as CommandStructures[Commands.DELETE_QUERY];
specificMessage.parameters.forEach((param: any) => {
SparqlClient(specificMessage.query, "update", param);
});
if (specificMessage.selectedElements) {
specificMessage.selectedElements.forEach((param: any) => {
SparqlClient(specificMessage.query, "update", param);
});
} else {
SparqlClient(specificMessage.query, "update", specificMessage);
}
break;

default:
Expand Down
7 changes: 4 additions & 3 deletions controller/src/database/queryEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
globalUpdateInferenceEndpoint,
} from "../utilities/loaders/loadSparqlConfigFiles";
import ITriplestoreStatus from "../interfaces/ITriplestoreStatus";
import { addGraphToQuery } from "./addGraphQuery";
import { addGraphToQuery } from "../sparql/format/addGraphToQuery";
import { removeGraphFromQuery } from "../sparql/format/removeGraphFromQuery";

/**
This async function creates a new query engine.
Expand Down Expand Up @@ -46,14 +47,14 @@ export const queryEngine = async (query: string): Promise<any> => {
// UPDATE, DELETE, or CREATE query is executed to named (assertions) and default (inferences) graphs
// globalUpdateAssertionEndpoint & globalUpdateInferenceEndpoint are fetched from sparqlConfig.json file in OML Model
// Refer to controller/src/utilities/loaders/loadSparqlConfigFiles.ts
const inferenceQuery = query;
const inferenceQuery = removeGraphFromQuery(query);
await qe.queryVoid(inferenceQuery, {
sources: [globalUpdateInferenceEndpoint],
// timeout in ms
httpTimeout: 6000,
});

const assertionQuery = addGraphToQuery(query);
const assertionQuery = query;
await qe.queryVoid(assertionQuery, {
sources: [globalUpdateAssertionEndpoint],
// timeout in ms
Expand Down
2 changes: 2 additions & 0 deletions controller/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,3 +514,5 @@ export function activate(context: vscode.ExtensionContext) {
function cloneSelectedRows(context: Record<string, any>) {
throw new Error("Function not implemented.");
}


56 changes: 41 additions & 15 deletions controller/src/sparql/SparqlClient.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,75 @@
import * as vscode from "vscode";
import { globalSparqlContents } from '../extension';
import { queryEngine } from '../database/queryEngine';
import { globalSparqlContents } from "../extension";
import { queryEngine } from "../database/queryEngine";

// SPARQL service types
import { SparqlServiceType } from '../types/SparqlServiceType';
import { addGraphToQuery } from "../database/addGraphQuery";
import { SparqlServiceType } from "../types/SparqlServiceType";
import { addGraphToQuery } from "./format/addGraphToQuery";
import { addParametersToQuery } from "./format/addParametersToQuery";
import { removeGraphFromQuery } from "./format/removeGraphFromQuery";

/**
* SparqlClient connects to the SPARQL query engine
* SparqlClient connects to the SPARQL query engine
* @param query - The SPARQL query as a string. Can be "query" or "update"
* @param service - The SPARQL service as a string. Either query or update service.
* @param iri - The target IRI used to get a particular element
* @param beforeParameters - The parameters object which represents the data before the update.
* @param afterParemeters - The parameters object which represents the data after the update.
* @returns A promise that resolves with the data as a JSON object, or null if an error occurred
*/
export async function SparqlClient(query: string, service: SparqlServiceType, iri?: string): Promise<Record<string, any>[]> {
export async function SparqlClient(
query: string,
service: SparqlServiceType,
iri?: string,
beforeParameters?: Object,
afterParameters?: Object
): Promise<Record<string, any>[]> {
let QUERY = globalSparqlContents[query];

if (Object.keys(globalSparqlContents).length === 0) {
vscode.window.showErrorMessage(`No SPARQL queries found in src/vision/sparql directory.`);
vscode.window.showErrorMessage(
`No SPARQL queries found in src/vision/sparql directory.`
);
throw new Error(`No SPARQL queries found in current model.`);
}

if (!QUERY) {
QUERY = query
QUERY = query;
// Uncomment to have VSCode notify users about SPARQL query not being defined in src/vision/sparql directory
// More info here https://code.visualstudio.com/api/ux-guidelines/notifications
// vscode.window.showWarningMessage(`SPARQL query not defined in src/vision/sparql directory: ${query}`);
console.warn(`SPARQL query not defined in src/vision/sparql directory: ${query}`)
};
console.warn(
`SPARQL query not defined in src/vision/sparql directory: ${query}`
);
}

// FIXME: Move this code to a separate function to lower coupling
if (iri) {
QUERY = QUERY.replace(/\$\{iri\}/g, iri);
}

// FIXME: Move this code to a separate function to lower coupling
if (beforeParameters && afterParameters) {
QUERY = addParametersToQuery(
QUERY,
beforeParameters,
afterParameters
);
}

if (!QUERY && !query) {
vscode.window.showErrorMessage(`Unknown SPARQL query: ${query}`);
throw new Error(`Unknown SPARQL query: ${query}`);
}

if (service === "query") {
console.log(`EXECUTE QUERY SERVICE: ${QUERY}`)
console.log(`EXECUTE QUERY SERVICE: ${QUERY}`);
return await queryEngine(QUERY);
} else {
console.log(`EXECUTE UPDATE (DEFAULT GRAPH) SERVICE: ${QUERY}`)
console.log(`EXECUTE UPDATE (NAMED GRAPH) SERVICE: ${addGraphToQuery(QUERY)}`)
return await queryEngine(QUERY)
console.log(`EXECUTE UPDATE (DEFAULT GRAPH) SERVICE: ${removeGraphFromQuery(QUERY)}`);
console.log(
`EXECUTE UPDATE (NAMED GRAPH) SERVICE: ${QUERY}`
);
return await queryEngine(QUERY);
}
}
}
Loading

0 comments on commit 0ffc45a

Please sign in to comment.