From 0a52ba5cd5523aabf96bbd632bf356c92606c5f1 Mon Sep 17 00:00:00 2001 From: Odei Maiz <33152403+odeimaiz@users.noreply.github.com> Date: Tue, 19 Nov 2024 15:28:27 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20[Frontend]=20Check=20all=20linke?= =?UTF-8?q?d=20nodes=20exist=20before=20loading=20Study=20(#6762)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/source/class/osparc/data/model/Node.js | 14 +++++++++++++- .../client/source/class/osparc/data/model/Study.js | 13 ++++++++++++- .../source/class/osparc/data/model/Workbench.js | 11 ++++++++++- .../source/class/osparc/desktop/MainPageHandler.js | 11 ++++++++++- 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Node.js b/services/static-webserver/client/source/class/osparc/data/model/Node.js index 0a1be2d9ae8..7a37517f898 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Node.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Node.js @@ -312,7 +312,19 @@ qx.Class.define("osparc.data.model.Node", { return outputs[outputKey]["value"]; } return null; - } + }, + + getLinkedNodeIds: function(nodeData) { + const linkedNodeIds = new Set([]); + if ("inputs" in nodeData) { + Object.values(nodeData["inputs"]).forEach(link => { + if (link && typeof link === "object" && "nodeUuid" in link) { + linkedNodeIds.add(link["nodeUuid"]); + } + }); + } + return Array.from(linkedNodeIds); + }, }, members: { diff --git a/services/static-webserver/client/source/class/osparc/data/model/Study.js b/services/static-webserver/client/source/class/osparc/data/model/Study.js index ab178aca669..dc96044e99f 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Study.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Study.js @@ -345,7 +345,18 @@ qx.Class.define("osparc.data.model.Study", { "STARTED", "RETRY" ].includes(state); - } + }, + + __isAnyLinkedNodeMissing: function(studyData) { + const existingNodeIds = Object.keys(studyData["workbench"]); + const linkedNodeIds = osparc.data.model.Workbench.getLinkedNodeIds(studyData["workbench"]); + const allExist = linkedNodeIds.every(linkedNodeId => existingNodeIds.includes(linkedNodeId)); + return !allExist; + }, + + isCorrupt: function(studyData) { + return this.__isAnyLinkedNodeMissing(studyData); + }, }, members: { diff --git a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js index 63cd8212fe2..822f5d59eff 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js @@ -78,7 +78,16 @@ qx.Class.define("osparc.data.model.Workbench", { statics: { CANT_ADD_NODE: qx.locale.Manager.tr("Nodes can't be added while the pipeline is running"), - CANT_DELETE_NODE: qx.locale.Manager.tr("Nodes can't be deleted while the pipeline is running") + CANT_DELETE_NODE: qx.locale.Manager.tr("Nodes can't be deleted while the pipeline is running"), + + getLinkedNodeIds: function(workbenchData) { + const linkedNodeIDs = new Set([]); + Object.values(workbenchData).forEach(nodeData => { + const linkedNodes = osparc.data.model.Node.getLinkedNodeIds(nodeData); + linkedNodes.forEach(linkedNodeID => linkedNodeIDs.add(linkedNodeID)) + }); + return Array.from(linkedNodeIDs); + }, }, members: { diff --git a/services/static-webserver/client/source/class/osparc/desktop/MainPageHandler.js b/services/static-webserver/client/source/class/osparc/desktop/MainPageHandler.js index 165d4cf5f08..0872a1b627b 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/MainPageHandler.js +++ b/services/static-webserver/client/source/class/osparc/desktop/MainPageHandler.js @@ -85,6 +85,8 @@ qx.Class.define("osparc.desktop.MainPageHandler", { }, loadStudy: function(studyData) { + const studyAlias = osparc.product.Utils.getStudyAlias({firstUpperCase: true}); + // check if it's locked let locked = false; let lockedBy = false; if ("state" in studyData && "locked" in studyData["state"]) { @@ -92,13 +94,20 @@ qx.Class.define("osparc.desktop.MainPageHandler", { lockedBy = studyData["state"]["locked"]["owner"]; } if (locked && lockedBy["user_id"] !== osparc.auth.Data.getInstance().getUserId()) { - const msg = `${qx.locale.Manager.tr("Study is already open by ")} ${ + const msg = `${studyAlias} ${qx.locale.Manager.tr("is already open by")} ${ "first_name" in lockedBy && lockedBy["first_name"] != null ? lockedBy["first_name"] : qx.locale.Manager.tr("another user.") }`; throw new Error(msg); } + + // check if it's corrupt + if (osparc.data.model.Study.isCorrupt(studyData)) { + const msg = `${qx.locale.Manager.tr("We encountered an issue with the")} ${studyAlias}
${qx.locale.Manager.tr("Please contact support.")}`; + throw new Error(msg); + } + this.setLoadingPageHeader(qx.locale.Manager.tr("Loading ") + studyData.name); this.showLoadingPage(); const inaccessibleServices = osparc.study.Utils.getInaccessibleServices(studyData["workbench"])