From 7c40d6bd1a3b56fe04ff4900af20d4fb6fd6478f Mon Sep 17 00:00:00 2001 From: Daniil Palagin Date: Tue, 12 Nov 2024 13:30:10 +0100 Subject: [PATCH 1/2] [#86] Install Axios for HTTP requests --- package-lock.json | 48 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 49 insertions(+) diff --git a/package-lock.json b/package-lock.json index fa1fef5..7ad5524 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,7 @@ "@tippyjs/react": "^4.2.5", "@triply/yasgui": "^4.2.14", "@vitejs/plugin-react": "^4.3.1", + "axios": "^1.7.7", "bootstrap": "^4.5.3", "cytoscape": "^3.30.2", "cytoscape-compound-drag-and-drop": "^1.1.0", @@ -2068,6 +2069,29 @@ "remove-accents": "^0.4.2" } }, + "node_modules/axios": { + "version": "1.7.7", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", + "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, + "node_modules/axios/node_modules/form-data": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz", + "integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/babel-plugin-emotion": { "version": "10.2.2", "resolved": "https://registry.npmjs.org/babel-plugin-emotion/-/babel-plugin-emotion-10.2.2.tgz", @@ -3135,6 +3159,25 @@ "node": ">=0.10.0" } }, + "node_modules/follow-redirects": { + "version": "1.15.9", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", + "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/form-data": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz", @@ -4558,6 +4601,11 @@ "react": ">=0.14.0" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/qs": { "version": "6.13.0", "resolved": "https://registry.npmjs.org/qs/-/qs-6.13.0.tgz", diff --git a/package.json b/package.json index 2c9ab82..0060da7 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "@tippyjs/react": "^4.2.5", "@triply/yasgui": "^4.2.14", "@vitejs/plugin-react": "^4.3.1", + "axios": "^1.7.7", "bootstrap": "^4.5.3", "cytoscape": "^3.30.2", "cytoscape-compound-drag-and-drop": "^1.1.0", From 21d20f91c264321d728e10f0cf07a0da6f0bb1c1 Mon Sep 17 00:00:00 2001 From: Daniil Palagin Date: Tue, 12 Nov 2024 13:36:17 +0100 Subject: [PATCH 2/2] [#86] Implement Axios API instance, create apiFetchers, and refactor API endpoints into separate constants file --- src/components/Executions.jsx | 2 +- src/components/ModuleTypesSelection.jsx | 2 +- src/components/ScriptFunctionSelection.jsx | 2 +- src/components/dagre/Dagre.jsx | 2 +- .../modal/FunctionExecutionModal.jsx | 2 +- src/components/modal/MoveModuleModal.jsx | 2 +- src/components/modal/ScriptOntologyModal.jsx | 1 + src/components/rest/Rest.jsx | 270 ------------------ src/components/sform/SFormsFunctionModal.jsx | 2 +- src/components/sform/SFormsModal.jsx | 2 +- .../sform/ScriptInputOutputModal.jsx | 2 +- src/components/treebeard/ScriptsTree.jsx | 2 +- src/rest/Rest.jsx | 205 +++++++++++++ src/rest/api.js | 5 + src/rest/apiUrls.js | 27 ++ src/rest/fetchers.js | 26 ++ 16 files changed, 274 insertions(+), 280 deletions(-) delete mode 100644 src/components/rest/Rest.jsx create mode 100644 src/rest/Rest.jsx create mode 100644 src/rest/api.js create mode 100644 src/rest/apiUrls.js create mode 100644 src/rest/fetchers.js diff --git a/src/components/Executions.jsx b/src/components/Executions.jsx index f10041f..7471003 100644 --- a/src/components/Executions.jsx +++ b/src/components/Executions.jsx @@ -1,7 +1,7 @@ import React from "react"; import Layout from "./Layout"; import { ABSOLUTE_PATH, DISPLAY_NAME, EXECUTION_DURATION, TRANSFORMATION } from "../constants/Vocabulary.js"; -import Rest from "./rest/Rest.jsx"; +import Rest from "../rest/Rest.jsx"; import { Col, Container, Row, Table } from "react-bootstrap"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faMugHot, faEdit, faQuestion } from "@fortawesome/free-solid-svg-icons"; diff --git a/src/components/ModuleTypesSelection.jsx b/src/components/ModuleTypesSelection.jsx index a8e7475..1505ca7 100644 --- a/src/components/ModuleTypesSelection.jsx +++ b/src/components/ModuleTypesSelection.jsx @@ -1,6 +1,6 @@ import React from "react"; import { Dropdown } from "semantic-ui-react"; -import Rest from "./rest/Rest"; +import Rest from "../rest/Rest"; import { ICONS_MAP } from "./dagre/DagreIcons"; class ModuleTypesSelection extends React.Component { diff --git a/src/components/ScriptFunctionSelection.jsx b/src/components/ScriptFunctionSelection.jsx index 692e010..55d05da 100644 --- a/src/components/ScriptFunctionSelection.jsx +++ b/src/components/ScriptFunctionSelection.jsx @@ -1,7 +1,7 @@ import React from "react"; import { Dropdown } from "semantic-ui-react"; import { FUNCTION_URI, FUNCTION_NAME } from "../constants/Vocabulary.js"; -import Rest from "./rest/Rest.jsx"; +import Rest from "../rest/Rest.jsx"; class ScriptFunctionSelection extends React.Component { constructor(props) { diff --git a/src/components/dagre/Dagre.jsx b/src/components/dagre/Dagre.jsx index 03841e0..562bec9 100644 --- a/src/components/dagre/Dagre.jsx +++ b/src/components/dagre/Dagre.jsx @@ -6,7 +6,7 @@ import cxtmenu from "cytoscape-cxtmenu"; import popper from "cytoscape-popper"; import navigator from "cytoscape-navigator"; import expandCollapse from "cytoscape-expand-collapse"; -import Rest from "../rest/Rest.jsx"; +import Rest from "../../rest/Rest.jsx"; import NavbarMenu from "../NavbarMenu"; import SFormsModal from "../sform/SFormsModal"; import ModuleTypesSelection from "../ModuleTypesSelection"; diff --git a/src/components/modal/FunctionExecutionModal.jsx b/src/components/modal/FunctionExecutionModal.jsx index 084b70b..152d7f2 100644 --- a/src/components/modal/FunctionExecutionModal.jsx +++ b/src/components/modal/FunctionExecutionModal.jsx @@ -1,6 +1,6 @@ import React from "react"; import { Button, Form, Modal } from "react-bootstrap"; -import { Rest } from "../rest/Rest"; +import { Rest } from "../../rest/Rest"; class FunctionExecutionModal extends React.Component { constructor(props) { diff --git a/src/components/modal/MoveModuleModal.jsx b/src/components/modal/MoveModuleModal.jsx index adeb52d..72bd09a 100644 --- a/src/components/modal/MoveModuleModal.jsx +++ b/src/components/modal/MoveModuleModal.jsx @@ -2,7 +2,7 @@ import React from "react"; import { Alert, Button, Col, Container, Modal, Row } from "react-bootstrap"; import { ONTOLOGY_URI, SCRIPT_PATH } from "../../constants/Vocabulary.js"; -import Rest from "../rest/Rest.jsx"; +import Rest from "../../rest/Rest.jsx"; class MoveModuleModal extends React.Component { constructor(props) { diff --git a/src/components/modal/ScriptOntologyModal.jsx b/src/components/modal/ScriptOntologyModal.jsx index 35d2786..ad94cc1 100644 --- a/src/components/modal/ScriptOntologyModal.jsx +++ b/src/components/modal/ScriptOntologyModal.jsx @@ -1,6 +1,7 @@ import React from "react"; import { Alert, Button, Col, Container, Form, Modal, Row } from "react-bootstrap"; +import Rest from "../../rest/Rest.jsx"; class ScriptOntologyModal extends React.Component { constructor(props) { diff --git a/src/components/rest/Rest.jsx b/src/components/rest/Rest.jsx deleted file mode 100644 index a612854..0000000 --- a/src/components/rest/Rest.jsx +++ /dev/null @@ -1,270 +0,0 @@ -import * as Vocabulary from "../../constants/Vocabulary.js"; - -const postRequestOptions = { - method: "POST", - headers: { - Accept: "application/json, text/plain, */*", - "Content-Type": "application/json", - }, -}; - -const Rest = { - getScripts: function () { - return fetch("/rest/scripts") - .then((res) => res.json()) - .catch((error) => { - return error; - }); - }, - - getExecutions: function () { - return fetch("/rest/execution/history").then((res) => res.json()); - }, - - getScript: function (script, transformation) { - postRequestOptions["body"] = JSON.stringify({ - "@type": Vocabulary.SCRIPT_DTO, - [Vocabulary.SCRIPT_PATH]: script, - [Vocabulary.TRANSFORMATION_ID]: transformation, - }); - return fetch("/rest/views/new", postRequestOptions) - .then((res) => res.json()) - .then((result) => { - return result; - }); - }, - - deleteScript: function (script) { - postRequestOptions["body"] = JSON.stringify({ - "@type": Vocabulary.SCRIPT_DTO, - [Vocabulary.ABSOLUTE_PATH]: script, - }); - return fetch("/rest/scripts/delete", postRequestOptions).then((result) => { - return result; - }); - }, - - getScriptOntologies: function (script) { - postRequestOptions["body"] = JSON.stringify({ - "@type": Vocabulary.SCRIPT_DTO, - [Vocabulary.ABSOLUTE_PATH]: script, - }); - return fetch("/rest/scripts/ontologies", postRequestOptions) - .then((res) => res.json()) - .then((result) => { - return result; - }); - }, - - removeScriptOwnOntology: function (script, ontologyURI) { - postRequestOptions["body"] = JSON.stringify({ - "@type": Vocabulary.SCRIPT_ONTOLOGY_CREATE_DTO, - [Vocabulary.SCRIPT_PATH]: script, - [Vocabulary.ONTOLOGY_URI]: ontologyURI, - }); - return fetch("/rest/scripts/ontology/remove", postRequestOptions).then((result) => { - return result; - }); - }, - - addScriptOwnOntology: function (script, ontologyURI) { - postRequestOptions["body"] = JSON.stringify({ - "@type": Vocabulary.SCRIPT_ONTOLOGY_CREATE_DTO, - [Vocabulary.SCRIPT_PATH]: script, - [Vocabulary.ONTOLOGY_URI]: ontologyURI, - }); - return fetch("/rest/scripts/ontology/add", postRequestOptions).then((result) => { - return result; - }); - }, - - getScriptOwnOntology: function (script) { - postRequestOptions["body"] = JSON.stringify({ - "@type": Vocabulary.SCRIPT_DTO, - [Vocabulary.ABSOLUTE_PATH]: script, - }); - return fetch("/rest/scripts/own-ontology", postRequestOptions) - .then((res) => res.json()) - .then((result) => { - return result; - }); - }, - - getScriptForm: function (moduleTypeUri, moduleUri, scriptPath) { - postRequestOptions["body"] = JSON.stringify({ - "@type": Vocabulary.QUESTION_DTO, - [Vocabulary.MODULE_TYPE_URI]: moduleTypeUri, - [Vocabulary.MODULE_URI]: moduleUri, - [Vocabulary.SCRIPT_PATH]: scriptPath, - }); - return fetch("/rest/scripts/forms", postRequestOptions) - .then((res) => res.json()) - .then((result) => { - return result; - }); - }, - - getFunctionForm: function (scriptPath, functionUri) { - postRequestOptions["body"] = JSON.stringify({ - "@type": Vocabulary.EXECUTION_FUNCTION_DTO, - [Vocabulary.SCRIPT_PATH]: scriptPath, - [Vocabulary.FUNCTION_URI]: functionUri, - }); - return fetch("/rest/function/form", postRequestOptions) - .then((res) => res.json()) - .then((result) => { - return result; - }); - }, - - createScript: function (ontologyURI, scriptName, scriptPath) { - postRequestOptions["body"] = JSON.stringify({ - "@type": Vocabulary.SCRIPT_CREATE_DTO, - [Vocabulary.ONTOLOGY_URI]: ontologyURI, - [Vocabulary.SCRIPT_NAME]: scriptName, - [Vocabulary.SCRIPT_PATH]: scriptPath, - }); - return fetch("/rest/scripts/create", postRequestOptions).then((result) => { - return result; - }); - }, - - getLogForm: function (logPath) { - postRequestOptions["body"] = JSON.stringify({ - "@type": Vocabulary.MODULE_LOG, - [Vocabulary.ABSOLUTE_PATH]: logPath, - }); - return fetch("/rest/scripts/load-log", postRequestOptions) - .then((res) => res.json()) - .then((result) => { - return result; - }); - }, - - updateScriptForm: function (moduleTypeUri, rootQuestion, scriptPath) { - postRequestOptions["body"] = JSON.stringify({ - "@type": Vocabulary.QUESTION_DTO, - [Vocabulary.MODULE_TYPE_URI]: moduleTypeUri, - [Vocabulary.ROOT_QUESTION]: rootQuestion, - [Vocabulary.SCRIPT_PATH]: scriptPath, - }); - console.log("update script json: " + postRequestOptions); - return fetch("/rest/scripts/forms/answers", postRequestOptions); - }, - - deleteScriptNode: function (filepath, nodeId) { - postRequestOptions["body"] = JSON.stringify({ - "@type": Vocabulary.MODULE_DTO, - [Vocabulary.ABSOLUTE_PATH]: filepath, - [Vocabulary.MODULE_URI]: nodeId, - }); - return fetch("/rest/scripts/modules/delete", postRequestOptions); - }, - - deleteScriptEdge: function (filepath, fromNodeId, toNodeId) { - postRequestOptions["body"] = JSON.stringify({ - "@type": Vocabulary.DEPENDENCY_DTO, - [Vocabulary.ABSOLUTE_PATH]: filepath, - [Vocabulary.MODULE_URI]: fromNodeId, - [Vocabulary.TARGET_MODULE_URI]: toNodeId, - }); - return fetch("/rest/scripts/modules/dependencies/delete", postRequestOptions); - }, - - moveModule: function (fromScript, toScript, moduleUri, rename) { - postRequestOptions["body"] = JSON.stringify({ - "@type": Vocabulary.MOVE_MODULE_DTO, - [Vocabulary.MODULE_FROM_PATH]: fromScript, - [Vocabulary.MODULE_TO_PATH]: toScript, - [Vocabulary.MODULE_URI]: moduleUri, - [Vocabulary.RENAME_MODULE]: rename, - }); - return fetch("/rest/scripts/modules/move", postRequestOptions).then((result) => { - return result; - }); - }, - - getModulesTypes: function (filepath) { - postRequestOptions["body"] = JSON.stringify({ - "@type": Vocabulary.SCRIPT_DTO, - [Vocabulary.ABSOLUTE_PATH]: filepath, - }); - return fetch("/rest/scripts/moduleTypes", postRequestOptions) - .then((res) => res.json()) - .then((result) => { - return result; - }); - }, - - getModulesFunctions: function (filepath) { - postRequestOptions["body"] = JSON.stringify({ - "@type": Vocabulary.SCRIPT_DTO, - [Vocabulary.ABSOLUTE_PATH]: filepath, - }); - return fetch("/rest/function/script", postRequestOptions) - .then((res) => res.json()) - .then((result) => { - return result; - }); - }, - - executeFunction: function (functionUri, params) { - postRequestOptions["body"] = JSON.stringify({ - "@type": Vocabulary.EXECUTION_FUNCTION_DTO, - [Vocabulary.FUNCTION_URI]: functionUri, - [Vocabulary.PARAMETER]: params, - }); - return fetch("/rest/function/execute", postRequestOptions); - }, - - executeModule: function (scriptPath, moduleURI, moduleInput, params) { - postRequestOptions["body"] = JSON.stringify({ - "@type": Vocabulary.EXECUTION_MODULE_DTO, - [Vocabulary.SCRIPT_PATH]: scriptPath, - [Vocabulary.MODULE_URI]: moduleURI, - [Vocabulary.INPUT_PARAMETER]: moduleInput, - [Vocabulary.PARAMETER]: params, - }); - return fetch("/rest/function/module/execute", postRequestOptions) - .then((res) => res.text()) - .then((result) => { - return result; - }); - }, - - addModuleDependency: function (scriptPath, moduleUri, targetModuleUri) { - postRequestOptions["body"] = JSON.stringify({ - "@type": Vocabulary.DEPENDENCY_DTO, - [Vocabulary.ABSOLUTE_PATH]: scriptPath, - [Vocabulary.MODULE_URI]: moduleUri, - [Vocabulary.TARGET_MODULE_URI]: targetModuleUri, - }); - return fetch("/rest/scripts/modules/dependency", postRequestOptions); - }, - - validateScript: function (filepath) { - postRequestOptions["body"] = JSON.stringify({ - "@type": Vocabulary.SCRIPT_DTO, - [Vocabulary.ABSOLUTE_PATH]: filepath, - }); - return fetch("/rest/scripts/validate", postRequestOptions) - .then((res) => res.json()) - .then((result) => { - return result; - }); - }, - - getScriptModuleExecution: function (transformationId) { - postRequestOptions["body"] = JSON.stringify({ - "@type": Vocabulary.SCRIPT_DTO, - [Vocabulary.TRANSFORMATION_ID]: transformationId, - }); - return fetch("/rest/execution/history-modules", postRequestOptions) - .then((res) => res.json()) - .then((result) => { - return result; - }); - }, -}; - -export default Rest; diff --git a/src/components/sform/SFormsFunctionModal.jsx b/src/components/sform/SFormsFunctionModal.jsx index 518f51b..982d8db 100644 --- a/src/components/sform/SFormsFunctionModal.jsx +++ b/src/components/sform/SFormsFunctionModal.jsx @@ -2,7 +2,7 @@ import React from "react"; import SForms from "@kbss-cvut/s-forms"; import { Button, Modal } from "react-bootstrap"; -import Rest from "../rest/Rest"; +import Rest from "../../rest/Rest"; import "@triply/yasgui/build/yasgui.min.css"; import ErrorModal from "../modal/ErrorModal"; diff --git a/src/components/sform/SFormsModal.jsx b/src/components/sform/SFormsModal.jsx index 7857630..76e8c94 100644 --- a/src/components/sform/SFormsModal.jsx +++ b/src/components/sform/SFormsModal.jsx @@ -1,7 +1,7 @@ import React from "react"; import SForms from "@kbss-cvut/s-forms"; import { Button, Modal } from "react-bootstrap"; -import Rest from "../rest/Rest"; +import Rest from "../../rest/Rest"; import Loading from "../Loading"; import "@triply/yasgui/build/yasgui.min.css"; import ErrorModal from "../modal/ErrorModal"; diff --git a/src/components/sform/ScriptInputOutputModal.jsx b/src/components/sform/ScriptInputOutputModal.jsx index b433748..fe08000 100644 --- a/src/components/sform/ScriptInputOutputModal.jsx +++ b/src/components/sform/ScriptInputOutputModal.jsx @@ -1,7 +1,7 @@ import React from "react"; import { Alert, Button, Form, Modal } from "react-bootstrap"; -import Rest from "../rest/Rest"; +import Rest from "../../rest/Rest"; import "@triply/yasgui/build/yasgui.min.css"; import JSONPretty from "react-json-pretty"; import "react-json-pretty/themes/monikai.css"; diff --git a/src/components/treebeard/ScriptsTree.jsx b/src/components/treebeard/ScriptsTree.jsx index 9266442..408b183 100644 --- a/src/components/treebeard/ScriptsTree.jsx +++ b/src/components/treebeard/ScriptsTree.jsx @@ -4,7 +4,7 @@ import { includes } from "lodash"; import styles from "./styles"; import Header from "./Header"; import { Treebeard, decorators } from "react-treebeard"; -import Rest from "../rest/Rest"; +import Rest from "../../rest/Rest"; import ScriptActionsModuleModal from "../modal/ScriptActionsModuleModal"; import Loading from "../Loading"; import ErrorModal from "../modal/ErrorModal"; diff --git a/src/rest/Rest.jsx b/src/rest/Rest.jsx new file mode 100644 index 0000000..a36ed10 --- /dev/null +++ b/src/rest/Rest.jsx @@ -0,0 +1,205 @@ +import URLs from "./apiUrls.js"; +import * as Vocabulary from "../constants/Vocabulary.js"; +import { getFetcher, postFetcher } from "./fetchers"; + +export const Rest = { + getScripts: function () { + return getFetcher(URLs.SCRIPTS); + }, + + getExecutions: function () { + return getFetcher(URLs.EXECUTION_HISTORY); + }, + + getScript: function (script, transformation) { + const data = { + "@type": Vocabulary.SCRIPT_DTO, + [Vocabulary.SCRIPT_PATH]: script, + [Vocabulary.TRANSFORMATION_ID]: transformation, + }; + return postFetcher(URLs.VIEWS_NEW, data); + }, + + deleteScript: function (script) { + const data = { + "@type": Vocabulary.SCRIPT_DTO, + [Vocabulary.ABSOLUTE_PATH]: script, + }; + return postFetcher(URLs.SCRIPTS_DELETE, data); + }, + + getScriptOntologies: function (script) { + const data = { + "@type": Vocabulary.SCRIPT_DTO, + [Vocabulary.ABSOLUTE_PATH]: script, + }; + return postFetcher(URLs.SCRIPTS_ONTOLOGIES, data); + }, + + removeScriptOwnOntology: function (script, ontologyURI) { + const data = { + "@type": Vocabulary.SCRIPT_ONTOLOGY_CREATE_DTO, + [Vocabulary.SCRIPT_PATH]: script, + [Vocabulary.ONTOLOGY_URI]: ontologyURI, + }; + return postFetcher(URLs.SCRIPTS_OWN_ONTOLOGY, data); + }, + + addScriptOwnOntology: function (script, ontologyURI) { + const data = { + "@type": Vocabulary.SCRIPT_ONTOLOGY_CREATE_DTO, + [Vocabulary.SCRIPT_PATH]: script, + [Vocabulary.ONTOLOGY_URI]: ontologyURI, + }; + return postFetcher(URLs.SCRIPTS_OWN_ONTOLOGY, data); + }, + + getScriptOwnOntology: function (script) { + const data = { + "@type": Vocabulary.SCRIPT_DTO, + [Vocabulary.ABSOLUTE_PATH]: script, + }; + return postFetcher(URLs.SCRIPTS_OWN_ONTOLOGY, data); + }, + + getScriptForm: function (moduleTypeUri, moduleUri, scriptPath) { + const data = { + "@type": Vocabulary.QUESTION_DTO, + [Vocabulary.MODULE_TYPE_URI]: moduleTypeUri, + [Vocabulary.MODULE_URI]: moduleUri, + [Vocabulary.SCRIPT_PATH]: scriptPath, + }; + return postFetcher(URLs.SCRIPTS_FORMS, data); + }, + + getFunctionForm: function (scriptPath, functionUri) { + const data = { + "@type": Vocabulary.EXECUTION_FUNCTION_DTO, + [Vocabulary.SCRIPT_PATH]: scriptPath, + [Vocabulary.FUNCTION_URI]: functionUri, + }; + return postFetcher(URLs.FUNCTION_FORM, data); + }, + + createScript: function (ontologyURI, scriptName, scriptPath) { + const data = { + "@type": Vocabulary.SCRIPT_CREATE_DTO, + [Vocabulary.ONTOLOGY_URI]: ontologyURI, + [Vocabulary.SCRIPT_NAME]: scriptName, + [Vocabulary.SCRIPT_PATH]: scriptPath, + }; + return postFetcher(URLs.SCRIPTS_CREATE, data); + }, + + getLogForm: function (logPath) { + const data = { + "@type": Vocabulary.MODULE_LOG, + [Vocabulary.ABSOLUTE_PATH]: logPath, + }; + return postFetcher(URLs.LOAD_LOG, data); + }, + + updateScriptForm: function (moduleTypeUri, rootQuestion, scriptPath) { + const data = { + "@type": Vocabulary.QUESTION_DTO, + [Vocabulary.MODULE_TYPE_URI]: moduleTypeUri, + [Vocabulary.ROOT_QUESTION]: rootQuestion, + [Vocabulary.SCRIPT_PATH]: scriptPath, + }; + return postFetcher(URLs.SCRIPTS_FORMS_ANSWERS, data); + }, + + deleteScriptNode: function (filepath, nodeId) { + const data = { + "@type": Vocabulary.MODULE_DTO, + [Vocabulary.ABSOLUTE_PATH]: filepath, + [Vocabulary.MODULE_URI]: nodeId, + }; + return postFetcher(URLs.SCRIPTS_MODULES_DELETE, data); + }, + + deleteScriptEdge: function (filepath, fromNodeId, toNodeId) { + const data = { + "@type": Vocabulary.DEPENDENCY_DTO, + [Vocabulary.ABSOLUTE_PATH]: filepath, + [Vocabulary.MODULE_URI]: fromNodeId, + [Vocabulary.TARGET_MODULE_URI]: toNodeId, + }; + return postFetcher(URLs.SCRIPTS_DEPENDENCIES_DELETE, data); + }, + + moveModule: function (fromScript, toScript, moduleUri, rename) { + const data = { + "@type": Vocabulary.MOVE_MODULE_DTO, + [Vocabulary.MODULE_FROM_PATH]: fromScript, + [Vocabulary.MODULE_TO_PATH]: toScript, + [Vocabulary.MODULE_URI]: moduleUri, + [Vocabulary.RENAME_MODULE]: rename, + }; + return postFetcher(URLs.SCRIPTS_MODULES_MOVE, data); + }, + + getModulesTypes: function (filepath) { + const data = { + "@type": Vocabulary.SCRIPT_DTO, + [Vocabulary.ABSOLUTE_PATH]: filepath, + }; + return postFetcher(URLs.MODULE_TYPES, data); + }, + + getModulesFunctions: function (filepath) { + const data = { + "@type": Vocabulary.SCRIPT_DTO, + [Vocabulary.ABSOLUTE_PATH]: filepath, + }; + return postFetcher(URLs.FUNCTION_SCRIPT, data); + }, + + executeFunction: function (functionUri, params) { + const data = { + "@type": Vocabulary.EXECUTION_FUNCTION_DTO, + [Vocabulary.FUNCTION_URI]: functionUri, + [Vocabulary.PARAMETER]: params, + }; + return postFetcher(URLs.FUNCTION_EXECUTE, data); + }, + + executeModule: function (scriptPath, moduleURI, moduleInput, params) { + const data = { + "@type": Vocabulary.EXECUTION_MODULE_DTO, + [Vocabulary.SCRIPT_PATH]: scriptPath, + [Vocabulary.MODULE_URI]: moduleURI, + [Vocabulary.INPUT_PARAMETER]: moduleInput, + [Vocabulary.PARAMETER]: params, + }; + return postFetcher(URLs.FUNCTION_MODULE_EXECUTE, data); + }, + + addModuleDependency: function (scriptPath, moduleUri, targetModuleUri) { + const data = { + "@type": Vocabulary.DEPENDENCY_DTO, + [Vocabulary.ABSOLUTE_PATH]: scriptPath, + [Vocabulary.MODULE_URI]: moduleUri, + [Vocabulary.TARGET_MODULE_URI]: targetModuleUri, + }; + return postFetcher(URLs.SCRIPTS_MODULE_DEPENDENCY, data); + }, + + validateScript: function (filepath) { + const data = { + "@type": Vocabulary.SCRIPT_DTO, + [Vocabulary.ABSOLUTE_PATH]: filepath, + }; + return postFetcher(URLs.SCRIPTS_VALIDATE, data); + }, + + getScriptModuleExecution: function (transformationId) { + const data = { + "@type": Vocabulary.SCRIPT_DTO, + [Vocabulary.TRANSFORMATION_ID]: transformationId, + }; + return postFetcher(URLs.EXECUTION_HISTORY_MODULES, data); + }, +}; + +export default Rest; diff --git a/src/rest/api.js b/src/rest/api.js new file mode 100644 index 0000000..ac07587 --- /dev/null +++ b/src/rest/api.js @@ -0,0 +1,5 @@ +import axios from "axios"; + +const api = axios.create(); + +export default api; diff --git a/src/rest/apiUrls.js b/src/rest/apiUrls.js new file mode 100644 index 0000000..770515f --- /dev/null +++ b/src/rest/apiUrls.js @@ -0,0 +1,27 @@ +const BASE_URL = "/rest"; + +const URLs = { + SCRIPTS: `${BASE_URL}/scripts`, + EXECUTION_HISTORY: `${BASE_URL}/execution/history`, + VIEWS_NEW: `${BASE_URL}/views/new`, + SCRIPTS_DELETE: `${BASE_URL}/scripts/delete`, + SCRIPTS_ONTOLOGIES: `${BASE_URL}/scripts/ontologies`, + SCRIPTS_OWN_ONTOLOGY: `${BASE_URL}/scripts/own-ontology`, + SCRIPTS_FORMS: `${BASE_URL}/scripts/forms`, + FUNCTION_FORM: `${BASE_URL}/function/form`, + SCRIPTS_CREATE: `${BASE_URL}/scripts/create`, + LOAD_LOG: `${BASE_URL}/scripts/load-log`, + SCRIPTS_FORMS_ANSWERS: `${BASE_URL}/scripts/forms/answers`, + SCRIPTS_MODULES_DELETE: `${BASE_URL}/scripts/modules/delete`, + SCRIPTS_DEPENDENCIES_DELETE: `${BASE_URL}/scripts/modules/dependencies/delete`, + SCRIPTS_MODULES_MOVE: `${BASE_URL}/scripts/modules/move`, + MODULE_TYPES: `${BASE_URL}/scripts/moduleTypes`, + FUNCTION_SCRIPT: `${BASE_URL}/function/script`, + FUNCTION_EXECUTE: `${BASE_URL}/function/execute`, + FUNCTION_MODULE_EXECUTE: `${BASE_URL}/function/module/execute`, + SCRIPTS_MODULE_DEPENDENCY: `${BASE_URL}/scripts/modules/dependency`, + SCRIPTS_VALIDATE: `${BASE_URL}/scripts/validate`, + EXECUTION_HISTORY_MODULES: `${BASE_URL}/execution/history-modules`, +}; + +export default URLs; diff --git a/src/rest/fetchers.js b/src/rest/fetchers.js new file mode 100644 index 0000000..9cf3827 --- /dev/null +++ b/src/rest/fetchers.js @@ -0,0 +1,26 @@ +import api from "./api"; + +export const getFetcher = async (url) => { + const response = await api.get(url); + return response.data; +}; + +export const postFetcher = async (url, data) => { + const response = await api.post(url, data); + return response.data; +}; + +export const putFetcher = async (url, data) => { + const response = await api.put(url, data); + return response.data; +}; + +export const patchFetcher = async (url, data) => { + const response = await api.patch(url, data); + return response.data; +}; + +export const deleteFetcher = async (url) => { + const response = await api.delete(url); + return response.data; +};