Module: UU::OS::Attachment

Extended by:
Attachment
Included in:
Attachment
Defined in:
uu_os-0.29.16/lib/uu/os/attachment.rb,
uu_os-0.29.16/lib/uu/os/attachment/stream_wrapper.rb,
uu_os-0.29.16/lib/uu/os/attachment/attachment_create.rb,
uu_os-0.29.16/lib/uu/os/attachment/attachment_check_in.rb,
uu_os-0.29.16/lib/uu/os/attachment/attachment_check_out.rb,
uu_os-0.29.16/lib/uu/os/attachment/attachment_attributes.rb,
uu_os-0.29.16/lib/uu/os/attachment/attachment_set_attributes.rb,
uu_os-0.29.16/lib/uu/os/attachment/attachment_delete_version.rb,
uu_os-0.29.16/lib/uu/os/attachment/attachment_get_version_data.rb,
uu_os-0.29.16/lib/uu/os/attachment/attachment_get_version_list.rb,
uu_os-0.29.16/lib/uu/os/attachment/attachment_version_attributes.rb,
uu_os-0.29.16/lib/uu/os/attachment/attachment_get_attachment_list.rb,
uu_os-0.29.16/lib/uu/os/attachment/attachment_get_version_attributes.rb

Overview

Module Attachment.

Defined Under Namespace

Classes: AttachmentAttributes, AttachmentCheckIn, AttachmentCheckOut, AttachmentCreate, AttachmentDeleteVersion, AttachmentGetAttachmentList, AttachmentGetVersionAttributes, AttachmentGetVersionData, AttachmentGetVersionList, AttachmentSetAttributes, AttachmentVersionAttributes, StreamWrapper

Constant Summary

PATH =

Service path

'ues/core/attachment/UESAttachment'

Instance Method Summary (collapse)

Instance Method Details

- (Object) check_in(attachment_uri, attachment = nil)

Updates the attached file in the system and unlocks it by default. The command succeeds if the attachment is unlocked or if it is locked by the current user. Otherwise, the command fails. At the very least, attachment data and the filename have to be specified in this command. The data are streamed.

Parameters:

  • attachment_uri (String, UU::OS::UESURI)

    UESURI of the attachment

  • attachment (AttachmentCheckIn) (defaults to: nil)

    DTO containing attributes of the checked-in attachment



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'uu_os-0.29.16/lib/uu/os/attachment.rb', line 138

def check_in(attachment_uri, attachment = nil)
  svc = UU::OS::REST::RemoteClient.new(Attachment)
  payload = Attachment::AttachmentCheckIn.new(attachment)

  ###############
  ##IMPORTANT!!##
  ###############
  # Attachment.create and check_in are a special case. Unlike other commands that upload bigger data (Sheet.check_in etc.), these
  # don't do it directly by calling the REST api and sending the whole payload to it. Instead we first try to take the data
  # and upload them to UDS binary store. If that succeeds, only the resulting UDS uri is sent as attachment data so the attachment
  # command retrieves the actual data server-side from the UDS service. But should the uds upload fail, we need to send the data
  # the usual way. But some types of stream cant be re-used so we have to make a backup of them so in case of the UDS failure, there
  # is something to send again.
  ###############

  blob_uri = handle_input_data(payload)

  # Blob uri wasnt supplied, we need prepare backup before we proceed with UDS upload
  backup = backup_if_necessary(payload) if blob_uri.nil?

  # Upload data by uds (unless user has supplied his uds uri)
  blob_uri = upload_to_uds(payload.data, backup) unless blob_uri

  UU::OS::QoS::QoSHandler.auto_retry do
    payload = prepare_payload_for_upload(payload,blob_uri,backup)
    begin
      svc.post('checkIn', attachment_uri, payload)
    ensure
      silent_cleanup(backup,blob_uri)
    end
  end
end

- (UU::OS::REST::BinaryValue) check_out(attachment_uri, options = nil)

Locks the attachment specified by the attachment_uri attribute. If the operation is successful or if the attachment is already locked by the current user, attachment stream handler or nil is returned depending on the options set in the attribute options. If the attachment cannot be locked because the attachment is locked by another user, the command will fail.

