21448: adjusted test specs Arvados-DCO-1.1-Signed-off-by: Lisa Knox <lisa.knox@curii...
[arvados.git] / services / api / app / models / workflow.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 class Workflow < ArvadosModel
6   include HasUuid
7   include KindAndEtag
8   include CommonApiTemplate
9
10   validate :validate_definition
11   before_save :set_name_and_description
12
13   api_accessible :user, extend: :common do |t|
14     t.add :name
15     t.add :description
16     t.add :definition
17   end
18
19   def validate_definition
20     begin
21       @definition_yaml = YAML.safe_load self.definition if !definition.nil?
22     rescue => e
23       errors.add :definition, "is not valid yaml: #{e.message}"
24     end
25   end
26
27   def set_name_and_description
28     old_wf = {}
29     begin
30       old_wf = YAML.safe_load self.definition_was if !self.definition_was.nil?
31     rescue => e
32       logger.warn "set_name_and_description error: #{e.message}"
33       return
34     end
35
36     ['name', 'description'].each do |a|
37       if !self.changes.include?(a)
38         v = self.read_attribute(a)
39         if !v.present? or v == old_wf[a]
40           val = @definition_yaml[a] if self.definition and @definition_yaml
41           self[a] = val
42         end
43       end
44     end
45   end
46
47   def self.full_text_searchable_columns
48     super - ["definition"]
49   end
50
51   def self.limit_index_columns_read
52     ["definition"]
53   end
54 end