From 488b3081ccb84334e60591b911abc1ef705d818c Mon Sep 17 00:00:00 2001 From: Daniel Chang Date: Fri, 15 Nov 2024 17:55:17 -0500 Subject: [PATCH 1/6] clean up --- .../hmiserver/service/data/WorkflowService.java | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/data/WorkflowService.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/data/WorkflowService.java index f2f450239f..b36b8e6119 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/data/WorkflowService.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/data/WorkflowService.java @@ -128,13 +128,6 @@ public Optional updateAsset( continue; } - // FIXME: backwards compatibility for older workflows, remove in a few month. - // Aug 2024 - if (dbNode.getVersion() == null) { - dbNode.setVersion(1L); - continue; - } - if (dbNode.getVersion().equals(node.getVersion())) { node.setVersion(dbNode.getVersion() + 1L); dbWorkflowNodes.set(index, node); @@ -160,12 +153,6 @@ public Optional updateAsset( continue; } - // FIXME: backwards compatibility for older workflows, remove in a few month. - // Aug 2024 - if (dbEdge.getVersion() == null) { - dbEdge.setVersion(1L); - } - if (dbEdge.getVersion().equals(edge.getVersion())) { edge.setVersion(dbEdge.getVersion() + 1L); dbWorkflowEdges.set(index, edge); From 0f21e86a4fc16694c21c996a78d4ad9fee55d2e8 Mon Sep 17 00:00:00 2001 From: Daniel Chang Date: Tue, 19 Nov 2024 09:53:06 -0500 Subject: [PATCH 2/6] track node creator --- packages/client/hmi-client/src/services/workflow.ts | 6 ++++++ packages/client/hmi-client/src/types/workflow.ts | 2 ++ .../hmiserver/models/dataservice/workflow/WorkflowNode.java | 3 +++ 3 files changed, 11 insertions(+) diff --git a/packages/client/hmi-client/src/services/workflow.ts b/packages/client/hmi-client/src/services/workflow.ts index 2600ccce05..75a169d395 100644 --- a/packages/client/hmi-client/src/services/workflow.ts +++ b/packages/client/hmi-client/src/services/workflow.ts @@ -23,6 +23,9 @@ import { Transform } from '@/types/workflow'; import { useProjects } from '@/composables/project'; +import useAuthStore from '@/stores/auth'; + +const currentUserId = useAuthStore().user?.id; /** * A wrapper class around the workflow data struture to make it easier @@ -222,6 +225,9 @@ export class WorkflowWrapper { x: pos.x, y: pos.y, + createdBy: currentUserId, + createdAt: Date.now(), + active: null, state: options.state ?? {}, uniqueInputs: op.uniqueInputs ?? false, diff --git a/packages/client/hmi-client/src/types/workflow.ts b/packages/client/hmi-client/src/types/workflow.ts index 42d23e7f19..f502638e01 100644 --- a/packages/client/hmi-client/src/types/workflow.ts +++ b/packages/client/hmi-client/src/types/workflow.ts @@ -97,6 +97,8 @@ export interface WorkflowNode { workflowId: string; isDeleted?: boolean; version?: number; + createdBy?: string; + createdAt?: number; displayName: string; operationType: string; diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/models/dataservice/workflow/WorkflowNode.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/models/dataservice/workflow/WorkflowNode.java index 0d4017d66b..f32c31a1bc 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/models/dataservice/workflow/WorkflowNode.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/models/dataservice/workflow/WorkflowNode.java @@ -24,6 +24,9 @@ public class WorkflowNode extends SupportAdditionalProperties implements Seri private Boolean isDeleted; + private String createdBy; + private Long createdAt; + private String displayName; private String operationType; From 002c2ce78cafdac6c8a417e739c025f4180ae33a Mon Sep 17 00:00:00 2001 From: Daniel Chang Date: Tue, 19 Nov 2024 12:08:29 -0500 Subject: [PATCH 3/6] don't update deleted workflow nodes/edges --- packages/client/hmi-client/src/services/workflow.ts | 2 +- .../terarium/hmiserver/service/data/WorkflowService.java | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/client/hmi-client/src/services/workflow.ts b/packages/client/hmi-client/src/services/workflow.ts index 75a169d395..406aab3f51 100644 --- a/packages/client/hmi-client/src/services/workflow.ts +++ b/packages/client/hmi-client/src/services/workflow.ts @@ -136,7 +136,7 @@ export class WorkflowWrapper { } } - // New eleemnts + // New elements [...updatedNodeMap.values()].forEach((node) => this.wf.nodes.push(node)); [...updatedEdgeMap.values()].forEach((edge) => this.wf.edges.push(edge)); } diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/data/WorkflowService.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/data/WorkflowService.java index b36b8e6119..db27334748 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/data/WorkflowService.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/data/WorkflowService.java @@ -123,12 +123,13 @@ public Optional updateAsset( final JsonNode nodeContent = this.objectMapper.valueToTree(node); final JsonNode dbNodeContent = this.objectMapper.valueToTree(dbNode); + // No changes, skip if (nodeContent.equals(dbNodeContent)) { nodeMap.remove(node.getId()); continue; } - if (dbNode.getVersion().equals(node.getVersion())) { + if (dbNode.getIsDeleted() == false && dbNode.getVersion().equals(node.getVersion())) { node.setVersion(dbNode.getVersion() + 1L); dbWorkflowNodes.set(index, node); } @@ -148,12 +149,13 @@ public Optional updateAsset( final JsonNode edgeContent = this.objectMapper.valueToTree(edge); final JsonNode dbEdgeContent = this.objectMapper.valueToTree(dbEdge); + // No changes, skip if (edgeContent.equals(dbEdgeContent)) { edgeMap.remove(edge.getId()); continue; } - if (dbEdge.getVersion().equals(edge.getVersion())) { + if (dbEdge.getIsDeleted() == false && dbEdge.getVersion().equals(edge.getVersion())) { edge.setVersion(dbEdge.getVersion() + 1L); dbWorkflowEdges.set(index, edge); } From ce44706597f9a6985ecaa7889779f5bc4a56ba59 Mon Sep 17 00:00:00 2001 From: Daniel Chang Date: Tue, 19 Nov 2024 12:28:17 -0500 Subject: [PATCH 4/6] created auditing for workflow edge --- packages/client/hmi-client/src/services/workflow.ts | 8 +++++--- packages/client/hmi-client/src/types/workflow.ts | 2 ++ .../models/dataservice/workflow/WorkflowEdge.java | 3 +++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/client/hmi-client/src/services/workflow.ts b/packages/client/hmi-client/src/services/workflow.ts index 406aab3f51..ee2bc35cea 100644 --- a/packages/client/hmi-client/src/services/workflow.ts +++ b/packages/client/hmi-client/src/services/workflow.ts @@ -25,8 +25,6 @@ import { import { useProjects } from '@/composables/project'; import useAuthStore from '@/stores/auth'; -const currentUserId = useAuthStore().user?.id; - /** * A wrapper class around the workflow data struture to make it easier * to deal with CURD operations @@ -213,6 +211,7 @@ export class WorkflowWrapper { } addNode(op: Operation, pos: Position, options: { size?: OperatorNodeSize; state?: any }) { + const currentUserName = useAuthStore().user?.username; const nodeSize: Size = getOperatorNodeSize(options.size ?? OperatorNodeSize.medium); const node: WorkflowNode = { @@ -225,7 +224,7 @@ export class WorkflowWrapper { x: pos.x, y: pos.y, - createdBy: currentUserId, + createdBy: currentUserName, createdAt: Date.now(), active: null, @@ -295,6 +294,7 @@ export class WorkflowWrapper { * * */ addEdge(sourceId: string, sourcePortId: string, targetId: string, targetPortId: string, points: Position[]) { + const currentUserName = useAuthStore().user?.username; const sourceNode = this.wf.nodes.find((d) => d.id === sourceId); const targetNode = this.wf.nodes.find((d) => d.id === targetId); if (!sourceNode || !targetNode) return; @@ -363,6 +363,8 @@ export class WorkflowWrapper { sourcePortId, target: targetId, targetPortId, + createdBy: currentUserName, + createdAt: Date.now(), points: _.cloneDeep(points) }; this.wf.edges.push(edge); diff --git a/packages/client/hmi-client/src/types/workflow.ts b/packages/client/hmi-client/src/types/workflow.ts index f502638e01..5438a3f618 100644 --- a/packages/client/hmi-client/src/types/workflow.ts +++ b/packages/client/hmi-client/src/types/workflow.ts @@ -130,6 +130,8 @@ export interface WorkflowEdge { workflowId: string; isDeleted?: boolean; version?: number; + createdBy?: string; + createdAt?: number; points: Position[]; source?: WorkflowNode['id']; diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/models/dataservice/workflow/WorkflowEdge.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/models/dataservice/workflow/WorkflowEdge.java index 4db5baf34d..45dfb5cd21 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/models/dataservice/workflow/WorkflowEdge.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/models/dataservice/workflow/WorkflowEdge.java @@ -23,6 +23,9 @@ public class WorkflowEdge extends SupportAdditionalProperties implements Seriali @TSIgnore private Long version; + private String createdBy; + private Long createdAt; + private Boolean isDeleted; private UUID source; From 8ca11948789248ffcaad9f2fe0a1e6e44b7b0488 Mon Sep 17 00:00:00 2001 From: Daniel Chang Date: Tue, 19 Nov 2024 13:02:42 -0500 Subject: [PATCH 5/6] work around active-pinia not avilable in unit-tests --- .../client/hmi-client/src/services/workflow.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/client/hmi-client/src/services/workflow.ts b/packages/client/hmi-client/src/services/workflow.ts index ee2bc35cea..b56ca6840b 100644 --- a/packages/client/hmi-client/src/services/workflow.ts +++ b/packages/client/hmi-client/src/services/workflow.ts @@ -211,7 +211,13 @@ export class WorkflowWrapper { } addNode(op: Operation, pos: Position, options: { size?: OperatorNodeSize; state?: any }) { - const currentUserName = useAuthStore().user?.username; + let currentUserName: string | undefined = ''; + try { + currentUserName = useAuthStore().user?.username; + } catch (err) { + // do nothing + } + const nodeSize: Size = getOperatorNodeSize(options.size ?? OperatorNodeSize.medium); const node: WorkflowNode = { @@ -294,7 +300,13 @@ export class WorkflowWrapper { * * */ addEdge(sourceId: string, sourcePortId: string, targetId: string, targetPortId: string, points: Position[]) { - const currentUserName = useAuthStore().user?.username; + let currentUserName: string | undefined = ''; + try { + currentUserName = useAuthStore().user?.username; + } catch (err) { + // do nothing + } + const sourceNode = this.wf.nodes.find((d) => d.id === sourceId); const targetNode = this.wf.nodes.find((d) => d.id === targetId); if (!sourceNode || !targetNode) return; From b211339d9a7b0a637349c06206570626409e31f1 Mon Sep 17 00:00:00 2001 From: Daniel Chang Date: Tue, 19 Nov 2024 14:39:54 -0500 Subject: [PATCH 6/6] comments --- .../terarium/hmiserver/service/data/WorkflowService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/data/WorkflowService.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/data/WorkflowService.java index afa12215b8..0eee4ba1ef 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/data/WorkflowService.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/data/WorkflowService.java @@ -136,6 +136,7 @@ public Optional updateAsset( continue; } + // Only update if if node is not already deleted in the db if (dbNode.getIsDeleted() == false && dbNode.getVersion().equals(node.getVersion())) { node.setVersion(dbNode.getVersion() + 1L); dbWorkflowNodes.set(index, node); @@ -162,6 +163,7 @@ public Optional updateAsset( continue; } + // Only update if if edge is not already deleted in the db if (dbEdge.getIsDeleted() == false && dbEdge.getVersion().equals(edge.getVersion())) { edge.setVersion(dbEdge.getVersion() + 1L); dbWorkflowEdges.set(index, edge);