Parameters:

  • attachment_uri (String, UU::OS::UESURI)

    UESURI of the attachment

  • options (AttachmentCheckOut) (defaults to: nil)

    DTO with options containing a flag whether to return the stream with attachment data

Returns:



118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'uu_os-0.29.16/lib/uu/os/attachment.rb', line 118

def check_out(attachment_uri, options = nil)
  svc = UU::OS::REST::RemoteClient.new(Attachment)
  dto = Attachment::AttachmentCheckOut.new(options)
  payload = dto.to_json
  UU::OS::QoS::QoSHandler.auto_retry do
    if dto.return_stream_handler == TRUE
      return svc.post_binary('checkOut', attachment_uri, payload)
    else
      svc.post('checkOut', attachment_uri, payload)
      return nil
    end
  end
end

- (UU::OS::UESURI) create(artifact_uri, attachment = nil)

Creates a new attachment to the specified artifact. At the very least, attachment data and filename have to be specified in this command. The data are streamed.

Parameters:

  • artifact_uriUESURI (String, UU::OS::UESURI)

    of the artifact where the new attachment is created

  • attachment (AttachmentCreate) (defaults to: nil)

    DTO containing attributes of a new attachment

Returns:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'uu_os-0.29.16/lib/uu/os/attachment.rb', line 37

def create(artifact_uri, attachment = nil)
  svc = UU::OS::REST::RemoteClient.new(Attachment)
  payload = Attachment::AttachmentCreate.new(attachment)

  ###############
  ##IMPORTANT!!##
  ###############
  # Attachment.create and check_in are a special case. Unlike other commands that upload bigger data (Sheet.check_in etc.), these
  # don't do it directly by calling the REST api and sending the whole payload to it. Instead we first try to take the data
  # and upload them to UDS binary store. If that succeeds, only the resulting UDS uri is sent as attachment data so the attachment
  # command retrieves the actual data server-side from the UDS service. But should the uds upload fail, we need to send the data
  # the usual way. But some types of stream cant be re-used so we have to make a backup of them so in case of the UDS failure, there
  # is something to send again.
  ###############

  blob_uri = handle_input_data(payload)

  # Blob uri wasnt supplied, we need prepare backup before we proceed with UDS upload
  backup = backup_if_necessary(payload) if blob_uri.nil?

  # Upload data by uds (unless user has supplied his uds uri)
  blob_uri = upload_to_uds(payload.data, backup) unless blob_uri

  UU::OS::QoS::QoSHandler.auto_retry do
    payload = prepare_payload_for_upload(payload,blob_uri,backup)
    begin
      res = svc.post('create', artifact_uri, payload)
      return UU::OS::UESURI.new(res)
    ensure
      silent_cleanup(backup,blob_uri)
    end
  end
end

- (Object) delete(attachment_uri)

Deletes the specified attachment.

Parameters:

  • attachment_uri (String, UU::OS::UESURI)

    UESURI of the attachment which is about to be deleted.



189
190
191
192
193
194
# File 'uu_os-0.29.16/lib/uu/os/attachment.rb', line 189

def delete(attachment_uri)
  svc = UU::OS::REST::RemoteClient.new(Attachment)
  UU::OS::QoS::QoSHandler.auto_retry do
    svc.post('delete', attachment_uri)
  end
end

- (Object) delete_version(attachment_uri, version = nil)

Deletes an attachment version from the system.

Examples:

# Delete attachment version (uri needs to be replaced with one of an existing attachment for the example to work)
UU::OS::Attachment.delete_version('ues:TERRITORY:ARTIFACT:ATTACH', :version_id => "123456789")

Parameters:

  • attachment_uri (String, UU::OS::UESURI)

    UESURI of the attachment whose version is going to be deleted.

  • version (AttachmentDeleteVersion) (defaults to: nil)

    Object containing ID of the version which is to be deleted.

Options Hash (version):

  • :version_id (String)

    Not null. Id of the attachment version, which is going to be deleted.



220
221
222
223
224
225
226
227
# File 'uu_os-0.29.16/lib/uu/os/attachment.rb', line 220

