2024-07-18 11:51:12 +02:00
package data
import (
2024-07-18 14:39:54 +02:00
"encoding/json"
2024-07-30 12:08:13 +02:00
"cloud.o-forge.io/core/oc-lib/models/resource_model"
2024-07-18 13:35:14 +02:00
"cloud.o-forge.io/core/oc-lib/models/utils"
2024-08-12 16:11:25 +02:00
"cloud.o-forge.io/core/oc-lib/tools"
2024-07-18 11:51:12 +02:00
)
2024-11-07 11:05:24 +01:00
// enum of public private or licenced data
type DataLicense string
const (
PUBLIC = "public"
PRIVATE = "private"
LICENCED = "licenced"
)
/ *
* Struct of Usage Conditions
* /
type UsageConditions struct {
Usage string ` json:"usage,omitempty" bson:"usage,omitempty" description:"usage of the data" ` // Usage is the usage of the data
Actors [ ] string ` json:"actors,omitempty" bson:"actors,omitempty" description:"actors of the data" ` // Actors is the actors of the data
}
2024-08-30 14:50:48 +02:00
/ *
* DataResource is a struct that represents a data resource
* it defines the resource data
* /
2024-07-19 10:54:58 +02:00
type DataResource struct {
2024-10-09 09:05:49 +02:00
resource_model . AbstractResource // AbstractResource contains the basic fields of an object (id, name)
resource_model . WebResource
2024-11-07 11:05:24 +01:00
Type string ` bson:"type,omitempty" json:"type,omitempty" ` // Type is the type of the storage
UsageConditions UsageConditions ` json:"usage_conditions,omitempty" bson:"usage_conditions,omitempty" description:"usage conditions of the data" ` // UsageConditions is the usage conditions of the data
License DataLicense ` json:"license,omitempty" bson:"license,omitempty" description:"license of the data" ` // License is the license of the data
Interest DataLicense ` json:"interest,omitempty" bson:"interest,omitempty" description:"interest of the data" ` // Interest is the interest of the data
2024-10-09 09:05:49 +02:00
Example string ` json:"example,omitempty" bson:"example,omitempty" description:"base64 encoded data" ` // Example is an example of the 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 )
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
}
2024-07-24 09:53:30 +02:00
json . Unmarshal ( b , & m )
2024-07-19 09:32:58 +02:00
return m
}
2024-08-12 16:11:25 +02:00
func ( d * DataResource ) GetAccessor ( caller * tools . HTTPCaller ) utils . Accessor {
2024-08-30 14:50:48 +02:00
data := New ( ) // Create a new instance of the accessor
2024-10-02 11:35:22 +02:00
data . Init ( tools . DATA_RESOURCE , caller ) // Initialize the accessor with the DATA_RESOURCE model type
2024-07-18 11:51:12 +02:00
return data
}