Class: OpenWFE::FlowExpressionId

Inherits:
Object
  • Object
show all
Defined in:
lib/openwfe/flowexpressionid.rb,
lib/openwfe/storage/yamlcustom.rb

Overview

making sure that the FlowExpressionId is serialized as a unique String

Constant Summary collapse

FIELDS =
[ 
    :owfe_version, 
    :engine_id, 
    #:initial_engine_id,
    :workflow_definition_url,
    :workflow_definition_name,
    :workflow_definition_revision,
    :workflow_instance_id,
    :expression_name,
    :expression_id
]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_h(h) ⇒ Object

Rebuilds a FlowExpressionId from its Hash representation.



124
125
126
127
128
129
130
# File 'lib/openwfe/flowexpressionid.rb', line 124

def FlowExpressionId.from_h (h)

    FIELDS.inject FlowExpressionId.new do |fei, f| 
        fei.instance_variable_set("@#{f}", h[f] || h[f.to_s])
        fei
    end
end

.from_s(string) ⇒ Object

An alias for to_fei(string)



333
334
335
336
# File 'lib/openwfe/flowexpressionid.rb', line 333

def self.from_s (string)

    to_fei string
end

.split_web_s(s) ⇒ Object

Splits the web fei into the workflow instance id and the expression id.



217
218
219
220
221
222
# File 'lib/openwfe/flowexpressionid.rb', line 217

def self.split_web_s (s)

    i = s.rindex("__")

    [ s[0..i-1], s[i+2..-1].gsub("\_", ".") ]
end

.to_fei(string) ⇒ Object

This class method parses a string into a FlowExpressionId instance



301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/openwfe/flowexpressionid.rb', line 301

def self.to_fei (string)

    fei = FlowExpressionId.new

    ss = string.split(" ")

    #require 'pp'; puts; pp ss

    ss = ss[1..-1] if ss[0] == "("

    fei.owfe_version = ss[1]

    ssRawEngineId = ss[2].split("/")
    fei.engine_id = ssRawEngineId[0]
    #fei.initial_engine_id = ssRawEngineId[1]

    fei.workflow_definition_url = ss[3]
    fei.workflow_definition_name = ss[4]
    fei.workflow_definition_revision = ss[5]
    fei.workflow_instance_id = ss[6]
    fei.expression_name = ss[7]
    fei.expression_id = ss[8][0..-2]

    fei.expression_id = fei.expression_id[0..-2] \
        if fei.expression_id[-1, 1] == ")"

    fei
end

.to_parent_wfid(wfid) ⇒ Object

If wfid is already a ‘parent wfid’ (no sub id), returns it. Else returns the parent wfid (whatever is before the first “.”).



342
343
344
345
346
347
# File 'lib/openwfe/flowexpressionid.rb', line 342

def self.to_parent_wfid (wfid)

    i = wfid.index(".")
    return wfid unless i
    wfid[0..i-1]
end

.yaml_new(klass, tag, val) ⇒ Object



93
94
95
96
97
98
99
100
101
# File 'lib/openwfe/storage/yamlcustom.rb', line 93

def FlowExpressionId.yaml_new (klass, tag, val)

    s = val["s"]
    begin
        FlowExpressionId.to_fei(s)
    rescue Exception => e
        raise "failed to decode FlowExpressionId out of '#{s}'"
    end
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/openwfe/flowexpressionid.rb', line 137

def == (other)

    return false if not other.kind_of?(FlowExpressionId)

    #return self.to_s == other.to_s
        # no perf gain

    @workflow_instance_id == other.workflow_instance_id and
    @expression_id == other.expression_id and
    @workflow_definition_url == other.workflow_definition_url and
    @workflow_definition_revision == other.workflow_definition_revision and
    @workflow_definition_name == other.workflow_definition_name and
    @expression_name == other.expression_name and
    @owfe_version == other.owfe_version and 
    @engine_id == other.engine_id
    #@initial_engine_id == other.initial_engine_id
        #
        # Made sure to put on top of the 'and' the things that
        # change the most...
end

#ancestor_of?(other_fei) ⇒ Boolean

Returns true if this other FlowExpressionId is nested within this one.

For example (fei TestTag 3 20070331-goyunodabu 0.0.0 sequence) is an ancestor of (fei TestTag 3 20070331-goyunodabu 0.0.0.1 redo)

This current implementation doesn’t cross the subprocesses boundaries.

Returns:

  • (Boolean)


168
169
170
171
172
173
174
175
176
177
# File 'lib/openwfe/flowexpressionid.rb', line 168

def ancestor_of? (other_fei)

    o = other_fei.dup
    o.expression_name = @expression_name
    o.expression_id = @expression_id

    return false unless self == o

    OpenWFE::starts_with other_fei.expression_id, @expression_id
end

#child_idObject

Returns the last part of the expression_id. For example, if the expression_id is “0.1.0.4”, “4” will be returned.

This method is used in “concurrence” when merging workitems coming backing from the children expressions.



291
292
293
294
295
296
# File 'lib/openwfe/flowexpressionid.rb', line 291