def delete_version(attachment_uri, version = nil)
  svc = UU::OS::REST::RemoteClient.new(Attachment)
  payload = UU::OS::Attachment::AttachmentDeleteVersion.new(version).to_json

  UU::OS::QoS::QoSHandler.auto_retry do
    svc.post('deleteVersion', attachment_uri, payload)
  end
end

- (UU::OS::REST::BinaryValue) get_attachment_data(attachment_uri)

Returns stream handler containing data content of the attachment. If the attachment is locked by the same user, command returns data of the private version. If the attachment is locked by another user (or if the attachment is unlocked), command returns data of the public version. Command does not change the state of the attachment or its lock in the system.

Parameters:

  • attachment_uri (String, UU::OS::UESURI)

    UESURI of the attachment

Returns:



179
180
181
182
183
184
# File 'uu_os-0.29.16/lib/uu/os/attachment.rb', line 179

def get_attachment_data(attachment_uri)
  svc = UU::OS::REST::RemoteClient.new(Attachment)
  UU::OS::QoS::QoSHandler.auto_retry do
    return svc.get_binary('getAttachmentData', attachment_uri)
  end
end

- (UU::OS::REST::ResultList<Attachment::AttachmentGetAttachmentList, Attachment::AttachmentAttributes>) get_attachment_list(artifact_uri, criteria = nil)

Retrieves a result list of attachments for the artifact specified by the artifact_uri parameter. The resulting attachment list is filtered according to the criteria provided by the criteria attribute. These criteria specify the page to return and name and code filters. The list is sorted (ascending) according to the attachment name and code.

Parameters:

  • artifact_uri (String, UU::OS::UESURI)

    UESURI of the artifact to get the list of attachments from.

  • criteria (AttachmentGetAttachmentList) (defaults to: nil)

    DTO containing paging and filtering criteria.

Returns:



97
98
99
100
101
102
103
104
105
106
107
# File 'uu_os-0.29.16/lib/uu/os/attachment.rb', line 97

def get_attachment_list(artifact_uri, criteria = nil)
  svc = UU::OS::REST::RemoteClient.new(Attachment)
  dto = Attachment::AttachmentGetAttachmentList.new(criteria)
  svc.add_parameter('pageIndex', dto.page_index)
  svc.add_parameter('pageSize', dto.page_size)
  svc.add_parameter('query', dto.query)
  UU::OS::QoS::QoSHandler.auto_retry do
    res = svc.get('getAttachmentList', artifact_uri)
    return UU::OS::REST::ResultList.new(Attachment::AttachmentGetAttachmentList, Attachment::AttachmentAttributes, res)
  end
end

- (AttachmentAttributes) get_attributes(attachment_uri)

Returns attributes representing the attachment specified by the attachment_uri attribute. If the attachment is locked by the current user, this command returns attributes of the private version. If the attachment is locked by another user (or if the attachment is unlocked), the command returns attributes of the public version. The command does not change the state of the attachment or its lock in the system.

Parameters:

  • attachment_uri (String, UU::OS::UESURI)

    UESURI of the attachment

Returns:



80
81
82
83
84
85
86
# File 'uu_os-0.29.16/lib/uu/os/attachment.rb', line 80

def get_attributes(attachment_uri)
  svc = UU::OS::REST::RemoteClient.new(Attachment)
  UU::OS::QoS::QoSHandler.auto_retry do
    res = svc.get('getAttributes', attachment_uri)
    return Attachment::AttachmentAttributes.new(res)
  end
end

- (AttachmentVersionAttributes) get_version_attributes(attachment_uri, version = nil)

The uuCommand returns attributes of given attachment version.

Examples:

# Get attachment version attributes (uri needs to be replaced with one of an existing attachment for the example to work)
attributes = UU::OS::Attachment.get_version_attributes('ues:TERRITORY:ARTIFACT:ATTACH', :version_id => "123456789")

Parameters:

  • attachment_uri (String, UU::OS::UESURI)

    UESURI of the attachment whose version’s attributes are going to be retrieved.

  • version (AttachmentGetVersionAttributes) (defaults to: nil)

    Object containing ID of the searched version.

Options Hash (version):

  • :version_id (String)

    Not null. ID of the attachment version, which attributes are going to be retrieved.

