This commit is contained in:
mr 2024-07-19 13:15:51 +02:00
parent 5c44b46bcb
commit cdc077c59e
8 changed files with 78 additions and 1 deletions

View File

@ -20,6 +20,7 @@ func (dma *DataResource) Deserialize(j map[string]interface{}) utils.DBObject {
return nil
}
json.Unmarshal(b, dma)
dma.AbstractResource.ObjDeserialize(j)
return dma
}
@ -30,6 +31,7 @@ func (dma *DataResource) Serialize() map[string]interface{} {
return nil
}
json.Unmarshal(b, dma)
dma.AbstractResource.ObjSerialize()
return m
}

View File

@ -43,6 +43,7 @@ func (dma *DatacenterResource) Deserialize(j map[string]interface{}) utils.DBObj
return nil
}
json.Unmarshal(b, dma)
dma.AbstractResource.ObjDeserialize(j)
return dma
}
@ -53,6 +54,7 @@ func (dma *DatacenterResource) Serialize() map[string]interface{} {
return nil
}
json.Unmarshal(b, dma)
dma.AbstractResource.ObjSerialize()
return m
}

View File

@ -37,6 +37,7 @@ func (dma *ProcessingResource) Deserialize(j map[string]interface{}) utils.DBObj
return nil
}
json.Unmarshal(b, dma)
dma.AbstractResource.ObjDeserialize(j)
return dma
}
@ -47,6 +48,7 @@ func (dma *ProcessingResource) Serialize() map[string]interface{} {
return nil
}
json.Unmarshal(b, dma)
dma.AbstractResource.ObjSerialize()
return m
}

View File

@ -1,6 +1,8 @@
package resources
import (
"encoding/json"
"cloud.o-forge.io/core/oc-lib/models/utils"
)
@ -24,6 +26,27 @@ type AbstractResource struct {
SourceUrl string `json:"source_url" required:"true" bson:"source_url" validate:"required"`
}
func (dma *AbstractResource) ObjDeserialize(j map[string]interface{}) *AbstractResource {
b, err := json.Marshal(j)
if err != nil {
return nil
}
json.Unmarshal(b, dma)
dma.AbstractObject.ObjDeserialize(j)
return dma
}
func (dma *AbstractResource) ObjSerialize() map[string]interface{} {
var m map[string]interface{}
b, err := json.Marshal(dma)
if err != nil {
return nil
}
json.Unmarshal(b, dma)
dma.AbstractObject.ObjSerialize()
return m
}
func (r *AbstractResource) GetID() string {
return r.UUID
}

View File

@ -30,6 +30,7 @@ func (dma *StorageResource) Deserialize(j map[string]interface{}) utils.DBObject
return nil
}
json.Unmarshal(b, dma)
dma.AbstractResource.ObjDeserialize(j)
return dma
}
@ -40,6 +41,7 @@ func (dma *StorageResource) Serialize() map[string]interface{} {
return nil
}
json.Unmarshal(b, dma)
dma.AbstractResource.ObjSerialize()
return m
}

View File

@ -22,6 +22,25 @@ type AbstractWorkflow struct {
Schedule WorkflowSchedule `bson:"schedule,omitempty" json:"schedule,omitempty"`
}
func (w *AbstractWorkflow) ObjDeserialize(j map[string]interface{}) *AbstractWorkflow {
b, err := json.Marshal(j)
if err != nil {
return nil
}
json.Unmarshal(b, w)
return w
}
func (w *AbstractWorkflow) ObjSerialize() map[string]interface{} {
var m map[string]interface{}
b, err := json.Marshal(w)
if err != nil {
return nil
}
json.Unmarshal(b, w)
return m
}
func (w *AbstractWorkflow) isDCLink(link graph.GraphLink) bool {
if _, exists := w.Datacenters[link.Destination.ID]; exists {
return true
@ -50,6 +69,7 @@ func (dma *WorkflowResource) Deserialize(j map[string]interface{}) utils.DBObjec
return nil
}
json.Unmarshal(b, dma)
dma.AbstractResource.ObjDeserialize(j)
return dma
}
@ -60,5 +80,6 @@ func (dma *WorkflowResource) Serialize() map[string]interface{} {
return nil
}
json.Unmarshal(b, dma)
dma.AbstractResource.ObjSerialize()
return m
}

View File

@ -1,6 +1,8 @@
package utils
import (
"encoding/json"
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
"cloud.o-forge.io/core/oc-lib/logs"
"github.com/go-playground/validator/v10"
@ -15,6 +17,25 @@ type AbstractObject struct {
Name string `json:"name" required:"true" bson:"name" validate:"required"`
}
func (dma *AbstractObject) ObjDeserialize(j map[string]interface{}) *AbstractObject {
b, err := json.Marshal(j)
if err != nil {
return nil
}
json.Unmarshal(b, dma)
return dma
}
func (dma *AbstractObject) ObjSerialize() map[string]interface{} {
var m map[string]interface{}
b, err := json.Marshal(dma)
if err != nil {
return nil
}
json.Unmarshal(b, dma)
return m
}
func (r *AbstractObject) GenerateID() {
r.UUID = uuid.New().String()
}

View File

@ -9,7 +9,7 @@ import (
)
type Workflow struct {
*utils.AbstractObject
utils.AbstractObject
w.AbstractWorkflow
}
@ -29,6 +29,8 @@ func (dma *Workflow) Deserialize(j map[string]interface{}) utils.DBObject {
return nil
}
json.Unmarshal(b, dma)
dma.AbstractObject.ObjDeserialize(j)
dma.AbstractWorkflow.ObjDeserialize(j)
fmt.Println(j, dma)
return dma
}
@ -40,5 +42,7 @@ func (dma *Workflow) Serialize() map[string]interface{} {
return nil
}
json.Unmarshal(b, dma)
dma.AbstractObject.ObjSerialize()
dma.AbstractWorkflow.ObjSerialize()
return m
}