Skip to content

Commit 5b25536

Browse files
committed
fixes to Blob and BlobEntry helpers
1 parent 3e2eca0 commit 5b25536

File tree

2 files changed

+99
-39
lines changed

2 files changed

+99
-39
lines changed

src/DataBlobs/services/HelpersDataWrapEntryBlob.jl

Lines changed: 83 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,38 @@ $(METHODLIST)
4242
function deleteData! end
4343

4444

45+
# cosntruction helper from existing BlobEntry for user overriding via kwargs
46+
BlobEntry(
47+
entry::BlobEntry;
48+
id::Union{UUID,Nothing} = entry.id,
49+
blobId::Union{UUID,Nothing} = entry.blobId,
50+
originId::UUID = entry.originId,
51+
label::Symbol = entry.label,
52+
blobstore::Symbol = entry.blobstore,
53+
hash::String = entry.hash,
54+
origin::String = entry.origin,
55+
description::String = entry.description,
56+
mimeType::String = entry.mimeType,
57+
metadata::String = entry.metadata,
58+
timestamp::ZonedDateTime = entry.timestamp,
59+
_type::String = entry._type,
60+
_version::String = entry._version,
61+
) = BlobEntry(;
62+
id,
63+
blobId,
64+
originId,
65+
label,
66+
blobstore,
67+
hash,
68+
origin,
69+
description,
70+
mimeType,
71+
metadata,
72+
timestamp,
73+
_type,
74+
_version
75+
)
76+
4577
function getData(
4678
dfg::AbstractDFG,
4779
vlabel::Symbol,
@@ -97,21 +129,6 @@ function addData!(dfg::AbstractDFG, blobstore::AbstractBlobStore, label::Symbol,
97129
return de=>db
98130
end
99131

100-
#TODO check this one
101-
function addData!(
102-
::Type{<:BlobEntry},
103-
dfg::AbstractDFG,
104-
label::Symbol,
105-
key::Symbol,
106-
blob::AbstractVector{UInt8},
107-
timestamp=now(localzone());
108-
id::UUID = uuid4(),
109-
hashfunction::Function = sha256
110-
)
111-
fde = BlobEntry(key, id, timestamp, blob)
112-
de = addBlobEntry!(dfg, label, fde)
113-
return de=>blob
114-
end
115132

116133
addData!(
117134
dfg::AbstractDFG,
@@ -122,30 +139,31 @@ addData!(
122139
timestamp=now(localzone());
123140
kwargs...
124141
) = addData!(
125-
dfg,
126-
getBlobStore(dfg, blobstorekey),
127-
label,
128-
key,
129-
blob,
130-
timestamp;
131-
kwargs...
132-
)
142+
dfg,
143+
getBlobStore(dfg, blobstorekey),
144+
label,
145+
key,
146+
blob,
147+
timestamp;
148+
kwargs...
149+
)
133150

134151
function addData!(
135152
dfg::AbstractDFG,
136153
blobstore::AbstractBlobStore,
137154
label::Symbol,
138155
key::Symbol,
139-
blob::Vector{UInt8},
156+
blob::AbstractVector{UInt8},
140157
timestamp=now(localzone());
141-
description="",
158+
description="",
159+
metadata = "",
142160
mimeType = "application/octet-stream",
143161
id::UUID = uuid4(),
144162
hashfunction = sha256
145163
)
146164
#
147165
@warn "ID's and origin IDs should be reconciled here."
148-
entry = BlobEntry(
166+
entry = BlobEntry(;
149167
id = id,
150168
originId = id,
151169
label = key,
@@ -154,7 +172,7 @@ function addData!(
154172
origin = buildSourceString(dfg, label),
155173
description = description,
156174
mimeType = mimeType,
157-
metadata = "",
175+
metadata,
158176
timestamp = timestamp)
159177

160178
addData!(dfg, blobstore, label, entry, blob; hashfunction)
@@ -169,17 +187,29 @@ function updateData!(
169187
hashfunction = sha256,
170188
checkhash::Bool=true
171189
)
172-
checkhash && assertHash(entry, blob, hashfunction=hashfunction)
190+
checkhash && assertHash(entry, blob; hashfunction)
173191
de = updateBlobEntry!(dfg, label, entry)
174192
db = updateBlob!(dfg, de, blob)
175193
return de=>db
176194
end
177195

178-
function updateData!(dfg::AbstractDFG, blobstore::AbstractBlobStore, label::Symbol, entry::BlobEntry, blob::Vector{UInt8}; hashfunction = sha256)
196+
197+
function updateData!(
198+
dfg::AbstractDFG,
199+
blobstore::AbstractBlobStore,
200+
label::Symbol,
201+
entry::BlobEntry,
202+
blob::Vector{UInt8};
203+
hashfunction = sha256
204+
)
179205
# Recalculate the hash - NOTE Assuming that this is going to be a BlobEntry. TBD.
180-
newEntry = BlobEntry(entry.id, entry.blobId, entry.originId, entry.label, blobstore.key, bytes2hex(hashfunction(blob)),
181-
buildSourceString(dfg, label),
182-
entry.description, entry.mimeType, entry.metadata, entry.timestamp, entry._type, string(_getDFGVersion()))
206+
newEntry = BlobEntry(
207+
entry; # and kwargs to override new values
208+
blobstore = blobstore.key,
209+
hash = string(bytes2hex(hashfunction(blob))),
210+
origin = buildSourceString(dfg, label),
211+
_version = string(_getDFGVersion()),
212+
)
183213

184214
de = updateBlobEntry!(dfg, label, newEntry)
185215
db = updateBlob!(blobstore, de, blob)
@@ -188,20 +218,34 @@ end
188218

189219
function deleteData!(
190220
dfg::AbstractDFG,
191-
label::Symbol,
192-
key::Symbol
221+
vLbl::Symbol,
222+
bLbl::Symbol
193223
)
194-
de = deleteBlobEntry!(dfg, label, key)
224+
de = deleteBlobEntry!(dfg, vLbl, bLbl)
195225
db = deleteBlob!(dfg, de)
196226
return de=>db
197227
end
198228

199229

200-
deleteData!(dfg::AbstractDFG, blobstore::AbstractBlobStore, label::Symbol, entry::BlobEntry) =
201-
deleteBlob!(dfg, blobstore, label, entry.label)
230+
deleteData!(
231+
dfg::AbstractDFG,
232+
blobstore::AbstractBlobStore,
233+
label::Symbol,
234+
entry::BlobEntry
235+
) = deleteBlob!(
236+
dfg,
237+
blobstore,
238+
label,
239+
entry.label
240+
)
202241

203-
function deleteData!(dfg::AbstractDFG, blobstore::AbstractBlobStore, label::Symbol, key::Symbol)
204-
de = deleteBlobEntry!(dfg, label, key)
242+
function deleteData!(
243+
dfg::AbstractDFG,
244+
blobstore::AbstractBlobStore,
245+
vLbl::Symbol,
246+
bLbl::Symbol
247+
)
248+
de = deleteBlobEntry!(dfg, vLbl, bLbl)
205249
db = deleteBlob!(blobstore, de)
206250
return de=>db
207251
end

src/Deprecated.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@
44
##=================================================================================
55

66

7+
# #TODO check this one
8+
# function addData!(
9+
# ::Type{<:BlobEntry},
10+
# dfg::AbstractDFG,
11+
# vLbl::Symbol,
12+
# bLbl::Symbol,
13+
# blob::AbstractVector{UInt8},
14+
# timestamp=now(localzone());
15+
# id::UUID = uuid4(),
16+
# hashfunction::Function = sha256
17+
# )
18+
# fde = BlobEntry(bLbl, id, timestamp, blob)
19+
# de = addBlobEntry!(dfg, vLbl, fde)
20+
# return de=>blob
21+
# end
22+
723
"""
824
$(TYPEDEF)
925
Abstract parent struct for big data entry.

0 commit comments

Comments
 (0)