Class: UU::BinaryStore::BinaryStore
- Inherits:
-
Object
- Object
- UU::BinaryStore::BinaryStore
- Defined in:
- lib/uu_binarystore/binary_store.rb,
lib/uu_binarystore/binary_store/uu_binary.rb,
lib/uu_binarystore/binary_store/result_list.rb,
lib/uu_binarystore/binary_store/uu_binary_query.rb,
lib/uu_binarystore/binary_store/concurrency_strategy.rb
Overview
Binary store component provides external storage for data required by uuApps.
Defined Under Namespace
Classes: ConcurrencyStrategy, ResultList, UUBinary, UUBinaryQuery
Class Method Summary collapse
-
.init(binary_store_uri, parameters = {}) ⇒ Object
Creates new instance of binary store.
Instance Method Summary collapse
-
#close ⇒ Object
Method closes instance of binary store.
-
#delete(parameters) ⇒ Object
Method deletes existing uuBinary.
-
#load(parameters) ⇒ UUBinary
Loads binary according to given parameters.
-
#presign(parameters) ⇒ UUBinary
Preauthorize (create token) access role to download/upload uuBinary.
-
#query(query = nil) ⇒ UU::BinaryStore::BinaryStore::ResultList<UUBinaryQuery, UUBinary>
Method finds all uuBinaries matching given criteria.
-
#save(binary) ⇒ UU::OS::UESURI
Method saves given uuBinary (updates existing or creates new).
Class Method Details
.init(binary_store_uri, parameters = {}) ⇒ Object
Creates new instance of binary store.
105 106 107 |
# File 'lib/uu_binarystore/binary_store.rb', line 105 def self.init(binary_store_uri, parameters = {}) self.new(binary_store_uri, parameters) end |
Instance Method Details
#close ⇒ Object
Method closes instance of binary store. Once instance of binary store is closed, it cannot be used (Throws exception for each invoked operation. New instance must be created to access binary store).
350 351 352 |
# File 'lib/uu_binarystore/binary_store.rb', line 350 def close @closed = true end |
#delete(parameters) ⇒ Object
Method deletes existing uuBinary.
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/uu_binarystore/binary_store.rb', line 252 def delete(parameters) closed? params = {} if parameters.kind_of?(UUBinary) # Parameter was instance of uuBinary params[:uri] = parameters.uri return if params[:uri].nil? elsif (parameters.kind_of? String) || (parameters.kind_of? UU::OS::UESURI) # Parameter was uuBinary URI params[:uri] = parameters elsif parameters.kind_of? Hash if parameters.has_key?(:uri) # Parameter was Hash with uuBinary URI params[:uri] = parameters[:uri] elsif parameters.has_key?(:dataKey) || parameters.has_key?(:data_key) # We have to find uuBinary URI via query (using dataKey and schema) params[:dataKey] = parameters[:dataKey] || parameters[:data_key] else raise ArgumentError.new('Parameters must contain uuBinary URI or dataKey.') end else raise ArgumentError.new('Parameters must contain uuBinary URI or dataKey.') end cmd = UU::OS::CMD::CommandClient.new("uu-binarystore", @session) cmd.invoke('BinaryStore/deleteBinary', @binary_store_uri, parameters: params) nil end |
#load(parameters) ⇒ UUBinary
Loads binary according to given parameters.
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/uu_binarystore/binary_store.rb', line 214 def load(parameters) closed? params = {} if (parameters.kind_of? String) || (parameters.kind_of? UU::OS::UESURI) # Parameter was uuBinary URI params[:uri] = parameters elsif (parameters.kind_of? Hash) params[:uri] = parameters[:uri] if parameters[:uri] data_key = parameters[:dataKey] || parameters[:data_key] params[:dataKey] = data_key if data_key raise ArgumentError.new('Parameters must contain uuBinary URI or dataKey.') if params.empty? else raise ArgumentError.new('Parameters must contain uuBinary URI or dataKey.') end cmd = UU::OS::CMD::CommandClient.new("uu-binarystore", @session) result = cmd.invoke('BinaryStore/getBinaryAttributes', @binary_store_uri, parameters: params) UU::BinaryStore::BinaryStore::UUBinary.new(result, @session) end |
#presign(parameters) ⇒ UUBinary
Preauthorize (create token) access role to download/upload uuBinary.
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/uu_binarystore/binary_store.rb', line 300 def presign(parameters) closed? params = {} if parameters.kind_of? Hash if parameters.has_key?(:uri) # Parameter was Hash with uuBinary URI params[:uri] = parameters[:uri] end acr_uri = parameters[:accessRoleUri] || parameters[:access_role_uri] if acr_uri params[:accessRoleUri] = acr_uri else raise ArgumentError.new('Access Role have to be set.') end else raise ArgumentError.new('Parameters must be hash.') end cmd = UU::OS::CMD::CommandClient.new("uu-binarystore", @session) result = cmd.invoke('BinaryStore/presign', @binary_store_uri, parameters: params) UU::BinaryStore::BinaryStore::UUBinary.new(result) end |
#query(query = nil) ⇒ UU::BinaryStore::BinaryStore::ResultList<UUBinaryQuery, UUBinary>
Method finds all uuBinaries matching given criteria.
339 340 341 342 343 344 345 |
# File 'lib/uu_binarystore/binary_store.rb', line 339 def query(query = nil) closed? dto = BinaryStore::UUBinaryQuery.new(query) cmd = UU::OS::CMD::CommandClient.new("uu-binarystore", @session) result = cmd.invoke('BinaryStore/getBinaryList', @binary_store_uri, :parameters => dto.to_json) list = UU::BinaryStore::BinaryStore::ResultList.new(BinaryStore::UUBinaryQuery, BinaryStore::UUBinary, @session, result) end |
#save(binary) ⇒ UU::OS::UESURI
Method saves given uuBinary (updates existing or creates new). If the uri is set method will update existing uuBinary otherwise it will create new uuBinary. Method may throw concurrent modification exception in case current binary state violates constraints required by used Concurrency strategy. Each binary can be saved only once, it has to be re-loaded before next modification (with exception of concurrency strategy VERSION_BASED). Method will throw exception on repeated binary save.
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/uu_binarystore/binary_store.rb', line 168 def save(binary) closed? if binary.send(:saved) raise 'Instance of uuBinary was already saved. Re-load uuBinary before next modification.' end cmd = UU::OS::CMD::CommandClient.new("uu-binarystore", @session) binary_client = UU::OS::CMD::CommandClient.new("uu-binarystore-data", @session, :request_timeout => 0) bv = UU::OS::Lang::BinaryValue.new(content: binary.data.data, content_type: binary.content_type, name: binary.file_name) if binary.uri params = {:uri => binary.uri} params[:size] params[:attributes] = binary.to_hash if binary.send(:data_key_changed) params[:originalDataKey] = binary.send(:orig_data_key) end result = cmd.invoke('BinaryStore/setBinaryAttributes', @binary_store_uri, parameters: params) params = binary.to_hash params[:version] += 1 else params = binary.to_hash result = cmd.invoke('BinaryStore/createBinary', @binary_store_uri, parameters: params) end params[:data] = bv params[:concurrencyStrategy] = @concurrency_strategy params[:prevalidToken] = result[:token] result = binary_client.invoke('BinaryStore/setBinaryData', result[:uri], parameters: params) binary.send(:saved=, true) UU::OS::UESURI.new(result) end |