2024-07-18 11:51:12 +02:00
|
|
|
package data
|
|
|
|
|
|
|
|
import (
|
2024-07-18 14:39:54 +02:00
|
|
|
"encoding/json"
|
|
|
|
|
2024-07-18 13:35:14 +02:00
|
|
|
resources "cloud.o-forge.io/core/oc-lib/models/resources"
|
|
|
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
2024-07-18 11:51:12 +02:00
|
|
|
)
|
|
|
|
|
2024-07-19 10:54:58 +02:00
|
|
|
type DataResource struct {
|
2024-07-18 11:51:12 +02:00
|
|
|
resources.AbstractResource
|
|
|
|
Protocols []string `json:"protocol,omitempty" bson:"protocol,omitempty"` //TODO Enum type
|
2024-07-22 09:03:57 +02:00
|
|
|
DataType string `json:"datatype" bson:"datatype"`
|
|
|
|
Example string `json:"example" bson:"example" description:"base64 encoded data"`
|
2024-07-18 11:51:12 +02:00
|
|
|
}
|
|
|
|
|
2024-07-19 10:54:58 +02:00
|
|
|
func (dma *DataResource) Deserialize(j map[string]interface{}) utils.DBObject {
|
2024-07-18 14:39:54 +02:00
|
|
|
b, err := json.Marshal(j)
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
json.Unmarshal(b, dma)
|
2024-07-19 13:15:51 +02:00
|
|
|
dma.AbstractResource.ObjDeserialize(j)
|
2024-07-18 14:39:54 +02:00
|
|
|
return dma
|
|
|
|
}
|
|
|
|
|
2024-07-19 10:54:58 +02:00
|
|
|
func (dma *DataResource) Serialize() map[string]interface{} {
|
2024-07-19 09:32:58 +02:00
|
|
|
var m map[string]interface{}
|
|
|
|
b, err := json.Marshal(dma)
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
json.Unmarshal(b, dma)
|
2024-07-19 13:15:51 +02:00
|
|
|
dma.AbstractResource.ObjSerialize()
|
2024-07-19 09:32:58 +02:00
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2024-07-19 10:54:58 +02:00
|
|
|
func (d *DataResource) GetAccessor() utils.Accessor {
|
2024-07-18 15:02:39 +02:00
|
|
|
data := &DataMongoAccessor{}
|
2024-07-19 10:54:58 +02:00
|
|
|
data.SetLogger(utils.DATACENTER_RESOURCE)
|
2024-07-18 11:51:12 +02:00
|
|
|
return data
|
|
|
|
}
|