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"` Description string `json:"description" required:"true" validate:"required"` ShortDescription string `json:"short_description" required:"true" validate:"required"` Logo string `json:"logo" required:"true" validate:"required"` Dtype string `json:"dtype"` 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 Location string `json:"location" required:"true" validate:"required"` } type DataModel struct { ID string `json:"ID" bson:"_id" required:"true" validate:"required"` DataNEWModel `bson:",inline"` } func (obj DataModel) getRtype() rtype.Rtype { return rtype.DATA } func (model DataModel) getName() string { return model.Name } type DataIO struct { Counter uint `description:"Incremental number starting from 0"` } type DataObject struct { ReferenceID primitive.ObjectID `json:"referenceID" description:"Data model ID"` } 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 }