module Libis::Workflow::Base::WorkItem

Base module for all work items.

This module lacks the implementation for the data attributes. It functions as an interface that describes the common functionality regardless of the storage implementation. These attributes require some implementation:

The module is created so that it is possible to implement an ActiveRecord/Datamapper/… implementation easily. A simple in-memory implementation would require:

attr_accessor :parent attr_accessor :items attr_accessor :options, :properties attr_accessor :status_log attr_accessor :summary

def initialize

self.parent = nil
self.items = []
self.options = {}
self.properties = {}
self.status_log = []
self.summary = {}

end

protected

## Method below should be adapted to match the implementation of the status array

def add_status_log(info)

self.status_log << info

end

The implementation should also take care that the public methods save and save! are implemented. ActiveRecord and Mongoid are known to implement these, but others may not.

Public Instance Methods

<<(item)
Alias for: add_item
add_item(item) click to toggle source

Add a child work item

@param [WorkItem] item to be added to the child list :items

# File lib/libis/workflow/base/work_item.rb, line 133
def add_item(item)
  return self unless item and item.is_a?(Libis::Workflow::Base::WorkItem)
  self.items << item
  item.parent = self
  # noinspection RubyResolve
  self.save!
  # noinspection RubyResolve
  item.save!
  self
end
Also aliased as: <<
count()
Alias for: size
each(&block) click to toggle source

Iterates over the work item clients and invokes code on each of them.

# File lib/libis/workflow/base/work_item.rb, line 120
def each(&block)
  self.items.each(&block)
end
get_item_list() click to toggle source

Get list of items.

This method should return a list of items that is safe to iterate over while it is being altered.

# File lib/libis/workflow/base/work_item.rb, line 156
def get_item_list
  self.items.dup
end
get_items() click to toggle source

Get list of items.

This method should return a list of items that can be accessed during long processing times.

# File lib/libis/workflow/base/work_item.rb, line 149
def get_items
  self.items
end
get_parent() click to toggle source

Return item’s parent @return [Libis::Workflow::Base::WorkItem]

# File lib/libis/workflow/base/work_item.rb, line 162
def get_parent
  self.parent
end
get_root() click to toggle source

go up the hierarchy and return the topmost work item

@return [Libis::Workflow::Base::WorkItem]

# File lib/libis/workflow/base/work_item.rb, line 169
def get_root
  self.get_parent && self.get_parent.is_a?(Libis::Workflow::Base::WorkItem) && self.get_parent.get_root || self
end
get_run() click to toggle source

Get the top

@return [Libis::Workflow::Base::Run]

# File lib/libis/workflow/base/work_item.rb, line 176
def get_run
  return self if self.is_a?(Libis::Workflow::Base::Run)
  self.get_parent&.get_run
end
label() click to toggle source

Label is a more descriptive name

# File lib/libis/workflow/base/work_item.rb, line 92
def label
  self.properties['label'] || self.name
end
label=(value) click to toggle source
# File lib/libis/workflow/base/work_item.rb, line 96
def label=(value)
  self.properties['label'] = value
end
labelpath() click to toggle source
# File lib/libis/workflow/base/work_item.rb, line 104
def labelpath;
  self.labels.join('/');
end
labels() click to toggle source
# File lib/libis/workflow/base/work_item.rb, line 100
def labels
  (self.parent.labels rescue Array.new).push(label).compact
end
name() click to toggle source

String representation of the identity of the work item.

You may want to overwrite this method as it tries the :name property or whatever inspect returns if that failes. Typically this should return the key value, file name or id number. If that’s what your :name property contains, you’re fine.

@return [String] string identification for this work item.

# File lib/libis/workflow/base/work_item.rb, line 70
def name
  # noinspection RubyResolve
  self.properties['name'] || self.inspect
end
name=(n) click to toggle source
# File lib/libis/workflow/base/work_item.rb, line 75
def name=(n)
  self.properties['name'] = n
end
namepath() click to toggle source
# File lib/libis/workflow/base/work_item.rb, line 87
def namepath;
  self.names.join('/');
end
names() click to toggle source
# File lib/libis/workflow/base/work_item.rb, line 83
def names
  (self.parent.names rescue Array.new).push(name).compact
end
size() click to toggle source
# File lib/libis/workflow/base/work_item.rb, line 124
def size
  self.items.size
end
Also aliased as: count
to_filename() click to toggle source

File name safe version of the to_s output.

The output should be safe to use as a file name to store work item data. Typical use is when extra file items are created by a task and need to be stored on disk. The default implementation URL-encodes (%xx) all characters except alphanumeric, ‘.’ and ‘-’.

@return [String] file name

# File lib/libis/workflow/base/work_item.rb, line 115
def to_filename
  self.to_s.gsub(/[^\w.-]/) { |s| '%%%02x' % s.ord }
end
to_s() click to toggle source
# File lib/libis/workflow/base/work_item.rb, line 79
def to_s;
  self.name;
end