Returns:



262
263
264
265
266
267
268
269
270
271
# File 'uu_os-0.29.16/lib/uu/os/attachment.rb', line 262

def get_version_attributes(attachment_uri, version = nil)
  svc = UU::OS::REST::RemoteClient.new(Attachment)
  dto = UU::OS::Attachment::AttachmentGetVersionAttributes.new(version)
  svc.add_parameter('versionId', dto.version_id)

  UU::OS::QoS::QoSHandler.auto_retry do
    res = svc.get('getVersionAttributes', attachment_uri)
    return Attachment::AttachmentVersionAttributes.new(res)
  end
end

- (UU::OS::REST::BinaryValue) get_version_data(attachment_uri, version)

Retrieves the data of the specified attachment version.

Examples:

# Get version of the attachment 'ues:TER:ART:ATTACH' identified by its OID = 456232122
UU::OS::Attachment.get_version_data('ues:TER:ART:ATTACH', :version_id => "456232122")

Parameters:

Options Hash (version):

  • :version_id (String)

    Not null. Id of the attachment version, which data are going to be retrieved.

Returns:



240
241
242
243
244
245
246
247
248
# File 'uu_os-0.29.16/lib/uu/os/attachment.rb', line 240

def get_version_data(attachment_uri, version)
  svc = UU::OS::REST::RemoteClient.new(Attachment)
  dto = UU::OS::Attachment::AttachmentGetVersionData.new(version)
  svc.add_parameter('versionId', dto.version_id)
  UU::OS::QoS::QoSHandler.auto_retry do
    result = svc.get_binary('getVersionData', attachment_uri)
    return result
  end
end

- (Array) get_version_list(attachment_uri, criteria = nil)

The uuCommand returns a list of the specified attachment's versions.

Examples:

# Get attachment versions ordered by version in descending order (uri needs to be replaced with one of an existing attachment for the example to work)
list = UU::OS::Attachment.get_version_list('ues:TERRITORY:ARTIFACT:ATTACH', :query => "ORDER BY version DESC")

Parameters:

  • attachment_uri (String, UU::OS::UESURI)

    UESURI of the attachment whose versions are going to be listed.

  • criteria (AttachmentGetVersionList) (defaults to: nil)

    Criteria for selecting versions.

Options Hash (criteria):

  • :query (String)

    Query for filtering and ordering of the result list (more information in uuQuery - Guideline). It is possible to filter the result list by name, code, label, creationTime, creationStamp and version.

Returns:



284
285
286
287
288
289
290
291
292
293
294
295
# File 'uu_os-0.29.16/lib/uu/os/attachment.rb', line 284

def get_version_list(attachment_uri, criteria = nil)
  svc = UU::OS::REST::RemoteClient.new(Attachment)
  dto = UU::OS::Attachment::AttachmentGetVersionList.new(criteria)          
  svc.add_parameter('pageIndex', dto.page_index)
  svc.add_parameter('pageSize', dto.page_size)
  svc.add_parameter('query', dto.query)

  UU::OS::QoS::QoSHandler.auto_retry do
    res = svc.get('getVersionList', attachment_uri)
    return UU::OS::REST::ResultList.new(Attachment::AttachmentGetVersionList, Attachment::AttachmentVersionAttributes, res)
  end
end

- (Object) set_attributes(attachment_uri, attachment = nil)

Updates basic attributes of an attachment.

Parameters:

  • attachment_uriUESURI (String, UU::OS::UESURI)

    of the attachment whose attributes are to be changed.

  • attachment (AttachmentSetAttributes) (defaults to: nil)

    DTO containing the attachment attributes.

Returns:

  • UESURI of the attachment



202
203
204
205
206
207
208
209
# File 'uu_os-0.29.16/lib/uu/os/attachment.rb', line 202

def set_attributes(attachment_uri, attachment = nil)
  svc = UU::OS::REST::RemoteClient.new(Attachment)
  payload = UU::OS::Attachment::AttachmentSetAttributes.new(attachment).to_json
  UU::OS::QoS::QoSHandler.auto_retry do
    res = svc.post('setAttributes', attachment_uri, payload)
    return UU::OS::UESURI.new(res)
  end
end