Commit 228e43c28a958a90b9944311e45ff1ad5286f354

Authored by Marcos Pereira
Committed by Luciano Prestes
1 parent 353a9563

begin refactoring

src/noosfero-spb/software_communities/db/migrate/20151125175514_change_software_info_structure.rb 0 → 100644
... ... @@ -0,0 +1,26 @@
  1 +class CreateSispInfo < ActiveRecord::Migration
  2 + def up
  3 + create_table :sosftware_infos do |t|
  4 + t.integer :software_id
  5 + t.text :agency_identification
  6 + t.text :softawre_requirements
  7 + t.text :hardware_requirements
  8 + t.text :documentation
  9 + t.text :system_applications
  10 + t.text :active_versions
  11 + t.text :estimated_cost
  12 + t.text :responsible
  13 + t.text :responsible_for_acquirement
  14 + t.text :system_info
  15 + t.text :development_info
  16 + t.text :maintenance
  17 + t.text :standards_adherence
  18 + t.text :plataform
  19 + t.text :sisp_type
  20 + end
  21 + end
  22 +
  23 + def down
  24 + drop_table :software_infos
  25 + end
  26 +end
... ...
src/noosfero-spb/software_communities/lib/software.rb 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +class Software < Community
  2 + has_one :software_info
  3 + validates_presence_of :software_info
  4 + attr_accessible :software_info
  5 + after_save { software_info.save! }
  6 +end
... ...
src/noosfero-spb/software_communities/lib/software_info.rb
... ... @@ -8,7 +8,7 @@ class SoftwareInfo &lt; ActiveRecord::Base
8 8  
9 9 SEARCHABLE_SOFTWARE_CLASSES = [
10 10 SoftwareInfo,
11   - Community,
  11 + Software,
12 12 ProgrammingLanguage,
13 13 DatabaseDescription
14 14 ]
... ... @@ -18,7 +18,7 @@ class SoftwareInfo &lt; ActiveRecord::Base
18 18 search_fields = SoftwareInfo.pg_search_plugin_fields
19 19  
20 20 if query.empty?
21   - SoftwareInfo.joins(:community).where("profiles.visible = ?", true)
  21 + SoftwareInfo.joins(:software).where("profiles.visible = ?", true)
22 22 else
23 23 searchable_software_objects = SoftwareInfo.transform_list_in_methods_list(SEARCHABLE_SOFTWARE_CLASSES)
24 24 includes(searchable_software_objects).where("to_tsvector('simple', #{search_fields}) @@ to_tsquery('#{filtered_query}')").where("profiles.visible = ?", true)
... ... @@ -65,7 +65,7 @@ class SoftwareInfo &lt; ActiveRecord::Base
65 65 attr_accessible :demonstration_url, :acronym, :objectives, :features,
66 66 :license_info
67 67  
68   - attr_accessible :community_id, :finality, :repository_link, :public_software,
  68 + attr_accessible :software_id, :finality, :repository_link, :public_software,
69 69 :first_edit
70 70  
71 71 has_many :libraries, :dependent => :destroy
... ... @@ -76,7 +76,7 @@ class SoftwareInfo &lt; ActiveRecord::Base
76 76 has_many :programming_languages, :through => :software_languages
77 77 has_many :operating_system_names, :through => :operating_systems
78 78  
79   - belongs_to :community, :dependent => :destroy
  79 + belongs_to :software, :dependent => :destroy
80 80 belongs_to :license_info
81 81  
82 82 has_one :software_categories
... ... @@ -84,7 +84,7 @@ class SoftwareInfo &lt; ActiveRecord::Base
84 84 validates_length_of :finality, :maximum => 120
85 85 validates_length_of :objectives, :maximum => 4000
86 86 validates_length_of :features, :maximum => 4000
87   - validates_presence_of :finality, :community
  87 + validates_presence_of :finality, :software
88 88  
89 89 validate :validate_acronym
90 90  
... ... @@ -92,7 +92,7 @@ class SoftwareInfo &lt; ActiveRecord::Base
92 92  
93 93 # used on find_by_contents
94 94 scope :like_search, lambda{ |name|
95   - joins(:community).where(
  95 + joins(:software).where(
96 96 "name ILIKE ? OR acronym ILIKE ? OR finality ILIKE ?",
97 97 "%#{name}%", "%#{name}%", "%#{name}%"
98 98 )
... ... @@ -114,11 +114,15 @@ class SoftwareInfo &lt; ActiveRecord::Base
114 114 like_sql = like_sql[0..like_sql.length-5]
115 115  
116 116 {
117   - :joins => [:community],
  117 + :joins => [:software],
118 118 :conditions=>[like_sql, *values]
119 119 }
120 120 }
121 121  
  122 + def community
  123 + return self.software
  124 + end
  125 +
122 126 def license_info
123 127 license = LicenseInfo.find_by_id self.license_info_id
124 128 license_another = LicenseInfo.find_by_version("Another")
... ... @@ -145,7 +149,7 @@ class SoftwareInfo &lt; ActiveRecord::Base
145 149 end
146 150  
147 151 def validate_name_lenght
148   - if self.community.name.size > 100
  152 + if self.software.name.size > 100
149 153 self.errors.add(
150 154 :base,
151 155 _("Name is too long (maximum is %{count} characters)")
... ... @@ -181,21 +185,21 @@ class SoftwareInfo &lt; ActiveRecord::Base
181 185 else
182 186 software_template = Community["software"]
183 187  
184   - community_hash = {:name => name}
185   - community_hash[:identifier] = identifier
186   - community_hash[:image_builder] = image_builder if image_builder
  188 + software_hash = {:name => name}
  189 + software_hash[:identifier] = identifier
  190 + software_hash[:image_builder] = image_builder if image_builder
187 191  
188   - community = Community.new(community_hash)
189   - community.environment = environment
  192 + software = Software.new(software_hash)
  193 + software.environment = environment
190 194  
191 195 if (!software_template.blank? && software_template.is_template)
192   - community.template_id = software_template.id
  196 + software.template_id = software_template.id
193 197 end
194 198  
195   - community.save!
196   - community.add_admin(requestor)
  199 + software.save!
  200 + software.add_admin(requestor)
197 201  
198   - software_info.community = community
  202 + software_info.software = software
199 203 software_info.license_info = license_info
200 204 software_info.verify_license_info(another_license_version, another_license_link)
201 205 software_info.save!
... ... @@ -247,18 +251,18 @@ class SoftwareInfo &lt; ActiveRecord::Base
247 251 end
248 252  
249 253 def visible?
250   - self.community.visible?
  254 + self.software.visible?
251 255 end
252 256  
253 257 def name
254   - self.community.name
  258 + self.software.name
255 259 end
256 260  
257 261 def short_name
258   - self.community.short_name
  262 + self.software.short_name
259 263 end
260 264  
261 265 def identifier
262   - self.community.identifier
  266 + self.software.identifier
263 267 end
264 268 end
... ...
src/noosfero-spb/software_communities/lib/software_info2.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +class SispInfo < ActiveRecord::Base
  2 +
  3 + attr_accessible :agency_identification, :softawre_requirements, :hardware_requirements, :documentation,
  4 + :system_applications, :active_versions, :estimated_cost, :responsible, :sotware_identification,
  5 + :responsible_for_acquirement, :system_info, :development_info, :maintenance, :standards_adherence, :plataform
  6 +
  7 + belongs_to :sisp
  8 +
  9 +end
... ...