diff --git a/data/data.go b/data/data.go new file mode 100644 index 0000000..458c108 --- /dev/null +++ b/data/data.go @@ -0,0 +1,23 @@ +package data + +import ( + oclib "oc-lib" +) + +type Data struct { + oclib.AbstractResource + + Protocols []string `json:"protocol,omitempty" bson:"protocol,omitempty"` //TODO Enum type + DataType string `json:"datatype" required:"true" bson:"datatype"` + Example string `json:"example" bson:"example" required:"true" validate:"required" description:"base64 encoded data"` + +} + + +func (d *Data) GetType() oclib.ResourceType{ + return oclib.DATA +} + + + + diff --git a/data/data_mongo_accessor.go b/data/data_mongo_accessor.go new file mode 100644 index 0000000..6e66144 --- /dev/null +++ b/data/data_mongo_accessor.go @@ -0,0 +1,38 @@ +package data + +import ( + logger "oc-lib/logs" + mongo "oc-lib/mongo" +) + + type DataMongoAccessor struct{ + + } + + +func (dma *DataMongoAccessor) StoreOne(data Data) string { + + id, err := mongo.StoreOne(data,"data") + if err != nil{ + l := logger.CreateLogger("oclib","") + l.Error().Msg("Could not store " + data.Name + " to db. Error: " + err.Error()) + return "" + } + return id +} + +func (dma *DataMongoAccessor) LoadOne(id string) Data { + + var data Data + + res_mongo, err := mongo.LoadOne(id,"data") + if err != nil{ + l := logger.CreateLogger("oclib","") + l.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error()) + return Data{} + } + + res_mongo.Decode(&data) + + return data +} \ No newline at end of file diff --git a/data/data_test.go b/data/data_test.go new file mode 100644 index 0000000..6efdc2a --- /dev/null +++ b/data/data_test.go @@ -0,0 +1,47 @@ +package data + +import ( + oclib "oc-lib" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestStoreOneData(t *testing.T){ + d := Data{DataType: "jpeg", Example: "123456", + AbstractResource: oclib.AbstractResource{ + Uuid: "123", + Name: "testData", + Description: "Lorem Ipsum", + Logo : "azerty.com", + Owner: "toto", + OwnerLogo: "totoLogo", + SourceUrl: "azerty.fr", + }, + } + + dma := DataMongoAccessor{} + id := dma.StoreOne(d) + + assert.NotEmpty(t, id) +} + +func TestLoadOneDate(t *testing.T){ + d := Data{DataType: "jpeg", Example: "123456", + AbstractResource: oclib.AbstractResource{ + Uuid: "123", + Name: "testData", + Description: "Lorem Ipsum", + Logo : "azerty.com", + Owner: "toto", + OwnerLogo: "totoLogo", + SourceUrl: "azerty.fr", + }, + } + + dma := DataMongoAccessor{} + id := dma.StoreOne(d) + new_d := dma.LoadOne(id) + + assert.Equal(t,d, new_d) +} \ No newline at end of file diff --git a/data/datacenter_workflows.go b/data/datacenter_workflows.go new file mode 100644 index 0000000..0ad59c2 --- /dev/null +++ b/data/datacenter_workflows.go @@ -0,0 +1 @@ +package data