Class: Auth::Workflow::Requirement
- Inherits:
-
Object
- Object
- Auth::Workflow::Requirement
- Includes:
- Concerns::WorkflowConcern
- Defined in:
- app/models/auth/workflow/requirement.rb
Constant Summary collapse
- FIELDS_LOCKED_AFTER_ORDER_ADDED =
["applicable","schedulable","resolve_requirement","location_information","time_information"]
Instance Attribute Summary collapse
-
#assembly_doc_version ⇒ Object
Returns the value of attribute assembly_doc_version.
-
#assembly_id ⇒ Object
Returns the value of attribute assembly_id.
-
#requirement_index ⇒ Object
Returns the value of attribute requirement_index.
-
#sop_doc_version ⇒ Object
Returns the value of attribute sop_doc_version.
-
#sop_id ⇒ Object
Returns the value of attribute sop_id.
-
#sop_index ⇒ Object
Returns the value of attribute sop_index.
-
#stage_doc_version ⇒ Object
Returns the value of attribute stage_doc_version.
-
#stage_id ⇒ Object
Returns the value of attribute stage_id.
-
#stage_index ⇒ Object
Returns the value of attribute stage_index.
-
#step_doc_version ⇒ Object
Returns the value of attribute step_doc_version.
-
#step_id ⇒ Object
Returns the value of attribute step_id.
-
#step_index ⇒ Object
Returns the value of attribute step_index.
Class Method Summary collapse
- .find_self(id, signed_in_resource, options = {}) ⇒ Object
- .permitted_params ⇒ Object
-
.state_query_update_combiner_default ⇒ Object
basically we want to combine all the states required values to search for and mark the product.
Instance Method Summary collapse
-
#add_duration_from_step(step_duration) ⇒ Object
adds the duration of the step itself to this requirements time information.
-
#add_duration_since_first_step(duration_since_start) ⇒ Object
modulates the end time and start time to reflect the total elapsed duration since the start of the sop.
-
#add_requirement(req) ⇒ Object
a subsequent requirement is adding itself to this requirement.
- #add_to_query_hash(stage_index, sop_index, step_index, req_index, query_hash, force = false) ⇒ Object
- #build_query(query) ⇒ Object
- #calculate_required_states(order) ⇒ Object
-
#create_with_conditions(params, permitted_params, model) ⇒ Object
create method.
-
#emit_schedule_sop_event(arguments) ⇒ Object
@param arguments : the same arguments hash that was passed into #mark_requirement function.
-
#execute_product_mark(arguments) ⇒ Object
please note that you have to provide that product as is.
-
#follow_reference_requirement ⇒ Object
if true will not create a new entry in the schedule query hash for this requirement.
-
#get_self_address(index) ⇒ Object
@param index : the index of the requirment inside the step.
-
#mark_requirement(arguments = {}) ⇒ Object
now if the product mark is successfull then and only then,.
-
#name ⇒ Object
if this is set to true, will have to.
-
#product_id ⇒ Object
the product id of the requirement.
-
#reference_requirement_address ⇒ Object
eg: stages.1.sops.2.steps.4.requirements.4.
-
#schedulable ⇒ Object
set to true if this requirement needs to be scheduled.
Instance Attribute Details
#assembly_doc_version ⇒ Object
Returns the value of attribute assembly_doc_version.
36 37 38 |
# File 'app/models/auth/workflow/requirement.rb', line 36 def assembly_doc_version @assembly_doc_version end |
#assembly_id ⇒ Object
Returns the value of attribute assembly_id.
35 36 37 |
# File 'app/models/auth/workflow/requirement.rb', line 35 def assembly_id @assembly_id end |
#requirement_index ⇒ Object
Returns the value of attribute requirement_index.
46 47 48 |
# File 'app/models/auth/workflow/requirement.rb', line 46 def requirement_index @requirement_index end |
#sop_doc_version ⇒ Object
Returns the value of attribute sop_doc_version.
41 42 43 |
# File 'app/models/auth/workflow/requirement.rb', line 41 def sop_doc_version @sop_doc_version end |
#sop_id ⇒ Object
Returns the value of attribute sop_id.
42 43 44 |
# File 'app/models/auth/workflow/requirement.rb', line 42 def sop_id @sop_id end |
#sop_index ⇒ Object
Returns the value of attribute sop_index.
40 41 42 |
# File 'app/models/auth/workflow/requirement.rb', line 40 def sop_index @sop_index end |
#stage_doc_version ⇒ Object
Returns the value of attribute stage_doc_version.
38 39 40 |
# File 'app/models/auth/workflow/requirement.rb', line 38 def stage_doc_version @stage_doc_version end |
#stage_id ⇒ Object
Returns the value of attribute stage_id.
39 40 41 |
# File 'app/models/auth/workflow/requirement.rb', line 39 def stage_id @stage_id end |
#stage_index ⇒ Object
Returns the value of attribute stage_index.
37 38 39 |
# File 'app/models/auth/workflow/requirement.rb', line 37 def stage_index @stage_index end |
#step_doc_version ⇒ Object
Returns the value of attribute step_doc_version.
44 45 46 |
# File 'app/models/auth/workflow/requirement.rb', line 44 def step_doc_version @step_doc_version end |
#step_id ⇒ Object
Returns the value of attribute step_id.
45 46 47 |
# File 'app/models/auth/workflow/requirement.rb', line 45 def step_id @step_id end |
#step_index ⇒ Object
Returns the value of attribute step_index.
43 44 45 |
# File 'app/models/auth/workflow/requirement.rb', line 43 def step_index @step_index end |
Class Method Details
.find_self(id, signed_in_resource, options = {}) ⇒ Object
57 58 59 60 61 |
# File 'app/models/auth/workflow/requirement.rb', line 57 def self.find_self(id,signed_in_resource,={}) return nil unless collection = Auth.configuration.assembly_class.constantize.where("stages.sops.steps.requirements._id" => BSON::ObjectId(id) ) collection.first end |
.permitted_params ⇒ Object
63 64 65 |
# File 'app/models/auth/workflow/requirement.rb', line 63 def self.permitted_params [{:requirement => [:name, :applicable, :product_id, :reference_requirement, :assembly_id,:assembly_doc_version,:stage_id, :stage_doc_version, :stage_index, :sop_id, :sop_doc_version, :sop_index, :doc_version, :step_index, :step_id, :requirement_index, :step_doc_version, :schedulable, :resolve_requirement, :location_information, :time_information]},:id] end |
.state_query_update_combiner_default ⇒ Object
basically we want to combine all the states required values to search for and mark the product. we have to call eval on it. so here what we will do is to
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'app/models/auth/workflow/requirement.rb', line 150 def self.state_query_update_combiner_default ## we can find the relevant product. ## but thereafter, if we have to do it again ## then what ? ## it will have to be an upsert of some kind. ## for a particular requirement has the thing already been booked, for a particular order? ## how to do that? ## the product has a huge bunch of orders ## see the requirements hard code the product ids. ## or should they hardcode product categories? ## then they will have a product category. ## suppose you want a product nearby? ## then how does it work? ## it is like a large number of things with a product code. ## and we search where, order.requirement_address does not exist, and product code is as per other requirements -> there we update. ## so if that query changes, then this will also change. ## so what is different form ths " product_query = { \"$and\" => [ { \"_id\" => BSON::ObjectId(arguments[:requirement][:product_id]) } ] } product_update = {} arguments[:requirement][:states].each do |state| if state[:setter_function] == Auth.configuration.state_class.constantize.setter_function_default product_query[\"$and\"] << { \"stock\" => { \"$gte\" => state[:required_value].to_f } } product_update[\"$inc\"][:stock] = options[:required_stock]*-1 end end ## at the end it should do that query. return Auth.configuration.product_class.constantize.where(product_query).find_one_and_update(product_update,{:return_document => :after}) " end |
Instance Method Details
#add_duration_from_step(step_duration) ⇒ Object
adds the duration of the step itself to this requirements time information. also updates the end_time so that it reflects the duration of the step.
249 250 251 252 |
# File 'app/models/auth/workflow/requirement.rb', line 249 def add_duration_from_step(step_duration) self.time_information[:duration] = step_duration self.time_information[:end_time] = self.time_information[:end_time] + self.time_information[:duration] end |
#add_duration_since_first_step(duration_since_start) ⇒ Object
modulates the end time and start time to reflect the total elapsed duration since the start of the sop.
257 258 259 260 261 |
# File 'app/models/auth/workflow/requirement.rb', line 257 def add_duration_since_first_step(duration_since_start) self.time_information[:duration_since_start] = duration_since_start self.time_information[:start_time] = self.time_information[:start_time] + self.time_information[:duration_since_start] self.time_information[:end_time] = self.time_information[:end_time] + self.time_information[:duration_since_start] end |
#add_requirement(req) ⇒ Object
a subsequent requirement is adding itself to this requirement.
239 240 241 242 |
# File 'app/models/auth/workflow/requirement.rb', line 239 def add_requirement(req) ## take the duration from its time_information and add it to the self duration self.time_information[:duration] += req.time_information[:duration] end |
#add_to_query_hash(stage_index, sop_index, step_index, req_index, query_hash, force = false) ⇒ Object
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'app/models/auth/workflow/requirement.rb', line 219 def add_to_query_hash(stage_index,sop_index,step_index,req_index,query_hash,force=false) if force query_hash["stages.#{self.stage_index}.sops.#{self.sop_index}.steps.#{key}.requirements.#{req_index}"] = self else if self.follow_reference_requirement query_hash[self.reference_requirement_address].add_requirement(self) else query_hash["stages.#{self.stage_index}.sops.#{self.sop_index}.steps.#{key}.requirements.#{req_index}"] = self end end end |
#build_query(query) ⇒ Object
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'app/models/auth/workflow/requirement.rb', line 264 def build_query(query) ######################################################### ## ## TIME INFORMATION ## ######################################################### query["$or"] << {"$and" => []} query["$or"].last["$and"] << generate_time_query ######################################################### ## ## LOCATION INFORMATION ## ######################################################### query["$or"].last["$and"] << generate_location_query ######################################################### ## ## REQUIREMENT INFORMATION ## ######################################################### ## add the requirement category ## if the requirement was resolved, then add resolved_id if self.resolved_id query["$or"].last["$and"] << { "requirement_ids" => self.resolved_id } else query["$or"].last["$and"] << { "requirement_categories" => self.category } end end |
#calculate_required_states(order) ⇒ Object
141 142 143 144 145 |
# File 'app/models/auth/workflow/requirement.rb', line 141 def calculate_required_states(order) states.each do |state| state.calculate_required_state(order) end end |
#create_with_conditions(params, permitted_params, model) ⇒ Object
create method
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'app/models/auth/workflow/requirement.rb', line 74 def create_with_conditions(params,permitted_params,model) ## in this case the model is a stage model. return false unless model.valid? puts "these are the model attributes --------------" puts model.attributes.to_s assembly_updated = Auth.configuration.assembly_class.constantize.where({ "$and" => [ { "stages.#{model.stage_index}._id" => BSON::ObjectId(model.stage_id) }, { "stages.#{model.stage_index}.doc_version" => model.stage_doc_version }, { "_id" => BSON::ObjectId(model.assembly_id) }, { "doc_version" => model.assembly_doc_version }, { "stages.#{model.stage_index}.sops.#{model.sop_index}._id" => BSON::ObjectId(model.sop_id) }, { "stages.#{model.stage_index}.sops.#{model.sop_index}.doc_version" => model.sop_doc_version }, { "stages.#{model.stage_index}.sops.#{model.sop_index}.steps.#{step_index}._id" => BSON::ObjectId(model.step_id) }, { "stages.#{model.stage_index}.sops.#{model.sop_index}.steps.#{step_index}.doc_version" => model.step_doc_version }, { "stages.sops.orders" => { "$exists" => false } } ] }) .find_one_and_update( { "$push" => { "stages.#{stage_index}.sops.#{sop_index}.steps.#{step_index}.requirements" => model.attributes } }, { :return_document => :after } ) return false unless assembly_updated return model end |
#emit_schedule_sop_event(arguments) ⇒ Object
211 212 213 214 215 216 |
# File 'app/models/auth/workflow/requirement.rb', line 211 def emit_schedule_sop_event(arguments) e = Auth::Transaction::Event.new e.arguments = arguments e.method_to_call = "schedule_order" [e] end |
#execute_product_mark(arguments) ⇒ Object
please note that you have to provide that product as is. @param arguments : passed in from the mark_requirement, commit the required_value.
204 205 206 207 |
# File 'app/models/auth/workflow/requirement.rb', line 204 def execute_product_mark(arguments) result_of_marking_product = eval(state_query_update_combiner) puts "result of marking product is: #{result_of_marking_product}" end |
#follow_reference_requirement ⇒ Object
if true will not create a new entry in the schedule query hash for this requirement. otherwise will create.
18 |
# File 'app/models/auth/workflow/requirement.rb', line 18 field :follow_reference_requirement, type: Boolean, default: false |
#get_self_address(index) ⇒ Object
136 137 138 |
# File 'app/models/auth/workflow/requirement.rb', line 136 def get_self_address(index) "stages:#{self.stage_index}:sops:#{self.sop_index}:steps:#{self.step_index}:requirements:#{index}" end |
#mark_requirement(arguments = {}) ⇒ Object
now if the product mark is successfull then and only then,
313 314 315 316 317 318 |
# File 'app/models/auth/workflow/requirement.rb', line 313 def mark_requirement(arguments={}) return nil if (arguments[:requirement].blank?) execute_product_mark(arguments) unless self.schedulable return emit_schedule_sop_event(arguments) if arguments[:last_requirement] == true return [] end |
#name ⇒ Object
if this is set to true, will have to
22 |
# File 'app/models/auth/workflow/requirement.rb', line 22 field :name, type: String |
#product_id ⇒ Object
the product id of the requirement.
30 |
# File 'app/models/auth/workflow/requirement.rb', line 30 field :product_id, type: String |
#reference_requirement_address ⇒ Object
eg: stages.1.sops.2.steps.4.requirements.4
12 |
# File 'app/models/auth/workflow/requirement.rb', line 12 field :reference_requirement_address, type: String |
#schedulable ⇒ Object
set to true if this requirement needs to be scheduled. requirements which are schedulable are skipped during the mark requirement phase.
26 |
# File 'app/models/auth/workflow/requirement.rb', line 26 field :schedulable, type: Boolean, default: false |