Class: OpenWFE::RestoreWorkItemExpression

Inherits:
FlowExpression show all
Includes:
MergeMixin, ValueMixin
Defined in:
lib/openwfe/expressions/fe_save.rb

Overview

“restore” is often used in conjunction with “save” (SaveWorkItemExpression).

It can restore a workitem saved to a variable (it will actually restore the payload of that workitem) or transfer the content of a field as top attribute field.

restore :from_variable => "freezed_workitem"
    #
    # takes the freezed payload at 'freezed_workitem' and makes it
    # the payload of the current workitem

restore :from_field => "some_data"
    #
    # replaces the payload of the current workitem with the hash
    # found in the field "some_data"

restore :from_variable => "v", :to_field => "f"
    #
    # will copy the payload saved under variable "v" as the value
    # of the field "f"

restore :from_variable => "v", :merge_lead => :current
    #
    # will restore the payload of the workitem saved under v
    # but if fields of v are already present in the current workitem
    # the current values will be kept

restore :from_variable => "v", :merge_lead => :restored
    #
    # will restore the payload of the workitem saved under v
    # but the workitem v payload will have priority.

Beware : you should not restore from a field that is not a hash. The top level attributes (payload) of a workitem should always be a hash.

Since OpenWFEru 0.9.17, the ‘set-fields’ alias can be used for restore.

sequence do
    set_fields :value => { 
        "customer" => { "name" => "Zigue", "age" => 34 },
        "approved" => false }
    _print "${f:customer.name} (${f:customer.age}) ${f:approved}"
end

Along with this new alias, the expression now behave much like the ‘set’ expression, but still, targets the whole workitem payload.

Note that “set-fields” can be used outside of the body of a process definition (along with “set”) to separate ‘data preparation’ from actual process definition.

class Test44b6 < ProcessDefinition
    set_fields :value => { 
        "customer" => { "name" => "Zigue", "age" => 34 },
        "approved" => false }
    sequence do
        _print "${f:customer.name} (${f:customer.age}) ${f:approved}"
    end
end

Using set_fields at the beginning of a process can be useful for setting up forms (keys without values for now).

set_fields :value => {
    "name" => "",
    "address" => "",
    "email" => ""
}

Instance Attribute Summary

Attributes inherited from FlowExpression

#apply_time, #attributes, #children, #environment_id, #fei, #parent_id, #raw_representation

Attributes included from Contextual

#application_context

Instance Method Summary collapse

Methods included from ValueMixin

#apply, #lookup_field_attribute, #lookup_variable_attribute

Methods included from MergeMixin

#merge_workitems

Methods inherited from FlowExpression

#apply, #cancel, #clean_children, #delete_variable, #dup_environment, #fetch_environment, #fetch_text_content, #get_binding, #get_environment, #get_parent, #get_root_environment, #has_attribute, #initialize, is_definition, is_definition?, #lookup_attribute, #lookup_attributes, #lookup_boolean_attribute, #lookup_comma_list_attribute, #lookup_downcase_attribute, #lookup_ref, #lookup_string_attribute, #lookup_sym_attribute, #lookup_value, #lookup_variable, #lookup_vf_attribute, names, #new_environment, new_exp, #owns_its_environment?, #paused?, #remove_child, #reply_to_parent, #set_variable, #store_itself, #synchronize, #to_s, #to_yaml_properties

Methods included from Contextual

#get_work_directory, #init_service, #lookup

Methods included from Logging

#ldebug, #ldebug_callstack, #lerror, #lfatal, #linfo, #llog, #lunknown, #lwarn

Methods included from OwfeServiceLocator

#get_engine, #get_error_journal, #get_expool, #get_expression_map, #get_expression_pool, #get_expression_storage, #get_expression_storages, #get_journal, #get_participant_map, #get_scheduler, #get_wfid_generator

Methods inherited from ObjectWithMeta

#class_def, meta_def, meta_eval, metaclass

Constructor Details

This class inherits a constructor from OpenWFE::FlowExpression

Instance Method Details

#reply(workitem) ⇒ Object



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/openwfe/expressions/fe_save.rb', line 175

def reply (workitem)

    from_field = lookup_string_attribute :from_field, workitem
    from_variable = lookup_string_attribute :from_variable, workitem

    merge_lead = lookup_sym_attribute :merge_lead, workitem

    merge_lead = nil \
        unless [ nil, :current, :restored ].include?(merge_lead)

    value = workitem.attributes[FIELD_RESULT]

    source = if from_field

        att = workitem.lookup_attribute from_field

        lwarn {
            "apply() field '#{from_field}' is NOT a hash, " +
            "restored anyway"
        } unless att.kind_of?(Hash)

        att

    elsif from_variable

        lookup_variable from_variable

    elsif value

        value

    else

        nil
    end

    if source

        workitem = if merge_lead
            do_merge merge_lead, workitem, source
        else
            do_overwrite workitem, source
        end
    end
    # else, don't restore anything

    reply_to_parent workitem
end