From c7f65914bb93f2a0c1afd7f9ac6480aa85e9c20e Mon Sep 17 00:00:00 2001 From: mr Date: Mon, 29 Jul 2024 08:52:02 +0200 Subject: [PATCH] cast at root lib --- entrypoint.go | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/entrypoint.go b/entrypoint.go index b28e115..0b6c143 100644 --- a/entrypoint.go +++ b/entrypoint.go @@ -4,7 +4,15 @@ import ( "cloud.o-forge.io/core/oc-lib/dbs/mongo" "cloud.o-forge.io/core/oc-lib/logs" "cloud.o-forge.io/core/oc-lib/models" + "cloud.o-forge.io/core/oc-lib/models/resources/data" + "cloud.o-forge.io/core/oc-lib/models/resources/datacenter" + "cloud.o-forge.io/core/oc-lib/models/resources/processing" + "cloud.o-forge.io/core/oc-lib/models/resources/storage" + w "cloud.o-forge.io/core/oc-lib/models/resources/workflow" "cloud.o-forge.io/core/oc-lib/models/utils" + w2 "cloud.o-forge.io/core/oc-lib/models/workflow" + "cloud.o-forge.io/core/oc-lib/models/workflow_execution" + "cloud.o-forge.io/core/oc-lib/models/workspace" "github.com/rs/zerolog" ) @@ -109,3 +117,56 @@ func CopyOne(collection LibDataEnum, object map[string]interface{}) LibData { } return LibData{Data: d, Code: code} } + +// ================ CAST ========================= // + +func (l *LibData) ToDataResource() *data.DataResource { + if l.Data.GetAccessor().GetType() == utils.DATA_RESOURCE.String() { + return l.Data.(*data.DataResource) + } + return nil +} + +func (l *LibData) ToDatacenterResource() *datacenter.DatacenterResource { + if l.Data != nil && l.Data.GetAccessor().GetType() == utils.DATACENTER_RESOURCE.String() { + return l.Data.(*datacenter.DatacenterResource) + } + return nil +} +func (l *LibData) ToStorageResource() *storage.StorageResource { + if l.Data.GetAccessor().GetType() == utils.STORAGE_RESOURCE.String() { + return l.Data.(*storage.StorageResource) + } + return nil +} +func (l *LibData) ToProcessingResource() *processing.ProcessingResource { + if l.Data.GetAccessor().GetType() == utils.PROCESSING_RESOURCE.String() { + return l.Data.(*processing.ProcessingResource) + } + return nil +} +func (l *LibData) ToWorkflowResource() *w.WorkflowResource { + if l.Data.GetAccessor().GetType() == utils.WORKFLOW_RESOURCE.String() { + return l.Data.(*w.WorkflowResource) + } + return nil +} + +func (l *LibData) ToWorkflow() *w2.Workflow { + if l.Data.GetAccessor().GetType() == utils.WORKFLOW.String() { + return l.Data.(*w2.Workflow) + } + return nil +} +func (l *LibData) ToWorkspace() *workspace.Workspace { + if l.Data.GetAccessor().GetType() == utils.WORKSPACE.String() { + return l.Data.(*workspace.Workspace) + } + return nil +} +func (l *LibData) ToWorkflowExecution() *workflow_execution.WorkflowExecution { + if l.Data.GetAccessor().GetType() == utils.WORKSPACE.String() { + return l.Data.(*workflow_execution.WorkflowExecution) + } + return nil +}