deprecated-oc-catalog/models/data.go

125 lines
3.1 KiB
Go
Raw Permalink Normal View History

2023-03-03 14:43:11 +01:00
package models
import (
"cloud.o-forge.io/core/oc-catalog/models/rtype"
"cloud.o-forge.io/core/oc-catalog/services"
"github.com/beego/beego/v2/core/logs"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// TODO: Define better the different types of Data model with model herarchy
// TODO: review why swagger are not using the metadata when we do herarchy
type DataNEWModel struct {
Name string `json:"name,omitempty" required:"true" validate:"required" description:"Name of the data"`
2024-03-18 11:25:59 +01:00
Description string `json:"description" required:"true" validate:"required"`
2023-03-03 14:43:11 +01:00
ShortDescription string `json:"short_description" required:"true" validate:"required"`
Logo string `json:"logo" required:"true" validate:"required"`
2024-04-02 15:17:18 +02:00
Dtype string `json:"dtype"`
2023-03-03 14:43:11 +01:00
Type string `json:"type,omitempty" required:"true" validate:"required" description:"Define type of data" example:"file"`
Example string `json:"example" required:"true" validate:"required" description:"base64 encoded data"`
Protocol []string `json:"protocol"` //TODO Enum type
2024-03-18 11:25:59 +01:00
Location string `json:"location" required:"true" validate:"required"`
2023-03-03 14:43:11 +01:00
}
2024-04-04 16:44:46 +02:00
type DataIO struct {
Counter uint `description:"Incremental number starting from 0"`
}
type DataObject struct {
ReferenceID primitive.ObjectID `json:"referenceID" description:"Data model ID"`
}
2023-03-03 14:43:11 +01:00
type DataModel struct {
ID string `json:"ID" bson:"_id" required:"true" validate:"required"`
DataNEWModel `bson:",inline"`
2024-04-04 16:44:46 +02:00
}
2023-03-03 14:43:11 +01:00
func (obj DataModel) getRtype() rtype.Rtype {
return rtype.DATA
2024-04-04 16:44:46 +02:00
}
2023-03-03 14:43:11 +01:00
func (model DataModel) getName() string {
return model.Name
2024-04-04 16:44:46 +02:00
}
2023-03-03 14:43:11 +01:00
func (obj DataObject) getHost() *string {
return nil // Host is DC only attribute
}
func (obj DataObject) getModel() (ret ResourceModel, err error) {
var ret2 DataModel
res := services.MngoCollData.FindOne(services.MngoCtx,
primitive.M{"_id": obj.ReferenceID},
)
if err = res.Err(); err != nil {
return
}
err = res.Decode(&ret2)
return ret2, err
}
func (obj *DataObject) setReference(rID primitive.ObjectID) {
obj.ReferenceID = rID
}
func (obj DataObject) getReference() primitive.ObjectID {
return obj.ReferenceID
}
func (obj DataObject) getRtype() rtype.Rtype {
return rtype.DATA
}
func (obj DataObject) getName() (name *string) {
res := services.MngoCollData.FindOne(services.MngoCtx, primitive.M{"_id": obj.ReferenceID})
if res.Err() != nil {
logs.Error(res)
return
}
var ret DataModel
res.Decode(&ret)
return &ret.Name
}
func (obj DataObject) isLinked(rID string) LinkingState {
return NO_LINK
}
func (obj *DataObject) addLink(direction LinkingState, rObjID string) {
}
func PostOneData(obj DataNEWModel) (string, error) {
return postOneResource(obj, rtype.DATA)
}
func GetMultipleData(IDs []string) (object *[]DataModel, err error) {
objArray, err := getMultipleResourceByIDs(IDs, rtype.DATA)
if err != nil {
return nil, err
}
object = objArray.(*[]DataModel)
return object, err
}
func GetOneData(ID string) (object *DataModel, err error) {
obj, err := getOneResourceByID(ID, rtype.DATA)
if err != nil {
return nil, err
}
object = obj.(*DataModel)
return object, err
}