Class: T2Server::Interaction::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/t2-server/interaction.rb

Overview

This class represents a Taverna notification.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry, run) ⇒ Notification

:stopdoc:



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/t2-server/interaction.rb', line 143

def initialize(entry, run)
  @run = run
  reply_to = entry[FEED_NS, "in-reply-to"]
  if reply_to.empty?
    @is_reply = false
    @has_reply = false
    @id = entry[FEED_NS, "id"][0]
    @is_notification = entry[FEED_NS, "progress"].empty? ? false : true
    @uri = get_link(entry.links)
    @serial = "#{entry[FEED_NS, 'path'][0]}-#{entry[FEED_NS, 'count'][0]}"
  else
    @is_reply = true
    @is_notification = false
    @reply_to = reply_to[0]
  end
end

Instance Attribute Details

#idObject (readonly)

The identifier of this notification.



129
130
131
# File 'lib/t2-server/interaction.rb', line 129

def id
  @id
end

#reply_toObject (readonly)

If this notification is a reply then this is the identifier of the notification that it is a reply to.



133
134
135
# File 'lib/t2-server/interaction.rb', line 133

def reply_to
  @reply_to
end

#serialObject (readonly)

The serial number of a notification. This identifies a notification within a workflow.



140
141
142
# File 'lib/t2-server/interaction.rb', line 140

def serial
  @serial
end

#uriObject (readonly)

The URI of the notification page to show.



136
137
138
# File 'lib/t2-server/interaction.rb', line 136

def uri
  @uri
end

Instance Method Details

#has_replyObject

:stopdoc:



179
180
181
# File 'lib/t2-server/interaction.rb', line 179

def has_reply
  @has_reply = true
end

#has_reply?Boolean

:call-seq:

has_reply? -> true or false

Does this notification have a reply? This only makes sense for notifications that are not replies or pure notifications.

Returns:

  • (Boolean)


189
190
191
# File 'lib/t2-server/interaction.rb', line 189

def has_reply?
  @has_reply
end

#input_dataObject

:call-seq:

input_data -> data

Get the input data associated with this notification. Returns an empty string if this notification is a reply.



198
199
200
201
202
203
204
205
206
# File 'lib/t2-server/interaction.rb', line 198

def input_data
  return "" if is_reply?

  data_name = "interaction#{@id}InputData.json"
  @run.read_interaction_data(data_name)
rescue AttributeNotFoundError
  # It does not matter if the file doesn't exist.
  ""
end

#is_notification?Boolean

:call-seq:

is_notification? -> true or false

Is this notification a pure notification only? There is no user response to a pure notification, it is for information only.

Returns:

  • (Boolean)


174
175
176
# File 'lib/t2-server/interaction.rb', line 174

def is_notification?
  @is_notification
end

#is_reply?Boolean

:call-seq:

is_reply? -> true or false

Is this notification a reply to another notification?

Returns:

  • (Boolean)


165
166
167
# File 'lib/t2-server/interaction.rb', line 165

def is_reply?
  @is_reply
end

#reply(status, data) ⇒ Object

:call-seq:

reply(status, data)

Given a status and some data this method uploads the data and publishes an interaction reply on the run’s notification feed.



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/t2-server/interaction.rb', line 213

def reply(status, data)
  data_name = "interaction#{@id}OutputData.json"

  notification = Atom::Entry.new do |entry|
    entry.title = "A reply to #{@id}"
    entry.id = "#{@id}reply"
    entry.content = ""
    entry[FEED_NS, "run-id"] << @run.id
    entry[FEED_NS, "in-reply-to"] << @id
    entry[FEED_NS, "result-status"] << status
  end.to_xml

  @run.write_interaction_data(data_name, data)
  @run.write_notification(notification)
end