Class OpenWFE::FilterDefinitionExpression
In: lib/openwfe/expressions/fe_filter_definition.rb
Parent: FlowExpression

This expression binds a filter definition into a variable.

    class TestFilter48a0 < ProcessDefinition
        sequence do

            set :field => "readable", :value => "bible"
            set :field => "writable", :value => "sand"
            set :field => "randw", :value => "notebook"
            set :field => "hidden", :value => "playboy"

            alice

            filter :name => "filter0" do
                sequence do
                    bob
                    charly
                end
            end

            doug
        end

        filter_definition :name => "filter0" do
            field :regex => "readable", :permissions => "r"
            field :regex => "writable", :permissions => "w"
            field :regex => "randw", :permissions => "rw"
            field :regex => "hidden", :permissions => ""
        end
    end

In that example, the filter definition is done for filter ‘filter0’.

A filter definition accepts 4 attributes :

  • ‘name’ - simply naming the filter, the filter is then bound as a variable. This is the only mandatory attribute.
  • ‘closed’ - by default, set to ‘false’. A closed filter will not allow modifications to unspecified fields.
  • ‘add’ - by default, set to ‘true’. When true, this filter accepts adding new fields to the filtered workitem.
  • ‘remove’ - by default, set to ‘true’. When true, this filter accepts removing fields to the filtered workitem.

Inside of the process definition, fields are identified via regular expressions (‘regex’), a ‘permissions’ string is then expected with four possible values "rw", "w", "r" and "".

Methods

Public Instance methods

Will build the filter and bind it as a variable.

[Source]

     # File lib/openwfe/expressions/fe_filter_definition.rb, line 103
103:         def apply (workitem)
104: 
105:             filter = build_filter workitem
106:             filter_name = lookup_attribute :name, workitem
107: 
108:             set_variable filter_name, filter \
109:                 if filter_name and filter
110: 
111:             reply_to_parent workitem
112:         end

Protected Instance methods

builds and add a field (a line) of the filter.

[Source]

     # File lib/openwfe/expressions/fe_filter_definition.rb, line 153
153:             def add_field (filter, rawexp, workitem)
154: 
155:                 rawexp.load_attributes
156: 
157:                 regex = rawexp.lookup_attribute :regex, workitem
158:                 regex = rawexp.lookup_attribute :name, workitem unless regex
159: 
160:                 permissions = 
161:                     rawexp.lookup_downcase_attribute :permissions, workitem
162: 
163:                 filter.add_field regex, permissions
164:             end

Builds the filter (as described in the process definition) and returns it.

[Source]

     # File lib/openwfe/expressions/fe_filter_definition.rb, line 120
120:             def build_filter (workitem)
121: 
122:                 filter = FilterDefinition.new
123: 
124:                 # filter attributes
125: 
126:                 type = lookup_downcase_attribute :type, workitem
127:                 closed = lookup_downcase_attribute :closed, workitem
128: 
129:                 filter.closed = (type == "closed" or closed == "true")
130: 
131:                 add = lookup_downcase_attribute :add, workitem
132:                 remove = lookup_downcase_attribute :remove, workitem
133: 
134:                 filter.add_allowed = (add == "true")
135:                 filter.remove_allowed = (remove == "true")
136: 
137:                 # field by field
138: 
139:                 @children.each do |fei|
140: 
141:                     rawexp = get_expression_pool.fetch_expression fei
142:                     get_expression_pool.remove fei
143: 
144:                     add_field filter, rawexp, workitem
145:                 end
146: 
147:                 filter
148:             end

[Validate]