def child_id

    i = @expression_id.rindex(".")
    return @expression_id unless i
    @expression_id[i+1..-1]
end

#dupObject

Returns a deep copy of this FlowExpressionId instance.



182
183
184
185
# File 'lib/openwfe/flowexpressionid.rb', line 182

def dup

    OpenWFE::fulldup(self)
end

#hashObject



132
133
134
135
# File 'lib/openwfe/flowexpressionid.rb', line 132

def hash

    to_s.hash
end

#initial_engine_idObject

silently discard



101
102
103
104
# File 'lib/openwfe/flowexpressionid.rb', line 101

def initial_engine_id

    @engine_id
end

#initial_engine_id=(s) ⇒ Object

the old ‘initial_engine_id’ is now deprecated, the methods are still around though.



97
98
99
100
# File 'lib/openwfe/flowexpressionid.rb', line 97

def initial_engine_id= (s)

    # silently discard
end

#is_in_parent_process?Boolean

Returns true if this flow expression id belongs to a process which is not a subprocess.

Returns:

  • (Boolean)


279
280
281
282
# File 'lib/openwfe/flowexpressionid.rb', line 279

def is_in_parent_process?

    (sub_instance_id == "")
end

#last_sub_instance_idObject

If this flow expression id belongs to a sub instance, a call to this method will return the last number of the sub instanceid.

For example, in the case of the instance “20071114-dukikomino.1”, “1” will be returned. For “20071114-dukikomino.1.0”, “0” will be returned.

If the flow expression id doesn’t belong to a sub instance, nil will be returned.



268
269
270
271
272
273
# File 'lib/openwfe/flowexpressionid.rb', line 268

def last_sub_instance_id

    i = workflow_instance_id.rindex(".")
    return nil unless i
    workflow_instance_id[i+1..-1]
end

#parent_workflow_instance_idObject Also known as: parent_wfid

Returns the workflow instance id without any subflow indices. For example, if the wfid is “1234.0.1”, this method will return “1234”.



238
239
240
241
# File 'lib/openwfe/flowexpressionid.rb', line 238

def parent_workflow_instance_id

    FlowExpressionId.to_parent_wfid workflow_instance_id
end

#sub_instance_idObject

Returns “” if this expression id belongs to a top process, returns something like “.0” or “.1.3” if this exp id belongs to an expression in a subprocess. (Only used in some unit tests for now)



251
252
253
254
255
256
# File 'lib/openwfe/flowexpressionid.rb', line 251

def sub_instance_id

    i = workflow_instance_id.index(".")
    return "" unless i
    workflow_instance_id[i..-1]
end

#to_debug_sObject



189
190
191
# File 'lib/openwfe/flowexpressionid.rb', line 189

def to_debug_s
    "(fei #{wfname} #{wfrevision} #{wfid} #{expid} #{expname})"
end

#to_env_sObject

Yet another debugging method. Just returns the sub_instance_id and the expression_id, in a string.



228
229
230
231
# File 'lib/openwfe/flowexpressionid.rb', line 228

def to_env_s

    "i#{sub_instance_id}  #{@expression_id}"
end

#to_hObject

Returns a hash version of this FlowExpressionId instance.



116
117
118
119
# File 'lib/openwfe/flowexpressionid.rb', line 116

def to_h

    FIELDS.inject({}) { |r, f| r[f] = instance_eval("@#{f.to_s}"); r }
end

#to_sObject

Overrides the classical to_s()



109
110
111
# File 'lib/openwfe/flowexpressionid.rb', line 109

def to_s
    "(fei #{@owfe_version} #{@engine_id} #{wfurl} #{wfname} #{wfrevision} #{wfid} #{expname} #{expid})"
end

#to_short_sObject

Returns a very short string representation (fei wfid expid expname).



196
197
198
# File 'lib/openwfe/flowexpressionid.rb', line 196

def to_short_s
    "(fei #{wfid} #{expid} #{expname})"
end

#to_web_sObject

Returns a URI escaped string with just the wfid and the expid, like ‘20070917-dupibodasa__0.0.1’

Useful for unique identifier in URIs.



206
207
208
209
210
211
# File 'lib/openwfe/flowexpressionid.rb', line 206

def to_web_s

    eid = expid.gsub("\.", "_")

    URI.escape "#{wfid}__#{eid}"
end

#to_yaml(opts = {}) ⇒ Object

def to_yaml (opts={})

@s = to_s
super

end def to_yaml_properties

[ "@s" ]

end



84
85
86
87
88
89
90
91
# File 'lib/openwfe/storage/yamlcustom.rb', line 84

def to_yaml (opts={})

    YAML::quick_emit(self.object_id, opts) do |out|
        out.map(taguri) do |map|
            map.add("s", to_s)
        end
    end
end

#wfid(parent = false) ⇒ Object

This method return @workflow_instance_id. If parent is set to true, if will return the same result as parent_workflow_instance_id().



83
84
85
86
87
88
89
90
# File 'lib/openwfe/flowexpressionid.rb', line 83

def wfid (parent=false)

    if parent
        parent_workflow_instance_id
    else
        workflow_instance_id
    end
end