Class: EBatch

Inherits:
Object
  • Object
show all
Defined in:
app/models/e_batch.rb

Overview

The EBatch table

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.free?(batchid, user) ⇒ Boolean

Check if a batch is in progress. Return true if the batch is free or was launched by the current user

Returns:

  • (Boolean)


194
195
196
# File 'app/models/e_batch.rb', line 194

def self.free?(batchid, user)
  find(batchid).free?(user)
end

Instance Method Details

#assign_to(user) ⇒ Object



123
124
125
# File 'app/models/e_batch.rb', line 123

def assign_to(user)
  update_attribute(:inprogress, user)
end

#belongs_to?(user) ⇒ Boolean

Returns:

  • (Boolean)


181
182
183
# File 'app/models/e_batch.rb', line 181

def belongs_to?(user)
  inprogress == user.to_s
end

#clean_filename_for_import!Object



198
199
200
201
202
203
204
205
206
# File 'app/models/e_batch.rb', line 198

def clean_filename_for_import!
  unless original_filename.blank?
    # The file path may be pasted in from the Windows command prompt,
    # so swap back slashes for forward slashes
    original_filename.gsub!('\\', '/')
    original_filename.sub!(/\Asvn[\/]/i, 'svn/') # TODO: required?
    original_filename.strip!
  end
end

#done_action?(target_action) ⇒ Boolean

Is the batch past `target_action' in the workflow?

Returns:

  • (Boolean)


154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'app/models/e_batch.rb', line 154

def done_action?(target_action)
  return false if last_finished_action.nil? # Haven't start any e_actions

  at_new  = false                 # Reached the start of the workflow?
  done_it = false                 # Have we done `target_action'?
  # Where are we in the workflow?
  action  = next_available_action || last_finished_action.e_actiontype

  # Traverse the workflow in reverse from the current action to see
  # if there is a prior `target_action` step for this batch type:
  begin
    step = EWorkflow.find_by_e_type_and_next_e_actiontype(e_type, action)

    at_new  = step.nil?
    action  = step.try(:last_e_actiontype)
    done_it = (target_action == action)
  end until (done_it || at_new)

  done_it
end

#ensure_provider_not_blankObject

rdoc validation provider cannot be nil.



82
83
84
# File 'app/models/e_batch.rb', line 82

def ensure_provider_not_blank
  errors.add(:provider, 'cannot be blank.') if provider.blank?
end

#ensure_registryid_not_blankObject

rdoc validation registryid cannot be nil.



88
89
90
# File 'app/models/e_batch.rb', line 88

def ensure_registryid_not_blank
  errors.add(:registry, 'cannot be blank.') if registryid.blank?
end

#ensure_valid_providerObject

rdoc validation provider must exist in our lookup table.



101
102
103
104
# File 'app/models/e_batch.rb', line 101

def ensure_valid_provider
  return if Zprovider.valid_value?(provider)
  errors.add(:provider, 'does not exist.')
end

#ensure_valid_registryidObject

rdoc validation registryid must exist in our lookup table.



108
109
110
111
# File 'app/models/e_batch.rb', line 108

def ensure_valid_registryid
  return if Zprovider.valid_value?(registryid)
  errors.add(:registry, 'does not exist.')
end

#ensure_valid_typeObject

rdoc validation e_type must exist in our lookup table.



94
95
96
97
# File 'app/models/e_batch.rb', line 94

def ensure_valid_type
  return if ZeType.valid_value?(e_type)
  errors.add(:e_type, 'does not exist.')
end

#free?(user) ⇒ Boolean

Returns:

  • (Boolean)


184
185
186
# File 'app/models/e_batch.rb', line 184

def free?(user)
  !in_progress? || belongs_to?(user)
end

#in_progress?Boolean

Returns:

  • (Boolean)


177
178
179
# File 'app/models/e_batch.rb', line 177

def in_progress?
  !inprogress.nil?
end

#last_finished_actionObject



131
132
133
# File 'app/models/e_batch.rb', line 131

def last_finished_action
  e_actions.completed.except(:order).order('finished desc, e_actionid desc').first
end

#next_available_actionObject

Returns the actiontype that is available for this batch (if known) Method is updated on 2 Mar, 2009: each action will only have one proceeded action in Unified Esources. (Removed old PAS's RECE and MANU actions)



141
142
143
144
145
146
147
148
149
150
151
# File 'app/models/e_batch.rb', line 141

def next_available_action
  begin
    # TODO: Output of this sometimes disagrees with ROVBATCHACTION, resulting
    #       in inconsistent orderings, and batch automator failures. At very
    #       least, the batch automator should object more vigorously if the
    #       next_available_action disagrees with the ROVBATCHACTION output.
    if la = last_finished_action
      EWorkflow.next_action(e_type, la.e_actiontype)
    end
  end
end

#provider_descObject



113
114
115
116
117
118
119
120
121
# File 'app/models/e_batch.rb', line 113

def provider_desc
  lookup = Zprovider.find_by_zproviderid(provider)
  if lookup
    description = lookup.shortdesc
    return (description.upcase == description ? description.titlecase : description)
  else
    return provider
  end
end

#unlockObject



127
128
129
# File 'app/models/e_batch.rb', line 127

def unlock
  assign_to(nil)
end