lib/openwfe/workitem.rb in openwferu-0.9.15 vs lib/openwfe/workitem.rb in openwferu-0.9.16

- old
+ new

@@ -31,52 +31,52 @@ #++ # # # "hecho en Costa Rica" +# and "made in Japan" # # john.mettraux@openwfe.org # -require 'base64' - require 'openwfe/utils' -require 'openwfe/rest/definitions' - # hmmm, only used for MAP_TYPE - module OpenWFE # # The convention for the result of some expressions is to store # their result in a workitem field named "__result__". # FIELD_RESULT = "__result__" - # + #-- # WORKITEMS - # + #++ # # The base class for all the workitems. # class WorkItem attr_accessor :last_modified, :attributes - def initialize () - + def initialize @last_modified = nil - @attributes = {} - @attributes[MAP_TYPE] = E_SMAP end alias :fields :attributes alias :fields= :attributes= + # + # Sets the last_modified field to now + # + def touch + @last_modified = Time.now + end + def to_h h = {} h[:type] = self.class.name h[:last_modified] = @last_modified h[:attributes] = @attributes @@ -246,29 +246,34 @@ # # Outputting the workitem in a human readable format # def to_s + s = "" - s << " >>>#{self.class}>>>\n" + s << " #{self.class} :\n" s << " - flow_expression_id : #{@flow_expression_id}\n" s << " - participant_name : #{@participant_name}\n" s << " - last_modified : #{@last_modified}\n" s << " - dispatch_time : #{@dispatch_time}\n" s << " - attributes :\n" - @attributes.each do |k, v| - s << " * '#{k}' --> '#{v}'\n" + + s << " {\n" + @attributes.keys.sort.each do |k| + v = @attributes[k] + s << " #{k.inspect} => #{v.inspect},\n" end - s << " <<<#{self.class}<<<" + s << " }" s end # # For some easy YAML encoding, turns the workitem into a Hash # (Any YAML-enabled platform can thus read it). # def to_h + h = super h[:dispatch_time] = @dispatch_time h[:history] = @history h[:filter] = @filter h @@ -372,17 +377,17 @@ # """.strip # LaunchItem.new(definition) # # # Load an XML process definition from a local file # require 'uri' - # LaunchItem.new(URI.new("file:///tmp/my_process_definition.xml")) + # LaunchItem.new(URI.parse("file:///tmp/my_process_definition.xml")) # # # If you initialized your engine with # # {:remote_definitions_allowed => true}, then you can also load an # # XML process definition from a remote url # require 'uri' - # LaunchItem.new(URI.new("http://foo.bar/my_process_definition.xml")) + # LaunchItem.new(URI.parse("http://foo.bar/my_process_definition.xml")) # def initialize (process_definition=nil) super() @@ -415,157 +420,9 @@ # def OpenWFE.workitem_from_h (h) wi_class = h[:type] wi_class = eval(wi_class) wi_class.from_h(h) - end - - # - # HISTORY ITEM - # - - # - # HistoryItem instances are used to keep track of what happened to - # a workitem. - # - class HistoryItem - - attr_accessor \ - :date, \ - :author, \ - :host, \ - :text, \ - :wfd_name, \ - :wfd_revision, \ - :wf_instance_id, \ - :expression_id - - def dup - return OpenWFE::fulldup(self) - end - end - - - # - # STORES - # - - # - # Models the information about a store as viewed by the current user - # (upon calling the listStores or getStoreNames methods) - # - class Store - - attr_accessor :name, :workitem_count, :permissions - - def initialize () - super() - #@name = nil - #@workitem_count = nil - #@permissions = nil - end - - # - # Returns true if the current user may read headers and workitems - # from this store - # - def may_read? () - return @permissions.index('r') > -1 - end - - # - # Returns true if the current user may modify workitems (and at least - # proceed/forward them) in this store - # - def may_write? () - return @permissions.index('w') > -1 - end - - # - # Returns true if the current user may browse the headers of this - # store - # - def may_browse? () - return @permissions.index('b') > -1 - end - - # - # Returns true if the current user may delegate workitems to this store - # - def may_delegate? () - return @permissions.index('d') > -1 - end - end - - # - # A header is a summary of a workitem, returned by the getHeader - # worklist method. - # - class Header < InFlowWorkItem - - attr_accessor :locked - end - - - # - # MISC ATTRIBUTES - # - # in openwfe-ruby, OpenWFE attributes are immediately mapped to - # Ruby instances, but some attributes still deserve their own class - # - - # - # a wrapper for some binary content - # - class Base64Attribute - - attr_accessor :content - - def initialize (base64content) - - @content = base64content - end - - # - # dewraps (decode) the current content and returns it - # - def dewrap () - - return Base64.decode64(@content) - end - - # - # wraps some binary content and stores it in this attribute - # (class method) - # - def Base64Attribute.wrap (binaryData) - - return Base64Attribute.new(Base64.encode64(binaryData)) - end - end - - - # - # LAUNCHABLE - # - - # - # A worklist will return list of Launchable instances indicating - # what processes (URL) a user may launch on which engine. - # - class Launchable - - attr_accessor :url, :engine_id - end - - - # - # Expression, somehow equivalent to FlowExpression, but only used - # by the control interface. - # - class Expression - - attr_accessor :id, :apply_time, :state, :state_since end end