Class: Auth::Workflow::State

Inherits:
Object
  • Object
show all
Includes:
Concerns::WorkflowConcern
Defined in:
app/models/auth/workflow/state.rb

Constant Summary collapse

FIELDS_LOCKED_AFTER_ORDER_ADDED =
["applicable"]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#assembly_doc_versionObject

Returns the value of attribute assembly_doc_version.



34
35
36
# File 'app/models/auth/workflow/state.rb', line 34

def assembly_doc_version
  @assembly_doc_version
end

#assembly_idObject

Returns the value of attribute assembly_id.



33
34
35
# File 'app/models/auth/workflow/state.rb', line 33

def assembly_id
  @assembly_id
end

#required_valueObject

Returns the value of attribute required_value.



29
30
31
# File 'app/models/auth/workflow/state.rb', line 29

def required_value
  @required_value
end

#requirement_doc_versionObject

Returns the value of attribute requirement_doc_version.



45
46
47
# File 'app/models/auth/workflow/state.rb', line 45

def requirement_doc_version
  @requirement_doc_version
end

#requirement_idObject

Returns the value of attribute requirement_id.



46
47
48
# File 'app/models/auth/workflow/state.rb', line 46

def requirement_id
  @requirement_id
end

#requirement_indexObject

Returns the value of attribute requirement_index.



44
45
46
# File 'app/models/auth/workflow/state.rb', line 44

def requirement_index
  @requirement_index
end

#sop_doc_versionObject

Returns the value of attribute sop_doc_version.



39
40
41
# File 'app/models/auth/workflow/state.rb', line 39

def sop_doc_version
  @sop_doc_version
end

#sop_idObject

Returns the value of attribute sop_id.



40
41
42
# File 'app/models/auth/workflow/state.rb', line 40

def sop_id
  @sop_id
end

#sop_indexObject

Returns the value of attribute sop_index.



38
39
40
# File 'app/models/auth/workflow/state.rb', line 38

def sop_index
  @sop_index
end

#stage_doc_versionObject

Returns the value of attribute stage_doc_version.



36
37
38
# File 'app/models/auth/workflow/state.rb', line 36

def stage_doc_version
  @stage_doc_version
end

#stage_idObject

Returns the value of attribute stage_id.



37
38
39
# File 'app/models/auth/workflow/state.rb', line 37

def stage_id
  @stage_id
end

#stage_indexObject

Returns the value of attribute stage_index.



35
36
37
# File 'app/models/auth/workflow/state.rb', line 35

def stage_index
  @stage_index
end

#state_indexObject

Returns the value of attribute state_index.



47
48
49
# File 'app/models/auth/workflow/state.rb', line 47

def state_index
  @state_index
end

#step_doc_versionObject

Returns the value of attribute step_doc_version.



42
43
44
# File 'app/models/auth/workflow/state.rb', line 42

def step_doc_version
  @step_doc_version
end

#step_idObject

Returns the value of attribute step_id.



43
44
45
# File 'app/models/auth/workflow/state.rb', line 43

def step_id
  @step_id
end

#step_indexObject

Returns the value of attribute step_index.



41
42
43
# File 'app/models/auth/workflow/state.rb', line 41

def step_index
  @step_index
end

Class Method Details

.find_self(id, signed_in_resource, options = {}) ⇒ Object

common methods to all workflow classes



58
59
60
61
62
# File 'app/models/auth/workflow/state.rb', line 58

def self.find_self(id,signed_in_resource,options={})
  return nil unless collection =  Auth.configuration.assembly_class.constantize.where("stages.sops.steps.requirements.states._id" => BSON::ObjectId(id)
  )
  collection.first
end

.permitted_paramsObject



64
65
66
# File 'app/models/auth/workflow/state.rb', line 64

def self.permitted_params
  [{:state => [: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, :step_doc_version, :step_index, :step_id, :requirement_index, :requirement_doc_version, :requirement_id, :state_index, :doc_version]},:id]
end

.setter_function_defaultObject



159
160
161
162
163
164
165
# File 'app/models/auth/workflow/state.rb', line 159

def self.setter_function_default
   ## here we have to commit the required value.
   ## it will have to be an update_with_conditions.
	"
		self.required_value = order.cart_item_ids.size
	"
end

Instance Method Details

#calculate_required_state(order) ⇒ Object

@param array of order objects @return just sets the required_value of this state.



172
173
174
# File 'app/models/auth/workflow/state.rb', line 172

def calculate_required_state(order)
	eval(setter_function)
end

#create_with_conditions(params, permitted_params, model) ⇒ Object

create method



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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'app/models/auth/workflow/state.rb', line 75

def create_with_conditions(params,permitted_params,model)
## in this case the model is a state model.
  
  return false unless model.valid?

=begin
  puts "these are the model attributes --------------"
  puts model.attributes.to_s

  puts model.stage_id
  puts model.stage_doc_version
  puts model.sop_id
  puts model.sop_doc_version
  puts model.step_id
  puts model.step_doc_version
  puts model.requirement_id
  puts model.requirement_doc_version
=end


  query = 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.#{model.stage_index}.sops.#{model.sop_index}.steps.#{step_index}.requirements.#{requirement_index}._id" => BSON::ObjectId(model.requirement_id)
      },
      {
        "stages.#{model.stage_index}.sops.#{model.sop_index}.steps.#{step_index}.requirements.#{requirement_index}.doc_version" => model.requirement_doc_version
      },
      {
        "stages.sops.orders" => {
              "$exists" => false
          }
      }
    ]
  })

  puts "the query count is: #{query.size.to_s}"

  assembly_updated = query
  .find_one_and_update(
    {
      "$push" => 
      {
        "stages.#{stage_index}.sops.#{sop_index}.steps.#{step_index}.requirements.#{requirement_index}.states" => model.attributes
      }
    },
    {
      :return_document => :after
    }
  )

  

  return false unless assembly_updated
  return model

end

#permitted_valuesObject

current_value.



17
# File 'app/models/auth/workflow/state.rb', line 17

field :permitted_values, type: Array